-
Notifications
You must be signed in to change notification settings - Fork 255
Conversation
// as others may emit required metadata for dependent crate types | ||
if a.starts_with("--emit") && is_final_crate_type && !self.workspace_mode { | ||
cmd.arg("--emit=dep-info"); | ||
} else if a != "-Zsave-analysis" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this mean we don't ever pass "-Zsave-analysis"
to the deps?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, we pass it to the deps, but when we save the args for our own rustc call, then we don't use -Zsave-analysis
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, that's for the primary crate units, my bad. But does that mean that when compiling lib for the final bin target, we don't generate save-analysis as well? Shouldn't we? Or am I missing something still?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, to be clear, when running on the deps, we use the RLS as a rustc shim which effectively always has -Zsave-analysis set. So we never explicitly set -Zsave-analysis - for black-listed deps, we don't want it, for non-black-listed-deps we use the RLS as a shim, and for the primary crates we call rustc directly (where again collecting save-analysis data does not require the flag).
src/build/cargo.rs
Outdated
let rustc_exe = env::var("RUSTC").unwrap_or(env::args().next().unwrap()); | ||
let mut cmd = Command::new(&rustc_exe); | ||
// Cargo should handle `$RUSTC` wrapper override already | ||
let mut cmd = cargo_cmd.clone(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will use the same program that's inside cargo_cmd
, is it correct wrt shim (and env::args().next()
)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, so for shim, we want to call the RLS itself, which acts as a shim (sorry, I should really have documented that). We have to avoid using the shim in favour of $RUSTC at least for tests (both in our repo and in the Rust repo, where there is a different shim).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So on top of that, we'd still need some API for ProcessBuilder
to change the program, right? And then we'd need to substitute with previous rustc_exe
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nrc apart from other fixes needed, I guess this is also blocked on new ProcessBuilder
api to set a program?
src/build/cargo.rs
Outdated
} | ||
return cmd.exec(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In both cases I'm running the command with cmd.env(::RUSTC_SHIM_ENV_VAR_NAME, "1");
applied, will this caues any problems?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is necessary - that env var causes the RLS to operate as a rustc shim
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previously, if the crate was blacklisted, a command with cmd.env(::RUSTC_SHIM_ENV_VAR_NAME, "1");
was run, and if the crate wasn't blacklisted, the original cargo_cmd
(without cmd.env(::RUSTC_SHIM_ENV_VAR_NAME, "1");
) was run.
My change uses the one with the shim env var name set in both cases.
From what I understand, being on a blacklist should only change the save analysis argument and not change the process that's run, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From what I understand, being on a blacklist should only change the save analysis argument and not change the process that's run, right?
Yeah, correct.
Calling the shim is the same as calling rustc -Zsave-analysis. If you're running rustc
, the shim env var doesn't make difference either way, but if you're running the shim (which we must if we want to collect data), then it must be set
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO: Don't use shim when the crate is blacklisted - we don't need to, because we won't pass -Zsave-analysis
(or any other unstable option?)
@@ -405,7 +389,7 @@ impl Executor for RlsExecutor { | |||
_ => {} | |||
} | |||
} else { | |||
cmd.status().expect("Couldn't execute rustc"); | |||
cmd.exec()?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This changes the semantics, I believe - it will still error out when the process can't be run, but also when the exit code is non 0 (e.g. dep can't be compiled). Maybe this will somehow prevent the spontaneous fingerprint crashes (as per my #443 (comment))?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just as a note, it does roughly the same what this does, minus returning from the function on success - we still store the cached args/envs at the end of the function
217396d
to
6d7ca16
Compare
The Cargo PR landed already, reverted Cargo.toml to Cargo master and force-pushed. |
src/build/cargo.rs
Outdated
let rustc_exe = env::var("RUSTC").unwrap_or(env::args().next().unwrap()); | ||
let mut cmd = Command::new(&rustc_exe); | ||
// Cargo should handle `$RUSTC` wrapper override already | ||
let mut cmd = cargo_cmd.clone(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, so for shim, we want to call the RLS itself, which acts as a shim (sorry, I should really have documented that). We have to avoid using the shim in favour of $RUSTC at least for tests (both in our repo and in the Rust repo, where there is a different shim).
src/build/cargo.rs
Outdated
} | ||
return cmd.exec(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is necessary - that env var causes the RLS to operate as a rustc shim
return match cmd.status() { | ||
Ok(ref e) if e.success() => Ok(()), | ||
_ => Err(CargoErrorKind::ProcessErrorKind(process_error( | ||
"process didn't exit successfully", None, None)).into()), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we not need the env vars and current dir?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do - cmd
is the clone of the exec
argument, cargo_cmd
, so it has it already
// as others may emit required metadata for dependent crate types | ||
if a.starts_with("--emit") && is_final_crate_type && !self.workspace_mode { | ||
cmd.arg("--emit=dep-info"); | ||
} else if a != "-Zsave-analysis" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, we pass it to the deps, but when we save the args for our own rustc call, then we don't use -Zsave-analysis
7aeb4b2
to
24a7e1c
Compare
We need to substitute the program for the shim, so that's still blocked on the Cargo side: rust-lang/cargo#4442. |
@@ -296,37 +295,35 @@ impl Executor for RlsExecutor { | |||
} | |||
} | |||
|
|||
let rustc_exe = env::var("RUSTC").unwrap_or(env::args().next().unwrap()); | |||
let mut cmd = Command::new(&rustc_exe); | |||
// Prepare our own call to `rustc` as follows: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Am I commenting too much? Wanted to draw a high level plan, mostly why we need to use the rls executable, so it made sense to present more high-level overview of what'll be done, but the later parts are also commented. Should I only retain a comment regarding the shim and why it's needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, looks like a good comment!
7c29aff
to
4ceae4d
Compare
Depends on #466 for compilation fix. |
4ceae4d
to
60a2e87
Compare
Updated cargo dep as it needs rust-lang/cargo@814c389, force-pushed. |
cf8223e
to
68efd54
Compare
if !self.is_primary_crate(id) || is_build_script { | ||
let mut cmd = Command::new(&env::var("RUSTC").unwrap_or("rustc".to_owned())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, any crate we want save-analysis from we must use the shim
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should, but not for black-listed crates. Note that currently we only use cmd for blacklisted crates, so this is not wrong atm (but it should really be inside the next if
).
68efd54
to
68ffac0
Compare
Thanks! |
As with #449, this depends on rust-lang/cargo#4424.
Will change Cargo.toml back when the PR is merged.