Bug 1482810 - set COMPILE_FLAGS var to hide warnings for Rust crates r=chmanchester
authorMyk Melez <myk@mykzilla.org>
Thu, 30 Aug 2018 17:29:54 +0000
changeset 434095 b9197ece79556d5e565bb5350383b75f1448f06c
parent 434094 7e58b028df95389c1994c268161a0c7ba6e7f957
child 434096 7eae34bda99ca4c30b6f995fc85a69a58e56664c
push id34538
push userrgurzau@mozilla.com
push dateThu, 30 Aug 2018 21:48:04 +0000
treeherdermozilla-central@c45b51ec248e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerschmanchester
bugs1482810
milestone63.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1482810 - set COMPILE_FLAGS var to hide warnings for Rust crates r=chmanchester In conjunction with the cc crate changes in https://github.com/alexcrichton/cc-rs/pull/342 (which I'll land in https://phabricator.services.mozilla.com/D4699), this hides warnings generated by C code in Rust crates (by removing warnings flags from CFLAGS when compiling Rust libraries). MozReview-Commit-ID: 9CZgLGbWjbA Differential Revision: https://phabricator.services.mozilla.com/D3939
build/clang-plugin/tests/moz.build
build/templates.mozbuild
config/rules.mk
js/src/old-configure.in
old-configure.in
python/mozbuild/mozbuild/frontend/context.py
python/mozbuild/mozbuild/test/frontend/data/disable-compiler-warnings/moz.build
python/mozbuild/mozbuild/test/frontend/data/disable-compiler-warnings/test1.c
python/mozbuild/mozbuild/test/frontend/test_emitter.py
--- a/build/clang-plugin/tests/moz.build
+++ b/build/clang-plugin/tests/moz.build
@@ -62,10 +62,14 @@ COMPILE_FLAGS['OS_CXXFLAGS'] = (
     ['-fsyntax-only', '-Xclang', '-verify', '-ferror-limit=0', '-Wno-invalid-noreturn']
 )
 COMPILE_FLAGS['OS_CFLAGS'] = (
     [f for f in COMPILE_FLAGS.get('OS_CFLAGS', []) if not f.startswith('-W')] +
     ['-fsyntax-only', '-Xclang', '-verify', '-ferror-limit=0', '-std=c11',
      '-Wno-invalid-noreturn']
 )
 
+# Don't reflect WARNINGS_CFLAGS into CFLAGS, as the warnings flags should be
+# as specified in OS_CFLAGS above.
+DisableCompilerWarnings()
+
 if CONFIG['ENABLE_CLANG_PLUGIN'] and CONFIG['CC_TYPE'] == 'clang-cl':
     AllowCompilerWarnings()  # workaround for bug 1090497
--- a/build/templates.mozbuild
+++ b/build/templates.mozbuild
@@ -53,24 +53,33 @@ def Library(name):
     '''Template for libraries.'''
     LIBRARY_NAME = name
 
 @template
 def AllowCompilerWarnings():
     COMPILE_FLAGS['WARNINGS_AS_ERRORS'] = []
 
 @template
+def DisableCompilerWarnings():
+    COMPILE_FLAGS['WARNINGS_CFLAGS'] = []
+
+@template
 def RustLibrary(name, features=None, target_dir=None, output_category=None):
     '''Template for Rust libraries.'''
     Library(name)
 
     IS_RUST_LIBRARY = True
     # Some Rust build scripts compile C/C++ sources, don't error on warnings for them.
     AllowCompilerWarnings()
 
+    # And furthermore, don't even show warnings for them, so they don't regress
+    # the Compiler Warnings build metric
+    # <https://developer.mozilla.org/en-US/docs/Mozilla/Performance/Automated_Performance_Testing_and_Sheriffing/Build_Metrics#compiler_warnings>.
+    DisableCompilerWarnings()
+
     if features:
         RUST_LIBRARY_FEATURES = features
 
     if target_dir:
         RUST_LIBRARY_TARGET_DIR = target_dir
 
     if output_category:
         RUST_LIBRARY_OUTPUT_CATEGORY = output_category
