Skip to content

Commit 0d2cf67

Browse files
committed
Use the launcher_maker toolchain if available
1 parent c678623 commit 0d2cf67

File tree

6 files changed

+55
-12
lines changed

6 files changed

+55
-12
lines changed

MODULE.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module(
44
compatibility_level = 1,
55
)
66

7-
bazel_dep(name = "bazel_features", version = "1.21.0")
7+
bazel_dep(name = "bazel_features", version = "1.30.0")
88
bazel_dep(name = "bazel_skylib", version = "1.7.1")
99
bazel_dep(name = "rules_cc", version = "0.0.16")
1010
bazel_dep(name = "platforms", version = "0.0.11")

internal_dev_deps.bzl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,9 @@ def rules_python_internal_deps():
221221

222222
http_archive(
223223
name = "bazel_features",
224-
sha256 = "d7787da289a7fb497352211ad200ec9f698822a9e0757a4976fd9f713ff372b3",
225-
strip_prefix = "bazel_features-1.9.1",
226-
url = "https://github.com/bazel-contrib/bazel_features/releases/download/v1.9.1/bazel_features-v1.9.1.tar.gz",
224+
sha256 = "a660027f5a87f13224ab54b8dc6e191693c554f2692fcca46e8e29ee7dabc43b",
225+
strip_prefix = "bazel_features-1.30.0",
226+
url = "https://github.com/bazel-contrib/bazel_features/releases/download/v1.30.0/bazel_features-v1.30.0.tar.gz",
227227
)
228228

229229
http_archive(

python/private/py_executable.bzl

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# limitations under the License.
1414
"""Common functionality between test/binary executables."""
1515

16+
load("@bazel_features//:features.bzl", "bazel_features")
1617
load("@bazel_skylib//lib:dicts.bzl", "dicts")
1718
load("@bazel_skylib//lib:paths.bzl", "paths")
1819
load("@bazel_skylib//lib:structs.bzl", "structs")
@@ -70,6 +71,7 @@ _py_builtins = py_internal
7071
_EXTERNAL_PATH_PREFIX = "external"
7172
_ZIP_RUNFILES_DIRECTORY_NAME = "runfiles"
7273
_PYTHON_VERSION_FLAG = str(Label("//python/config_settings:python_version"))
74+
_LAUNCHER_MAKER_TOOLCHAIN_TYPE = "@bazel_tools//tools/launcher:launcher_maker_toolchain_type"
7375

7476
# Non-Google-specific attributes for executables
7577
# These attributes are for rules that accept Python sources.
@@ -228,17 +230,19 @@ accepting arbitrary Python versions.
228230
"@platforms//os:windows",
229231
],
230232
),
231-
"_windows_launcher_maker": lambda: attrb.Label(
232-
default = "@bazel_tools//tools/launcher:launcher_maker",
233-
cfg = "exec",
234-
executable = True,
235-
),
236233
"_zipper": lambda: attrb.Label(
237234
cfg = "exec",
238235
executable = True,
239236
default = "@bazel_tools//tools/zip:zipper",
240237
),
241238
},
239+
{
240+
"_windows_launcher_maker": lambda: attrb.Label(
241+
default = "@bazel_tools//tools/launcher:launcher_maker",
242+
cfg = "exec",
243+
executable = True,
244+
),
245+
} if not bazel_features.rules._has_launcher_maker_toolchain else {},
242246
)
243247

244248
def convert_legacy_create_init_to_int(kwargs):
@@ -842,6 +846,11 @@ def _create_stage1_bootstrap(
842846
substitutions = subs,
843847
)
844848

