Commit 18fbbd37 authored by Bruce Dawson's avatar Bruce Dawson Committed by Commit Bot

Update vs_toolchain.py to handle ARM64

ARM64 on Win32 adds a third Win32 target platform which requires updates
to the script which configures the toolchain. This includes handling
build\win_toolchain.json listing either two or three toolchains, and not
copying UCRT DLLs in the ARM64 case, except for ucrtbased.dll.

This also fixes some erroneous double quotes, probably left over from
previous changes I made to this file.

This is in preparation for landing and then using crrev.com/c/1330185

Bug: 893460
Change-Id: I1fa775b662e3c0483174c32ad3c73f30f2802ea9
Reviewed-on: https://chromium-review.googlesource.com/c/1339101Reviewed-by: default avataragrieve <agrieve@chromium.org>
Commit-Queue: Bruce Dawson <brucedawson@chromium.org>
Cr-Commit-Position: refs/heads/master@{#608951}
parent fce715c8
...@@ -53,9 +53,14 @@ def SetEnvironmentAndGetRuntimeDllDirs(): ...@@ -53,9 +53,14 @@ def SetEnvironmentAndGetRuntimeDllDirs():
win_sdk = toolchain_data['win8sdk'] win_sdk = toolchain_data['win8sdk']
wdk = toolchain_data['wdk'] wdk = toolchain_data['wdk']
# TODO(scottmg): The order unfortunately matters in these. They should be # TODO(scottmg): The order unfortunately matters in these. They should be
# split into separate keys for x86 and x64. (See CopyDlls call below). # split into separate keys for x64/x86/arm64. (See CopyDlls call below).
# http://crbug.com/345992 # http://crbug.com/345992
vs_runtime_dll_dirs = toolchain_data['runtime_dirs'] vs_runtime_dll_dirs = toolchain_data['runtime_dirs']
# The number of runtime_dirs in the toolchain_data was two (x64/x86) but
# changed to three (x64/x86/arm64) and this code needs to handle both
# possibilities, which can change independently from this code.
if len(vs_runtime_dll_dirs) == 2:
vs_runtime_dll_dirs.append('Arm64Unused')
os.environ['GYP_MSVS_OVERRIDE_PATH'] = toolchain os.environ['GYP_MSVS_OVERRIDE_PATH'] = toolchain
os.environ['GYP_MSVS_VERSION'] = version os.environ['GYP_MSVS_VERSION'] = version
...@@ -77,9 +82,12 @@ def SetEnvironmentAndGetRuntimeDllDirs(): ...@@ -77,9 +82,12 @@ def SetEnvironmentAndGetRuntimeDllDirs():
# directory ensures that they are available when needed. # directory ensures that they are available when needed.
bitness = platform.architecture()[0] bitness = platform.architecture()[0]
# When running 64-bit python the x64 DLLs will be in System32 # When running 64-bit python the x64 DLLs will be in System32
# ARM64 binaries will not be available in the system directories because we
# don't build on ARM64 machines.
x64_path = 'System32' if bitness == '64bit' else 'Sysnative' x64_path = 'System32' if bitness == '64bit' else 'Sysnative'
x64_path = os.path.join(os.path.expandvars('%windir%'), x64_path) x64_path = os.path.join(os.path.expandvars('%windir%'), x64_path)
vs_runtime_dll_dirs = [x64_path, os.path.expandvars('%windir%/SysWOW64')] vs_runtime_dll_dirs = [x64_path, os.path.expandvars('%windir%/SysWOW64'),
'Arm64Unused']
return vs_runtime_dll_dirs return vs_runtime_dll_dirs
...@@ -190,16 +198,21 @@ def _CopyUCRTRuntime(target_dir, source_dir, target_cpu, dll_pattern, suffix): ...@@ -190,16 +198,21 @@ def _CopyUCRTRuntime(target_dir, source_dir, target_cpu, dll_pattern, suffix):
os.environ.get('WINDOWSSDKDIR', os.environ.get('WINDOWSSDKDIR',
os.path.expandvars('%ProgramFiles(x86)%' os.path.expandvars('%ProgramFiles(x86)%'
'\\Windows Kits\\10'))) '\\Windows Kits\\10')))
ucrt_dll_dirs = os.path.join(win_sdk_dir, 'Redist', 'ucrt', 'DLLs', # ARM64 doesn't have a redist for the ucrt DLLs because they are always
target_cpu) # present in the OS.
ucrt_files = glob.glob(os.path.join(ucrt_dll_dirs, 'api-ms-win-*.dll')) if target_cpu != 'arm64':
assert len(ucrt_files) > 0 ucrt_dll_dirs = os.path.join(win_sdk_dir, 'Redist', 'ucrt', 'DLLs',
for ucrt_src_file in ucrt_files: target_cpu)
file_part = os.path.basename(ucrt_src_file) ucrt_files = glob.glob(os.path.join(ucrt_dll_dirs, 'api-ms-win-*.dll'))
ucrt_dst_file = os.path.join(target_dir, file_part) assert len(ucrt_files) > 0
_CopyRuntimeImpl(ucrt_dst_file, ucrt_src_file, False) for ucrt_src_file in ucrt_files:
_CopyRuntimeImpl(os.path.join(target_dir, 'ucrtbase' + suffix), file_part = os.path.basename(ucrt_src_file)
os.path.join(source_dir, 'ucrtbase' + suffix)) ucrt_dst_file = os.path.join(target_dir, file_part)
_CopyRuntimeImpl(ucrt_dst_file, ucrt_src_file, False)
# We must copy ucrtbase.dll for x64/x86, and ucrtbased.dll for all CPU types.
if target_cpu != 'arm64' or not suffix.startswith('.'):
_CopyRuntimeImpl(os.path.join(target_dir, 'ucrtbase' + suffix),
os.path.join(source_dir, 'ucrtbase' + suffix))
def FindVCToolsRoot(): def FindVCToolsRoot():
...@@ -254,7 +267,7 @@ def _CopyPGORuntime(target_dir, target_cpu): ...@@ -254,7 +267,7 @@ def _CopyPGORuntime(target_dir, target_cpu):
elif target_cpu == 'arm64': elif target_cpu == 'arm64':
source = os.path.join(pgo_arm64_runtime_dir, runtime) source = os.path.join(pgo_arm64_runtime_dir, runtime)
else: else:
raise NotImplementedError("Unexpected target_cpu value: " + target_cpu) raise NotImplementedError('Unexpected target_cpu value: ' + target_cpu)
if not os.path.exists(source): if not os.path.exists(source):
raise Exception('Unable to find %s.' % source) raise Exception('Unable to find %s.' % source)
_CopyRuntimeImpl(os.path.join(target_dir, runtime), source) _CopyRuntimeImpl(os.path.join(target_dir, runtime), source)
...@@ -263,7 +276,7 @@ def _CopyPGORuntime(target_dir, target_cpu): ...@@ -263,7 +276,7 @@ def _CopyPGORuntime(target_dir, target_cpu):
def _CopyRuntime(target_dir, source_dir, target_cpu, debug): def _CopyRuntime(target_dir, source_dir, target_cpu, debug):
"""Copy the VS runtime DLLs, only if the target doesn't exist, but the target """Copy the VS runtime DLLs, only if the target doesn't exist, but the target
directory does exist. Handles VS 2015 and VS 2017.""" directory does exist. Handles VS 2015 and VS 2017."""
suffix = "d.dll" if debug else ".dll" suffix = 'd.dll' if debug else '.dll'
# VS 2017 uses the same CRT DLLs as VS 2015. # VS 2017 uses the same CRT DLLs as VS 2015.
_CopyUCRTRuntime(target_dir, source_dir, target_cpu, '%s140' + suffix, _CopyUCRTRuntime(target_dir, source_dir, target_cpu, '%s140' + suffix,
suffix) suffix)
...@@ -282,8 +295,15 @@ def CopyDlls(target_dir, configuration, target_cpu): ...@@ -282,8 +295,15 @@ def CopyDlls(target_dir, configuration, target_cpu):
if not vs_runtime_dll_dirs: if not vs_runtime_dll_dirs:
return return
x64_runtime, x86_runtime = vs_runtime_dll_dirs x64_runtime, x86_runtime, arm64_runtime = vs_runtime_dll_dirs
runtime_dir = x64_runtime if target_cpu == 'x64' else x86_runtime if target_cpu == 'x64':
runtime_dir = x64_runtime
elif target_cpu == 'x86':
runtime_dir = x86_runtime
elif target_cpu == 'arm64':
runtime_dir = arm64_runtime
else:
raise Exception('Unknown target_cpu: ' + target_cpu)
_CopyRuntime(target_dir, runtime_dir, target_cpu, debug=False) _CopyRuntime(target_dir, runtime_dir, target_cpu, debug=False)
if configuration == 'Debug': if configuration == 'Debug':
_CopyRuntime(target_dir, runtime_dir, target_cpu, debug=True) _CopyRuntime(target_dir, runtime_dir, target_cpu, debug=True)
...@@ -416,7 +436,7 @@ def Update(force=False): ...@@ -416,7 +436,7 @@ def Update(force=False):
def NormalizePath(path): def NormalizePath(path):
while path.endswith("\\"): while path.endswith('\\'):
path = path[:-1] path = path[:-1]
return path return path
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment