Skip to content

Commit

Permalink
Update a part of PR#1109 as a preparation to merge that PR.
Browse files Browse the repository at this point in the history
* #1109

This change is a preparation to merge PR#1109.
The difference from PR#1109 is the implementation of `mozc_win32_cc_prod_binary` and `mozc_cc_win32_library`.

* mozc_win32_cc_prod_binary: In this change, this is a wrapper of `mozc_win_build_target` migrated from `trasition.bzl` to `build_defs.bzl`.
* mozc_cc_win32_library: In this change, nothing is changed.

PiperOrigin-RevId: 704201709
  • Loading branch information
hiroyuki-komatsu committed Dec 9, 2024
1 parent bc3c413 commit bc546b2
Show file tree
Hide file tree
Showing 11 changed files with 305 additions and 266 deletions.
175 changes: 175 additions & 0 deletions src/build_defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ load("@build_bazel_rules_apple//apple:macos.bzl", "macos_application", "macos_bu
load("@windows_sdk//:windows_sdk_rules.bzl", "windows_resource")
load(
"//:config.bzl",
"BAZEL_TOOLS_PREFIX",
"BRANDING",
"MACOS_BUNDLE_ID_PREFIX",
"MACOS_MIN_OS_VER",
Expand Down Expand Up @@ -203,6 +204,180 @@ register_extension_info(
label_regex_for_dep = "{extension_name}",
)

def _win_executable_transition_impl(
settings, # @unused
attr):
features = []
if attr.static_crt:
features = ["static_link_msvcrt"]
return {
"//command_line_option:features": features,
"//command_line_option:cpu": attr.cpu,
}

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

def _mozc_win_build_rule_impl(ctx):
input_file = ctx.file.target
output = ctx.actions.declare_file(
ctx.label.name + "." + input_file.extension,
)
if input_file.path == output.path:
fail("input=%d and output=%d are the same." % (input_file.path, output.path))

# Create a symlink as we do not need to create an actual copy.
ctx.actions.symlink(
output = output,
target_file = input_file,
is_executable = True,
)
return [DefaultInfo(
files = depset([output]),
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
)

_mozc_win_build_rule = rule(
implementation = _mozc_win_build_rule_impl,
cfg = _win_executable_transition,
attrs = {
"_allowlist_function_transition": attr.label(
default = BAZEL_TOOLS_PREFIX + "//tools/allowlists/function_transition_allowlist",
),
"target": attr.label(
allow_single_file = [".dll", ".exe"],
doc = "the actual Bazel target to be built.",
mandatory = True,
),
"static_crt": attr.bool(),
"cpu": attr.string(),
},
)

# Define a transition target with the given build target with the given build configurations.
#
# For instance, the following code creates a target "my_target" with setting "cpu" as "x64_windows"
# and setting "static_link_msvcrt" feature.
#
# mozc_win_build_rule(
# name = "my_target",
# cpu = CPU.X64,
# static_crt = True,
# target = "//bath/to/target:my_target",
# )
#
# See the following page for the details on transition.
# https://bazel.build/rules/lib/builtins/transition
def mozc_win_build_target(
name,
target,
cpu = CPU.X64,
static_crt = False,
target_compatible_with = [],
tags = [],
**kwargs):
"""Define a transition target with the given build target with the given build configurations.
The following code creates a target "my_target" with setting "cpu" as "x64_windows" and setting
"static_link_msvcrt" feature.
mozc_win_build_target(
name = "my_target",
cpu = CPU.X64,
static_crt = True,
target = "//bath/to/target:my_target",
)
Args:
name: name of the target.
target: the actual Bazel target to be built with the specified configurations.
cpu: CPU type of the target.
static_crt: True if the target should be built with static CRT.
target_compatible_with: optional. Visibility for the unit test target.
tags: optional. Tags for both the library and unit test targets.
**kwargs: other arguments passed to mozc_objc_library.
"""
mandatory_target_compatible_with = [
"@platforms//os:windows",
]
for item in mandatory_target_compatible_with:
if item not in target_compatible_with:
target_compatible_with.append(item)

mandatory_tags = MOZC_TAGS.WIN_ONLY
for item in mandatory_tags:
if item not in tags:
tags.append(item)

_mozc_win_build_rule(
name = name,
target = target,
cpu = cpu,
static_crt = static_crt,
target_compatible_with = target_compatible_with,
tags = tags,
**kwargs
)

def mozc_win32_cc_prod_binary(
name,
executable_name_map = {}, # @unused
srcs = [], # @unused
deps = [], # @unused
linkopts = [], # @unused
cpu = CPU.X64,
static_crt = False,
tags = MOZC_TAGS.WIN_ONLY,
win_def_file = None, # @unused
target_compatible_with = ["@platforms//os:windows"],
visibility = ["//visibility:public"], # @unused
**kwargs):
"""A rule to build production binaries for Windows.
This wraps mozc_cc_binary so that you can specify the target CPU
architecture and CRT linkage type in a declarative manner with also building
a debug symbol file (*.pdb).
Implicit output targets:
name.pdb: A debug symbol file.
Args:
name: name of the target.
executable_name_map: a map from the branding name to the executable name.
srcs: .cc files to build the executable.
deps: deps to build the executable.
linkopts: linker options to build the executable.
cpu: optional. The target CPU architecture.
static_crt: optional. True if the target should be built with static CRT.
tags: optional. Tags for both the library and unit test targets.
win_def_file: optional. win32 def file to define exported functions.
target_compatible_with: optional. Defines target platforms.
visibility: optional. The visibility of the target.
**kwargs: other arguments passed to mozc_cc_binary.
"""
mozc_win_build_target(
name = name,
target = "//data/prod:prod_binary",
cpu = cpu,
static_crt = static_crt,
target_compatible_with = target_compatible_with,
tags = tags,
**kwargs
)

def mozc_cc_win32_library(
name,
srcs = [],
Expand Down
19 changes: 19 additions & 0 deletions src/gui/tool/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ load(
"MOZC_TAGS",
"mozc_cc_library",
"mozc_select",
"mozc_win32_cc_prod_binary",
"mozc_win32_resource_from_template",
)
load("//:config.bzl", "BRANDING")
Expand Down Expand Up @@ -132,6 +133,24 @@ mozc_cc_qt_binary(
),
)

mozc_win32_cc_prod_binary(
name = "mozc_tool_win",
cpu = "x64_windows",
executable_name_map = {
"Mozc": "mozc_tool.exe",
"GoogleJapaneseInput": "GoogleIMEJaTool.exe",
},
static_crt = False,
tags = MOZC_TAGS.WIN_ONLY,
target_compatible_with = ["@platforms//os:windows"],
visibility = ["//:__subpackages__"],
deps = [
":mozc_tool_main_lib",
":mozc_tool_win32_resource",
"@qt_win",
],
)

mozc_macos_qt_application(
name = "mozc_tool_macos",
bundle_name = "MozcTool",
Expand Down
9 changes: 8 additions & 1 deletion src/renderer/win32/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ load(
"mozc_cc_binary",
"mozc_cc_library",
"mozc_cc_test",
"mozc_win32_cc_prod_binary",
"mozc_win32_resource_from_template",
)

Expand All @@ -44,9 +45,15 @@ package(
features = ["gdi"],
)

mozc_cc_binary(
mozc_win32_cc_prod_binary(
name = "win32_renderer_main",
srcs = ["win32_renderer_main.cc"],
cpu = "x64_windows",
executable_name_map = {
"Mozc": "mozc_renderer.exe",
"GoogleJapaneseInput": "GoogleIMEJaRenderer.exe",
},
static_crt = False,
tags = MOZC_TAGS.WIN_ONLY,
target_compatible_with = ["@platforms//os:windows"],
visibility = ["//win32/installer:__subpackages__"], # Scheuklappen: keep
Expand Down
18 changes: 18 additions & 0 deletions src/server/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@

load(
"//:build_defs.bzl",
"MOZC_TAGS",
"mozc_cc_binary",
"mozc_cc_library",
"mozc_macos_application",
"mozc_select",
"mozc_win32_cc_prod_binary",
"mozc_win32_resource_from_template",
)
load(
Expand All @@ -55,6 +57,22 @@ mozc_cc_binary(
),
)

mozc_win32_cc_prod_binary(
name = "mozc_server_win",
cpu = "x64_windows",
executable_name_map = {
"Mozc": "mozc_server.exe",
"GoogleJapaneseInput": "GoogleIMEJaConverter.exe",
},
static_crt = False,
tags = MOZC_TAGS.WIN_ONLY,
target_compatible_with = ["@platforms//os:windows"],
deps = [
":mozc_server_lib",
":mozc_server_resources",
],
)

mozc_win32_resource_from_template(
name = "mozc_server_resources",
src = "mozc_server.rc",
Expand Down
10 changes: 8 additions & 2 deletions src/win32/broker/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,24 @@
load(
"//:build_defs.bzl",
"MOZC_TAGS",
"mozc_cc_binary",
"mozc_cc_library",
"mozc_win32_cc_prod_binary",
"mozc_win32_resource_from_template",
)

package(
default_visibility = ["//visibility:private"],
)

mozc_cc_binary(
mozc_win32_cc_prod_binary(
name = "mozc_broker_main",
srcs = ["mozc_broker_main.cc"],
cpu = "x64_windows",
executable_name_map = {
"Mozc": "mozc_broker.exe",
"GoogleJapaneseInput": "GoogleIMEJaBroker.exe",
},
static_crt = False,
tags = MOZC_TAGS.WIN_ONLY,
target_compatible_with = ["@platforms//os:windows"],
visibility = ["//win32/installer:__subpackages__"], # Scheuklappen: keep
Expand Down
10 changes: 8 additions & 2 deletions src/win32/cache_service/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,22 @@ load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library")
load(
"//:build_defs.bzl",
"MOZC_TAGS",
"mozc_cc_binary",
"mozc_cc_library",
"mozc_win32_cc_prod_binary",
"mozc_win32_resource_from_template",
)

package(default_visibility = ["//:__subpackages__"])

mozc_cc_binary(
mozc_win32_cc_prod_binary(
name = "mozc_cache_service",
srcs = ["mozc_cache_service.cc"],
cpu = "x64_windows",
executable_name_map = {
"Mozc": "mozc_cache_service.exe",
"GoogleJapaneseInput": "GoogleIMEJaCacheService.exe",
},
static_crt = False,
tags = MOZC_TAGS.WIN_ONLY,
target_compatible_with = ["@platforms//os:windows"],
deps = [
Expand Down
11 changes: 8 additions & 3 deletions src/win32/custom_action/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,23 @@
load(
"//:build_defs.bzl",
"MOZC_TAGS",
"mozc_cc_binary",
"mozc_win32_cc_prod_binary",
"mozc_win32_resource_from_template",
)

mozc_cc_binary(
mozc_win32_cc_prod_binary(
name = "custom_action",
srcs = [
"custom_action.cc",
"custom_action.h",
"resource.h",
],
linkshared = True,
cpu = "x64_windows",
executable_name_map = {
"Mozc": "mozc_installer_helper.dll",
"GoogleJapaneseInput": "GoogleIMEJaInstallerHelper.dll",
},
static_crt = True,
tags = MOZC_TAGS.WIN_ONLY,
target_compatible_with = ["@platforms//os:windows"],
visibility = ["//win32/installer:__subpackages__"], # Scheuklappen: keep
Expand Down
Loading

0 comments on commit bc546b2

Please sign in to comment.