Skip to content

Commit

Permalink
Build mozc_tip64.dll for ARM64 with GYP
Browse files Browse the repository at this point in the history
As a preparation to build Mozc for ARM64 in Windows (google#1130), this commit
demonstrates that it is technically possible for us to build
'mozc_tip64.dll' as an ARM64 DLL with GYP even though GYP itself does
not officially support it.

With this commit you need to install the following additional Visual
Studio components even when you do not build Mozc for ARM64 Windows.

  * 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

Note that 'mozc_tip64.dll' for ARM64 will be built only when explicitly
specified in 'build_mozc.py build'. There must be no change in the final
artifacts when just building the installer package.

Note also that we still need to build ARM64X DLL to actually support
ARM64 Windows environment.
  • Loading branch information
yukawa committed Dec 16, 2024
1 parent bc546b2 commit dab7d7e
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 2 deletions.
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):
"""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)
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

0 comments on commit dab7d7e

Please sign in to comment.