From 0960a755bb693cbfa7132410d0300d76e83e5c1a Mon Sep 17 00:00:00 2001 From: Yohei Yukawa Date: Sat, 7 Dec 2024 17:23:08 +0900 Subject: [PATCH 1/2] Remove platform macros from `tip_text_service.cc` (#1132) This commit removes the dependency on platform macros such as _M_X64 and _M_IX86 from tip_text_service.cc. There must be no change in the final artifacts. This is a preparation to build Mozc for ARM64 (#1130). PiperOrigin-RevId: 703735488 --- src/win32/tip/tip_text_service.cc | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/win32/tip/tip_text_service.cc b/src/win32/tip/tip_text_service.cc index 71aafdb7f..7ea8df23f 100644 --- a/src/win32/tip/tip_text_service.cc +++ b/src/win32/tip/tip_text_service.cc @@ -36,6 +36,8 @@ #include #include +#include +#include #include #include #include @@ -249,15 +251,11 @@ wil::com_ptr_nothrow GetCategoryMgr() { template struct ComPtrHash { size_t operator()(const wil::com_ptr_nothrow &value) const { - // Caveats: On x86 environment, both _M_X64 and _M_IX86 are defined. So we - // need to check _M_X64 first. -#if defined(_M_X64) - constexpr size_t kUnusedBits = 3; // assuming 8-byte aligned -#elif defined(_M_IX86) // defined(_M_X64) - constexpr size_t kUnusedBits = 2; // assuming 4-byte aligned -#else // defined(_M_IX86) -#error "unsupported platform" -#endif // defined(_M_IX86) + // The minimum size of COM objects is the pointer to vtable. + // For instance the last 3 bits are guaranteed to be zero on 64-bit + // processes. + constexpr size_t kUnusedBits = + std::max(std::bit_width(sizeof(void *)), 1) - 1; // Compress the data by shifting unused bits. return reinterpret_cast(value.get()) >> kUnusedBits; } From e983ab86bb77b9ceb49f268fc824dc64e4ab87d8 Mon Sep 17 00:00:00 2001 From: Yohei Yukawa Date: Sat, 7 Dec 2024 17:24:09 +0900 Subject: [PATCH 2/2] Simplify ninja env file logic in `build_mozc.py` (#1134) As a preparation to build Mozc for ARM64 in Windows (#1130), this commit aims to simplify UpdateEnvironmentFilesForWindows in build_mozc.py so that we can tweak environment file for ARM64 build configurations in a subsequent commit easily. This is still a mechanical code clean up. There must be no difference in the final artifacts. PiperOrigin-RevId: 703739072 --- src/build_mozc.py | 41 +++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/src/build_mozc.py b/src/build_mozc.py index f3f55e9dc..6e17812cc 100755 --- a/src/build_mozc.py +++ b/src/build_mozc.py @@ -349,6 +349,27 @@ def ParseCleanOptions(args): return parser.parse_args(args) +def ReadEnvironmentFile(path): + nul = chr(0) + with open(path, 'rb') as f: + content = f.read() + entries = content.decode('utf-8').split(nul) + env = dict() + for e in entries: + if '=' in e: + key, value = e.split('=', 1) + env[key] = value + return env + + +def WriteEnvironmentFile(path, env): + nul = chr(0) + entries = [f'{key}={value}' for (key, value) in env.items()] + entries.extend(['', '']) + with open(path, 'wb') as f: + f.write(nul.join(entries).encode('utf-8')) + + def UpdateEnvironmentFilesForWindows(out_dir): """Add required environment variables for Ninja build.""" python_path_root = MOZC_ROOT @@ -356,22 +377,14 @@ def UpdateEnvironmentFilesForWindows(out_dir): original_python_paths = os.environ.get('PYTHONPATH', '') if original_python_paths: python_path = os.pathsep.join([original_python_paths, python_path]) - nul = chr(0) - additional_content = nul.join([ - 'PYTHONPATH=' + python_path, - 'VSLANG=1033', # 1033 == MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US) - nul]).encode('utf-8') for d in os.listdir(out_dir): abs_dir = os.path.abspath(os.path.join(out_dir, d)) - with open(os.path.join(abs_dir, 'environment.x86'), 'rb') as x86_file: - x86_content = x86_file.read()[:-1] + additional_content - with open(os.path.join(abs_dir, 'environment.x86'), 'wb') as x86_file: - x86_file.write(x86_content) - with open(os.path.join(abs_dir, 'environment.x64'), 'rb') as x64_file: - x64_content = x64_file.read()[:-1] + additional_content - with open(os.path.join(abs_dir, 'environment.x64'), 'wb') as x64_file: - x64_file.write(x64_content) - + for arch in ['x86', 'x64']: + env_file = os.path.join(abs_dir, f'environment.{arch}') + env = ReadEnvironmentFile(env_file) + env['PYTHONPATH'] = python_path + env['VSLANG'] = '1033' # == MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US) + WriteEnvironmentFile(env_file, env) def GypMain(options, unused_args):