1
1
use crate :: config:: { Channel , ConfigInfo } ;
2
- use crate :: utils:: { create_dir, run_command, run_command_with_output_and_env, walk_dir} ;
2
+ use crate :: utils:: {
3
+ copy_file, create_dir, get_sysroot_dir, run_command, run_command_with_output_and_env, walk_dir,
4
+ } ;
3
5
use std:: collections:: HashMap ;
4
6
use std:: ffi:: OsStr ;
5
7
use std:: fs;
@@ -101,10 +103,24 @@ fn cleanup_sysroot_previous_build(start_dir: &Path) {
101
103
let _ = fs:: remove_dir_all ( start_dir. join ( "sysroot" ) ) ;
102
104
}
103
105
106
+ pub fn create_build_sysroot_content ( start_dir : & Path ) -> Result < ( ) , String > {
107
+ if !start_dir. is_dir ( ) {
108
+ create_dir ( start_dir) ?;
109
+ }
110
+ copy_file ( "build_system/build_sysroot/Cargo.toml" , & start_dir. join ( "Cargo.toml" ) ) ?;
111
+
112
+ let src_dir = start_dir. join ( "src" ) ;
113
+ if !src_dir. is_dir ( ) {
114
+ create_dir ( & src_dir) ?;
115
+ }
116
+ copy_file ( "build_system/build_sysroot/lib.rs" , & start_dir. join ( "src/lib.rs" ) )
117
+ }
118
+
104
119
pub fn build_sysroot ( env : & HashMap < String , String > , config : & ConfigInfo ) -> Result < ( ) , String > {
105
- let start_dir = Path :: new ( "build_sysroot" ) ;
120
+ let start_dir = get_sysroot_dir ( ) ;
106
121
107
122
cleanup_sysroot_previous_build ( & start_dir) ;
123
+ create_build_sysroot_content ( & start_dir) ?;
108
124
109
125
// Builds libs
110
126
let mut rustflags = env. get ( "RUSTFLAGS" ) . cloned ( ) . unwrap_or_default ( ) ;
@@ -115,7 +131,6 @@ pub fn build_sysroot(env: &HashMap<String, String>, config: &ConfigInfo) -> Resu
115
131
if config. no_default_features {
116
132
rustflags. push_str ( " -Csymbol-mangling-version=v0" ) ;
117
133
}
118
- let mut env = env. clone ( ) ;
119
134
120
135
let mut args: Vec < & dyn AsRef < OsStr > > = vec ! [ & "cargo" , & "build" , & "--target" , & config. target] ;
121
136
@@ -132,8 +147,9 @@ pub fn build_sysroot(env: &HashMap<String, String>, config: &ConfigInfo) -> Resu
132
147
"debug"
133
148
} ;
134
149
150
+ let mut env = env. clone ( ) ;
135
151
env. insert ( "RUSTFLAGS" . to_string ( ) , rustflags) ;
136
- run_command_with_output_and_env ( & args, Some ( start_dir) , Some ( & env) ) ?;
152
+ run_command_with_output_and_env ( & args, Some ( & start_dir) , Some ( & env) ) ?;
137
153
138
154
// Copy files to sysroot
139
155
let sysroot_path = start_dir. join ( format ! ( "sysroot/lib/rustlib/{}/lib/" , config. target_triple) ) ;
0 commit comments