Replies: 1 comment
-
|
I support this direction and also believe that Starlarkifying genrule would be great, but there are likely more native-only features (e.g. the A related proposal that I unfortunately haven't found the time to fully think through: https://github.com/bazelbuild/proposals/blob/main/designs/2025-06-18-sh-toolchain-for-run-shell.md |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Summary
It should be possible to, in some way, add dependencies that are currently expected to be implicitly present to
genrules (for example, the shell or coreutils). This will allow third-party genrules to work properly when--experimental_use_hermetic_linux_sandboxis enabled.Background
We are currently trying to increase the reproducibility of our build system at my company, and in general the reproducibility of Bazel as a whole. Currently, Bazel has a few defaults that result in diminished hermeticity OOTB:
cc_toolchain, is automatically configured from the user's system.ctx.actions.run_shellandgenrulesimply assume that a shell such as Bash, and various tools such as GNU coreutils exist in the file system view.--shell_executable(used forctx.action.run_shellandgenrule) andsh_toolchain(used forsh_*targets) both take an absolute path parameter, which cannot carry dependencies into the sandbox closure.We are fixing some of our issues on our side using Nix for toolchains and final artifacts. To ensure that hermeticity is actually accomplished, we use
--experimental_use_hermetic_linux_sandboxwhich eliminates any implicit filesystem dependencies that can happen. However, some things likegenruleare currently not possible to make hermetic automatically. Further, while we could manually add a custom toolchain which would make them available, this doesn't work for third-party packages on the BCR, for example.Therefore, there should be a way to either pass a launcher to these rules that works in Unix, or a way to add default inputs to
genrulesuch that they're included by default.Suggested Approach
Assuming the launcher approach is taken:
sh_toolchainshould makelauncherused in all platforms, if available (perhaps this could be introduced in a backwards-compatible way likeunix_launcher).launchershould be exposed togenruleby:CcToolchainInfo, introducing a toolchain type that Java can recognize, and makesh_toolchainemit this provider. (This is definitely not my favorite approach because it adds more stuff to the Java side.)genruleto be completely Starlark-based, making anything Java-only that it needs available to Starlark as well (I looked throughGenRuleBaseand nothing jumped out as being impossible to do in Starlark, except perhaps observing--stampwhich there is an open issue for: Allow Starlark rules to observe the--stampsetting #11164), and then depending on the shell toolchain in the rule definition.ctx.action.run_shellwould work. In my mind it's kind of a misfeature anyhow.genruleshould use thelauncherinstead of the hardcoded default shell for running the code. This launcher would then adjust thePATHto make available a set of binaries thatgenrules are likely to want before exec'ing into the shell.I'm aware that making stuff like the shell completely hermetic by default is likely out-of-scope for Bazel; therefore, doing this would give the leeway for projects to set it up themselves.
Workarounds
There is currently a workaround to this in the form of the obscure
bazel_preludefunctionality, which would allow us to overridegenrulewith a rule that doesctx.actions.runon the hermetic launcher.Beta Was this translation helpful? Give feedback.
All reactions