Bug 1397263 - move AS checks to toolchain.configure; r=glandium
authorNathan Froyd <froydnj@mozilla.com>
Wed, 03 Oct 2018 20:29:29 -0400
changeset 439564 b4dec9b774a82ccbe834eeb9727186e793699e97
parent 439563 73a4e7ed19f3447370cbe5fa7b7b30fc1a41710b
child 439565 b3ad0438392892aeab8c88826d347164640ba602
push id34779
push usernbeleuzu@mozilla.com
push dateThu, 04 Oct 2018 15:49:20 +0000
treeherdermozilla-central@f66e525e6978 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersglandium
bugs1397263
milestone64.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 1397263 - move AS checks to toolchain.configure; r=glandium This is a fairly straightforward port of the AS tool checks from old-configure to toolchain.configure. AS is a little quirky in that we currently do a normal-looking check for it, but then override that value to be the C compiler for non-Windows builds, and ml[64]/armasm64 for Windows builds. After migrating those checks, the only things left in the MOZ_DEFAULT_COMPILER macro in compiler-opts.m4 were some unused bits, so I removed them: * Setting of CPP/CXXCPP, which are set in toolchain.configure now * Setting HOST_LDFLAGS to empty, which doesn't seem particularly useful. There was also a quirky old test that the assembler was ml[64] when js-ctypes is enabled that I removed, I don't think it provides any value since this patch will ensure that we're using the right assembler for Windows builds.
build/autoconf/compiler-opts.m4
build/moz.configure/toolchain.configure
js/src/old-configure.in
old-configure.in
python/mozbuild/mozbuild/backend/tup.py
--- a/build/autoconf/compiler-opts.m4
+++ b/build/autoconf/compiler-opts.m4
@@ -1,47 +1,14 @@
 dnl This Source Code Form is subject to the terms of the Mozilla Public
 dnl License, v. 2.0. If a copy of the MPL was not distributed with this
 dnl file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 dnl Add compiler specific options
 
