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

Inline mozc_win_build_target in build_defs.bzl #1160

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
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 = [
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move this block (line 309 - 321) after mozc_cc_binary (line 322 - 336) to keep the consistency with the current implementation. It causes an error in my environment.

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