Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 29a5d76

Browse files
authored
[toolchain] Update Windows VS toolchain to current Chromium one (18fbbd3). (#195)
Copied from https://dart-review.googlesource.com/c/84630.
1 parent 7e555ae commit 29a5d76

File tree

1 file changed

+42
-19
lines changed

1 file changed

+42
-19
lines changed

build/vs_toolchain.py

Lines changed: 42 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import stat
2222
import subprocess
2323
import sys
24+
2425
from gn_helpers import ToGNString
2526

2627

@@ -63,9 +64,14 @@ def SetEnvironmentAndGetRuntimeDllDirs():
6364
win_sdk = toolchain_data['win8sdk']
6465
wdk = toolchain_data['wdk']
6566
# TODO(scottmg): The order unfortunately matters in these. They should be
66-
# split into separate keys for x86 and x64. (See CopyDlls call below).
67+
# split into separate keys for x64/x86/arm64. (See CopyDlls call below).
6768
# http://crbug.com/345992
6869
vs_runtime_dll_dirs = toolchain_data['runtime_dirs']
70+
# The number of runtime_dirs in the toolchain_data was two (x64/x86) but
71+
# changed to three (x64/x86/arm64) and this code needs to handle both
72+
# possibilities, which can change independently from this code.
73+
if len(vs_runtime_dll_dirs) == 2:
74+
vs_runtime_dll_dirs.append('Arm64Unused')
6975

7076
os.environ['GYP_MSVS_OVERRIDE_PATH'] = toolchain
7177
os.environ['GYP_MSVS_VERSION'] = version
@@ -87,9 +93,12 @@ def SetEnvironmentAndGetRuntimeDllDirs():
8793
# directory ensures that they are available when needed.
8894
bitness = platform.architecture()[0]
8995
# When running 64-bit python the x64 DLLs will be in System32
96+
# ARM64 binaries will not be available in the system directories because we
97+
# don't build on ARM64 machines.
9098
x64_path = 'System32' if bitness == '64bit' else 'Sysnative'
9199
x64_path = os.path.join(os.path.expandvars('%windir%'), x64_path)
92-
vs_runtime_dll_dirs = [x64_path, os.path.expandvars('%windir%/SysWOW64')]
100+
vs_runtime_dll_dirs = [x64_path, os.path.expandvars('%windir%/SysWOW64'),
101+
'Arm64Unused']
93102

94103
return vs_runtime_dll_dirs
95104

@@ -141,7 +150,6 @@ def DetectVisualStudioPath():
141150
raise Exception(('Visual Studio version %s (from GYP_MSVS_VERSION)'
142151
' not supported. Supported versions are: %s') % (
143152
version_as_year, ', '.join(year_to_version.keys())))
144-
version = year_to_version[version_as_year]
145153
if version_as_year == '2017':
146154
# The VC++ 2017 install location needs to be located using COM instead of
147155
# the registry. For details see:
@@ -201,16 +209,21 @@ def _CopyUCRTRuntime(target_dir, source_dir, target_cpu, dll_pattern, suffix):
201209
os.environ.get('WINDOWSSDKDIR',
202210
os.path.expandvars('%ProgramFiles(x86)%'
203211
'\\Windows Kits\\10')))
204-
ucrt_dll_dirs = os.path.join(win_sdk_dir, 'Redist', 'ucrt', 'DLLs',
205-
target_cpu)
206-
ucrt_files = glob.glob(os.path.join(ucrt_dll_dirs, 'api-ms-win-*.dll'))
207-
assert len(ucrt_files) > 0
208-
for ucrt_src_file in ucrt_files:
209-
file_part = os.path.basename(ucrt_src_file)
210-
ucrt_dst_file = os.path.join(target_dir, file_part)
211-
_CopyRuntimeImpl(ucrt_dst_file, ucrt_src_file, False)
212-
_CopyRuntimeImpl(os.path.join(target_dir, 'ucrtbase' + suffix),
213-
os.path.join(source_dir, 'ucrtbase' + suffix))
212+
# ARM64 doesn't have a redist for the ucrt DLLs because they are always
213+
# present in the OS.
214+
if target_cpu != 'arm64':
215+
ucrt_dll_dirs = os.path.join(win_sdk_dir, 'Redist', 'ucrt', 'DLLs',
216+
target_cpu)
217+
ucrt_files = glob.glob(os.path.join(ucrt_dll_dirs, 'api-ms-win-*.dll'))
218+
assert len(ucrt_files) > 0
219+
for ucrt_src_file in ucrt_files:
220+
file_part = os.path.basename(ucrt_src_file)
221+
ucrt_dst_file = os.path.join(target_dir, file_part)
222+
_CopyRuntimeImpl(ucrt_dst_file, ucrt_src_file, False)
223+
# We must copy ucrtbase.dll for x64/x86, and ucrtbased.dll for all CPU types.
224+
if target_cpu != 'arm64' or not suffix.startswith('.'):
225+
_CopyRuntimeImpl(os.path.join(target_dir, 'ucrtbase' + suffix),
226+
os.path.join(source_dir, 'ucrtbase' + suffix))
214227

