chore: Do not bust Rust build cache when opening projects with dev build #26278
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.
Problem
Running
cargo run .
twice in Zed repository required a rebuild two times in a row. The second rebuild was triggered around libz-sys, which in practice caused a rebuild of the ~entire project.Some concrete examples:
or
What's going on
Zed build script on MacOS sets MACOSX_DEPLOYMENT_TARGET to 10.15. This is fine. However, cargo propagates all environment variables to child processes during
cargo run
. This then affects Rust Analyzer spawned by dev Zed - it clobbers build cache of whatever package it touches, because it's behavior is not same between running it withcargo run
(where MACOS_DEPLOYMENT_TARGET gets propagated to child Zed) and running it directly viatarget/debug/zed
or whatever (where the env variable is not set, so that build behaves roughly like Zed Dev.app).Solution
We'll unset that env variable from user environment when we're reasonably confident that we're running undercargo run
by exploiting other env variables set by cargo: https://doc.rust-lang.org/cargo/reference/environment-variables.html CARGO_PKG_NAME is always set tozed
when running it viacargo run
, as it's the value propagated from the build.The alternative I've considered is running via a custom runner, though the problem here is that we'd have to use a shell script to unset the env variable - that could be problematic with e.g. fish. I just didn't want to deal with that, though admittedly it would've been cleaner in other aspects.Redact all above. We'll just set MACOSX_DEPLOYMENT_TARGET regardless of whether you have it in your OG shell environment or not. This means that
target/debug/zed
is now the one that can run into the same problem, but.. 🤷Release Notes: