@@ -7,56 +7,61 @@ use std::process::Command;
7
7
use super :: rustc_info:: { get_file_name, get_rustc_path, get_rustc_version} ;
8
8
use super :: utils:: { cargo_command, copy_dir_recursively, spawn_and_wait} ;
9
9
10
+ pub ( crate ) const ABI_CAFE : GitRepo = GitRepo :: github (
11
+ "Gankra" ,
12
+ "abi-cafe" ,
13
+ "4c6dc8c9c687e2b3a760ff2176ce236872b37212" ,
14
+ "abi-cafe" ,
15
+ ) ;
16
+
17
+ pub ( crate ) const RAND : GitRepo =
18
+ GitRepo :: github ( "rust-random" , "rand" , "0f933f9c7176e53b2a3c7952ded484e1783f0bf1" , "rand" ) ;
19
+
20
+ pub ( crate ) const REGEX : GitRepo =
21
+ GitRepo :: github ( "rust-lang" , "regex" , "341f207c1071f7290e3f228c710817c280c8dca1" , "regex" ) ;
22
+
23
+ pub ( crate ) const PORTABLE_SIMD : GitRepo = GitRepo :: github (
24
+ "rust-lang" ,
25
+ "portable-simd" ,
26
+ "d5cd4a8112d958bd3a252327e0d069a6363249bd" ,
27
+ "portable-simd" ,
28
+ ) ;
29
+
30
+ pub ( crate ) const SIMPLE_RAYTRACER : GitRepo = GitRepo :: github (
31
+ "ebobby" ,
32
+ "simple-raytracer" ,
33
+ "804a7a21b9e673a482797aa289a18ed480e4d813" ,
34
+ "<none>" ,
35
+ ) ;
36
+
10
37
pub ( crate ) fn prepare ( ) {
38
+ if Path :: new ( "download" ) . exists ( ) {
39
+ std:: fs:: remove_dir_all ( Path :: new ( "download" ) ) . unwrap ( ) ;
40
+ }
41
+ std:: fs:: create_dir_all ( Path :: new ( "download" ) ) . unwrap ( ) ;
42
+
11
43
prepare_sysroot ( ) ;
12
44
45
+ // FIXME maybe install this only locally?
13
46
eprintln ! ( "[INSTALL] hyperfine" ) ;
14
47
Command :: new ( "cargo" ) . arg ( "install" ) . arg ( "hyperfine" ) . spawn ( ) . unwrap ( ) . wait ( ) . unwrap ( ) ;
15
48
16
- clone_repo_shallow_github (
17
- "abi-cafe" ,
18
- "Gankra" ,
19
- "abi-cafe" ,
20
- "4c6dc8c9c687e2b3a760ff2176ce236872b37212" ,
21
- ) ;
22
- apply_patches ( "abi-cafe" , Path :: new ( "abi-cafe" ) ) ;
23
-
24
- clone_repo_shallow_github (
25
- "rand" ,
26
- "rust-random" ,
27
- "rand" ,
28
- "0f933f9c7176e53b2a3c7952ded484e1783f0bf1" ,
29
- ) ;
30
- apply_patches ( "rand" , Path :: new ( "rand" ) ) ;
31
-
32
- clone_repo_shallow_github (
33
- "regex" ,
34
- "rust-lang" ,
35
- "regex" ,
36
- "341f207c1071f7290e3f228c710817c280c8dca1" ,
37
- ) ;
38
-
39
- clone_repo_shallow_github (
40
- "portable-simd" ,
41
- "rust-lang" ,
42
- "portable-simd" ,
43
- "d5cd4a8112d958bd3a252327e0d069a6363249bd" ,
44
- ) ;
45
- apply_patches ( "portable-simd" , Path :: new ( "portable-simd" ) ) ;
46
-
47
- clone_repo_shallow_github (
48
- "simple-raytracer" ,
49
- "ebobby" ,
50
- "simple-raytracer" ,
51
- "804a7a21b9e673a482797aa289a18ed480e4d813" ,
52
- ) ;
49
+ ABI_CAFE . fetch ( ) ;
50
+ RAND . fetch ( ) ;
51
+ REGEX . fetch ( ) ;
52
+ PORTABLE_SIMD . fetch ( ) ;
53
+ SIMPLE_RAYTRACER . fetch ( ) ;
53
54
54
55
eprintln ! ( "[LLVM BUILD] simple-raytracer" ) ;
55
- let build_cmd = cargo_command ( "cargo" , "build" , None , Path :: new ( "simple-raytracer" ) ) ;
56
+ let build_cmd = cargo_command ( "cargo" , "build" , None , & SIMPLE_RAYTRACER . source_dir ( ) ) ;
56
57
spawn_and_wait ( build_cmd) ;
57
58
fs:: copy (
58
- Path :: new ( "simple-raytracer/target/debug" ) . join ( get_file_name ( "main" , "bin" ) ) ,
59
- Path :: new ( "simple-raytracer" ) . join ( get_file_name ( "raytracer_cg_llvm" , "bin" ) ) ,
59
+ SIMPLE_RAYTRACER
60
+ . source_dir ( )
61
+ . join ( "target" )
62
+ . join ( "debug" )
63
+ . join ( get_file_name ( "main" , "bin" ) ) ,
64
+ SIMPLE_RAYTRACER . source_dir ( ) . join ( get_file_name ( "raytracer_cg_llvm" , "bin" ) ) ,
60
65
)
61
66
. unwrap ( ) ;
62
67
}
@@ -88,38 +93,78 @@ fn prepare_sysroot() {
88
93
apply_patches ( "sysroot" , & sysroot_src) ;
89
94
}
90
95
96
+ pub ( crate ) struct GitRepo {
97
+ url : GitRepoUrl ,
98
+ rev : & ' static str ,
99
+ patch_name : & ' static str ,
100
+ }
101
+
102
+ enum GitRepoUrl {
103
+ Github { user : & ' static str , repo : & ' static str } ,
104
+ }
105
+
106
+ impl GitRepo {
107
+ const fn github (
108
+ user : & ' static str ,
109
+ repo : & ' static str ,
110
+ rev : & ' static str ,
111
+ patch_name : & ' static str ,
112
+ ) -> GitRepo {
113
+ GitRepo { url : GitRepoUrl :: Github { user, repo } , rev, patch_name }
114
+ }
115
+
116
+ pub ( crate ) fn source_dir ( & self ) -> PathBuf {
117
+ match self . url {
118
+ GitRepoUrl :: Github { user : _, repo } => {
119
+ std:: env:: current_dir ( ) . unwrap ( ) . join ( "download" ) . join ( repo)
120
+ }
121
+ }
122
+ }
123
+
124
+ fn fetch ( & self ) {
125
+ match self . url {
126
+ GitRepoUrl :: Github { user, repo } => {
127
+ clone_repo_shallow_github ( & self . source_dir ( ) , user, repo, self . rev ) ;
128
+ }
129
+ }
130
+ apply_patches ( self . patch_name , & self . source_dir ( ) ) ;
131
+ }
132
+ }
133
+
91
134
#[ allow( dead_code) ]
92
- fn clone_repo ( target_dir : & str , repo : & str , rev : & str ) {
135
+ fn clone_repo ( download_dir : & Path , repo : & str , rev : & str ) {
93
136
eprintln ! ( "[CLONE] {}" , repo) ;
94
137
// Ignore exit code as the repo may already have been checked out
95
- Command :: new ( "git" ) . arg ( "clone" ) . arg ( repo) . arg ( target_dir ) . spawn ( ) . unwrap ( ) . wait ( ) . unwrap ( ) ;
138
+ Command :: new ( "git" ) . arg ( "clone" ) . arg ( repo) . arg ( & download_dir ) . spawn ( ) . unwrap ( ) . wait ( ) . unwrap ( ) ;
96
139
97
140
let mut clean_cmd = Command :: new ( "git" ) ;
98
- clean_cmd. arg ( "checkout" ) . arg ( "--" ) . arg ( "." ) . current_dir ( target_dir ) ;
141
+ clean_cmd. arg ( "checkout" ) . arg ( "--" ) . arg ( "." ) . current_dir ( & download_dir ) ;
99
142
spawn_and_wait ( clean_cmd) ;
100
143
101
144
let mut checkout_cmd = Command :: new ( "git" ) ;
102
- checkout_cmd. arg ( "checkout" ) . arg ( "-q" ) . arg ( rev) . current_dir ( target_dir ) ;
145
+ checkout_cmd. arg ( "checkout" ) . arg ( "-q" ) . arg ( rev) . current_dir ( download_dir ) ;
103
146
spawn_and_wait ( checkout_cmd) ;
104
147
}
105
148
106
- fn clone_repo_shallow_github ( target_dir : & str , username : & str , repo : & str , rev : & str ) {
149
+ fn clone_repo_shallow_github ( download_dir : & Path , user : & str , repo : & str , rev : & str ) {
107
150
if cfg ! ( windows) {
108
151
// Older windows doesn't have tar or curl by default. Fall back to using git.
109
- clone_repo ( target_dir , & format ! ( "https://github.com/{}/{}.git" , username , repo) , rev) ;
152
+ clone_repo ( download_dir , & format ! ( "https://github.com/{}/{}.git" , user , repo) , rev) ;
110
153
return ;
111
154
}
112
155
113
- let archive_url = format ! ( "https://github.com/{}/{}/archive/{}.tar.gz" , username, repo, rev) ;
114
- let archive_file = format ! ( "{}.tar.gz" , rev) ;
115
- let archive_dir = format ! ( "{}-{}" , repo, rev) ;
156
+ let downloads_dir = std:: env:: current_dir ( ) . unwrap ( ) . join ( "download" ) ;
116
157
117
- eprintln ! ( "[DOWNLOAD] {}/{} from {}" , username, repo, archive_url) ;
158
+ let archive_url = format ! ( "https://github.com/{}/{}/archive/{}.tar.gz" , user, repo, rev) ;
159
+ let archive_file = downloads_dir. join ( format ! ( "{}.tar.gz" , rev) ) ;
160
+ let archive_dir = downloads_dir. join ( format ! ( "{}-{}" , repo, rev) ) ;
161
+
162
+ eprintln ! ( "[DOWNLOAD] {}/{} from {}" , user, repo, archive_url) ;
118
163
119
164
// Remove previous results if they exists
120
165
let _ = std:: fs:: remove_file ( & archive_file) ;
121
166
let _ = std:: fs:: remove_dir_all ( & archive_dir) ;
122
- let _ = std:: fs:: remove_dir_all ( target_dir ) ;
167
+ let _ = std:: fs:: remove_dir_all ( & download_dir ) ;
123
168
124
169
// Download zip archive
125
170
let mut download_cmd = Command :: new ( "curl" ) ;
@@ -128,13 +173,13 @@ fn clone_repo_shallow_github(target_dir: &str, username: &str, repo: &str, rev:
128
173
129
174
// Unpack tar archive
130
175
let mut unpack_cmd = Command :: new ( "tar" ) ;
131
- unpack_cmd. arg ( "xf" ) . arg ( & archive_file) ;
176
+ unpack_cmd. arg ( "xf" ) . arg ( & archive_file) . current_dir ( downloads_dir ) ;
132
177
spawn_and_wait ( unpack_cmd) ;
133
178
134
179
// Rename unpacked dir to the expected name
135
- std:: fs:: rename ( archive_dir, target_dir ) . unwrap ( ) ;
180
+ std:: fs:: rename ( archive_dir, & download_dir ) . unwrap ( ) ;
136
181
137
- init_git_repo ( Path :: new ( target_dir ) ) ;
182
+ init_git_repo ( & download_dir ) ;
138
183
139
184
// Cleanup
140
185
std:: fs:: remove_file ( archive_file) . unwrap ( ) ;
@@ -175,6 +220,10 @@ fn get_patches(source_dir: &Path, crate_name: &str) -> Vec<PathBuf> {
175
220
}
176
221
177
222
fn apply_patches ( crate_name : & str , target_dir : & Path ) {
223
+ if crate_name == "<none>" {
224
+ return ;
225
+ }
226
+
178
227
for patch in get_patches ( & std:: env:: current_dir ( ) . unwrap ( ) , crate_name) {
179
228
eprintln ! (
180
229
"[PATCH] {:?} <- {:?}" ,
0 commit comments