From 5177cc2fffafd2d05f394f605e1e818c8e5695e0 Mon Sep 17 00:00:00 2001 From: Yohei Yukawa Date: Wed, 8 Jan 2025 21:56:07 +0900 Subject: [PATCH] Inline `mozc_win_build_target` in `build_defs.bzl` This follows up to our previous commit [1], which intended to be a preparation to address #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]: bc546b239bccff494773104e108ba08fcff40d5b --- src/build_defs.bzl | 103 +++++++++++---------------------------------- 1 file changed, 25 insertions(+), 78 deletions(-) diff --git a/src/build_defs.bzl b/src/build_defs.bzl index 715150cee..e41a65960 100644 --- a/src/build_defs.bzl +++ b/src/build_defs.bzl @@ -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 @@ -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, @@ -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,