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

Rely on CC toolchain resolution on Windows Bazel builds #1156

Merged
merged 1 commit into from
Jan 8, 2025
Merged
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
16 changes: 11 additions & 5 deletions src/.bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,17 @@ test:macos_env --test_tag_filters=-nomac
build:windows_env --build_tag_filters=-nowin
test:windows_env --test_tag_filters=-nowin

# A temporary workaround to make "mozc_win_build_rule" work.
# Note that "incompatible_enable_cc_toolchain_resolution" is now enabled by
# default. See https://github.com/bazelbuild/bazel/issues/7260
# TODO: Re-enable "incompatible_enable_cc_toolchain_resolution"
build:windows_env --noincompatible_enable_cc_toolchain_resolution
# Bazel does not register cc toolchains for Windows by default.
# We need to explicitly specify them to be compatible with the new behavior
# introduced by --incompatible_enable_cc_toolchain_resolution
# https://github.com/google/mozc/issues/1112
# https://bazel.build/extending/toolchains#registering-building-toolchains
build:windows_env --extra_toolchains=@@rules_cc++cc_configure_extension+local_config_cc//:cc-toolchain-arm64_windows
build:windows_env --extra_toolchains=@@rules_cc++cc_configure_extension+local_config_cc//:cc-toolchain-x64_windows
build:windows_env --extra_toolchains=@@rules_cc++cc_configure_extension+local_config_cc//:cc-toolchain-x64_x86_windows
test:windows_env --extra_toolchains=@@rules_cc++cc_configure_extension+local_config_cc//:cc-toolchain-arm64_windows
test:windows_env --extra_toolchains=@@rules_cc++cc_configure_extension+local_config_cc//:cc-toolchain-x64_windows
test:windows_env --extra_toolchains=@@rules_cc++cc_configure_extension+local_config_cc//:cc-toolchain-x64_x86_windows

# Android specific options
build:android_env --copt "-DOS_ANDROID"
Expand Down
26 changes: 18 additions & 8 deletions src/build_defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -212,15 +212,15 @@ def _win_executable_transition_impl(
features = ["static_link_msvcrt"]
return {
"//command_line_option:features": features,
"//command_line_option:cpu": attr.cpu,
"//command_line_option:platforms": [attr.platform],
}

_win_executable_transition = transition(
implementation = _win_executable_transition_impl,
inputs = [],
outputs = [
"//command_line_option:features",
"//command_line_option:cpu",
"//command_line_option:platforms",
],
)

Expand All @@ -243,11 +243,10 @@ def _mozc_win_build_rule_impl(ctx):
executable = output,
)]

# The follwoing CPU values are mentioned in https://bazel.build/configure/windows#build_cpp
CPU = struct(
ARM64 = "arm64_windows", # aarch64 (64-bit) environment
X64 = "x64_windows", # x86-64 (64-bit) environment
X86 = "x64_x86_windows", # x86 (32-bit) environment
ARM64 = "@platforms//cpu:arm64", # aarch64 (64-bit) environment
X64 = "@platforms//cpu:x86_64", # x86-64 (64-bit) environment
X86 = "@platforms//cpu:x86_32", # x86 (32-bit) environment
)

_mozc_win_build_rule = rule(
Expand All @@ -263,7 +262,7 @@ _mozc_win_build_rule = rule(
mandatory = True,
),
"static_crt": attr.bool(),
"cpu": attr.string(),
"platform": attr.label(),
},
)

Expand Down Expand Up @@ -311,6 +310,7 @@ def mozc_win_build_target(
**kwargs: other arguments passed to mozc_objc_library.
"""
mandatory_target_compatible_with = [
cpu,
"@platforms//os:windows",
]
for item in mandatory_target_compatible_with:
Expand All @@ -322,10 +322,20 @@ def mozc_win_build_target(
if item not in tags:
tags.append(item)

platform_name = "_" + name + "_platform"
native.platform(
name = platform_name,
constraint_values = [
cpu,
"@platforms//os:windows",
],
visibility = ["//visibility:private"],
)

_mozc_win_build_rule(
name = name,
target = target,
cpu = cpu,
platform = platform_name,
static_crt = static_crt,
target_compatible_with = target_compatible_with,
tags = tags,
Expand Down
2 changes: 1 addition & 1 deletion src/gui/tool/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ mozc_cc_qt_binary(

mozc_win32_cc_prod_binary(
name = "mozc_tool_win",
cpu = "x64_windows",
cpu = "@platforms//cpu:x86_64",
executable_name_map = {
"Mozc": "mozc_tool.exe",
"GoogleJapaneseInput": "GoogleIMEJaTool.exe",
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/win32/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ package(
mozc_win32_cc_prod_binary(
name = "win32_renderer_main",
srcs = ["win32_renderer_main.cc"],
cpu = "x64_windows",
cpu = "@platforms//cpu:x86_64",
executable_name_map = {
"Mozc": "mozc_renderer.exe",
"GoogleJapaneseInput": "GoogleIMEJaRenderer.exe",
Expand Down
2 changes: 1 addition & 1 deletion src/server/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ mozc_cc_binary(

mozc_win32_cc_prod_binary(
name = "mozc_server_win",
cpu = "x64_windows",
cpu = "@platforms//cpu:x86_64",
executable_name_map = {
"Mozc": "mozc_server.exe",
"GoogleJapaneseInput": "GoogleIMEJaConverter.exe",
Expand Down
2 changes: 1 addition & 1 deletion src/win32/broker/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ package(
mozc_win32_cc_prod_binary(
name = "mozc_broker_main",
srcs = ["mozc_broker_main.cc"],
cpu = "x64_windows",
cpu = "@platforms//cpu:x86_64",
executable_name_map = {
"Mozc": "mozc_broker.exe",
"GoogleJapaneseInput": "GoogleIMEJaBroker.exe",
Expand Down
2 changes: 1 addition & 1 deletion src/win32/cache_service/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ package(default_visibility = ["//:__subpackages__"])
mozc_win32_cc_prod_binary(
name = "mozc_cache_service",
srcs = ["mozc_cache_service.cc"],
cpu = "x64_windows",
cpu = "@platforms//cpu:x86_64",
executable_name_map = {
"Mozc": "mozc_cache_service.exe",
"GoogleJapaneseInput": "GoogleIMEJaCacheService.exe",
Expand Down
2 changes: 1 addition & 1 deletion src/win32/custom_action/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ mozc_win32_cc_prod_binary(
"custom_action.h",
"resource.h",
],
cpu = "x64_windows",
cpu = "@platforms//cpu:x86_64",
executable_name_map = {
"Mozc": "mozc_installer_helper.dll",
"GoogleJapaneseInput": "GoogleIMEJaInstallerHelper.dll",
Expand Down
4 changes: 2 additions & 2 deletions src/win32/tip/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ mozc_cc_library(
mozc_win32_cc_prod_binary(
name = "mozc_tip32",
srcs = ["mozc_tip_main.cc"],
cpu = "x64_x86_windows",
cpu = "@platforms//cpu:x86_32",
executable_name_map = {
"Mozc": "mozc_tip32.dll",
"GoogleJapaneseInput": "GoogleIMEJaTIP32.dll",
Expand All @@ -87,7 +87,7 @@ mozc_win32_cc_prod_binary(
mozc_win32_cc_prod_binary(
name = "mozc_tip64",
srcs = ["mozc_tip_main.cc"],
cpu = "x64_windows",
cpu = "@platforms//cpu:x86_64",
executable_name_map = {
"Mozc": "mozc_tip64.dll",
"GoogleJapaneseInput": "GoogleIMEJaTIP64.dll",
Expand Down