11use std:: ffi:: OsStr ;
22use std:: fs;
33use std:: path:: { Path , PathBuf } ;
4- use std:: process:: Command ;
4+ use std:: process:: { Command , Stdio } ;
55
66use crate :: build_system:: rustc_info:: get_default_sysroot;
77
@@ -10,28 +10,57 @@ use super::path::{Dirs, RelPath};
1010use super :: rustc_info:: get_rustc_version;
1111use super :: utils:: { copy_dir_recursively, git_command, retry_spawn_and_wait, spawn_and_wait} ;
1212
13- pub ( crate ) fn prepare ( dirs : & Dirs ) {
13+ pub ( crate ) fn prepare ( dirs : & Dirs , vendor : bool ) {
1414 if RelPath :: DOWNLOAD . to_path ( dirs) . exists ( ) {
1515 std:: fs:: remove_dir_all ( RelPath :: DOWNLOAD . to_path ( dirs) ) . unwrap ( ) ;
1616 }
1717 std:: fs:: create_dir_all ( RelPath :: DOWNLOAD . to_path ( dirs) ) . unwrap ( ) ;
1818
19- spawn_and_wait ( super :: build_backend:: CG_CLIF . fetch ( "cargo" , dirs) ) ;
19+ if Path :: new ( ".cargo/config.toml" ) . exists ( ) {
20+ std:: fs:: remove_file ( ".cargo/config.toml" ) . unwrap ( ) ;
21+ }
22+
23+ let mut cargo_workspaces = vec ! [ super :: build_backend:: CG_CLIF . manifest_path( dirs) ] ;
2024
2125 prepare_sysroot ( dirs) ;
22- spawn_and_wait ( super :: build_sysroot:: STANDARD_LIBRARY . fetch ( "cargo" , dirs) ) ;
23- spawn_and_wait ( super :: tests:: LIBCORE_TESTS . fetch ( "cargo" , dirs) ) ;
26+ cargo_workspaces . push ( super :: build_sysroot:: STANDARD_LIBRARY . manifest_path ( dirs) ) ;
27+ cargo_workspaces . push ( super :: tests:: LIBCORE_TESTS . manifest_path ( dirs) ) ;
2428
2529 super :: abi_cafe:: ABI_CAFE_REPO . fetch ( dirs) ;
26- spawn_and_wait ( super :: abi_cafe:: ABI_CAFE . fetch ( "cargo" , dirs) ) ;
30+ cargo_workspaces . push ( super :: abi_cafe:: ABI_CAFE . manifest_path ( dirs) ) ;
2731 super :: tests:: RAND_REPO . fetch ( dirs) ;
28- spawn_and_wait ( super :: tests:: RAND . fetch ( "cargo" , dirs) ) ;
32+ cargo_workspaces . push ( super :: tests:: RAND . manifest_path ( dirs) ) ;
2933 super :: tests:: REGEX_REPO . fetch ( dirs) ;
30- spawn_and_wait ( super :: tests:: REGEX . fetch ( "cargo" , dirs) ) ;
34+ cargo_workspaces . push ( super :: tests:: REGEX . manifest_path ( dirs) ) ;
3135 super :: tests:: PORTABLE_SIMD_REPO . fetch ( dirs) ;
32- spawn_and_wait ( super :: tests:: PORTABLE_SIMD . fetch ( "cargo" , dirs) ) ;
36+ cargo_workspaces . push ( super :: tests:: PORTABLE_SIMD . manifest_path ( dirs) ) ;
3337 super :: bench:: SIMPLE_RAYTRACER_REPO . fetch ( dirs) ;
34- spawn_and_wait ( super :: bench:: SIMPLE_RAYTRACER . fetch ( "cargo" , dirs) ) ;
38+ cargo_workspaces. push ( super :: bench:: SIMPLE_RAYTRACER . manifest_path ( dirs) ) ;
39+
40+ if vendor {
41+ let mut vendor_cmd = Command :: new ( "cargo" ) ;
42+
43+ vendor_cmd. arg ( "vendor" ) . arg ( "--manifest-path" ) . arg ( & cargo_workspaces[ 0 ] ) ;
44+
45+ for workspace in cargo_workspaces. iter ( ) . skip ( 1 ) {
46+ vendor_cmd. arg ( "--sync" ) . arg ( workspace) ;
47+ }
48+
49+ vendor_cmd. arg ( "download/vendor" ) ;
50+
51+ let vendor_output = vendor_cmd. stderr ( Stdio :: inherit ( ) ) . output ( ) . unwrap ( ) ;
52+ assert ! ( vendor_output. status. success( ) ) ;
53+ let replacement_config = String :: from_utf8 ( vendor_output. stdout ) . unwrap ( ) ;
54+
55+ std:: fs:: create_dir_all ( ".cargo" ) . unwrap ( ) ;
56+ std:: fs:: write ( ".cargo/config.toml" , replacement_config) . unwrap ( ) ;
57+ } else {
58+ for workspace in & cargo_workspaces {
59+ let mut fetch_cmd = Command :: new ( "cargo" ) ;
60+ fetch_cmd. arg ( "fetch" ) . arg ( "--manifest-path" ) . arg ( workspace) ;
61+ spawn_and_wait ( fetch_cmd)
62+ }
63+ }
3564}
3665
3766fn prepare_sysroot ( dirs : & Dirs ) {
0 commit comments