Bug 1426555 - Move --enable-stdcxx-compat to python configure. r?build draft
authorMike Hommey <mh+mozilla@glandium.org>
Thu, 21 Dec 2017 11:13:08 +0900
changeset 713855 07d18a1943e292e13a0d4362eb84b50df768f122
parent 713853 632cb70705ae211ad263b35c05fa137589970492
child 713883 0129c9d78298a093ae85833f1915377cf6cc861e
push id93780
push userbmo:mh+mozilla@glandium.org
push dateThu, 21 Dec 2017 03:15:09 +0000
reviewersbuild
bugs1426555
milestone59.0a1
Bug 1426555 - Move --enable-stdcxx-compat to python configure. r?build At the same time, we make it actually do something on spidermonkey builds. We also add an environment variable alternative, that we use in mozconfig.stdcxx, allowing for mozconfig.no-compile to override it and avoid configure failures on e.g. artifact builds.
browser/config/mozconfigs/linux32/l10n-mozconfig
browser/config/mozconfigs/linux32/l10n-mozconfig-devedition
browser/config/mozconfigs/linux64/l10n-mozconfig
browser/config/mozconfigs/linux64/l10n-mozconfig-devedition
browser/config/mozconfigs/linux64/nightly-fuzzing-asan
build/moz.configure/old.configure
build/moz.configure/toolchain.configure
build/mozconfig.no-compile
build/unix/mozconfig.stdcxx
old-configure.in
python/mozbuild/mozbuild/configure/libstdcxx.py
--- a/browser/config/mozconfigs/linux32/l10n-mozconfig
+++ b/browser/config/mozconfigs/linux32/l10n-mozconfig
@@ -9,15 +9,13 @@ if test `uname -m` = "x86_64"; then
   ac_add_options --host=i686-pc-linux
 fi
 
 export MOZILLA_OFFICIAL=1
 
 # Enable Telemetry
 export MOZ_TELEMETRY_REPORTING=1
 
-ac_add_options --disable-stdcxx-compat
-
 # Don't autoclobber l10n, as this can lead to missing binaries and broken builds
 # Bug 1283438
 mk_add_options AUTOCLOBBER=
 
 . "$topsrcdir/build/mozconfig.common.override"
--- a/browser/config/mozconfigs/linux32/l10n-mozconfig-devedition
+++ b/browser/config/mozconfigs/linux32/l10n-mozconfig-devedition
@@ -9,17 +9,15 @@ if test `uname -m` = "x86_64"; then
   ac_add_options --host=i686-pc-linux
 fi
 
 export MOZILLA_OFFICIAL=1
 
 # Enable Telemetry
 export MOZ_TELEMETRY_REPORTING=1
 
-ac_add_options --disable-stdcxx-compat
-
 # Don't autoclobber l10n, as this can lead to missing binaries and broken builds
 # Bug 1283438
 mk_add_options AUTOCLOBBER=
 # Enable MOZ_ALLOW_LEGACY_EXTENSIONS
 ac_add_options "MOZ_ALLOW_LEGACY_EXTENSIONS=1"
 
 . "$topsrcdir/build/mozconfig.common.override"
--- a/browser/config/mozconfigs/linux64/l10n-mozconfig
+++ b/browser/config/mozconfigs/linux64/l10n-mozconfig
@@ -4,15 +4,13 @@ ac_add_options --with-branding=browser/b
 
 . "$topsrcdir/build/mozconfig.no-compile"
 
 export MOZILLA_OFFICIAL=1
 
 # Enable Telemetry
 export MOZ_TELEMETRY_REPORTING=1
 
-ac_add_options --disable-stdcxx-compat
-
 # Don't autoclobber l10n, as this can lead to missing binaries and broken builds
 # Bug 1283438
 mk_add_options AUTOCLOBBER=
 
 . "$topsrcdir/build/mozconfig.common.override"
--- a/browser/config/mozconfigs/linux64/l10n-mozconfig-devedition
+++ b/browser/config/mozconfigs/linux64/l10n-mozconfig-devedition
@@ -4,18 +4,16 @@ ac_add_options --with-branding=browser/b
 
 . "$topsrcdir/build/mozconfig.no-compile"
 
 export MOZILLA_OFFICIAL=1
 
 # Enable Telemetry
 export MOZ_TELEMETRY_REPORTING=1
 
