From 3254ff443da57e62d9215919e769af20a0a2dc2c Mon Sep 17 00:00:00 2001 From: Pierrick Bouvier Date: Thu, 18 Aug 2022 11:48:23 +0200 Subject: [PATCH 1/4] find DLL depending on Visual Studio version --- build/vs_toolchain.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/build/vs_toolchain.py b/build/vs_toolchain.py index 6314e5e947..3f2bbd9c8b 100644 --- a/build/vs_toolchain.py +++ b/build/vs_toolchain.py @@ -41,6 +41,12 @@ ('2022', '17.0'), ]) +VC_VERSIONS = { + '2017': 'VC141', + '2019': 'VC142', + '2022': 'VC143', +} + def SetEnvironmentAndGetRuntimeDllDirs(): """Sets up os.environ to use the depot_tools VS toolchain with gyp, and @@ -247,15 +253,19 @@ def _CopyUCRTRuntime(target_dir, source_dir, target_cpu, dll_pattern, suffix): """Copy both the msvcp and vccorlib runtime DLLs, only if the target doesn't exist, but the target directory does exist.""" if target_cpu == 'arm64': + env_version = GetVisualStudioVersion() + vc_version = VC_VERSIONS[env_version] + prefix = 'Microsoft.' + vc_version + # Windows ARM64 VCRuntime is located at {toolchain_root}/VC/Redist/MSVC/ - # {x.y.z}/[debug_nonredist/]arm64/Microsoft.VC141.CRT/. + # {x.y.z}/[debug_nonredist/]arm64/Microsoft.VC14{1,2,3}.CRT/. vc_redist_root = FindVCRedistRoot() if suffix.startswith('.'): source_dir = os.path.join(vc_redist_root, - 'arm64', 'Microsoft.VC141.CRT') + 'arm64', prefix + '.CRT') else: source_dir = os.path.join(vc_redist_root, 'debug_nonredist', - 'arm64', 'Microsoft.VC141.DebugCRT') + 'arm64', prefix + '.DebugCRT') for file_part in ('msvcp', 'vccorlib', 'vcruntime'): dll = dll_pattern % file_part target = os.path.join(target_dir, dll) From 151c6614952145b663b37769ed3157d7aeab687c Mon Sep 17 00:00:00 2001 From: Pierrick Bouvier Date: Thu, 18 Aug 2022 11:50:02 +0200 Subject: [PATCH 2/4] avoid double definition of win_toolchain for arm64 --- build/toolchain/win/BUILD.gn | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/build/toolchain/win/BUILD.gn b/build/toolchain/win/BUILD.gn index c51cddf77c..8ef7109aa2 100644 --- a/build/toolchain/win/BUILD.gn +++ b/build/toolchain/win/BUILD.gn @@ -288,7 +288,9 @@ if (target_cpu == "arm64") { win_toolchains("arm64") { toolchain_arch = "arm64" } - win_toolchains(host_cpu) { - toolchain_arch = host_cpu + if (host_cpu != "arm64") { + win_toolchains(host_cpu) { + toolchain_arch = host_cpu + } } } From 0f20292f432a72eef58518929337a99c94c28179 Mon Sep 17 00:00:00 2001 From: Pierrick Bouvier Date: Thu, 18 Aug 2022 11:54:00 +0200 Subject: [PATCH 3/4] set correct vcvars arch for arm64 --- build/toolchain/win/setup_toolchain.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/build/toolchain/win/setup_toolchain.py b/build/toolchain/win/setup_toolchain.py index d1d4fb5ecc..ffc919fe02 100644 --- a/build/toolchain/win/setup_toolchain.py +++ b/build/toolchain/win/setup_toolchain.py @@ -61,12 +61,17 @@ def _SetupScript(target_cpu, sdk_dir): return [os.path.normpath(os.path.join(sdk_dir, 'Bin/SetEnv.Cmd')), '/' + target_cpu] else: + vcvars_arch = { + 'x86': 'amd64_x86', + 'x64': 'amd64', + 'arm64': 'amd64_arm64', + } # We only support x64-hosted tools. # TODO(scottmg|dpranke): Non-depot_tools toolchain: need to get Visual # Studio install location from registry. return [os.path.normpath(os.path.join(os.environ['GYP_MSVS_OVERRIDE_PATH'], 'VC/Auxiliary/Build/vcvarsall.bat')), - 'amd64_x86' if target_cpu == 'x86' else 'amd64'] + vcvars_arch[target_cpu]] def _FormatAsEnvironmentBlock(envvar_dict): From 17daf3f3475c044aefe0669892957cdda27607f0 Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Thu, 8 Sep 2022 17:33:44 -0700 Subject: [PATCH 4/4] Add comment. --- build/toolchain/win/BUILD.gn | 1 + 1 file changed, 1 insertion(+) diff --git a/build/toolchain/win/BUILD.gn b/build/toolchain/win/BUILD.gn index 8ef7109aa2..f8f73326f1 100644 --- a/build/toolchain/win/BUILD.gn +++ b/build/toolchain/win/BUILD.gn @@ -288,6 +288,7 @@ if (target_cpu == "arm64") { win_toolchains("arm64") { toolchain_arch = "arm64" } + # Cross-compilation support for x64 hosts. if (host_cpu != "arm64") { win_toolchains(host_cpu) { toolchain_arch = host_cpu