849+
def _find_launcher_maker(ctx):
850+
if bazel_features.rules._has_launcher_maker_toolchain:
851+
return ctx.toolchains[_LAUNCHER_MAKER_TOOLCHAIN_TYPE].binary
852+
return ctx.executable._windows_launcher_maker
853+
845854
def _create_windows_exe_launcher(
846855
ctx,
847856
*,
@@ -862,7 +871,7 @@ def _create_windows_exe_launcher(
862871

863872
launcher = ctx.attr._launcher[DefaultInfo].files_to_run.executable
864873
ctx.actions.run(
865-
executable = ctx.executable._windows_launcher_maker,
874+
executable = _find_launcher_maker(ctx),
866875
arguments = [launcher.path, launch_info, output.path],
867876
inputs = [launcher],
868877
outputs = [output],
@@ -1910,7 +1919,7 @@ def create_executable_rule_builder(implementation, **kwargs):
19101919
ruleb.ToolchainType(TOOLCHAIN_TYPE),
19111920
ruleb.ToolchainType(EXEC_TOOLS_TOOLCHAIN_TYPE, mandatory = False),
19121921
ruleb.ToolchainType("@bazel_tools//tools/cpp:toolchain_type", mandatory = False),
1913-
],
1922+
] + ([ruleb.ToolchainType(_LAUNCHER_MAKER_TOOLCHAIN_TYPE)] if bazel_features.rules._has_launcher_maker_toolchain else []),
19141923
cfg = dict(
19151924
implementation = _transition_executable_impl,
19161925
inputs = [_PYTHON_VERSION_FLAG],

tests/base_rules/py_executable_base_tests.bzl

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ load("//python/private:util.bzl", "IS_BAZEL_7_OR_HIGHER") # buildifier: disable
2424
load("//tests/base_rules:base_tests.bzl", "create_base_tests")
2525
load("//tests/base_rules:util.bzl", "WINDOWS_ATTR", pt_util = "util")
2626
load("//tests/support:py_executable_info_subject.bzl", "PyExecutableInfoSubject")
27-
load("//tests/support:support.bzl", "BOOTSTRAP_IMPL", "CC_TOOLCHAIN", "CROSSTOOL_TOP", "LINUX_X86_64", "WINDOWS_X86_64")
27+
load("//tests/support:support.bzl", "BOOTSTRAP_IMPL", "CC_TOOLCHAIN", "CROSSTOOL_TOP", "EXOTIC_UNIX", "LINUX_X86_64", "WINDOWS_X86_64")
2828

2929
_tests = []
3030

@@ -115,6 +115,28 @@ def _test_basic_zip_impl(env, target):
115115

116116
_tests.append(_test_basic_zip)
117117

118+
def _test_cross_compile_to_unix(name, config):
119+
rt_util.helper_target(
120+
config.rule,
121+
name = name + "_subject",
122+
main_module = "dummy",
123+
)
124+
analysis_test(
125+
name = name,
126+
impl = _test_cross_compile_to_unix_impl,
127+
target = name + "_subject",
128+
config_settings = {
129+
"//command_line_option:host_platform": EXOTIC_UNIX,
130+
"//command_line_option:platforms": [EXOTIC_UNIX],
131+
},
132+
expect_failure = True,
133+
)
134+
135+
def _test_cross_compile_to_unix_impl(_, _):
136+
pass
137+
138+
_tests.append(_test_cross_compile_to_unix)
139+
118140
def _test_executable_in_runfiles(name, config):
119141
rt_util.helper_target(
120142
config.rule,

tests/support/BUILD.bazel

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,14 @@ platform(
8787
],
8888
)
8989

90+
platform(
91+
name = "exotic_unix",
92+
constraint_values = [
93+
"@platforms//os:linux",
94+
"@platforms//cpu:s390x",
95+
],
96+
)
97+
9098
current_build_settings(
9199
name = "current_build_settings",
92100
)

tests/support/support.bzl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ LINUX_X86_64 = Label("//tests/support:linux_x86_64")
2828
WINDOWS = Label("//tests/support:windows")
2929
WINDOWS_X86_64 = Label("//tests/support:windows_x86_64")
3030

31+
# Unspecified Unix platform that are unlikely to be the host platform in CI,
32+
# but still provide a Python toolchain.
33+
EXOTIC_UNIX = Label("//tests/support:exotic_unix")
34+
3135
PY_TOOLCHAINS = str(Label("//tests/support/py_toolchains:all"))
3236
CC_TOOLCHAIN = str(Label("//tests/support/cc_toolchains:all"))
3337
CROSSTOOL_TOP = Label("//tests/support/cc_toolchains:cc_toolchain_suite")

0 commit comments

Comments
 (0)