Skip to content

Commit 9d94470

Browse files
Mark Christianalexeagle
authored andcommitted
Remove BASH_BIN in favor of referencing bash via /usr/bin/env
While using rules_py in combination with rules_oci, I discovered an unexpected behaviour: rules_py generates #! shebang lines using the path to bin that the sh toolchain uses. This has the unexpected side effect of baking in the bash path from the machine that built the container, which may or may not be the same bash path that the container itself will have. I discovered that macOS, Ubuntu, and the default @python docker image all have bash at `/bin/bash`, but surprisingly, GitHub Actions workers have it at `/usr/bin/bash`. We can side step this problem entirely by using `#!/usr/bin/env bash` as our shebang line, which I believe to be sufficiently portable and robust to use for rules_py's scripts. See [this Stack Overflow](https://stackoverflow.com/questions/21612980/why-is-usr-bin-env-bash-superior-to-bin-bash) question for further discussion on the approach.
1 parent 9ee2b08 commit 9d94470

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed

MODULE.bazel.orig

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
"aspect-build/rules_py"
2+
3+
module(
4+
name = "aspect_rules_py",
5+
compatibility_level = 1,
6+
version = "0.0.0",
7+
)
8+
9+
# Lower-bound versions of direct dependencies.
10+
# When bumping, add a comment explaining what's required from the newer release.
11+
bazel_dep(name = "aspect_bazel_lib", version = "1.40.0")
12+
bazel_dep(name = "bazel_skylib", version = "1.4.2")
13+
bazel_dep(name = "rules_python", version = "0.29.0")
14+
bazel_dep(name = "platforms", version = "0.0.7")
15+
16+
tools = use_extension("//py:extensions.bzl", "py_tools")
17+
tools.rules_py_tools()
18+
use_repo(tools, "rules_py_tools")
19+
20+
register_toolchains(
21+
"@rules_py_tools//:all",
22+
23+
# Register the "from source" toolchains last, so there's no accidental dependency on Rust
24+
# For manual testing: comment these out to force use of pre-built binaries.
25+
"@aspect_rules_py//py/private/toolchain/venv/...",
26+
"@aspect_rules_py//py/private/toolchain/unpack/...",
27+
)
28+
29+
# To allow Rust binaries in /py/tools to be built from source
30+
# NOTE: when publishing to BCR, we patch these to be dev_dependency, as we publish pre-built binaries
31+
# along with our releases.
32+
33+
bazel_dep(
34+
name = "rules_rust",
35+
version = "0.38.0",
36+
# In released versions: dev_dependency = True
37+
)
38+
39+
rust = use_extension(
40+
"@rules_rust//rust:extensions.bzl",
41+
"rust",
42+
# In released versions: dev_dependency = True
43+
)
44+
45+
rust.toolchain(
46+
edition = "2021",
47+
versions = ["1.74.1"],
48+
)
49+
use_repo(rust, "rust_toolchains")
50+
51+
register_toolchains(
52+
"@rust_toolchains//:all",
53+
# In released versions: dev_dependency = True
54+
)
55+
56+
crate = use_extension(
57+
"@rules_rust//crate_universe:extension.bzl",
58+
"crate",
59+
# In released versions: dev_dependency = True
60+
)
61+
62+
crate.from_cargo(
63+
name = "crate_index",
64+
cargo_lockfile = "//:Cargo.lock",
65+
# Apparently not needed under bzlmod?
66+
# lockfile = "//:Cargo.Bazel.lock",
67+
manifests = [
68+
"//:Cargo.toml",
69+
"//py/tools/py:Cargo.toml",
70+
"//py/tools/venv_bin:Cargo.toml",
71+
"//py/tools/unpack_bin:Cargo.toml",
72+
],
73+
)
74+
75+
use_repo(crate, "crate_index")

0 commit comments

Comments
 (0)