fix: Fix target-data-layout fetching incorrectly passing 'rustc' to rustc

This commit is contained in:
Lukas Wirth 2023-01-19 19:21:44 +01:00
parent c9d33cddc9
commit 384fa4b84a
8 changed files with 144 additions and 63 deletions

View file

@ -1,6 +1,7 @@
//! Runs `rustc --print target-spec-json` to get the target_data_layout.
use std::process::Command;
use anyhow::Result;
use rustc_hash::FxHashMap;
use crate::{utf8_stdout, ManifestPath};
@ -9,7 +10,7 @@ pub(super) fn get(
cargo_toml: Option<&ManifestPath>,
target: Option<&str>,
extra_env: &FxHashMap<String, String>,
) -> Option<String> {
) -> Result<String> {
let output = (|| {
if let Some(cargo_toml) = cargo_toml {
let mut cmd = Command::new(toolchain::rustc());
@ -28,13 +29,13 @@ pub(super) fn get(
// using unstable cargo features failed, fall back to using plain rustc
let mut cmd = Command::new(toolchain::rustc());
cmd.envs(extra_env)
.args(["-Z", "unstable-options", "rustc", "--print", "target-spec-json"])
.args(["-Z", "unstable-options", "--print", "target-spec-json"])
.env("RUSTC_BOOTSTRAP", "1");
if let Some(target) = target {
cmd.args(["--target", target]);
}
utf8_stdout(cmd)
})()
.ok()?;
Some(output.split_once(r#""data-layout": ""#)?.1.split_once('"')?.0.to_owned())
})()?;
(|| Some(output.split_once(r#""data-layout": ""#)?.1.split_once('"')?.0.to_owned()))()
.ok_or_else(|| anyhow::format_err!("could not fetch target-spec-json from command output"))
}