@@ -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,24 +38,30 @@ 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
58
+ let mut patches = Vec :: new ( ) ;
54
59
walk_dir ( "patches" , |_| Ok ( ( ) ) , |file_path : & Path | {
60
+ patches. push ( file_path. to_path_buf ( ) ) ;
61
+ Ok ( ( ) )
62
+ } ) ?;
63
+ patches. sort ( ) ;
64
+ for file_path in patches {
55
65
println ! ( "[GIT] apply `{}`" , file_path. display( ) ) ;
56
66
let path = Path :: new ( "../.." ) . join ( file_path) ;
57
67
run_command_with_output ( & [ & "git" , & "apply" , & path] , Some ( & sysroot_dir) ) ?;
@@ -60,15 +70,19 @@ fn prepare_libcore() -> Result<(), String> {
60
70
& [ & "git" , & "commit" , & "--no-gpg-sign" , & "-m" , & format ! ( "Patch {}" , path. display( ) ) ] ,
61
71
Some ( & sysroot_dir) ,
62
72
) ?;
63
- Ok ( ( ) )
64
- } ) ?;
73
+ }
65
74
println ! ( "Successfully prepared libcore for building" ) ;
66
75
Ok ( ( ) )
67
76
}
68
77
69
78
// build with cg_llvm for perf comparison
70
79
fn build_raytracer ( repo_dir : & Path ) -> Result < ( ) , String > {
71
80
run_command ( & [ & "cargo" , & "build" ] , Some ( repo_dir) ) ?;
81
+ let mv_target = repo_dir. join ( "raytracer_cg_llvm" ) ;
82
+ if mv_target. is_file ( ) {
83
+ std:: fs:: remove_file ( & mv_target)
84
+ . map_err ( |e| format ! ( "Failed to remove file `{}`: {e:?}" , mv_target. display( ) ) ) ?;
85
+ }
72
86
run_command ( & [ & "mv" , & "target/debug/main" , & "raytracer_cg_llvm" ] , Some ( repo_dir) ) ?;
73
87
Ok ( ( ) )
74
88
}
@@ -82,18 +96,21 @@ where
82
96
println ! ( "`{}` has already been cloned" , clone_result. repo_name) ;
83
97
}
84
98
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) ) ?;
99
+ run_command ( & [ & "git" , & "checkout" , & "--" , & "." ] , Some ( & repo_path) ) ?;
100
+ run_command ( & [ & "git" , & "checkout" , & checkout_commit] , Some ( & repo_path) ) ?;
87
101
let filter = format ! ( "-{}-" , clone_result. repo_name) ;
88
102
walk_dir ( "crate_patches" , |_| Ok ( ( ) ) , |file_path| {
89
103
let s = file_path. as_os_str ( ) . to_str ( ) . unwrap ( ) ;
90
104
if s. contains ( & filter) && s. ends_with ( ".patch" ) {
91
- run_command ( & [ & "git" , & "am" , & s] , Some ( repo_path) ) ?;
105
+ run_command_with_output (
106
+ & [ & "git" , & "am" , & file_path. canonicalize ( ) . unwrap ( ) ] ,
107
+ Some ( & repo_path) ,
108
+ ) ?;
92
109
}
93
110
Ok ( ( ) )
94
111
} ) ?;
95
112
if let Some ( extra) = extra {
96
- extra ( repo_path) ?;
113
+ extra ( & repo_path) ?;
97
114
}
98
115
Ok ( ( ) )
99
116
}
@@ -136,7 +153,8 @@ pub fn run() -> Result<(), String> {
136
153
Some ( a) => a,
137
154
None => return Ok ( ( ) ) ,
138
155
} ;
139
- prepare_libcore ( ) ?;
156
+ let sysroot_path = Path :: new ( "build_sysroot" ) ;
157
+ prepare_libcore ( sysroot_path) ?;
140
158
141
159
if !args. only_libcore {
142
160
cargo_install ( "hyperfine" ) ?;
0 commit comments