Skip to content

Commit 744071a

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 9de6200 commit 744071a

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

xtask/src/cargo.rs

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,19 @@ pub fn fix_nested_cargo_env(cmd: &mut Command) {
162162
cmd.env("PATH", sanitized_path(orig_path));
163163
}
164164

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

223236
if let Some(target) = self.target {
224-
cmd.args([
225-
"--target",
226-
target.as_triple(),
227-
"-Zbuild-std=core,compiler_builtins,alloc",
228-
"-Zbuild-std-features=compiler-builtins-mem",
229-
]);
237+
cmd.args(["--target", target.as_triple()]);
238+
239+
// If the target is not installed, use build-std. Keep this
240+
// around until our minimum-supported nightly version is at
241+
// least 2022-11-10.
242+
if !is_target_installed(target.as_triple())? {
243+
cmd.args([
244+
"-Zbuild-std=core,compiler_builtins,alloc",
245+
"-Zbuild-std-features=compiler-builtins-mem",
246+
]);
247+
}
230248
}
231249

232250
if self.packages.is_empty() {

0 commit comments

Comments
 (0)