Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Recompiles due to RUSTC_BOOTSTRAP #16621

Merged
merged 2 commits into from
Feb 23, 2024

Conversation

txase
Copy link
Contributor

@txase txase commented Feb 21, 2024

Some packages (e.g. thiserror) force a recompile if the value of the RUSTC_BOOTSTRAP env var changes. RA sets the variable to 1 in order to enable rustc / cargo unstable options. This causes flapping recompiles when building outside of RA.

Fixes #15057

Some packages (e.g. thiserror) force a recompile if the value of the `RUSTC_BOOTSTRAP` env var changes. RA sets the variable to 1 in order to enable rustc / cargo unstable options it uses. This causes flapping recompiles when building outside of RA.

As of Cargo 1.75 the `--keep-going` flag is stable. This change uses the flag without `RUSTC_BOOTSTRAP` if the Cargo version is >= 1.75, and drops `--keep-going` otherwise. This fixes build script recompilation.
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 21, 2024
`cargo rustc -- <args>` first builds dependencies then calls `rustc <args>` for the current package. Here, we don't want to build dependencies, we just want to call `rustc --print`. An unstable `cargo rustc` `--print` command bypasses building dependencies first. This speeds up execution of this code path and ensures RA doesn't recompile dependencies with the `RUSTC_BOOTSRAP=1` env var flag set.

Note that we must pass `-Z unstable-options` twice, first to enable the `cargo` unstable `--print` flag, then later to enable the unstable `rustc` `target-spec-json` print request.
@txase txase force-pushed the no-build-with-bootstrap branch from dc54800 to 2826eb5 Compare February 21, 2024 03:17
Comment on lines +35 to +44
.args([
"rustc",
"-Z",
"unstable-options",
"--print",
"target-spec-json",
"--",
"-Z",
"unstable-options",
])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this an accidental change (from debugging perhaps)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While it looks wonky, it's intended. I explained it in the commit message for this change, which I'm pasting here:

cargo rustc -- <args> first builds dependencies then calls rustc <args> for the current package. Here, we don't want to build dependencies, we just want to call rustc --print. An unstable cargo rustc --print command bypasses building dependencies first. This speeds up execution of this code path and ensures RA doesn't recompile dependencies with the RUSTC_BOOTSRAP=1 env var flag set.

Note that we must pass -Z unstable-options twice, first to enable the cargo unstable --print flag, then later to enable the unstable rustc target-spec-json print request.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see, I was very confused by the invoked command as it looks somewhat funny 😅

This is a great change thanks, I've been wondering if we could do better as one other downside of the current command is that it doesnt work in virtual workspaces, whereas this does!

@Veykril Veykril mentioned this pull request Feb 23, 2024
@Veykril
Copy link
Member

Veykril commented Feb 23, 2024

Thanks! This is a nice small change!
@bors r+

@bors
Copy link
Contributor

bors commented Feb 23, 2024

📌 Commit 2826eb5 has been approved by Veykril

It is now in the queue for this repository.

@bors
Copy link
Contributor

bors commented Feb 23, 2024

⌛ Testing commit 2826eb5 with merge 838523d...

@bors
Copy link
Contributor

bors commented Feb 23, 2024

☀️ Test successful - checks-actions
Approved by: Veykril
Pushing 838523d to master...

@bors bors merged commit 838523d into rust-lang:master Feb 23, 2024
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

rust-analyzer can invoke build scripts with RUSTC_BOOTSTRAP=1, wreaking havoc on feature detection
4 participants