Skip to content

Commit

Permalink
Inline mozc_win_build_target in build_defs.bzl
Browse files Browse the repository at this point in the history
This follows up to our previous commit [1], which intended to be a
preparation to address google#1109.

As another preparation this commit aims to simplify 'build_defs.bzl' by
inlining 'mozc_win_build_target' into 'mozc_win32_cc_prod_binary'.

There must be no change in the final artifacts.

 [1]: bc546b2
  • Loading branch information
yukawa committed Jan 8, 2025
1 parent 4aad25e commit 5177cc2
Showing 1 changed file with 25 additions and 78 deletions.
103 changes: 25 additions & 78 deletions src/build_defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -266,82 +266,6 @@ _mozc_win_build_rule = rule(
},
)

# 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 = [
cpu,
"@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)

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,
platform = platform_name,
static_crt = static_crt,
target_compatible_with = target_compatible_with,
tags = tags,
**kwargs
)

def mozc_win32_cc_prod_binary(
name,
executable_name_map = {}, # @unused
Expand Down Expand Up @@ -382,6 +306,19 @@ def mozc_win32_cc_prod_binary(
visibility: optional. The visibility of the target.
**kwargs: other arguments passed to mozc_cc_binary.
"""
mandatory_target_compatible_with = [
cpu,
"@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)

target_name = name + "_cc_binary"
mozc_cc_binary(
name = target_name,
Expand All @@ -397,9 +334,19 @@ def mozc_win32_cc_prod_binary(
**kwargs
)

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

_mozc_win_build_rule(
name = name,
cpu = cpu,
platform = platform_name,
static_crt = static_crt,
tags = tags,
target = target_name,
Expand Down

0 comments on commit 5177cc2

Please sign in to comment.