diff --git a/docs/build_mozc_in_windows.md b/docs/build_mozc_in_windows.md index 5eab1e7a9..ad8bc1a30 100644 --- a/docs/build_mozc_in_windows.md +++ b/docs/build_mozc_in_windows.md @@ -38,6 +38,12 @@ Building Mozc on Windows requires the following software. * [Visual Studio 2022 Community Edition](https://visualstudio.microsoft.com/downloads/#visual-studio-community-2022) * [Build Tools for Visual Studio 2022](https://visualstudio.microsoft.com/downloads/#build-tools-for-visual-studio-2022) should also work + * Make sure that the following components are installed. + * `Microsoft.VisualStudio.Component.VC.Redist.14.Latest` + * `Microsoft.VisualStudio.Component.VC.ATL` + * `Microsoft.VisualStudio.Component.VC.Tools.x86.x64` + * `Microsoft.VisualStudio.Component.VC.ATL.ARM64` + * `Microsoft.VisualStudio.Component.VC.Tools.ARM64` * Python 3.9 or later with the following pip modules. * `six` * `requests` diff --git a/src/build_mozc.py b/src/build_mozc.py index 6e17812cc..53a0aa54d 100755 --- a/src/build_mozc.py +++ b/src/build_mozc.py @@ -43,6 +43,7 @@ import optparse import os import pathlib +import platform import re import subprocess import sys @@ -370,18 +371,40 @@ def WriteEnvironmentFile(path, env): f.write(nul.join(entries).encode('utf-8')) -def UpdateEnvironmentFilesForWindows(out_dir): +def UpdateEnvironmentFilesForWindows(out_dir, vcvarsall_path): """Add required environment variables for Ninja build.""" python_path_root = MOZC_ROOT python_path = os.path.abspath(python_path_root) original_python_paths = os.environ.get('PYTHONPATH', '') if original_python_paths: python_path = os.pathsep.join([original_python_paths, python_path]) + for d in os.listdir(out_dir): abs_dir = os.path.abspath(os.path.join(out_dir, d)) + # Tweak generated build rules for ARM64 + if d.endswith('arm64'): + build_ninja = os.path.join(abs_dir, 'build.ninja') + with open(build_ninja, 'r', encoding='utf-8') as f: + lines = f.readlines() + for i in range(0, 2): + lines[i] = lines[i].replace('x64\\cl.exe', 'arm64\\cl.exe') + lines[i] = lines[i].replace('x86\\cl.exe', 'arm64\\cl.exe') + with open(build_ninja, 'w', encoding='utf-8') as f: + f.writelines(lines) + for arch in ['x86', 'x64']: env_file = os.path.join(abs_dir, f'environment.{arch}') env = ReadEnvironmentFile(env_file) + # Tweak for ARM64 + if d.endswith('arm64'): + vs_arch = platform.uname().machine + if vs_arch != 'arm64': + vs_arch = vs_arch + '_arm64' + vs_env = get_vs_env_vars(vs_arch, vcvarsall_path_hint=vcvarsall_path) + env['INCLUDE'] = vs_env['INCLUDE'] + env['LIB'] = vs_env['LIB'] + env['LIBPATH'] = vs_env['LIBPATH'] + env['PATH'] = vs_env['PATH'] env['PYTHONPATH'] = python_path env['VSLANG'] = '1033' # == MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US) WriteEnvironmentFile(env_file, env) @@ -561,7 +584,7 @@ def GypMain(options, unused_args): # For internal Ninja build on Windows, set up environment files if IsWindows(): out_dir = os.path.join(MOZC_ROOT, 'out_win') - UpdateEnvironmentFilesForWindows(out_dir) + UpdateEnvironmentFilesForWindows(out_dir, options.vcvarsall_path) if IsWindows() and qt_dir and qt_ver: # When Windows build is configured to use DLL version of Qt, copy Qt's DLLs diff --git a/src/build_tools/protoc_wrapper.py b/src/build_tools/protoc_wrapper.py index e1e507292..b684b16c4 100755 --- a/src/build_tools/protoc_wrapper.py +++ b/src/build_tools/protoc_wrapper.py @@ -85,6 +85,12 @@ def main(): protoc_path = opts.protoc_command if opts.protoc_dir: protoc_path = os.path.join(os.path.abspath(opts.protoc_dir), protoc_path) + # A hack for ARM64 build with GYP on Windows. + # https://github.com/google/mozc/issues/1130 + # ARM64 version of protoc.exe does not work on x64 machine, so use x64 + # version with an assumption that it's already built. + if os.name == 'nt' and protoc_path.endswith('_arm64\\protoc.exe'): + protoc_path = protoc_path.replace('_arm64\\protoc', '_x64\\protoc') # The path of proto file should be transformed as a relative path from # the project root so that correct relative paths should be embedded into diff --git a/src/gyp/common_win.gypi b/src/gyp/common_win.gypi index 32efbe5c0..1593a8c16 100644 --- a/src/gyp/common_win.gypi +++ b/src/gyp/common_win.gypi @@ -167,6 +167,27 @@ }, }, }, + 'arm64_Base': { + 'abstract': 1, + 'msvs_configuration_attributes': { + 'OutputDirectory': '<(build_base)/$(ConfigurationName)_arm64', + 'IntermediateDirectory': '<(build_base)/$(ConfigurationName)_arm64/obj/$(ProjectName)', + }, + 'msvs_target_platform': 'arm64', + 'msvs_settings': { + 'VCCLCompilerTool': { + 'AdditionalOptions': [ + '/bigobj', + ], + }, + 'VCLinkerTool': { + 'ImageHasSafeExceptionHandlers': 'false', + 'AdditionalOptions': [ + '/MACHINE:ARM64', + ], + }, + }, + }, 'Win_Static_Debug_CRT_Base': { 'abstract': 1, 'msvs_settings': { @@ -276,6 +297,12 @@ 'Release_x64': { 'inherit_from': ['x64_Base', 'Release_Base', 'Win_Static_Release_CRT_Base'], }, + 'Debug_arm64': { + 'inherit_from': ['arm64_Base', 'Debug_Base', 'Win_Static_Debug_CRT_Base'], + }, + 'Release_arm64': { + 'inherit_from': ['arm64_Base', 'Release_Base', 'Win_Static_Release_CRT_Base'], + }, }, 'default_configuration': 'Debug', 'defines': [