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: rust-project.json projects not preferring sysroot rustc #16693

Merged
merged 1 commit into from
Feb 27, 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
3 changes: 1 addition & 2 deletions crates/project-model/src/build_scripts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -440,8 +440,7 @@ impl WorkspaceBuildScripts {
if let Ok(it) = utf8_stdout(cargo_config) {
return Ok(it);
}
let mut cmd = Command::new(Tool::Rustc.path());
Sysroot::set_rustup_toolchain_env(&mut cmd, sysroot);
let mut cmd = Sysroot::rustc(sysroot);
cmd.envs(extra_env);
cmd.args(["--print", "target-libdir"]);
utf8_stdout(cmd)
Expand Down
3 changes: 1 addition & 2 deletions crates/project-model/src/cargo_workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -501,8 +501,7 @@ fn rustc_discover_host_triple(
extra_env: &FxHashMap<String, String>,
sysroot: Option<&Sysroot>,
) -> Option<String> {
let mut rustc = Command::new(Tool::Rustc.path());
Sysroot::set_rustup_toolchain_env(&mut rustc, sysroot);
let mut rustc = Sysroot::rustc(sysroot);
rustc.envs(extra_env);
rustc.current_dir(cargo_toml.parent()).arg("-vV");
tracing::debug!("Discovering host platform by {:?}", rustc);
Expand Down
3 changes: 1 addition & 2 deletions crates/project-model/src/rustc_cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ fn get_rust_cfgs(
RustcCfgConfig::Rustc(sysroot) => sysroot,
};

let mut cmd = Command::new(toolchain::Tool::Rustc.path());
Sysroot::set_rustup_toolchain_env(&mut cmd, sysroot);
let mut cmd = Sysroot::rustc(sysroot);
cmd.envs(extra_env);
cmd.args(["--print", "cfg", "-O"]);
if let Some(target) = target {
Expand Down
13 changes: 13 additions & 0 deletions crates/project-model/src/sysroot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,19 @@ impl Sysroot {
}
}

/// Returns a `Command` that is configured to run `rustc` from the sysroot if it exists,
/// otherwise returns what [toolchain::Tool::Rustc] returns.
pub fn rustc(sysroot: Option<&Self>) -> Command {
let mut cmd = Command::new(match sysroot {
Some(sysroot) => {
toolchain::Tool::Rustc.path_in_or_discover(sysroot.root.join("bin").as_ref())
}
None => toolchain::Tool::Rustc.path(),
});
Self::set_rustup_toolchain_env(&mut cmd, sysroot);
cmd
}

pub fn discover_proc_macro_srv(&self) -> anyhow::Result<AbsPathBuf> {
["libexec", "lib"]
.into_iter()
Expand Down
3 changes: 1 addition & 2 deletions crates/project-model/src/target_data_layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ pub fn get(
RustcDataLayoutConfig::Rustc(sysroot) => sysroot,
};

let mut cmd = Command::new(toolchain::Tool::Rustc.path());
Sysroot::set_rustup_toolchain_env(&mut cmd, sysroot);
let mut cmd = Sysroot::rustc(sysroot);
cmd.envs(extra_env)
.args(["-Z", "unstable-options", "--print", "target-spec-json"])
.env("RUSTC_BOOTSTRAP", "1");
Expand Down
18 changes: 8 additions & 10 deletions crates/project-model/src/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,14 +172,11 @@ impl fmt::Debug for ProjectWorkspace {

fn get_toolchain_version(
current_dir: &AbsPath,
sysroot: Option<&Sysroot>,
tool: Tool,
mut cmd: Command,
extra_env: &FxHashMap<String, String>,
prefix: &str,
) -> Result<Option<Version>, anyhow::Error> {
let cargo_version = utf8_stdout({
let mut cmd = Command::new(tool.path());
Sysroot::set_rustup_toolchain_env(&mut cmd, sysroot);
cmd.envs(extra_env);
cmd.arg("--version").current_dir(current_dir);
cmd
Expand Down Expand Up @@ -300,8 +297,11 @@ impl ProjectWorkspace {

let toolchain = get_toolchain_version(
cargo_toml.parent(),
sysroot_ref,
toolchain::Tool::Cargo,
{
let mut cmd = Command::new(toolchain::Tool::Cargo.path());
Sysroot::set_rustup_toolchain_env(&mut cmd, sysroot_ref);
cmd
},
&config.extra_env,
"cargo ",
)?;
Expand Down Expand Up @@ -386,8 +386,7 @@ impl ProjectWorkspace {
let data_layout_config = RustcDataLayoutConfig::Rustc(sysroot_ref);
let toolchain = match get_toolchain_version(
project_json.path(),
sysroot_ref,
toolchain::Tool::Rustc,
Sysroot::rustc(sysroot_ref),
extra_env,
"rustc ",
) {
Expand Down Expand Up @@ -436,8 +435,7 @@ impl ProjectWorkspace {
let sysroot_ref = sysroot.as_ref().ok();
let toolchain = match get_toolchain_version(
dir,
sysroot_ref,
toolchain::Tool::Rustc,
Sysroot::rustc(sysroot_ref),
&config.extra_env,
"rustc ",
) {
Expand Down
Loading