Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build mozc_tip64.dll for ARM64 with GYP #1139

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/build_mozc_in_windows.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
27 changes: 25 additions & 2 deletions src/build_mozc.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import optparse
import os
import pathlib
import platform
import re
import subprocess
import sys
Expand Down Expand Up @@ -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):
yukawa marked this conversation as resolved.
Show resolved Hide resolved
"""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)
yukawa marked this conversation as resolved.
Show resolved Hide resolved
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)
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions src/build_tools/protoc_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 27 additions & 0 deletions src/gyp/common_win.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -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': {
Expand Down Expand Up @@ -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': [
Expand Down