fix(buck2): allow rustc to use Nix environment when compiling #2266
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.
This change enables our project to build using the Nix environment running on Linux and macOS platforms.
Background
The upstream
rustc_action.py
script which invokesrustc
filters the environment in an effort to maintain a better sandboxed build. When we build in a Nix environment (currently used for development and shortly in CI), there are several environment variables that cause the correct linking behavior under Nix.The Nix environment provides wrapper scripts for
clang
andclang++
which use these environment variables. Therustc
program is responsible for invoking the linker (by default this tends to becc
/clang
) which means these environment variables need to be present in therustc
process so that its children can inherit them.The Fix
While there were many attempts at a solution to this problem, we went with a "patch the upstream" approach. In other words, the
rustc_action.py
script is what prevents our correct Nix behavior, so we slightly augmented it with support for more environment variables. This script is provided to us via the upstreamfacebookincubator/buck2-prelude
Git repository which we currently vendor usinggit subtree
. This means that our "patch" will be wiped out when we re-vendor/update against upstream changes. With this in mind, we provide athird-party/patches/nix_rustc_action.patch
file which should allow us to patch over upstream updates similar to upstream patching in a packaging system.