Auto merge of #16693 - Veykril:system-rustc-sysroot, r=Veykril

fix: rust-project.json projects not preferring sysroot rustc
This commit is contained in:
bors 2024-02-27 14:28:36 +00:00
commit c031246546
6 changed files with 25 additions and 18 deletions

View file

@ -440,8 +440,7 @@ impl WorkspaceBuildScripts {
if let Ok(it) = utf8_stdout(cargo_config) { if let Ok(it) = utf8_stdout(cargo_config) {
return Ok(it); return Ok(it);
} }
let mut cmd = Command::new(Tool::Rustc.path()); let mut cmd = Sysroot::rustc(sysroot);
Sysroot::set_rustup_toolchain_env(&mut cmd, sysroot);
cmd.envs(extra_env); cmd.envs(extra_env);
cmd.args(["--print", "target-libdir"]); cmd.args(["--print", "target-libdir"]);
utf8_stdout(cmd) utf8_stdout(cmd)

View file

@ -501,8 +501,7 @@ fn rustc_discover_host_triple(
extra_env: &FxHashMap<String, String>, extra_env: &FxHashMap<String, String>,
sysroot: Option<&Sysroot>, sysroot: Option<&Sysroot>,
) -> Option<String> { ) -> Option<String> {
let mut rustc = Command::new(Tool::Rustc.path()); let mut rustc = Sysroot::rustc(sysroot);
Sysroot::set_rustup_toolchain_env(&mut rustc, sysroot);
rustc.envs(extra_env); rustc.envs(extra_env);
rustc.current_dir(cargo_toml.parent()).arg("-vV"); rustc.current_dir(cargo_toml.parent()).arg("-vV");
tracing::debug!("Discovering host platform by {:?}", rustc); tracing::debug!("Discovering host platform by {:?}", rustc);

View file

@ -90,8 +90,7 @@ fn get_rust_cfgs(
RustcCfgConfig::Rustc(sysroot) => sysroot, RustcCfgConfig::Rustc(sysroot) => sysroot,
}; };
let mut cmd = Command::new(toolchain::Tool::Rustc.path()); let mut cmd = Sysroot::rustc(sysroot);
Sysroot::set_rustup_toolchain_env(&mut cmd, sysroot);
cmd.envs(extra_env); cmd.envs(extra_env);
cmd.args(["--print", "cfg", "-O"]); cmd.args(["--print", "cfg", "-O"]);
if let Some(target) = target { if let Some(target) = target {

View file

@ -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> { pub fn discover_proc_macro_srv(&self) -> anyhow::Result<AbsPathBuf> {
["libexec", "lib"] ["libexec", "lib"]
.into_iter() .into_iter()

View file

@ -57,8 +57,7 @@ pub fn get(
RustcDataLayoutConfig::Rustc(sysroot) => sysroot, RustcDataLayoutConfig::Rustc(sysroot) => sysroot,
}; };
let mut cmd = Command::new(toolchain::Tool::Rustc.path()); let mut cmd = Sysroot::rustc(sysroot);
Sysroot::set_rustup_toolchain_env(&mut cmd, sysroot);
cmd.envs(extra_env) cmd.envs(extra_env)
.args(["-Z", "unstable-options", "--print", "target-spec-json"]) .args(["-Z", "unstable-options", "--print", "target-spec-json"])
.env("RUSTC_BOOTSTRAP", "1"); .env("RUSTC_BOOTSTRAP", "1");

View file

@ -172,14 +172,11 @@ impl fmt::Debug for ProjectWorkspace {
fn get_toolchain_version( fn get_toolchain_version(
current_dir: &AbsPath, current_dir: &AbsPath,
sysroot: Option<&Sysroot>, mut cmd: Command,
tool: Tool,
extra_env: &FxHashMap<String, String>, extra_env: &FxHashMap<String, String>,
prefix: &str, prefix: &str,
) -> Result<Option<Version>, anyhow::Error> { ) -> Result<Option<Version>, anyhow::Error> {
let cargo_version = utf8_stdout({ 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.envs(extra_env);
cmd.arg("--version").current_dir(current_dir); cmd.arg("--version").current_dir(current_dir);
cmd cmd
@ -300,8 +297,11 @@ impl ProjectWorkspace {
let toolchain = get_toolchain_version( let toolchain = get_toolchain_version(
cargo_toml.parent(), 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, &config.extra_env,
"cargo ", "cargo ",
)?; )?;
@ -386,8 +386,7 @@ impl ProjectWorkspace {
let data_layout_config = RustcDataLayoutConfig::Rustc(sysroot_ref); let data_layout_config = RustcDataLayoutConfig::Rustc(sysroot_ref);
let toolchain = match get_toolchain_version( let toolchain = match get_toolchain_version(
project_json.path(), project_json.path(),
sysroot_ref, Sysroot::rustc(sysroot_ref),
toolchain::Tool::Rustc,
extra_env, extra_env,
"rustc ", "rustc ",
) { ) {
@ -436,8 +435,7 @@ impl ProjectWorkspace {
let sysroot_ref = sysroot.as_ref().ok(); let sysroot_ref = sysroot.as_ref().ok();
let toolchain = match get_toolchain_version( let toolchain = match get_toolchain_version(
dir, dir,
sysroot_ref, Sysroot::rustc(sysroot_ref),
toolchain::Tool::Rustc,
&config.extra_env, &config.extra_env,
"rustc ", "rustc ",
) { ) {