Skip to content

Commit be0ae53

Browse files
dzbarskygithub-actions[bot]
authored andcommitted
fix: run executable zip action with execution Python to better support windows building (#3890)
The legacy self-executable zip action invokes `cat` through `run_shell`. The action does not declare `cat`, and a Windows-hosted Bazel invocation cannot use that action reliably when the selected execution platform is Linux. Run the existing `exe_zip_maker` through `actions_run` instead. This selects the helper and Python runtime from the execution configuration, preserves the prelude-plus-zip output format, and removes the ambient shell utility dependency. A news entry documents the fix. The Bazel integration that motivated this fix is [bazelbuild/bazel#30121](bazelbuild/bazel#30121). --------- Co-authored-by: Richard Levasseur <richardlev@gmail.com> (cherry picked from commit 1d99f70) Work towards #3867
1 parent df4acbd commit be0ae53

2 files changed

Lines changed: 17 additions & 8 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ compatibility.
4646
* Fixed a flaky error on Windows 2022 when looking up the win32 version during
4747
site initialization by retrying the lookup
4848
([#3721](https://github.com/bazel-contrib/rules_python/issues/3721)).
49+
* (binaries) Fixed building of legacy zipapps on Windows execution platforms by
50+
using a hermetic tool instead of host `cat`.
4951
* (bootstrap) Fixed stage 1 bootstrap imports when target outputs shadow standard
5052
library modules.
5153
* (coverage) Skip lcov report when no data was collected.
@@ -78,6 +80,7 @@ and [#1975](https://github.com/bazel-contrib/rules_python/issues/1975).
7880

7981

8082

83+
8184
{#v2-1-0}
8285
## [2.1.0] - 2026-06-17
8386

python/private/py_executable.bzl

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ load(":cc_helper.bzl", "cc_helper")
3838
load(
3939
":common.bzl",
4040
"ExplicitSymlink",
41+
"actions_run",
4142
"collect_cc_info",
4243
"collect_deps",
4344
"collect_imports",
@@ -218,6 +219,10 @@ accepting arbitrary Python versions.
218219
default = "//python/private:debugger_if_target_config",
219220
providers = [PyInfo],
220221
),
222+
"_exe_zip_maker": lambda: attrb.Label(
223+
cfg = "exec",
224+
default = "//tools/private/zipapp:exe_zip_maker",
225+
),
221226
"_launcher": lambda: attrb.Label(
222227
cfg = "target",
223228
# NOTE: This is an executable, but is only used for Windows. It
@@ -1094,15 +1099,16 @@ def _create_executable_zip_file(
10941099
else:
10951100
ctx.actions.write(prelude, "#!/usr/bin/env python3\n")
10961101

1097-
ctx.actions.run_shell(
1098-
command = "cat {prelude} {zip} > {output}".format(
1099-
prelude = prelude.path,
1100-
zip = zip_file.path,
1101-
output = output.path,
1102-
),
1103-
inputs = [prelude, zip_file],
1102+
args = ctx.actions.args()
1103+
args.add(prelude)
1104+
args.add(zip_file)
1105+
args.add(output)
1106+
actions_run(
1107+
ctx,
1108+
executable = ctx.attr._exe_zip_maker,
1109+
arguments = [args],
1110+
inputs = depset([prelude, zip_file]),
11041111
outputs = [output],
1105-
use_default_shell_env = True,
11061112
mnemonic = "PyBuildExecutableZip",
11071113
progress_message = "Build Python zip executable: %{label}",
11081114
)

0 commit comments

Comments
 (0)