1- use anstream:: eprintln as println;
2- use color_print:: cprintln;
31use std:: path:: { Path , PathBuf } ;
42use std:: process:: Command ;
53
4+ use anstream:: eprintln as println;
5+ use color_print:: cprintln;
6+
7+ use crate :: Run ;
8+
9+ #[ derive( Debug ) ]
610pub struct Manifest {
711 pub verbose : bool ,
812 pub release : bool ,
@@ -12,36 +16,8 @@ pub struct Manifest {
1216impl Manifest {
1317 /// Builds the rustc codegen c library
1418 pub fn prepare ( & self ) {
15- cprintln ! ( "<b>[BUILD]</b> codegen backend" ) ;
16- let mut command = Command :: new ( "cargo" ) ;
17- command. arg ( "build" ) . args ( [ "--manifest-path" , "crates/Cargo.toml" ] ) ;
18- if self . verbose {
19- command. args ( [ "-F" , "debug" ] ) ;
20- }
21- if self . release {
22- command. arg ( "--release" ) ;
23- }
24- log:: debug!( "running {:?}" , command) ;
25- command. status ( ) . unwrap ( ) ;
26-
27- cprintln ! ( "<b>[BUILD]</b> librust_runtime" ) ;
28- std:: fs:: create_dir_all ( & self . out_dir ) . unwrap ( ) ;
29- let cc = std:: env:: var ( "CC" ) . unwrap_or ( "clang" . to_string ( ) ) ;
30- let mut command = Command :: new ( & cc) ;
31- command
32- . arg ( "rust_runtime/rust_runtime.c" )
33- . arg ( "-o" )
34- . arg ( self . out_dir . join ( "rust_runtime.o" ) )
35- . arg ( "-c" ) ;
36- log:: debug!( "running {:?}" , command) ;
37- command. status ( ) . unwrap ( ) ;
38- let mut command = Command :: new ( "ar" ) ;
39- command
40- . arg ( "rcs" )
41- . arg ( self . out_dir . join ( "librust_runtime.a" ) )
42- . arg ( self . out_dir . join ( "rust_runtime.o" ) ) ;
43- log:: debug!( "running {:?}" , command) ;
44- command. status ( ) . unwrap ( ) ;
19+ let prepare = PrepareAction { verbose : self . verbose } ;
20+ prepare. run ( & self ) ;
4521 }
4622
4723 /// The path to the rustc codegen c library
@@ -72,3 +48,60 @@ impl Manifest {
7248 command
7349 }
7450}
51+
52+ struct PrepareAction {
53+ verbose : bool ,
54+ }
55+
56+ impl Run for PrepareAction {
57+ const STEP_DISPLAY_NAME : & ' static str = "prepare" ;
58+
59+ fn run ( & self , manifest : & Manifest ) {
60+ // action: Build codegen backend
61+ self . log_action_start ( "building" , "codegen backend" ) ;
62+ self . log_action_context ( "target" , manifest. codegen_backend ( ) . display ( ) ) ;
63+
64+ let mut command = Command :: new ( "cargo" ) ;
65+ command. arg ( "build" ) . args ( [ "--manifest-path" , "crates/Cargo.toml" ] ) ;
66+ if manifest. verbose {
67+ command. args ( [ "-v" ] ) ;
68+ }
69+ if manifest. release {
70+ command. arg ( "--release" ) ;
71+ }
72+ self . command_status ( "build" , & mut command) ;
73+
74+ // action: Build runtime library
75+ self . log_action_start ( "building" , "librust_runtime" ) ;
76+ self . log_action_context ( "output dir" , & manifest. out_dir . to_path_buf ( ) . display ( ) ) ;
77+
78+ // cmd: Create output directory
79+ if let Err ( e) = std:: fs:: create_dir_all ( & manifest. out_dir ) {
80+ cprintln ! ( " <r>failed</r> to create output directory: {}" , e) ;
81+ std:: process:: exit ( 1 ) ;
82+ }
83+
84+ let cc = std:: env:: var ( "CC" ) . unwrap_or ( "clang" . to_string ( ) ) ;
85+
86+ // cmd: Compile runtime.c
87+ let mut command = Command :: new ( & cc) ;
88+ command
89+ . arg ( "rust_runtime/rust_runtime.c" )
90+ . arg ( "-o" )
91+ . arg ( manifest. out_dir . join ( "rust_runtime.o" ) )
92+ . arg ( "-c" ) ;
93+ self . command_status ( "build" , & mut command) ;
94+
95+ // cmd: Create static library
96+ let mut command = Command :: new ( "ar" ) ;
97+ command
98+ . arg ( "rcs" )
99+ . arg ( manifest. out_dir . join ( "librust_runtime.a" ) )
100+ . arg ( manifest. out_dir . join ( "rust_runtime.o" ) ) ;
101+ self . command_status ( "archive" , & mut command) ;
102+ }
103+
104+ fn verbose ( & self ) -> bool {
105+ self . verbose
106+ }
107+ }
0 commit comments