11use 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+ } ;
35use std:: collections:: HashMap ;
46use std:: ffi:: OsStr ;
57use std:: fs;
@@ -101,10 +103,24 @@ fn cleanup_sysroot_previous_build(start_dir: &Path) {
101103 let _ = fs:: remove_dir_all ( start_dir. join ( "sysroot" ) ) ;
102104}
103105
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+
104119pub 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 ( ) ;
106121
107122 cleanup_sysroot_previous_build ( & start_dir) ;
123+ create_build_sysroot_content ( & start_dir) ?;
108124
109125 // Builds libs
110126 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
115131 if config. no_default_features {
116132 rustflags. push_str ( " -Csymbol-mangling-version=v0" ) ;
117133 }
118- let mut env = env. clone ( ) ;
119134
120135 let mut args: Vec < & dyn AsRef < OsStr > > = vec ! [ & "cargo" , & "build" , & "--target" , & config. target] ;
121136
@@ -132,8 +147,9 @@ pub fn build_sysroot(env: &HashMap<String, String>, config: &ConfigInfo) -> Resu
132147 "debug"
133148 } ;
134149
150+ let mut env = env. clone ( ) ;
135151 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) ) ?;
137153
138154 // Copy files to sysroot
139155 let sysroot_path = start_dir. join ( format ! ( "sysroot/lib/rustlib/{}/lib/" , config. target_triple) ) ;
0 commit comments