1
1
/*
2
- * Copyright 2024 Oxide Computer Company
2
+ * Copyright 2025 Oxide Computer Company
3
3
*/
4
4
5
5
mod common;
@@ -17,7 +17,6 @@ use std::os::unix::fs::PermissionsExt;
17
17
use std:: os:: unix:: process:: CommandExt ;
18
18
use std:: path:: Path ;
19
19
use std:: process:: Command ;
20
- use std:: process:: Stdio ;
21
20
use std:: time:: { Instant , SystemTime } ;
22
21
use time:: { format_description, OffsetDateTime } ;
23
22
use walkdir:: WalkDir ;
@@ -2419,9 +2418,10 @@ fn cmd_setup(ca: &CommandArg) -> Result<()> {
2419
2418
}
2420
2419
2421
2420
let path = top_path ( & [ "projects" , & name] ) ?;
2421
+ rustup_install_toolchain ( log, & path) ?;
2422
+
2422
2423
info ! ( log, "building project {:?} at {}" , name, path. display( ) ) ;
2423
2424
let start = Instant :: now ( ) ;
2424
- rustup_install_toolchain ( log, & path) ?;
2425
2425
let mut args = vec ! [ "cargo" , "build" , "--locked" ] ;
2426
2426
if !project. use_debug {
2427
2427
args. push ( "--release" ) ;
@@ -2622,30 +2622,34 @@ fn extract_hash(s: &str) -> Option<&str> {
2622
2622
} )
2623
2623
}
2624
2624
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
+
2629
2628
/*
2630
2629
* 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
2634
2633
* releases, and there was no transition period.
2635
2634
*
2636
- * ` rustup show active-toolchain || rustup toolchain install` is the
2635
+ * " rustup show active-toolchain || rustup toolchain install" is the
2637
2636
* recommended way to just install the toolchain regardless of rustup
2638
2637
* version.
2639
2638
*/
2640
- let status = Command :: new ( "rustup" )
2639
+ info ! ( log, "checking rust toolchain is installed for {p:?}" ) ;
2640
+ let out = Command :: new ( "rustup" )
2641
2641
. 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" ] ) ?;
2648
2651
}
2652
+
2649
2653
Ok ( ( ) )
2650
2654
}
2651
2655
0 commit comments