Bug 1564097 - Set HOST_LINKER when host OS is Windows too. r=glandium
authorMakoto Kato <m_kato@ga2.so-net.ne.jp>
Wed, 13 Nov 2019 11:48:25 +0000
changeset 501902 f01d761796534e46b655e27a634d65ffa5934be9
parent 501901 c2d3e0e0367b65dafc5a419358e16ef00763fda5
child 501903 752fca530835e61a9ba5b1131b91e7d17b1e4564
push id36801
push userdvarga@mozilla.com
push dateThu, 14 Nov 2019 17:12:31 +0000
treeherdermozilla-central@a19a226a8c6a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
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 1564097 - Set HOST_LINKER when host OS is Windows too. r=glandium When running Cargo on Windows, `HOST_LINKER` is required by `cargo-host-linker.bat`. So we should use windows.configure to set HOST_LINKER when host OS is Windows and target OS isn't Windows. Differential Revision: https://phabricator.services.mozilla.com/D37241
--- a/build/moz.configure/toolchain.configure
+++ b/build/moz.configure/toolchain.configure
@@ -1400,22 +1400,22 @@ def preprocess_option(compiler):
         return '-P -Fi'
 set_config('PREPROCESS_OPTION', preprocess_option)
 # We only want to include windows.configure when we are compiling on
-# Windows, for Windows.
+# Windows, or for Windows.
 @depends(target, host)
 def is_windows(target, host):
-    return host.kernel == 'WINNT' and target.kernel == 'WINNT'
+    return host.kernel == 'WINNT' or target.kernel == 'WINNT'
 include('windows.configure', when=is_windows)
 # On Power ISA, determine compiler flags for VMX, VSX and VSX-3.
