Skip to content

fix: Recompiles due to RUSTC_BOOTSTRAP #16621

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

Merged
merged 2 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions crates/project-model/src/build_scripts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ impl WorkspaceBuildScripts {
toolchain: &Option<Version>,
sysroot: Option<&Sysroot>,
) -> io::Result<WorkspaceBuildScripts> {
const RUST_1_62: Version = Version::new(1, 62, 0);
const RUST_1_75: Version = Version::new(1, 75, 0);

let current_dir = match &config.invocation_location {
InvocationLocation::Root(root) if config.run_build_script_command.is_some() => {
Expand All @@ -162,7 +162,7 @@ impl WorkspaceBuildScripts {
progress,
) {
Ok(WorkspaceBuildScripts { error: Some(error), .. })
if toolchain.as_ref().map_or(false, |it| *it >= RUST_1_62) =>
if toolchain.as_ref().map_or(false, |it| *it >= RUST_1_75) =>
{
// building build scripts failed, attempt to build with --keep-going so
// that we potentially get more build data
Expand All @@ -172,7 +172,8 @@ impl WorkspaceBuildScripts {
&workspace.workspace_root().to_path_buf(),
sysroot,
)?;
cmd.args(["-Z", "unstable-options", "--keep-going"]).env("RUSTC_BOOTSTRAP", "1");

cmd.args(["--keep-going"]);
let mut res = Self::run_per_ws(cmd, workspace, current_dir, progress)?;
res.error = Some(error);
Ok(res)
Expand Down
11 changes: 10 additions & 1 deletion crates/project-model/src/target_data_layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,16 @@ pub fn get(
Sysroot::set_rustup_toolchain_env(&mut cmd, sysroot);
cmd.envs(extra_env);
cmd.current_dir(cargo_toml.parent())
.args(["rustc", "--", "-Z", "unstable-options", "--print", "target-spec-json"])
.args([
"rustc",
"-Z",
"unstable-options",
"--print",
"target-spec-json",
"--",
"-Z",
"unstable-options",
])
Comment on lines +35 to +44
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!

.env("RUSTC_BOOTSTRAP", "1");
if let Some(target) = target {
cmd.args(["--target", target]);
Expand Down