--- a/config/rules.mk
+++ b/config/rules.mk
@@ -900,48 +900,53 @@ rust_unlock_unstable =
 ifdef MOZ_RUST_SIMD
 rust_unlock_unstable += RUSTC_BOOTSTRAP=1
 endif
 
 ifdef MOZ_USING_SCCACHE
 sccache_wrap := RUSTC_WRAPPER='$(CCACHE)'
 endif
 
-ifneq (WINNT,$(HOST_OS_ARCH))
 ifndef MOZ_ASAN
 ifndef MOZ_TSAN
 ifndef MOZ_CODE_COVERAGE
 # Pass the compilers and flags in use to cargo for use in build scripts.
-# * Don't do this on Windows because msys path translation makes a mess of the paths, and
-#   we put MSVC in PATH there anyway.
 # * Don't do this for ASAN/TSAN builds because we don't pass our custom linker (see below)
 #   which will muck things up.
 # * Don't do this for code coverage builds because the way rustc invokes the linker doesn't
 #   work with GCC 6: https://bugzilla.mozilla.org/show_bug.cgi?id=1477305
 #
 # We don't pass HOST_{CC,CXX} down in any form because our host value might not match
 # what cargo chooses and there's no way to control cargo's selection, so we just have to
 # hope that if something needs to build a host C source file it can find a usable compiler!
 #
 # We're passing these for consumption by the `cc` crate, which doesn't use the same
 # convention as cargo itself:
 # https://github.com/alexcrichton/cc-rs/blob/baa71c0e298d9ad7ac30f0ad78f20b4b3b3a8fb2/src/lib.rs#L1715
 rust_cc_env_name := $(subst -,_,$(RUST_TARGET))
 
+ifeq (WINNT,$(HOST_OS_ARCH))
+# Don't do most of this on Windows because msys path translation makes a mess of the paths, and
+# we put MSVC in PATH there anyway.  But we do suppress warnings, since all such warnings
+# are in third-party code.
+cargo_c_compiler_envs := \
+ CFLAGS_$(rust_cc_env_name)="-w" \
+ $(NULL)
+else
 cargo_c_compiler_envs := \
  CC_$(rust_cc_env_name)="$(CC)" \
  CXX_$(rust_cc_env_name)="$(CXX)" \
  CFLAGS_$(rust_cc_env_name)="$(COMPUTED_CFLAGS)" \
  CXXFLAGS_$(rust_cc_env_name)="$(COMPUTED_CXXFLAGS)" \
  AR_$(rust_cc_env_name)="$(AR)" \
  $(NULL)
+endif # WINNT
 endif # MOZ_CODE_COVERAGE
 endif # MOZ_TSAN
 endif # MOZ_ASAN
-endif # WINNT
 
 # We use the + prefix to pass down the jobserver fds to cargo, but we
 # don't use the prefix when make -n is used, so that cargo doesn't run
 # in that case)
 define RUN_CARGO
 $(if $(findstring n,$(filter-out --%, $(MAKEFLAGS))),,+)env $(environment_cleaner) $(rust_unlock_unstable) $(sccache_wrap) \
 	CARGO_TARGET_DIR=$(CARGO_TARGET_DIR) \
 	RUSTFLAGS='$(2)' \
--- a/js/src/old-configure.in
+++ b/js/src/old-configure.in
@@ -418,18 +418,19 @@ dnl computed above.
 dnl ========================================================
 
 MOZ_ANDROID_CPU_ARCH
 MOZ_ANDROID_STLPORT
 
 dnl ========================================================
 dnl Suppress Clang Argument Warnings
 dnl ========================================================
+WARNINGS_CFLAGS="$_WARNINGS_CFLAGS"
 if test -n "${CLANG_CC}${CLANG_CL}"; then
-    _WARNINGS_CFLAGS="-Qunused-arguments ${_WARNINGS_CFLAGS}"
+    WARNINGS_CFLAGS="-Qunused-arguments $WARNINGS_CFLAGS"
     CPPFLAGS="-Qunused-arguments ${CPPFLAGS}"
 fi
 if test -n "${CLANG_CXX}${CLANG_CL}"; then
     _WARNINGS_CXXFLAGS="-Qunused-arguments ${_WARNINGS_CXXFLAGS}"
 fi
 
 MOZ_CONFIG_SANITIZE
 
