Skip to content

Commit c278c40

Browse files
ilianajclulow
andauthored
tools: work around breaking change in rustup 1.28.0 (#191)
Co-authored-by: Joshua M. Clulow <[email protected]>
1 parent 873badb commit c278c40

File tree

1 file changed

+37
-2
lines changed

1 file changed

+37
-2
lines changed

tools/helios-build/src/main.rs

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2024 Oxide Computer Company
2+
* Copyright 2025 Oxide Computer Company
33
*/
44

55
mod common;
@@ -1828,9 +1828,11 @@ fn cmd_image(ca: &CommandArg) -> Result<()> {
18281828
* Create the reset image for the Gimlet SPI ROM:
18291829
*/
18301830
info!(log, "creating reset image...");
1831+
let phbl_path = top_path(&["projects", "phbl"])?;
1832+
rustup_install_toolchain(log, &phbl_path)?;
18311833
ensure::run_in(
18321834
log,
1833-
&top_path(&["projects", "phbl"])?,
1835+
&phbl_path,
18341836
&[
18351837
"cargo",
18361838
"xtask",
@@ -2416,6 +2418,8 @@ fn cmd_setup(ca: &CommandArg) -> Result<()> {
24162418
}
24172419

24182420
let path = top_path(&["projects", &name])?;
2421+
rustup_install_toolchain(log, &path)?;
2422+
24192423
info!(log, "building project {:?} at {}", name, path.display());
24202424
let start = Instant::now();
24212425
let mut args = vec!["cargo", "build", "--locked"];
@@ -2618,6 +2622,37 @@ fn extract_hash(s: &str) -> Option<&str> {
26182622
})
26192623
}
26202624

2625+
fn rustup_install_toolchain<P: AsRef<Path>>(log: &Logger, p: P) -> Result<()> {
2626+
let p = p.as_ref();
2627+
2628+
/*
2629+
* rustup 1.28.0 removed the long-standing default behavior of automatically
2630+
* installing toolchains for projects. It also introduces the ability to
2631+
* call "rustup toolchain install" with no argument to automatically install
2632+
* the current toolchain. Of course, this does not exist in earlier
2633+
* releases, and there was no transition period.
2634+
*
2635+
* "rustup show active-toolchain || rustup toolchain install" is the
2636+
* recommended way to just install the toolchain regardless of rustup
2637+
* version.
2638+
*/
2639+
info!(log, "checking rust toolchain is installed for {p:?}");
2640+
let out = Command::new("rustup")
2641+
.args(["show", "active-toolchain"])
2642+
.current_dir(p)
2643+
.output()?;
2644+
2645+
if out.status.success() {
2646+
let ver = String::from_utf8_lossy(&out.stdout).trim().to_string();
2647+
info!(log, "rust toolchain for {p:?}: {ver:?}");
2648+
} else {
2649+
info!(log, "installing rust toolchain for {p:?}...");
2650+
ensure::run_in(log, p, &["rustup", "toolchain", "install"])?;
2651+
}
2652+
2653+
Ok(())
2654+
}
2655+
26212656
#[test]
26222657
fn hash_extract() {
26232658
assert_eq!(extract_hash("heads/trim-0-g49fb31d-dirty"), Some("49fb31d"));

0 commit comments

Comments
 (0)