@@ -4,7 +4,7 @@ use crate::utils::{cargo_install, git_clone, run_command, run_command_with_outpu
4
4
use std:: fs;
5
5
use std:: path:: Path ;
6
6
7
- fn prepare_libcore ( ) -> Result < ( ) , String > {
7
+ fn prepare_libcore ( sysroot_path : & Path ) -> Result < ( ) , String > {
8
8
let rustc_path = match get_rustc_path ( ) {
9
9
Some ( path) => path,
10
10
None => return Err ( "`rustc` path not found" . to_owned ( ) ) ,
@@ -15,14 +15,18 @@ fn prepare_libcore() -> Result<(), String> {
15
15
None => return Err ( format ! ( "No parent for `{}`" , rustc_path. display( ) ) ) ,
16
16
} ;
17
17
18
- let rustlib_dir = parent. join ( "../lib/rustlib/src/rust" ) ;
18
+ let rustlib_dir =
19
+ parent
20
+ . join ( "../lib/rustlib/src/rust" )
21
+ . canonicalize ( )
22
+ . map_err ( |e| format ! ( "Failed to canonicalize path: {e:?}" ) ) ?;
19
23
if !rustlib_dir. is_dir ( ) {
20
24
return Err ( "Please install `rust-src` component" . to_owned ( ) ) ;
21
25
}
22
26
23
- let sysroot_dir = Path :: new ( "build_sysroot/ sysroot_src") ;
27
+ let sysroot_dir = sysroot_path . join ( " sysroot_src") ;
24
28
if sysroot_dir. is_dir ( ) {
25
- if let Err ( e) = fs:: remove_dir_all ( sysroot_dir) {
29
+ if let Err ( e) = fs:: remove_dir_all ( & sysroot_dir) {
26
30
return Err ( format ! ( "Failed to remove `{}`: {:?}" , sysroot_dir. display( ) , e) ) ;
27
31
}
28
32
}
@@ -34,21 +38,21 @@ fn prepare_libcore() -> Result<(), String> {
34
38
sysroot_library_dir. display( ) ,
35
39
) ) ?;
36
40
37
- run_command ( & [ & "cp" , & "-r" , & rustlib_dir, & sysroot_library_dir ] , None ) ?;
41
+ run_command ( & [ & "cp" , & "-r" , & rustlib_dir. join ( "library" ) , & sysroot_dir ] , None ) ?;
38
42
39
43
println ! ( "[GIT] init (cwd): `{}`" , sysroot_dir. display( ) ) ;
40
- run_command_with_output ( & [ & "git" , & "init" ] , Some ( & sysroot_dir) ) ?;
44
+ run_command ( & [ & "git" , & "init" ] , Some ( & sysroot_dir) ) ?;
41
45
println ! ( "[GIT] add (cwd): `{}`" , sysroot_dir. display( ) ) ;
42
- run_command_with_output ( & [ & "git" , & "add" , & "." ] , Some ( & sysroot_dir) ) ?;
46
+ run_command ( & [ & "git" , & "add" , & "." ] , Some ( & sysroot_dir) ) ?;
43
47
println ! ( "[GIT] commit (cwd): `{}`" , sysroot_dir. display( ) ) ;
44
48
45
49
// This is needed on systems where nothing is configured.
46
50
// git really needs something here, or it will fail.
47
51
// Even using --author is not enough.
48
52
run_command ( & [ & "git" , & "config" , & "user.email" , & "[email protected] " ] , Some ( & sysroot_dir
) ) ?
;
49
53
run_command ( & [ & "git" , & "config" , & "user.name" , & "None" ] , Some ( & sysroot_dir) ) ?;
50
- run_command ( & [ & "git" , & "config" , & "core.autocrlf= false" ] , Some ( & sysroot_dir) ) ?;
51
- run_command ( & [ & "git" , & "config" , & "commit.gpgSign= false" ] , Some ( & sysroot_dir) ) ?;
54
+ run_command ( & [ & "git" , & "config" , & "core.autocrlf" , & " false"] , Some ( & sysroot_dir) ) ?;
55
+ run_command ( & [ & "git" , & "config" , & "commit.gpgSign" , & " false"] , Some ( & sysroot_dir) ) ?;
52
56
run_command ( & [ & "git" , & "commit" , & "-m" , & "Initial commit" , & "-q" ] , Some ( & sysroot_dir) ) ?;
53
57
54
58
walk_dir ( "patches" , |_| Ok ( ( ) ) , |file_path : & Path | {
@@ -69,31 +73,39 @@ fn prepare_libcore() -> Result<(), String> {
69
73
// build with cg_llvm for perf comparison
70
74
fn build_raytracer ( repo_dir : & Path ) -> Result < ( ) , String > {
71
75
run_command ( & [ & "cargo" , & "build" ] , Some ( repo_dir) ) ?;
76
+ let mv_target = repo_dir. join ( "raytracer_cg_llvm" ) ;
77
+ if mv_target. is_file ( ) {
78
+ std:: fs:: remove_file ( & mv_target)
79
+ . map_err ( |e| format ! ( "Failed to remove file `{}`: {e:?}" , mv_target. display( ) ) ) ?;
80
+ }
72
81
run_command ( & [ & "mv" , & "target/debug/main" , & "raytracer_cg_llvm" ] , Some ( repo_dir) ) ?;
73
82
Ok ( ( ) )
74
83
}
75
84
76
- fn clone_and_setup < F > ( repo_url : & str , checkout_commit : & str , extra : Option < F > ) -> Result < ( ) , String >
85
+ fn clone_and_setup < F > ( sysroot_path : & Path , repo_url : & str , checkout_commit : & str , extra : Option < F > ) -> Result < ( ) , String >
77
86
where
78
87
F : Fn ( & Path ) -> Result < ( ) , String > ,
79
88
{
80
- let clone_result = git_clone ( repo_url, None ) ?;
89
+ let clone_result = git_clone ( repo_url, Some ( sysroot_path ) ) ?;
81
90
if !clone_result. ran_clone {
82
91
println ! ( "`{}` has already been cloned" , clone_result. repo_name) ;
83
92
}
84
- let repo_path = Path :: new ( & clone_result. repo_name ) ;
85
- run_command ( & [ & "git" , & "checkout" , & "--" , & "." ] , Some ( repo_path) ) ?;
86
- run_command ( & [ & "git" , & "checkout" , & checkout_commit] , Some ( repo_path) ) ?;
93
+ let repo_path = sysroot_path . join ( & clone_result. repo_name ) ;
94
+ run_command ( & [ & "git" , & "checkout" , & "--" , & "." ] , Some ( & repo_path) ) ?;
95
+ run_command ( & [ & "git" , & "checkout" , & checkout_commit] , Some ( & repo_path) ) ?;
87
96
let filter = format ! ( "-{}-" , clone_result. repo_name) ;
88
97
walk_dir ( "crate_patches" , |_| Ok ( ( ) ) , |file_path| {
89
98
let s = file_path. as_os_str ( ) . to_str ( ) . unwrap ( ) ;
90
99
if s. contains ( & filter) && s. ends_with ( ".patch" ) {
91
- run_command ( & [ & "git" , & "am" , & s] , Some ( repo_path) ) ?;
100
+ run_command_with_output (
101
+ & [ & "git" , & "am" , & file_path. canonicalize ( ) . unwrap ( ) ] ,
102
+ Some ( & repo_path) ,
103
+ ) ?;
92
104
}
93
105
Ok ( ( ) )
94
106
} ) ?;
95
107
if let Some ( extra) = extra {
96
- extra ( repo_path) ?;
108
+ extra ( & repo_path) ?;
97
109
}
98
110
Ok ( ( ) )
99
111
}
@@ -136,7 +148,8 @@ pub fn run() -> Result<(), String> {
136
148
Some ( a) => a,
137
149
None => return Ok ( ( ) ) ,
138
150
} ;
139
- prepare_libcore ( ) ?;
151
+ let sysroot_path = Path :: new ( "build_sysroot" ) ;
152
+ prepare_libcore ( sysroot_path) ?;
140
153
141
154
if !args. only_libcore {
142
155
cargo_install ( "hyperfine" ) ?;
@@ -148,7 +161,7 @@ pub fn run() -> Result<(), String> {
148
161
] ;
149
162
150
163
for ( repo_url, checkout_commit, cb) in to_clone {
151
- clone_and_setup ( repo_url, checkout_commit, * cb) ?;
164
+ clone_and_setup ( sysroot_path , repo_url, checkout_commit, * cb) ?;
152
165
}
153
166
}
154
167
0 commit comments