-AC_DEFUN([MOZ_DEFAULT_COMPILER],
-[
-dnl Default to MSVC for win32 and gcc-4.2 for darwin
-dnl ==============================================================
-if test -z "$CROSS_COMPILE"; then
-case "$target" in
-*-mingw*)
-    if test -z "$CPP"; then CPP="$CC -E -nologo"; fi
-    if test -z "$CXXCPP"; then CXXCPP="$CXX -TP -E -nologo"; ac_cv_prog_CXXCPP="$CXXCPP"; fi
-    if test -z "$AS"; then
-        case "${target_cpu}" in
-        i*86)
-            AS=ml;
-            ;;
-        x86_64)
-            AS=ml64;
-            ;;
-        aarch64)
-            AS=armasm64;
-            ;;
-        esac
-    fi
-    if test -z "$MIDL"; then MIDL=midl; fi
-
-    # need override this flag since we don't use $(LDFLAGS) for this.
-    if test -z "$HOST_LDFLAGS" ; then
-        HOST_LDFLAGS=" "
-    fi
-    ;;
-esac
-fi
-])
-
 dnl ============================================================================
 dnl C++ rtti
 dnl We don't use it in the code, but it can be usefull for debugging, so give
 dnl the user the option of enabling it.
 dnl ============================================================================
 AC_DEFUN([MOZ_RTTI],
 [
 MOZ_ARG_ENABLE_BOOL(cpp-rtti,
--- a/build/moz.configure/toolchain.configure
+++ b/build/moz.configure/toolchain.configure
@@ -792,16 +792,43 @@ def default_cxx_compilers(c_compiler, ot
             return (os.path.join(dir, file.replace('clang', 'clang++')),)
 
         return (c_compiler.compiler,)
 
     return default_cxx_compilers
 
 
 @template
+def provided_program(env_var):
+    '''Template handling cases where a program can be specified either as a
+    path or as a path with applicable arguments.
+    '''
+
+    @depends_if(env_var)
+    @imports(_from='itertools', _import='takewhile')
+    @imports(_from='mozbuild.shellutil', _import='split', _as='shell_split')
+    def provided(cmd):
+        # Assume the first dash-prefixed item (and any subsequent items) are
+        # command-line options, the item before the dash-prefixed item is
+        # the program we're looking for, and anything before that is a wrapper
+        # of some kind (e.g. sccache).
+        cmd = shell_split(cmd[0])
+
+        without_flags = list(takewhile(lambda x: not x.startswith('-'), cmd))
+
+        return namespace(
+            wrapper=without_flags[:-1],
+            program=without_flags[-1],
+            flags=cmd[len(without_flags):],
+        )
+
+    return provided
+
+
+@template
 def compiler(language, host_or_target, c_compiler=None, other_compiler=None,
              other_c_compiler=None):
     '''Template handling the generic base checks for the compiler for the
     given `language` on the given platform (`host_or_target`).
     `host_or_target` is either `host` or `target` (the @depends functions
     from init.configure.
     When the language is 'C++', `c_compiler` is the result of the `compiler`
     template for the language 'C' for the same `host_or_target`.
@@ -836,41 +863,24 @@ def compiler(language, host_or_target, c
     }[language]()
 
     what = 'the %s %s compiler' % (host_or_target_str, language)
 
     option(env=var, nargs=1, help='Path to %s' % what)
 
     # Handle the compiler given by the user through one of the CC/CXX/HOST_CC/
     # HOST_CXX variables.
-    @depends_if(var)
-    @imports(_from='itertools', _import='takewhile')
-    @imports(_from='mozbuild.shellutil', _import='split', _as='shell_split')
-    def provided_compiler(cmd):
-        # Historically, the compiler variables have contained more than the
-        # path to the compiler itself. So for backwards compatibility, try to
-        # find what is what in there, assuming the first dash-prefixed item is
-        # a compiler option, the item before that is the compiler, and anything
-        # before that is a compiler wrapper.
-        cmd = shell_split(cmd[0])
-
-        without_flags = list(takewhile(lambda x: not x.startswith('-'), cmd))
-
-        return namespace(
-            wrapper=without_flags[:-1],
-            compiler=without_flags[-1],
-            flags=cmd[len(without_flags):],
-        )
+    provided_compiler = provided_program(var)
 
     # Normally, we'd use `var` instead of `_var`, but the interaction with
     # old-configure complicates things, and for now, we a) can't take the plain
     # result from check_prog as CC/CXX/HOST_CC/HOST_CXX and b) have to let
     # old-configure AC_SUBST it (because it's autoconf doing it, not us)
     compiler = check_prog('_%s' % var, what=what, progs=default_compilers,
-                          input=provided_compiler.compiler,
+                          input=provided_compiler.program,
                           paths=toolchain_search_path)
 
     @depends(compiler, provided_compiler, compiler_wrapper, host_or_target)
     @checking('whether %s can be used' % what, lambda x: bool(x))
     @imports(_from='mozbuild.shellutil', _import='quote')
     def valid_compiler(compiler, provided_compiler, compiler_wrapper,
                        host_or_target):
         wrapper = list(compiler_wrapper or ())
@@ -1803,16 +1813,81 @@ def select_linker(linker, c_compiler, de
     return result
 
 
 set_config('LD_IS_BFD', depends(select_linker.KIND)
            (lambda x: x == 'bfd' or None))
 add_old_configure_assignment('LINKER_LDFLAGS', select_linker.LINKER_FLAG)
 
 
+# Assembler detection
+# ==============================================================
+
+js_option(env='AS', nargs=1, help='Path to the assembler')
+
+@depends(target, c_compiler)
+def as_info(target, c_compiler):
+    if c_compiler.type in ('msvc', 'clang-cl'):
+        ml = {
+            'x86': 'ml',
+            'x86_64': 'ml64',
+            'aarch64': 'armasm64.exe',
+        }.get(target.cpu)
+        return namespace(
+            type='masm',
+            names=(ml, )
+        )
+    # When building with anything but MSVC, we just use the C compiler as the assembler.
+    return namespace(
+        type='gcc',
+        names=(c_compiler.compiler, )
+    )
+
+# One would expect the assembler to be specified merely as a program.  But in
+# cases where the assembler is passed down into js/, it can be specified in
+# the same way as CC: a program + a list of argument flags.  We might as well
+# permit the same behavior in general, even though it seems somewhat unusual.
+# So we have to do the same sort of dance as we did above with
+# `provided_compiler`.
+provided_assembler = provided_program('AS')
+assembler = check_prog('_AS', input=provided_assembler.program,
+                       what='the assembler', progs=as_info.names)
+
+@depends(as_info, assembler, provided_assembler, c_compiler)
+def as_with_flags(as_info, assembler, provided_assembler, c_compiler):
+    if provided_assembler:
+        return provided_assembler.wrapper + \
+            [provided_assembler.program] + \
+            provided_assembler.flags
+
+    if as_info.type == 'masm':
+        return assembler
+
+    assert as_info.type == 'gcc'
+
+    # Need to add compiler wrappers and flags as appropriate.
+    return c_compiler.wrapper + [assembler] + c_compiler.flags
+
+
+add_old_configure_assignment('AS', as_with_flags)
+
+@depends(as_info, target)
+def as_dash_c_flag(as_info, target):
+    # armasm64 doesn't understand -c.
+    if as_info.type == 'masm' and target.cpu == 'aarch64':
+        return ''
+    else:
+        return '-c'
+
+
+set_config('AS_DASH_C_FLAG', as_dash_c_flag)
+
+# clang plugin handling
+# ==============================================================
+
 js_option('--enable-clang-plugin', env='ENABLE_CLANG_PLUGIN',
           help="Enable building with the mozilla clang plugin")
 
 add_old_configure_assignment('ENABLE_CLANG_PLUGIN',
                              depends_if('--enable-clang-plugin')(lambda _: True))
 
 js_option('--enable-mozsearch-plugin', env='ENABLE_MOZSEARCH_PLUGIN',
           help="Enable building with the mozsearch indexer plugin")
--- a/js/src/old-configure.in
+++ b/js/src/old-configure.in
@@ -60,18 +60,16 @@ MISSING_X=
 dnl Initialize the Pthread test variables early so they can be
 dnl  overridden by each platform.
 dnl ========================================================
 USE_PTHREADS=
 _PTHREAD_LDFLAGS=""
 
 LDFLAGS="$LDFLAGS $LINKER_LDFLAGS"
 
-MOZ_DEFAULT_COMPILER
-
 if test -z "$JS_STANDALONE"; then
   autoconfmk=autoconf-js.mk
 fi
 AC_SUBST(autoconfmk)
 
 if test -n "$JS_STANDALONE"; then
   jsconfdefs=$_objdir/js/src/js-confdefs.h
 else
@@ -395,20 +393,17 @@ AC_SUBST(MOZJS_MAJOR_VERSION)
 AC_SUBST(MOZJS_MINOR_VERSION)
 AC_SUBST(MOZJS_PATCH_VERSION)
 AC_SUBST(MOZJS_ALPHA)
 
 
 dnl ========================================================
 dnl set the defaults first
 dnl ========================================================
-AS_BIN=$AS
 AR_EXTRACT='$(AR) x'
-AS='$(CC)'
-AS_DASH_C_FLAG='-c'
 MOZ_USER_DIR=".mozilla"
 
 MOZ_FIX_LINK_PATHS="-Wl,-rpath-link,${DIST}/bin -Wl,-rpath-link,${prefix}/lib"
 
 dnl Configure platform-specific CPU architecture compiler options.
 dnl ==============================================================
 MOZ_ARCH_OPTS
 
@@ -671,19 +666,16 @@ case "$target" in
         MOZ_OPTIMIZE_FLAGS="-O2"
 
         WIN32_CONSOLE_EXE_LDFLAGS=-mconsole
         WIN32_GUI_EXE_LDFLAGS=-mwindows
     else
         TARGET_COMPILER_ABI=msvc
         HOST_CC='$(CC)'
         HOST_CXX='$(CXX)'
-        if test "$AS_BIN"; then
-            AS="$(basename "$AS_BIN")"
-        fi
         case "$LINKER" in
         *lld*)
             AR='llvm-lib'
             AR_FLAGS='-llvmlibthin -out:$@'
             ;;
         *)
             AR='lib'
             AR_FLAGS='-NOLOGO -OUT:$@'
@@ -1656,25 +1648,16 @@ AC_SUBST_LIST(EDITLINE_LIBS)
 
 dnl ========================================================
 dnl =
 dnl = Standalone module options
 dnl =
 dnl ========================================================
 MOZ_ARG_HEADER(Standalone module options (Not for building Mozilla))
 
-if test "$JS_HAS_CTYPES"; then
-  dnl JS_HAS_CTYPES is defined by Python configure. This check remains
-  dnl as long as determining $AS remains in old-configure.
-  dnl Error out if we're on MSVC and MASM is unavailable.
-  if test -n "$_MSC_VER" -a \( "$AS" != "ml.exe" -a "$AS" != "ml64.exe" \); then
-    AC_MSG_ERROR([\"$AS\" is not a suitable assembler to build js-ctypes. If you are building with MS Visual Studio 8 Express, you may download the MASM 8.0 package, upgrade to Visual Studio 9 Express, or install the Vista SDK. Or do not use --enable-ctypes.])
-  fi
-fi
-
 dnl ========================================================
 dnl =
 dnl = Options for generating the shell as a script
 dnl =
 dnl ========================================================
 
 MOZ_ARG_WITH_STRING(qemu-exe,
 [  --with-qemu-exe=path   Use path as an arm emulator on host platforms],
@@ -1689,20 +1672,18 @@ dnl ====================================
 dnl =
 dnl = Maintainer debug option (no --enable equivalent)
 dnl =
 dnl ========================================================
 
 AC_SUBST(AR)
 AC_SUBST(AR_FLAGS)
 AC_SUBST(AR_EXTRACT)
-AC_SUBST(AS)
 AC_SUBST(NM)
 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)
--- a/old-configure.in
+++ b/old-configure.in
@@ -75,18 +75,16 @@ MISSING_X=
 dnl Initialize the Pthread test variables early so they can be
 dnl  overridden by each platform.
 dnl ========================================================
 MOZ_USE_PTHREADS=
 _PTHREAD_LDFLAGS=""
 
 LDFLAGS="$LDFLAGS $LINKER_LDFLAGS"
 
-MOZ_DEFAULT_COMPILER
-
 if test "$COMPILE_ENVIRONMENT"; then
     MOZ_ANDROID_NDK
 fi # COMPILE_ENVIRONMENT
 
 case "$target" in
 *-android*|*-linuxandroid*)
     AC_DEFINE(ANDROID)
     ;;
@@ -436,20 +434,17 @@ AC_PATH_XTRA
 
 XCFLAGS="$X_CFLAGS"
 
 fi # COMPILE_ENVIRONMENT
 
 dnl ========================================================
 dnl set the defaults first
 dnl ========================================================
-AS_BIN=$AS
 AR_EXTRACT='$(AR) x'
-AS='$(CC)'
-AS_DASH_C_FLAG='-c'
 MOZ_USER_DIR=".mozilla"
 
 MOZ_FIX_LINK_PATHS="-Wl,-rpath-link,${DIST}/bin -Wl,-rpath-link,${prefix}/lib"
 
 MOZ_FS_LAYOUT=unix
 
 dnl Configure platform-specific CPU architecture compiler options.
 dnl ==============================================================
@@ -856,23 +851,16 @@ case "$target" in
             # function thunks need to be generated for cross-DLL calls.
             MOZ_FOLD_LIBS_FLAGS="-mnop-fun-dllimport"
         else
             # Silence problematic clang warnings
             CXXFLAGS="$CXXFLAGS -Wno-incompatible-ms-struct"
         fi
     else
         TARGET_COMPILER_ABI=msvc
-        if test "$AS_BIN"; then
-            AS="$(basename "$AS_BIN")"
-        fi
-        # armasm64 doesn't understand -c.
-        if test "$CPU_ARCH" = "aarch64"; then
-            AS_DASH_C_FLAG=
-        fi
         case "$LINKER" in
         *lld*)
             AR='llvm-lib'
             AR_FLAGS='-llvmlibthin -out:$@'
             ;;
         *)
             AR='lib'
             AR_FLAGS='-NOLOGO -OUT:$@'
@@ -3907,20 +3895,18 @@ dnl ====================================
 dnl =
 dnl = Maintainer debug option (no --enable equivalent)
 dnl =
 dnl ========================================================
 
 AC_SUBST(AR)
 AC_SUBST(AR_FLAGS)
 AC_SUBST(AR_EXTRACT)
-AC_SUBST(AS)
 AC_SUBST(NM)
 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(MOZ_AUTH_EXTENSION)
 AC_SUBST(MOZ_PREF_EXTENSIONS)
 AC_SUBST_LIST(MOZ_DEBUG_LDFLAGS)
--- a/python/mozbuild/mozbuild/backend/tup.py
+++ b/python/mozbuild/mozbuild/backend/tup.py
@@ -180,20 +180,17 @@ class BackendTupfile(object):
             (sources['.cpp'], 'CXX', 'CXXFLAGS', '-c', ''),
             (sources['.c'], 'CC', 'CFLAGS', '-c', ''),
             (host_sources['.cpp'], 'HOST_CXX', 'HOST_CXXFLAGS', '-c', 'host_'),
             (host_sources['.c'], 'HOST_CC', 'HOST_CFLAGS', '-c', 'host_'),
         ]
         for srcs, compiler, flags, dash_c, prefix in compilers:
             for src in sorted(srcs):
                 self.export_icecc()
-                # AS can be set to $(CC), so we need to call expand_variables on
-                # the compiler to get the real value.
-                compiler_value = self.variables.get(compiler, self.environment.substs[compiler])
-                cmd = [expand_variables(compiler_value, self.environment.substs)]
+                cmd = [self.variables.get(compiler, self.environment.substs[compiler])]
                 cmd.extend(shell_quote(f) for f in self.local_flags[flags])
                 cmd.extend(shell_quote(f) for f in self.per_source_flags[src])
                 cmd.extend([dash_c, '%f', '-o', '%o'])
                 self.rule(
                     cmd=cmd,
                     inputs=[src],
                     extra_inputs=extra_inputs,
                     outputs=[prefix + '%B.o'],