From 0c338856feba4879332b0df4ef5ddce719eaec29 Mon Sep 17 00:00:00 2001 From: iliana etaoin Date: Mon, 3 Mar 2025 18:27:30 +0000 Subject: [PATCH 1/2] work around breaking change in rustup 1.28.0 --- tools/helios-build/src/main.rs | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/tools/helios-build/src/main.rs b/tools/helios-build/src/main.rs index 08fcca2..010016a 100644 --- a/tools/helios-build/src/main.rs +++ b/tools/helios-build/src/main.rs @@ -17,6 +17,7 @@ use std::os::unix::fs::PermissionsExt; use std::os::unix::process::CommandExt; use std::path::Path; use std::process::Command; +use std::process::Stdio; use std::time::{Instant, SystemTime}; use time::{format_description, OffsetDateTime}; use walkdir::WalkDir; @@ -1828,9 +1829,11 @@ fn cmd_image(ca: &CommandArg) -> Result<()> { * Create the reset image for the Gimlet SPI ROM: */ info!(log, "creating reset image..."); + let phbl_path = top_path(&["projects", "phbl"])?; + rustup_install_toolchain(log, &phbl_path)?; ensure::run_in( log, - &top_path(&["projects", "phbl"])?, + &phbl_path, &[ "cargo", "xtask", @@ -2418,6 +2421,7 @@ fn cmd_setup(ca: &CommandArg) -> Result<()> { let path = top_path(&["projects", &name])?; info!(log, "building project {:?} at {}", name, path.display()); let start = Instant::now(); + rustup_install_toolchain(log, &path)?; let mut args = vec!["cargo", "build", "--locked"]; if !project.use_debug { args.push("--release"); @@ -2618,6 +2622,33 @@ fn extract_hash(s: &str) -> Option<&str> { }) } +fn rustup_install_toolchain>( + log: &Logger, + pwd: P, +) -> Result<()> { + /* + * rustup 1.28.0 removed the long-standing default behavior of automatically + * installing toolchains for projects. It also introduces the ability + * to call `rustup toolchain install` with no argument to automatically + * install the current toolchain. Of course, this does not exist in earlier + * releases, and there was no transition period. + * + * `rustup show active-toolchain || rustup toolchain install` is the + * recommended way to just install the toolchain regardless of rustup + * version. + */ + let status = Command::new("rustup") + .args(["show", "active-toolchain"]) + .current_dir(pwd.as_ref()) + .stdin(Stdio::null()) + .stdout(Stdio::null()) + .status()?; + if !status.success() { + ensure::run_in(log, pwd, &["rustup", "toolchain", "install"])?; + } + Ok(()) +} + #[test] fn hash_extract() { assert_eq!(extract_hash("heads/trim-0-g49fb31d-dirty"), Some("49fb31d")); From b971a195d81fca7342b7802b9c75826964d6572f Mon Sep 17 00:00:00 2001 From: "Joshua M. Clulow" Date: Mon, 3 Mar 2025 11:06:37 -0800 Subject: [PATCH 2/2] add logging, move toolchain install outside timed portion of build --- tools/helios-build/src/main.rs | 40 +++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/tools/helios-build/src/main.rs b/tools/helios-build/src/main.rs index 010016a..928f3e0 100644 --- a/tools/helios-build/src/main.rs +++ b/tools/helios-build/src/main.rs @@ -1,5 +1,5 @@ /* - * Copyright 2024 Oxide Computer Company + * Copyright 2025 Oxide Computer Company */ mod common; @@ -17,7 +17,6 @@ use std::os::unix::fs::PermissionsExt; use std::os::unix::process::CommandExt; use std::path::Path; use std::process::Command; -use std::process::Stdio; use std::time::{Instant, SystemTime}; use time::{format_description, OffsetDateTime}; use walkdir::WalkDir; @@ -2419,9 +2418,10 @@ fn cmd_setup(ca: &CommandArg) -> Result<()> { } let path = top_path(&["projects", &name])?; + rustup_install_toolchain(log, &path)?; + info!(log, "building project {:?} at {}", name, path.display()); let start = Instant::now(); - rustup_install_toolchain(log, &path)?; let mut args = vec!["cargo", "build", "--locked"]; if !project.use_debug { args.push("--release"); @@ -2622,30 +2622,34 @@ fn extract_hash(s: &str) -> Option<&str> { }) } -fn rustup_install_toolchain>( - log: &Logger, - pwd: P, -) -> Result<()> { +fn rustup_install_toolchain>(log: &Logger, p: P) -> Result<()> { + let p = p.as_ref(); + /* * rustup 1.28.0 removed the long-standing default behavior of automatically - * installing toolchains for projects. It also introduces the ability - * to call `rustup toolchain install` with no argument to automatically - * install the current toolchain. Of course, this does not exist in earlier + * installing toolchains for projects. It also introduces the ability to + * call "rustup toolchain install" with no argument to automatically install + * the current toolchain. Of course, this does not exist in earlier * releases, and there was no transition period. * - * `rustup show active-toolchain || rustup toolchain install` is the + * "rustup show active-toolchain || rustup toolchain install" is the * recommended way to just install the toolchain regardless of rustup * version. */ - let status = Command::new("rustup") + info!(log, "checking rust toolchain is installed for {p:?}"); + let out = Command::new("rustup") .args(["show", "active-toolchain"]) - .current_dir(pwd.as_ref()) - .stdin(Stdio::null()) - .stdout(Stdio::null()) - .status()?; - if !status.success() { - ensure::run_in(log, pwd, &["rustup", "toolchain", "install"])?; + .current_dir(p) + .output()?; + + if out.status.success() { + let ver = String::from_utf8_lossy(&out.stdout).trim().to_string(); + info!(log, "rust toolchain for {p:?}: {ver:?}"); + } else { + info!(log, "installing rust toolchain for {p:?}..."); + ensure::run_in(log, p, &["rustup", "toolchain", "install"])?; } + Ok(()) }