Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What type of PR is this?
This is small PR to provide a proof of concept idea to allow "impure environment variables" to be passed into the rules_go sandbox. This is mostly for a discussion, as I imagine the "owners" of rules_go will have their own and probably better ideas for how to do this.
Really, I just wanted to be able to set LD_LIBRARY_PATH within the sandbox, but I implemented this in a very generic way, so that any environment variable can be set. Maybe people will want to limit this to a specific set of variable, or to exactly LD_LIBRARY_PATH. The docs do include WARNINGS about why this is a bad idea.
This is arguably a bug fix, and is a new feature.
What does this PR do? Why is it needed?
This PR allows environment variables to be set within the sandbox for rules_go.
The reason is that for golang race tests, the go code needs to be linked against the libraries precompiled with LLVM, and so you need a linker. The problem is that the ld.lld linker needs libxml2.so.2, and there's no way currently to set the LD_LIBRARY_PATH, so you can't supply libxml2.so.2 via a sysroot.
This PR introduces "impure_env" to allow you to set LD_LIBRARY_PATH, or any other environment variable.
Which issues(s) does this PR fix?
With this PR, I'm able to use bazel on NixOS to run the go race tests!
Fixes #
#4360
Other notes for review
To demonstrate this, there is a very simple repo: https://github.com/randomizedcoder/go_hello_world_race
The idea is to demonstrate how to execute go race tests.
The repo includes nix configuration to create a sysroot, which is hosted here: https://github.com/randomizedcoder/bazel_remote_runner_sysroot/
The sysroot contains the basic libraries clang needs to link the code required for the race test. Please note the included libraries is currently more than is strictly required, but the repo is still only ~22MB, so it's not too bad.
https://github.com/randomizedcoder/go_hello_world_race/blob/main/sysroot/default.nix#L6
The patched rules_go is currently applied as an archive_override in this repo :https://github.com/randomizedcoder/go_hello_world_race/blob/main/MODULE.bazel#L21
With the new rules_go, I'm finally after weeks for trying able to run go race tests with bazel!!
Looking forward to discussing the idea with you.
Thanks in advance,
Dave