@@ -1751,16 +1752,17 @@ AC_SUBST_LIST(ASFLAGS)
 AC_SUBST(AS_DASH_C_FLAG)
 AC_SUBST(RC)
 AC_SUBST(RCFLAGS)
 AC_SUBST(WINDRES)
 AC_SUBST(IMPLIB)
 AC_SUBST(FILTER)
 AC_SUBST_LIST(MOZ_DEBUG_LDFLAGS)
 AC_SUBST(WARNINGS_AS_ERRORS)
+AC_SUBST_LIST(WARNINGS_CFLAGS)
 AC_SUBST(LIBICONV)
 
 AC_SUBST(ENABLE_STRIP)
 AC_SUBST(PKG_SKIP_STRIP)
 AC_SUBST(INCREMENTAL_LINKER)
 
 AC_SUBST_LIST(MOZ_FIX_LINK_PATHS)
 
@@ -1778,17 +1780,16 @@ dnl ====================================
 
 dnl top-level configure may override this with --without-intl-api
 _INTL_API=yes
 
 MOZ_CONFIG_ICU()
 
 dnl Echo the CFLAGS to remove extra whitespace.
 CFLAGS=`echo \
-	$_WARNINGS_CFLAGS \
 	$_COMPILATION_CFLAGS \
 	$CFLAGS`
 
 CXXFLAGS=`echo \
 	$_WARNINGS_CXXFLAGS \
 	$_COMPILATION_CXXFLAGS \
 	$CXXFLAGS`
 
--- a/old-configure.in
+++ b/old-configure.in
@@ -472,18 +472,19 @@ dnl ====================================
 MOZ_ANDROID_CPU_ARCH
 if test "$COMPILE_ENVIRONMENT"; then
     MOZ_ANDROID_STLPORT
 fi # COMPILE_ENVIRONMENT
 
 dnl ========================================================
 dnl Suppress Clang Argument Warnings
 dnl ========================================================
+WARNINGS_CFLAGS="$_WARNINGS_CFLAGS"
 if test -n "${CLANG_CC}${CLANG_CL}"; then
-    _WARNINGS_CFLAGS="-Qunused-arguments ${_WARNINGS_CFLAGS}"
+    WARNINGS_CFLAGS="-Qunused-arguments $WARNINGS_CFLAGS"
     CPPFLAGS="-Qunused-arguments ${CPPFLAGS}"
 fi
 if test -n "${CLANG_CXX}${CLANG_CL}"; then
     _WARNINGS_CXXFLAGS="-Qunused-arguments ${_WARNINGS_CXXFLAGS}"
 fi
 
 if test -n "$COMPILE_ENVIRONMENT"; then
    MOZ_CONFIG_SANITIZE
@@ -4102,16 +4103,17 @@ AC_SUBST(RC)
 AC_SUBST(RCFLAGS)
 AC_SUBST(WINDRES)
 AC_SUBST(IMPLIB)
 AC_SUBST(FILTER)
 AC_SUBST(MOZ_AUTH_EXTENSION)
 AC_SUBST(MOZ_PREF_EXTENSIONS)
 AC_SUBST_LIST(MOZ_DEBUG_LDFLAGS)
 AC_SUBST(WARNINGS_AS_ERRORS)
+AC_SUBST_LIST(WARNINGS_CFLAGS)
 AC_SUBST_SET(MOZ_EXTENSIONS)
 AC_SUBST(MOZ_TOOLKIT_SEARCH)
 AC_SUBST(MOZ_FEEDS)
 
 AC_SUBST(MOZ_UNIVERSALCHARDET)
 AC_SUBST(ACCESSIBILITY)
 AC_SUBST(MOZ_SPELLCHECK)
 AC_SUBST(MOZ_ANDROID_ANR_REPORTER)