-ac_add_options --disable-stdcxx-compat
-
 # Don't autoclobber l10n, as this can lead to missing binaries and broken builds
 # Bug 1283438
 mk_add_options AUTOCLOBBER=
 
 # Enable MOZ_ALLOW_LEGACY_EXTENSIONS
 ac_add_options "MOZ_ALLOW_LEGACY_EXTENSIONS=1"
 
 . "$topsrcdir/build/mozconfig.common.override"
--- a/browser/config/mozconfigs/linux64/nightly-fuzzing-asan
+++ b/browser/config/mozconfigs/linux64/nightly-fuzzing-asan
@@ -5,17 +5,17 @@ ac_add_options --enable-optimize="-O2 -g
 . $topsrcdir/build/mozconfig.stylo
 
 # ASan specific options on Linux
 ac_add_options --enable-valgrind
 
 . $topsrcdir/build/unix/mozconfig.fuzzing
 
 ac_add_options --enable-fuzzing
-ac_add_options --disable-stdcxx-compat
+unset MOZ_STDCXX_COMPAT
 
 export PKG_CONFIG_LIBDIR=/usr/lib64/pkgconfig:/usr/share/pkgconfig
 . $topsrcdir/build/unix/mozconfig.gtk
 
 # Package js shell.
 export MOZ_PACKAGE_JSSHELL=1
 
 # Need this to prevent name conflicts with the normal nightly build packages
--- a/build/moz.configure/old.configure
+++ b/build/moz.configure/old.configure
@@ -211,17 +211,16 @@ def old_configure_options(*options):
     '--enable-pulseaudio',
     '--enable-raw',
     '--enable-readline',
     '--enable-reflow-perf',
     '--enable-sandbox',
     '--enable-signmar',
     '--enable-startup-notification',
     '--enable-startupcache',
-    '--enable-stdcxx-compat',
     '--enable-strip',
     '--enable-synth-pico',
     '--enable-system-cairo',
     '--enable-system-extension-dirs',
     '--enable-system-pixman',
     '--enable-system-sqlite',
     '--enable-tasktracer',
     '--enable-thread-sanitizer',