@@ -2378,22 +2378,23 @@ set_config('MKCSHLIB', make_shared_libra
 @depends(c_compiler, toolchain_prefix, when=target_is_windows)
 def rc_names(c_compiler, toolchain_prefix):
     if c_compiler.type in ('gcc', 'clang'):
         return tuple('%s%s' % (p, 'windres')
                      for p in ('',) + (toolchain_prefix or ()))
     return ('rc',)
-check_prog('RC', rc_names, paths=sdk_bin_path)
-@depends(link, toolchain_prefix)
-def ar_config(link, toolchain_prefix):
-    if link:  # if LINKER is set, it's either for lld-link or link
+check_prog('RC', rc_names, paths=sdk_bin_path, when=target_is_windows)
+@depends(link, toolchain_prefix, c_compiler)
+def ar_config(link, toolchain_prefix, c_compiler):
+    if c_compiler.type == 'clang-cl' and link:
+        # if LINKER is set, it's either for lld-link or link
         if 'lld-link' in link:
             return namespace(
                 flags=('-llvmlibthin', '-out:$@'),
             return namespace(
--- a/build/moz.configure/windows.configure
+++ b/build/moz.configure/windows.configure
@@ -20,20 +20,21 @@ def valid_windows_version(value):
             return version
     except ValueError:
     die('Invalid value for --with-windows-version (%s)', value[0])
 option(env='WINDOWSSDKDIR', nargs=1,
-       help='Directory containing the Windows SDK')
+       help='Directory containing the Windows SDK',
+       when=host_is_windows)
-@depends('WINDOWSSDKDIR', host)
+@depends('WINDOWSSDKDIR', host, when=host_is_windows)
 def windows_sdk_dir(value, host):
     if value:
         return value
     if host.kernel != 'WINNT':
         return ()
     return set(x[1] for x in get_registry_values(
         r'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows Kits\Installed Roots'
@@ -89,17 +90,18 @@ def get_sdk_dirs(sdk, subdir):
 @imports(_from='mozbuild.shellutil', _import='quote')
 def valid_windows_sdk_dir_result(value):
     if value:
         return '0x%04x in %s' % (value.version, quote(value.path))
-@depends(c_compiler, windows_sdk_dir, valid_windows_version, 'WINDOWSSDKDIR')
+@depends(c_compiler, windows_sdk_dir, valid_windows_version, 'WINDOWSSDKDIR',
+         when=host_is_windows)
 @checking('for Windows SDK', valid_windows_sdk_dir_result)
 @imports(_from='__builtin__', _import='sorted')
 @imports(_from='__builtin__', _import='Exception')
 @imports(_from='textwrap', _import='dedent')
 def valid_windows_sdk_dir(compiler, windows_sdk_dir, target_version,
     if windows_sdk_dir_env:
         windows_sdk_dir_env = windows_sdk_dir_env[0]
@@ -158,17 +160,17 @@ def valid_windows_sdk_dir(compiler, wind
 @imports(_from='mozbuild.shellutil', _import='quote')
 def valid_ucrt_sdk_dir_result(value):
     if value:
         return '%s in %s' % (value.version, quote(value.path))
-@depends(windows_sdk_dir, 'WINDOWSSDKDIR')
+@depends(windows_sdk_dir, 'WINDOWSSDKDIR', when=host_is_windows)
 @checking('for Universal CRT SDK', valid_ucrt_sdk_dir_result)
 @imports(_from='__builtin__', _import='sorted')
 @imports(_import='mozpack.path', _as='mozpath')
 def valid_ucrt_sdk_dir(windows_sdk_dir, windows_sdk_dir_env):
     if windows_sdk_dir_env:
         windows_sdk_dir_env = windows_sdk_dir_env[0]
     sdks = {}
@@ -231,20 +233,20 @@ def valid_ucrt_sdk_dir(windows_sdk_dir, 
     return namespace(
-@depends(c_compiler, toolchain_search_path)
+@depends(c_compiler, host_c_compiler, toolchain_search_path)
-def vc_path(c_compiler, toolchain_search_path):
-    if c_compiler.type != 'clang-cl':
+def vc_path(c_compiler, host_c_compiler, toolchain_search_path):
+    if c_compiler.type != 'clang-cl' and host_c_compiler.type != 'clang-cl':
     # In clang-cl builds, we need the headers and libraries from an MSVC installation.
     vc_program = find_program('cl.exe', paths=toolchain_search_path)
     if not vc_program:
         die('Cannot find a Visual C++ install for e.g. ATL headers.')
     result = os.path.dirname(vc_program)
@@ -270,16 +272,18 @@ def dia_sdk_dir(vc_path, dia_sdk_path):
     if dia_sdk_path:
         path = os.path.normpath(dia_sdk_path[0])
     elif vc_path:
         # This would be easier if we had the installationPath that
         # get_vc_paths works with, since 'DIA SDK' is relative to that.
         path = os.path.normpath(os.path.join(
             vc_path, r'..\..\..\..\DIA SDK'))
+    else:
+        return
     if os.path.exists(os.path.join(path, 'include', 'dia2.h')):
         return path
 @depends(vc_path, valid_windows_sdk_dir, valid_ucrt_sdk_dir, dia_sdk_dir)
 def include_path(vc_path, windows_sdk_dir, ucrt_sdk_dir, dia_sdk_dir):
@@ -380,53 +384,57 @@ def lib_path_for(host_or_target):
         if dia_sdk_lib_dir:
         return libs
     return lib_path
 def lib_path(libs):
     # Set in the environment for old-configure
     libs = os.pathsep.join(libs)
     os.environ['LIB'] = libs
     return libs
 set_config('LIB', lib_path)
 lib_path_for_host = lib_path_for(host)
 @imports(_from='mozbuild.shellutil', _import='quote')
 def host_linker_libpaths(libs):
     return ['-LIBPATH:%s' % quote(l) for l in libs]
 @imports(_from='mozbuild.shellutil', _import='quote')
 def host_linker_libpaths_bat(libs):
     # .bat files need a different style of quoting. Batch quoting is actually
     # not defined, and up to applications to handle, so it's not really clear
     # what should be escaped and what not, but most paths should work just
     # fine without escaping. And we don't care about double-quotes possibly
     # having to be escaped because they're not allowed in file names on
     # Windows.
     return ['"-LIBPATH:%s"' % l for l in libs]
 set_config('HOST_LINKER_LIBPATHS', host_linker_libpaths)
 set_config('HOST_LINKER_LIBPATHS_BAT', host_linker_libpaths_bat)
-option(env='MT', nargs=1, help='Path to the Microsoft Manifest Tool')
+# The when is technically wrong and should be removed and the code that
+# @depends on the option will need to be adapted when actual support for
+# clang-cl cross-builds emerge.
+option(env='MT', nargs=1, help='Path to the Microsoft Manifest Tool',
+       when=host_is_windows)
 @depends(valid_windows_sdk_dir, valid_ucrt_sdk_dir)
 @imports(_from='os', _import='environ')
 def sdk_bin_path(valid_windows_sdk_dir, valid_ucrt_sdk_dir):
     if not valid_windows_sdk_dir:
@@ -445,40 +453,40 @@ def sdk_bin_path(valid_windows_sdk_dir, 
     if vc_host == 'x64':
             os.path.join(valid_windows_sdk_dir.path, versioned_bin, 'x86'))
     return result
 mt = check_prog('MT', ('mt.exe',), input='MT',
-                paths=sdk_bin_path)
+                paths=sdk_bin_path, when=host_is_windows)
 # Check that MT is not something unexpected like "magnetic tape manipulation
 # utility".
 @checking('whether MT is really Microsoft Manifest Tool', lambda x: bool(x))
 def valid_mt(path):
     out = check_cmd_output(path, onerror=lambda: '').splitlines()
     out = '\n'.join(l for l in out
                     if 'Microsoft (R) Manifest Tool' in l)
     if out:
         return path
     raise FatalCheckError('%s is not Microsoft Manifest Tool')
 set_config('MSMANIFEST_TOOL', depends(valid_mt)(lambda x: bool(x)))
-js_option(env='LINKER', nargs=1, help='Path to the linker')
+js_option(env='LINKER', nargs=1, when=target_is_windows, help='Path to the linker')
 link = check_prog('LINKER', ('lld-link',), input='LINKER',
-                  paths=toolchain_search_path)
+                  when=target_is_windows, paths=toolchain_search_path)
-js_option(env='HOST_LINKER', nargs=1, help='Path to the host linker')
+js_option(env='HOST_LINKER', nargs=1, when=host_is_windows, help='Path to the host linker')
 host_link = check_prog('HOST_LINKER', ('lld-link',), input='HOST_LINKER',
-                       paths=host_toolchain_search_path)
+                       when=host_is_windows, paths=host_toolchain_search_path)
 add_old_configure_assignment('LINKER', link)
-check_prog('MAKECAB', ('makecab.exe',))
+check_prog('MAKECAB', ('makecab.exe',), when=host_is_windows)