1
1
use std:: ffi:: OsStr ;
2
2
use std:: fs;
3
3
use std:: path:: { Path , PathBuf } ;
4
- use std:: process:: Command ;
4
+ use std:: process:: { Command , Stdio } ;
5
5
6
6
use crate :: build_system:: rustc_info:: get_default_sysroot;
7
7
@@ -10,28 +10,57 @@ use super::path::{Dirs, RelPath};
10
10
use super :: rustc_info:: get_rustc_version;
11
11
use super :: utils:: { copy_dir_recursively, git_command, retry_spawn_and_wait, spawn_and_wait} ;
12
12
13
- pub ( crate ) fn prepare ( dirs : & Dirs ) {
13
+ pub ( crate ) fn prepare ( dirs : & Dirs , vendor : bool ) {
14
14
if RelPath :: DOWNLOAD . to_path ( dirs) . exists ( ) {
15
15
std:: fs:: remove_dir_all ( RelPath :: DOWNLOAD . to_path ( dirs) ) . unwrap ( ) ;
16
16
}
17
17
std:: fs:: create_dir_all ( RelPath :: DOWNLOAD . to_path ( dirs) ) . unwrap ( ) ;
18
18
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) ] ;
20
24
21
25
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) ) ;
24
28
25
29
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) ) ;
27
31
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) ) ;
29
33
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) ) ;
31
35
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) ) ;
33
37
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 ( ".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
+ }
35
64
}
36
65
37
66
fn prepare_sysroot ( dirs : & Dirs ) {
0 commit comments