--- a/build/moz.configure/toolchain.configure
+++ b/build/moz.configure/toolchain.configure
@@ -1543,8 +1543,36 @@ js_option('--enable-coverage', env='MOZ_
 @depends('--enable-coverage')
 def code_coverage(value):
     if value:
         return True
 
 
 set_config('MOZ_CODE_COVERAGE', code_coverage)
 set_define('MOZ_CODE_COVERAGE', code_coverage)
+
+# Libstdc++ compatibility hacks
+# ==============================================================
+#
+js_option('--enable-stdcxx-compat', env='MOZ_STDCXX_COMPAT',
+          help='Enable compatibility with older libstdc++')
+
+
+@template
+def libstdcxx_version(var, compiler):
+    @depends(compiler, when='--enable-stdcxx-compat')
+    @imports(_from='mozbuild.configure.libstdcxx', _import='find_version')
+    def version(compiler):
+        result = find_version(
+            compiler.wrapper + [compiler.compiler] + compiler.flags)
+        if result:
+            return str(result)
+
+    set_config(var, version)
+    return version
+
+
+add_gcc_flag(
+    '-D_GLIBCXX_USE_CXX11_ABI=0', cxx_compiler,
+    when=libstdcxx_version('MOZ_LIBSTDCXX_TARGET_VERSION', cxx_compiler))
+add_gcc_flag(
+    '-D_GLIBCXX_USE_CXX11_ABI=0', host_cxx_compiler,
+    when=libstdcxx_version('MOZ_LIBSTDCXX_HOST_VERSION', host_cxx_compiler))
--- a/build/mozconfig.no-compile
+++ b/build/mozconfig.no-compile
@@ -12,8 +12,10 @@ unset CXX
 unset HOST_CC
 unset HOST_CXX
 unset RUSTC
 unset CARGO
 unset MAKECAB
 unset TOOLCHAIN_PREFIX
 unset BINDGEN_CFLAGS
 unset LLVM_CONFIG
+
+unset MOZ_STDCXX_COMPAT
--- a/build/unix/mozconfig.stdcxx
+++ b/build/unix/mozconfig.stdcxx
@@ -1,10 +1,10 @@
 # Avoid dependency on libstdc++ 4.7
-ac_add_options --enable-stdcxx-compat
+export MOZ_STDCXX_COMPAT=1
 
 TOOLTOOL_DIR=${TOOLTOOL_DIR:-$topsrcdir}
 
 if [ -f "$TOOLTOOL_DIR/gcc/lib/libstdc++.so" ]; then
   # We put both 32-bits and 64-bits library path in LD_LIBRARY_PATH: ld.so
   # will prefer the files in the 32-bits path when loading 32-bits executables,
   # and the files in the 64-bits path when loading 64-bits executables.
   LD_LIBRARY_PATH=${LD_LIBRARY_PATH:+$LD_LIBRARY_PATH:}$TOOLTOOL_DIR/gcc/lib64:$TOOLTOOL_DIR/gcc/lib
--- a/old-configure.in
+++ b/old-configure.in
@@ -3776,33 +3776,16 @@ dnl ====================================
 dnl = Enable stripping of libs & executables when packaging
 dnl ========================================================
 MOZ_ARG_ENABLE_BOOL(install-strip,
 [  --enable-install-strip  Enable stripping of libs & executables when packaging ],
     PKG_SKIP_STRIP= ,
     PKG_SKIP_STRIP=1)
 
 dnl ========================================================
-dnl = libstdc++ compatibility hacks
-dnl ========================================================
-
-STDCXX_COMPAT=
-MOZ_ARG_ENABLE_BOOL(stdcxx-compat,
-[  --enable-stdcxx-compat  Enable compatibility with older libstdc++],
-    STDCXX_COMPAT=1)
-
-if test -n "$STDCXX_COMPAT" -a -n "$COMPILE_ENVIRONMENT"; then
-   eval $(CXX="$CXX" HOST_CXX="$HOST_CXX" $PYTHON -m mozbuild.configure.libstdcxx)
-   AC_SUBST(MOZ_LIBSTDCXX_TARGET_VERSION)
-   AC_SUBST(MOZ_LIBSTDCXX_HOST_VERSION)
-   CXXFLAGS="$CXXFLAGS -D_GLIBCXX_USE_CXX11_ABI=0"
-   HOST_CXXFLAGS="$HOST_CXXFLAGS -D_GLIBCXX_USE_CXX11_ABI=0"
-fi
-
-dnl ========================================================
 dnl = frontend JS debug mode
 dnl ========================================================
 
 MOZ_ARG_ENABLE_BOOL(debug-js-modules,
 [  --enable-debug-js-modules  Enable debug mode for frontend JS libraries],
    DEBUG_JS_MODULES=1,
    DEBUG_JS_MODULES=)
 
--- a/python/mozbuild/mozbuild/configure/libstdcxx.py
+++ b/python/mozbuild/mozbuild/configure/libstdcxx.py
@@ -50,32 +50,34 @@ def cmp_ver(a, b):
     return 0
 
 def encode_ver(v):
     """Encode the version as a single number.
     """
     t = split_ver(v)
     return t[0] << 16 | t[1] << 8 | t[2]
 
-def find_version(e):
-    """Given the value of environment variable CXX or HOST_CXX, find the
-    version of the libstdc++ it uses.
+def find_version(args):
+    """Given a base command line for a compiler, find the version of the
+    libstdc++ it uses.
     """
-    args = e.split()
     args +=  ['-shared', '-Wl,-t']
     p = subprocess.Popen(args, stderr=subprocess.STDOUT, stdout=subprocess.PIPE)
     candidates = [x for x in p.stdout if 'libstdc++.so' in x]
     if not candidates:
         return ''
     assert len(candidates) == 1
     libstdcxx = parse_ld_line(candidates[-1])
 
     p = subprocess.Popen(['readelf', '-V', libstdcxx], stdout=subprocess.PIPE)
     versions = [parse_readelf_line(x)
                 for x in p.stdout.readlines() if 'Name: GLIBCXX' in x]
     last_version = sorted(versions, cmp = cmp_ver)[-1]
     return encode_ver(last_version)
 
 if __name__ == '__main__':
+    """Given the value of environment variable CXX or HOST_CXX, find the
+    version of the libstdc++ it uses.
+    """
     cxx_env = os.environ['CXX']
-    print('MOZ_LIBSTDCXX_TARGET_VERSION=%s' % find_version(cxx_env))
+    print('MOZ_LIBSTDCXX_TARGET_VERSION=%s' % find_version(cxx_env.split()))
     host_cxx_env = os.environ.get('HOST_CXX', cxx_env)
-    print('MOZ_LIBSTDCXX_HOST_VERSION=%s' % find_version(host_cxx_env))
+    print('MOZ_LIBSTDCXX_HOST_VERSION=%s' % find_version(host_cxx_env.split()))