# HG changeset patch # User Myk Melez # Date 1535650194 0 # Node ID b9197ece79556d5e565bb5350383b75f1448f06c # Parent 53978ff2500c33f2d592e580cb28aa4b2bc5e912 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 diff --git a/build/clang-plugin/tests/moz.build b/build/clang-plugin/tests/moz.build --- a/build/clang-plugin/tests/moz.build +++ b/build/clang-plugin/tests/moz.build @@ -56,8 +56,12 @@ COMPILE_FLAGS['OS_CXXFLAGS'] = ( [f for f in COMPILE_FLAGS.get('OS_CXXFLAGS', []) if not f.startswith('-W')] + ['-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() diff --git a/build/templates.mozbuild b/build/templates.mozbuild --- 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 + # . + 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 diff --git a/config/rules.mk b/config/rules.mk --- a/config/rules.mk +++ b/config/rules.mk @@ -893,50 +893,55 @@ environment_cleaner += PYTHON='$(shell w else environment_cleaner = endif ifdef MOZ_USING_SCCACHE sccache_wrap := RUSTC_WRAPPER='$(CCACHE)' endif -ifneq (WINNT,$(OS_ARCH)) ifndef MOZ_ASAN ifndef MOZ_TSAN ifndef MOZ_UBSAN 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,$(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_UBSAN 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) $(rustflags_override) $(sccache_wrap) \ CARGO_TARGET_DIR=$(CARGO_TARGET_DIR) \ RUSTC=$(RUSTC) \ diff --git a/js/src/old-configure.in b/js/src/old-configure.in --- a/js/src/old-configure.in +++ b/js/src/old-configure.in @@ -413,18 +413,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 @@ -1686,16 +1687,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) @@ -1713,18 +1715,17 @@ 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 \ + $_COMPILATION_CFLAGS \ $CFLAGS` CXXFLAGS=`echo \ $_WARNINGS_CXXFLAGS \ $_COMPILATION_CFLAGS \ $CXXFLAGS` COMPILE_CFLAGS=`echo \ diff --git a/old-configure.in b/old-configure.in --- a/old-configure.in +++ b/old-configure.in @@ -463,18 +463,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 @@ -3776,16 +3777,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) @@ -4039,17 +4041,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_CFLAGS \ $CXXFLAGS` diff --git a/python/mozbuild/mozbuild/frontend/context.py b/python/mozbuild/mozbuild/frontend/context.py --- a/python/mozbuild/mozbuild/frontend/context.py +++ b/python/mozbuild/mozbuild/frontend/context.py @@ -477,16 +477,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 diff --git a/python/mozbuild/mozbuild/test/frontend/data/disable-compiler-warnings/moz.build b/python/mozbuild/mozbuild/test/frontend/data/disable-compiler-warnings/moz.build 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() diff --git a/python/mozbuild/mozbuild/test/frontend/data/disable-compiler-warnings/test1.c b/python/mozbuild/mozbuild/test/frontend/data/disable-compiler-warnings/test1.c new file mode 100644 diff --git a/python/mozbuild/mozbuild/test/frontend/test_emitter.py b/python/mozbuild/mozbuild/test/frontend/test_emitter.py --- a/python/mozbuild/mozbuild/test/frontend/test_emitter.py +++ b/python/mozbuild/mozbuild/test/frontend/test_emitter.py @@ -417,16 +417,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.