Skip to content

Commit 66dca7a

Browse files
xtask: Make build-std optional
If the target being built is installed via rustup, skip adding the build-std arguments. We still need build-std for our current minimum-supported nightly CI, but for nightly-2022-11-10 and later the UEFI targets are tier 2 and can be installed via rustup.
1 parent ded257d commit 66dca7a

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

xtask/src/cargo.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,19 @@ pub fn fix_nested_cargo_env(cmd: &mut Command) {
160160
cmd.env("PATH", sanitized_path(orig_path));
161161
}
162162

163+
/// Check if the three UEFI targets are installed via rustup (only
164+
/// supported since nightly-2022-11-10).
165+
fn is_target_installed(target: &str) -> Result<bool> {
166+
let output = Command::new("rustup")
167+
.args(["target", "list", "--installed"])
168+
.output()?;
169+
if !output.status.success() {
170+
bail!("failed to get installed targets");
171+
}
172+
let stdout = String::from_utf8(output.stdout)?;
173+
Ok(stdout.lines().any(|x| x == target))
174+
}
175+
163176
#[derive(Debug)]
164177
pub struct Cargo {
165178
pub action: CargoAction,
@@ -219,7 +232,14 @@ impl Cargo {
219232
}
220233

221234
if let Some(target) = self.target {
222-
cmd.args(["--target", target.as_triple(), "-Zbuild-std=core,alloc"]);
235+
cmd.args(["--target", target.as_triple()]);
236+
237+
// If the target is not installed, use build-std. Keep this
238+
// around until our minimum-supported nightly version is at
239+
// least 2022-11-10.
240+
if !is_target_installed(target.as_triple())? {
241+
cmd.args(["-Zbuild-std=core,alloc"]);
242+
}
223243
}
224244

225245
if self.packages.is_empty() {

0 commit comments

Comments
 (0)