215228

216229
def FindVCToolsRoot():
@@ -249,6 +262,7 @@ def _CopyPGORuntime(target_dir, target_cpu):
249262
# from HostX86/x86.
250263
pgo_x86_runtime_dir = os.path.join(pgo_runtime_root, 'HostX86', 'x86')
251264
pgo_x64_runtime_dir = os.path.join(pgo_runtime_root, 'HostX64', 'x64')
265+
pgo_arm64_runtime_dir = os.path.join(pgo_runtime_root, 'arm64')
252266
else:
253267
raise Exception('Unexpected toolchain version: %s.' % env_version)
254268

@@ -261,8 +275,10 @@ def _CopyPGORuntime(target_dir, target_cpu):
261275
source = os.path.join(pgo_x86_runtime_dir, runtime)
262276
elif target_cpu == 'x64':
263277
source = os.path.join(pgo_x64_runtime_dir, runtime)
278+
elif target_cpu == 'arm64':
279+
source = os.path.join(pgo_arm64_runtime_dir, runtime)
264280
else:
265-
raise NotImplementedError("Unexpected target_cpu value: " + target_cpu)
281+
raise NotImplementedError('Unexpected target_cpu value: ' + target_cpu)
266282
if not os.path.exists(source):
267283
raise Exception('Unable to find %s.' % source)
268284
_CopyRuntimeImpl(os.path.join(target_dir, runtime), source)
@@ -271,7 +287,7 @@ def _CopyPGORuntime(target_dir, target_cpu):
271287
def _CopyRuntime(target_dir, source_dir, target_cpu, debug):
272288
"""Copy the VS runtime DLLs, only if the target doesn't exist, but the target
273289
directory does exist. Handles VS 2015 and VS 2017."""
274-
suffix = "d.dll" if debug else ".dll"
290+
suffix = 'd.dll' if debug else '.dll'
275291
# VS 2017 uses the same CRT DLLs as VS 2015.
276292
_CopyUCRTRuntime(target_dir, source_dir, target_cpu, '%s140' + suffix,
277293
suffix)
@@ -290,8 +306,15 @@ def CopyDlls(target_dir, configuration, target_cpu):
290306
if not vs_runtime_dll_dirs:
291307
return
292308

293-
x64_runtime, x86_runtime = vs_runtime_dll_dirs
294-
runtime_dir = x64_runtime if target_cpu == 'x64' else x86_runtime
309+
x64_runtime, x86_runtime, arm64_runtime = vs_runtime_dll_dirs
310+
if target_cpu == 'x64':
311+
runtime_dir = x64_runtime
312+
elif target_cpu == 'x86':
313+
runtime_dir = x86_runtime
314+
elif target_cpu == 'arm64':
315+
runtime_dir = arm64_runtime
316+
else:
317+
raise Exception('Unknown target_cpu: ' + target_cpu)
295318
_CopyRuntime(target_dir, runtime_dir, target_cpu, debug=False)
296319
if configuration == 'Debug':
297320
_CopyRuntime(target_dir, runtime_dir, target_cpu, debug=True)
@@ -424,7 +447,7 @@ def Update(force=False):
424447

425448

426449
def NormalizePath(path):
427-
while path.endswith("\\"):
450+
while path.endswith('\\'):
428451
path = path[:-1]
429452
return path
430453

@@ -476,4 +499,4 @@ def main():
476499

477500

478501
if __name__ == '__main__':
479-
sys.exit(main())
502+
sys.exit(main())

0 commit comments

Comments
 (0)