11/*
2- * Copyright 2024 Oxide Computer Company
2+ * Copyright 2025 Oxide Computer Company
33 */
44
55mod common;
@@ -17,7 +17,6 @@ use std::os::unix::fs::PermissionsExt;
1717use std:: os:: unix:: process:: CommandExt ;
1818use std:: path:: Path ;
1919use std:: process:: Command ;
20- use std:: process:: Stdio ;
2120use std:: time:: { Instant , SystemTime } ;
2221use time:: { format_description, OffsetDateTime } ;
2322use walkdir:: WalkDir ;
@@ -2419,9 +2418,10 @@ fn cmd_setup(ca: &CommandArg) -> Result<()> {
24192418 }
24202419
24212420 let path = top_path ( & [ "projects" , & name] ) ?;
2421+ rustup_install_toolchain ( log, & path) ?;
2422+
24222423 info ! ( log, "building project {:?} at {}" , name, path. display( ) ) ;
24232424 let start = Instant :: now ( ) ;
2424- rustup_install_toolchain ( log, & path) ?;
24252425 let mut args = vec ! [ "cargo" , "build" , "--locked" ] ;
24262426 if !project. use_debug {
24272427 args. push ( "--release" ) ;
@@ -2622,30 +2622,34 @@ fn extract_hash(s: &str) -> Option<&str> {
26222622 } )
26232623}
26242624
2625- fn rustup_install_toolchain < P : AsRef < Path > > (
2626- log : & Logger ,
2627- pwd : P ,
2628- ) -> Result < ( ) > {
2625+ fn rustup_install_toolchain < P : AsRef < Path > > ( log : & Logger , p : P ) -> Result < ( ) > {
2626+ let p = p. as_ref ( ) ;
2627+
26292628 /*
26302629 * rustup 1.28.0 removed the long-standing default behavior of automatically
2631- * installing toolchains for projects. It also introduces the ability
2632- * to call ` rustup toolchain install` with no argument to automatically
2633- * install the current toolchain. Of course, this does not exist in earlier
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
26342633 * releases, and there was no transition period.
26352634 *
2636- * ` rustup show active-toolchain || rustup toolchain install` is the
2635+ * " rustup show active-toolchain || rustup toolchain install" is the
26372636 * recommended way to just install the toolchain regardless of rustup
26382637 * version.
26392638 */
2640- let status = Command :: new ( "rustup" )
2639+ info ! ( log, "checking rust toolchain is installed for {p:?}" ) ;
2640+ let out = Command :: new ( "rustup" )
26412641 . args ( [ "show" , "active-toolchain" ] )
2642- . current_dir ( pwd. as_ref ( ) )
2643- . stdin ( Stdio :: null ( ) )
2644- . stdout ( Stdio :: null ( ) )
2645- . status ( ) ?;
2646- if !status. success ( ) {
2647- ensure:: run_in ( log, pwd, & [ "rustup" , "toolchain" , "install" ] ) ?;
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" ] ) ?;
26482651 }
2652+
26492653 Ok ( ( ) )
26502654}
26512655
0 commit comments