From b2be53b8303cde39c22bc540cd7d30ed25faf634 Mon Sep 17 00:00:00 2001 From: Mike Hommey Date: Wed, 28 Dec 2022 22:48:51 +0000 Subject: [PATCH] Bug 1807779 - Allow to set a single variable for MSVC. r=firefox-build-system-reviewers,ahochheiden For builds using our toolchain artifact (or a similarly shaped copy of MSVC + SDKs) Differential Revision: https://phabricator.services.mozilla.com/D165592 --- build/moz.configure/toolchain.configure | 25 ++++++++++++++++++++++--- build/moz.configure/windows.configure | 9 +++++++-- build/mozconfig.no-compile | 3 +-- build/win32/mozconfig.vs2017 | 3 +-- build/win64-aarch64/mozconfig.vs2017 | 3 +-- build/win64/mozconfig.vs2017 | 3 +-- 6 files changed, 33 insertions(+), 13 deletions(-) diff --git a/build/moz.configure/toolchain.configure b/build/moz.configure/toolchain.configure index 2abd4201807c..76c5f1ad6cbd 100755 --- a/build/moz.configure/toolchain.configure +++ b/build/moz.configure/toolchain.configure @@ -548,6 +548,16 @@ def is_windows(target, host): return host.kernel == "WINNT" or target.kernel == "WINNT" +# Calling this a sysroot is a little weird, but it's the terminology clang went +# with with its -winsysroot flag. +option( + env="WINSYSROOT", + nargs=1, + when=is_windows, + help='Path to a Windows "sysroot" (directory containing MSVC, SDKs)', +) + + option( env="VC_PATH", nargs=1, @@ -561,12 +571,21 @@ option( vs_version, build_environment, "VC_PATH", + "WINSYSROOT", when=is_windows, ) +@imports("os") @imports(_from="operator", _import="itemgetter") -def vc_compiler_paths_for_version(host, vs_version, env, vc_path): - if vc_path and vs_version: - die("VC_PATH and --with-visual-studio-version cannot be used together.") +def vc_compiler_paths_for_version(host, vs_version, env, vc_path, winsysroot): + if (vc_path or winsysroot) and vs_version: + var = "VC_PATH" if vc_path else "WINSYSROOT" + die(f"{var} and --with-visual-studio-version cannot be used together.") + if winsysroot: + if vc_path: + die("WINSYSROOT and VC_PATH cannot be set together.") + base_vc_path = os.path.join(winsysroot[0], "VC", "Tools", "MSVC") + versions = os.listdir(base_vc_path) + vc_path = [os.path.join(base_vc_path, str(max(Version(v) for v in versions)))] if vc_path: # Use an arbitrary version, it doesn't matter. all_versions = [(Version("15"), vc_path[0])] diff --git a/build/moz.configure/windows.configure b/build/moz.configure/windows.configure index b4236001cf7c..637d9ff0b098 100644 --- a/build/moz.configure/windows.configure +++ b/build/moz.configure/windows.configure @@ -31,15 +31,20 @@ def valid_windows_version(value): option(env="WINDOWSSDKDIR", nargs=1, help="Directory containing the Windows SDK") -@depends("WINDOWSSDKDIR", c_compiler, host_c_compiler) -def windows_sdk_dir(value, compiler, host_compiler): +@depends("WINDOWSSDKDIR", "WINSYSROOT", c_compiler, host_c_compiler) +def windows_sdk_dir(value, winsysroot, compiler, host_compiler): if value: + if winsysroot: + die("WINDOWSSDKDIR and WINSYSROOT cannot be set together.") return value # Ideally, we'd actually check for host/target ABI being MSVC, but # that's waiting for bug 1617793. if compiler.type != "clang-cl" and host_compiler.type != "clang-cl": return () + if winsysroot: + return [os.path.join(winsysroot[0], "Windows Kits", "10")] + return set( normalize_path(x[1]) for x in get_registry_values( diff --git a/build/mozconfig.no-compile b/build/mozconfig.no-compile index 4632fabe0108..68dc06fb12ec 100644 --- a/build/mozconfig.no-compile +++ b/build/mozconfig.no-compile @@ -18,8 +18,7 @@ unset BINDGEN_CFLAGS unset ENABLE_CLANG_PLUGIN unset MACOS_SDK_DIR unset MACOS_PRIVATE_FRAMEWORKS_DIR -unset VC_PATH -unset WINDOWSSDKDIR +unset WINSYSROOT unset MOZ_LTO unset MOZ_STDCXX_COMPAT diff --git a/build/win32/mozconfig.vs2017 b/build/win32/mozconfig.vs2017 index ba607f3bfe65..967da8682d72 100644 --- a/build/win32/mozconfig.vs2017 +++ b/build/win32/mozconfig.vs2017 @@ -3,10 +3,9 @@ if [ -z "${VSPATH}" ]; then fi if [ -d "${VSPATH}" ]; then - export WINDOWSSDKDIR="${VSPATH}/windows kits/10" export WIN32_REDIST_DIR="${VSPATH}/vc/redist/msvc/14.16.27012/x86/microsoft.vc141.crt" export WIN_UCRT_REDIST_DIR="${VSPATH}/windows kits/10/redist/ucrt/dlls/x86" - export VC_PATH="${VSPATH}/vc/tools/msvc/14.16.27023" + export WINSYSROOT="${VSPATH}" fi ac_add_options --target=i686-pc-mingw32 diff --git a/build/win64-aarch64/mozconfig.vs2017 b/build/win64-aarch64/mozconfig.vs2017 index b687ea8dff74..db732613121f 100644 --- a/build/win64-aarch64/mozconfig.vs2017 +++ b/build/win64-aarch64/mozconfig.vs2017 @@ -3,7 +3,6 @@ if [ -z "${VSPATH}" ]; then fi if [ -d "${VSPATH}" ]; then - export WINDOWSSDKDIR="${VSPATH}/windows kits/10" export WIN32_REDIST_DIR="${VSPATH}/vc/redist/msvc/14.16.27012/arm64/microsoft.vc141.crt" - export VC_PATH="${VSPATH}/vc/tools/msvc/14.16.27023" + export WINSYSROOT="${VSPATH}" fi diff --git a/build/win64/mozconfig.vs2017 b/build/win64/mozconfig.vs2017 index ec9a1f25baed..5e33a537d8c1 100644 --- a/build/win64/mozconfig.vs2017 +++ b/build/win64/mozconfig.vs2017 @@ -3,8 +3,7 @@ if [ -z "${VSPATH}" ]; then fi if [ -d "${VSPATH}" ]; then - export WINDOWSSDKDIR="${VSPATH}/windows kits/10" export WIN32_REDIST_DIR=${VSPATH}/vc/redist/msvc/14.16.27012/x64/microsoft.vc141.crt export WIN_UCRT_REDIST_DIR="${VSPATH}/windows kits/10/redist/ucrt/dlls/x64" - export VC_PATH="${VSPATH}/vc/tools/msvc/14.16.27023" + export WINSYSROOT="${VSPATH}" fi