@@ -4370,17 +4372,16 @@ dnl ====================================
 if test "$MOZ_WIDGET_TOOLKIT" = "cocoa"; then
     USE_ICU=1
 fi
 
 MOZ_CONFIG_ICU()
 
 dnl Echo the CFLAGS to remove extra whitespace.
 CFLAGS=`echo \
-    $_WARNINGS_CFLAGS \
     $_COMPILATION_CFLAGS \
     $CFLAGS`
 
 CXXFLAGS=`echo \
     $_WARNINGS_CXXFLAGS \
     $_COMPILATION_CXXFLAGS \
     $CXXFLAGS`
 
--- a/python/mozbuild/mozbuild/frontend/context.py
+++ b/python/mozbuild/mozbuild/frontend/context.py
@@ -458,16 +458,18 @@ class CompileFlags(BaseCompileFlags):
             ('CLANG_PLUGIN', context.config.substs.get('CLANG_PLUGIN_FLAGS'),
              ('CFLAGS', 'CXXFLAGS', 'CXX_LDFLAGS', 'C_LDFLAGS')),
             ('OPTIMIZE', self._optimize_flags(),
              ('CFLAGS', 'CXXFLAGS', 'CXX_LDFLAGS', 'C_LDFLAGS')),
             ('FRAMEPTR', context.config.substs.get('MOZ_FRAMEPTR_FLAGS'),
              ('CFLAGS', 'CXXFLAGS', 'CXX_LDFLAGS', 'C_LDFLAGS')),
             ('WARNINGS_AS_ERRORS', self._warnings_as_errors(),
              ('CXXFLAGS', 'CFLAGS', 'CXX_LDFLAGS', 'C_LDFLAGS')),
+            ('WARNINGS_CFLAGS', context.config.substs.get('WARNINGS_CFLAGS'),
+             ('CFLAGS', 'C_LDFLAGS')),
             ('MOZBUILD_CFLAGS', None, ('CFLAGS',)),
             ('MOZBUILD_CXXFLAGS', None, ('CXXFLAGS',)),
         )
 
         BaseCompileFlags.__init__(self, context)
 
     def _debug_flags(self):
         if (self._context.config.substs.get('MOZ_DEBUG') or
new file mode 100644
--- /dev/null
+++ b/python/mozbuild/mozbuild/test/frontend/data/disable-compiler-warnings/moz.build
@@ -0,0 +1,17 @@
+# Any copyright is dedicated to the Public Domain.
+# http://creativecommons.org/publicdomain/zero/1.0/
+
+@template
+def DisableCompilerWarnings():
+    COMPILE_FLAGS['WARNINGS_CFLAGS'] = []
+
+@template
+def Library(name):
+    '''Template for libraries.'''
+    LIBRARY_NAME = name
+
+Library('dummy')
+
+UNIFIED_SOURCES += ['test1.c']
+
+DisableCompilerWarnings()
new file mode 100644
--- a/python/mozbuild/mozbuild/test/frontend/test_emitter.py
+++ b/python/mozbuild/mozbuild/test/frontend/test_emitter.py
@@ -418,16 +418,23 @@ class TestEmitterBasic(unittest.TestCase
 
     def test_allow_compiler_warnings(self):
         reader = self.reader('allow-compiler-warnings', extra_substs={
             'WARNINGS_AS_ERRORS': '-Werror',
         })
         sources, ldflags, lib, flags = self.read_topsrcdir(reader)
         self.assertEqual(flags.flags['WARNINGS_AS_ERRORS'], [])
 
+    def test_disable_compiler_warnings(self):
+        reader = self.reader('disable-compiler-warnings', extra_substs={
+            'WARNINGS_CFLAGS': '-Wall',
+        })
+        sources, ldflags, lib, flags = self.read_topsrcdir(reader)
+        self.assertEqual(flags.flags['WARNINGS_CFLAGS'], [])
+
     def test_use_yasm(self):
         # When yasm is not available, this should raise.
         reader = self.reader('use-yasm')
         with self.assertRaisesRegexp(SandboxValidationError,
             'yasm is not available'):
             self.read_topsrcdir(reader)
 
         # When yasm is available, this should work.