Skip to content

Commit 8ac324e

Browse files
bazel-ioBoleynSu
andauthored
[9.0.2] Fix launcher/launcher_maker for cross build (#29200) (#29238)
### Description Fix launcher/launcher_maker for cross build. launcher will be used in the build output, so it should use cfg=target. launcher_maker is used to combine a binary for target and launcher for target into the final output at build time, so it should use cfg=exec. ### Motivation To make py_binary launcher work when building on linux (exec) for windows (target). ### Build API Changes No ### Checklist - [ ] I have added tests for the new use cases (if any). - [ ] I have updated the documentation (if applicable). ### Release Notes RELNOTES: Fix launcher/launcher_maker for cross build, e.g. build windows binary on linux machine. Closes #29200. PiperOrigin-RevId: 895761405 Change-Id: I0b3dd3431d25fb4fb9ea827f344eb5cf42c11276 Commit 4ff3127 Co-authored-by: Boleyn Su <boleyn.su@gmail.com>
1 parent 48f447a commit 8ac324e

3 files changed

Lines changed: 31 additions & 9 deletions

File tree

tools/build_defs.bzl

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,17 @@ def _single_binary_toolchain_rule_impl(ctx):
2727
binary = ctx.file.binary,
2828
)
2929

30-
_single_binary_toolchain_rule = rule(
30+
_single_target_binary_toolchain_rule = rule(
31+
implementation = _single_binary_toolchain_rule_impl,
32+
attrs = {
33+
"binary": attr.label(
34+
allow_single_file = True,
35+
mandatory = True,
36+
),
37+
},
38+
)
39+
40+
_single_exec_binary_toolchain_rule = rule(
3141
implementation = _single_binary_toolchain_rule_impl,
3242
attrs = {
3343
"binary": attr.label(
@@ -41,12 +51,24 @@ def single_binary_toolchain(
4151
*,
4252
name,
4353
toolchain_type,
44-
binary = None,
54+
target_binary = None,
55+
exec_binary = None,
4556
target_compatible_with = [],
4657
exec_compatible_with = []):
4758
"""Declares a toolchain together with its implementation for an optional single binary."""
4859
impl_name = name + "_impl"
4960

61+
if exec_binary and target_binary:
62+
fail("Cannot specify both exec_binary and target_binary for a single_binary_toolchain.")
63+
elif target_binary:
64+
binary = target_binary
65+
_single_binary_toolchain_rule = _single_target_binary_toolchain_rule
66+
elif exec_binary:
67+
binary = exec_binary
68+
_single_binary_toolchain_rule = _single_exec_binary_toolchain_rule
69+
else:
70+
fail("Must specify either exec_binary or target_binary for a single_binary_toolchain.")
71+
5072
_single_binary_toolchain_rule(
5173
name = impl_name,
5274
binary = binary,

tools/launcher/BUILD.bootstrap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ toolchain_type(name = "launcher_maker_toolchain_type")
1616

1717
single_binary_toolchain(
1818
name = "foo",
19-
binary = ":launcher_maker",
19+
exec_binary = ":launcher_maker",
2020
toolchain_type = "launcher_maker_toolchain_type",
2121
)

tools/launcher/BUILD.tools

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,41 +43,41 @@ toolchain_type(name = "launcher_maker_toolchain_type")
4343
# needing to build from source.
4444
IS_HOST_WINDOWS and single_binary_toolchain(
4545
name = "1_prebuilt_launcher",
46-
binary = "launcher.exe",
46+
target_binary = "launcher.exe",
4747
target_compatible_with = HOST_CONSTRAINTS,
4848
toolchain_type = ":launcher_toolchain_type",
4949
)
5050

5151
single_binary_toolchain(
5252
name = "2_source_launcher_toolchain",
53-
binary = "//src/tools/launcher",
53+
target_binary = "//src/tools/launcher",
5454
target_compatible_with = ["@platforms//os:windows"],
5555
toolchain_type = ":launcher_toolchain_type",
5656
)
5757

5858
single_binary_toolchain(
5959
name = "3_no_launcher_toolchain",
60-
binary = "empty.sh",
60+
target_binary = "empty.sh",
6161
toolchain_type = ":launcher_toolchain_type",
6262
)
6363

6464
IS_HOST_WINDOWS and single_binary_toolchain(
6565
name = "1_prebuilt_launcher_maker",
66-
binary = "launcher_maker.exe",
66+
exec_binary = "launcher_maker.exe",
6767
exec_compatible_with = HOST_CONSTRAINTS,
6868
target_compatible_with = ["@platforms//os:windows"],
6969
toolchain_type = ":launcher_maker_toolchain_type",
7070
)
7171

7272
single_binary_toolchain(
7373
name = "2_source_launcher_maker_toolchain",
74-
binary = "//src/tools/launcher:launcher_maker",
74+
exec_binary = "//src/tools/launcher:launcher_maker",
7575
target_compatible_with = ["@platforms//os:windows"],
7676
toolchain_type = ":launcher_maker_toolchain_type",
7777
)
7878

7979
single_binary_toolchain(
8080
name = "3_no_launcher_maker_toolchain",
81-
binary = "empty.sh",
81+
exec_binary = "empty.sh",
8282
toolchain_type = ":launcher_maker_toolchain_type",
8383
)

0 commit comments

Comments
 (0)