@@ -7,49 +7,45 @@ 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 ( ) {
11
38
prepare_sysroot ( ) ;
12
39
40
+ // FIXME maybe install this only locally?
13
41
eprintln ! ( "[INSTALL] hyperfine" ) ;
14
42
Command :: new ( "cargo" ) . arg ( "install" ) . arg ( "hyperfine" ) . spawn ( ) . unwrap ( ) . wait ( ) . unwrap ( ) ;
15
43
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
- ) ;
44
+ ABI_CAFE . fetch ( ) ;
45
+ RAND . fetch ( ) ;
46
+ REGEX . fetch ( ) ;
47
+ PORTABLE_SIMD . fetch ( ) ;
48
+ SIMPLE_RAYTRACER . fetch ( ) ;
53
49
54
50
eprintln ! ( "[LLVM BUILD] simple-raytracer" ) ;
55
51
let build_cmd = cargo_command ( "cargo" , "build" , None , Path :: new ( "simple-raytracer" ) ) ;
@@ -88,38 +84,74 @@ fn prepare_sysroot() {
88
84
apply_patches ( "sysroot" , & sysroot_src) ;
89
85
}
90
86
87
+ pub ( crate ) struct GitRepo {
88
+ url : GitRepoUrl ,
89
+ rev : & ' static str ,
90
+ patch_name : & ' static str ,
91
+ }
92
+
93
+ enum GitRepoUrl {
94
+ Github { user : & ' static str , repo : & ' static str } ,
95
+ }
96
+
97
+ impl GitRepo {
98
+ const fn github (
99
+ user : & ' static str ,
100
+ repo : & ' static str ,
101
+ rev : & ' static str ,
102
+ patch_name : & ' static str ,
103
+ ) -> GitRepo {
104
+ GitRepo { url : GitRepoUrl :: Github { user, repo } , rev, patch_name }
105
+ }
106
+
107
+ pub ( crate ) fn source_dir ( & self ) -> PathBuf {
108
+ match self . url {
109
+ GitRepoUrl :: Github { user : _, repo } => PathBuf :: from ( format ! ( "{}" , repo) ) ,
110
+ }
111
+ }
112
+
113
+ fn fetch ( & self ) {
114
+ match self . url {
115
+ GitRepoUrl :: Github { user, repo } => {
116
+ clone_repo_shallow_github ( & self . source_dir ( ) , user, repo, self . rev ) ;
117
+ }
118
+ }
119
+ apply_patches ( self . patch_name , & self . source_dir ( ) ) ;
120
+ }
121
+ }
122
+
91
123
#[ allow( dead_code) ]
92
- fn clone_repo ( target_dir : & str , repo : & str , rev : & str ) {
124
+ fn clone_repo ( download_dir : & Path , repo : & str , rev : & str ) {
93
125
eprintln ! ( "[CLONE] {}" , repo) ;
94
126
// 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 ( ) ;
127
+ Command :: new ( "git" ) . arg ( "clone" ) . arg ( repo) . arg ( & download_dir ) . spawn ( ) . unwrap ( ) . wait ( ) . unwrap ( ) ;
96
128
97
129
let mut clean_cmd = Command :: new ( "git" ) ;
98
- clean_cmd. arg ( "checkout" ) . arg ( "--" ) . arg ( "." ) . current_dir ( target_dir ) ;
130
+ clean_cmd. arg ( "checkout" ) . arg ( "--" ) . arg ( "." ) . current_dir ( & download_dir ) ;
99
131
spawn_and_wait ( clean_cmd) ;
100
132
101
133
let mut checkout_cmd = Command :: new ( "git" ) ;
102
- checkout_cmd. arg ( "checkout" ) . arg ( "-q" ) . arg ( rev) . current_dir ( target_dir ) ;
134
+ checkout_cmd. arg ( "checkout" ) . arg ( "-q" ) . arg ( rev) . current_dir ( download_dir ) ;
103
135
spawn_and_wait ( checkout_cmd) ;
104
136
}
105
137
106
- fn clone_repo_shallow_github ( target_dir : & str , username : & str , repo : & str , rev : & str ) {
138
+ fn clone_repo_shallow_github ( download_dir : & Path , user : & str , repo : & str , rev : & str ) {
107
139
if cfg ! ( windows) {
108
140
// 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) ;
141
+ clone_repo ( download_dir , & format ! ( "https://github.com/{}/{}.git" , user , repo) , rev) ;
110
142
return ;
111
143
}
112
144
113
- let archive_url = format ! ( "https://github.com/{}/{}/archive/{}.tar.gz" , username , repo, rev) ;
145
+ let archive_url = format ! ( "https://github.com/{}/{}/archive/{}.tar.gz" , user , repo, rev) ;
114
146
let archive_file = format ! ( "{}.tar.gz" , rev) ;
115
147
let archive_dir = format ! ( "{}-{}" , repo, rev) ;
116
148
117
- eprintln ! ( "[DOWNLOAD] {}/{} from {}" , username , repo, archive_url) ;
149
+ eprintln ! ( "[DOWNLOAD] {}/{} from {}" , user , repo, archive_url) ;
118
150
119
151
// Remove previous results if they exists
120
152
let _ = std:: fs:: remove_file ( & archive_file) ;
121
153
let _ = std:: fs:: remove_dir_all ( & archive_dir) ;
122
- let _ = std:: fs:: remove_dir_all ( target_dir ) ;
154
+ let _ = std:: fs:: remove_dir_all ( & download_dir ) ;
123
155
124
156
// Download zip archive
125
157
let mut download_cmd = Command :: new ( "curl" ) ;
@@ -132,9 +164,9 @@ fn clone_repo_shallow_github(target_dir: &str, username: &str, repo: &str, rev:
132
164
spawn_and_wait ( unpack_cmd) ;
133
165
134
166
// Rename unpacked dir to the expected name
135
- std:: fs:: rename ( archive_dir, target_dir ) . unwrap ( ) ;
167
+ std:: fs:: rename ( archive_dir, & download_dir ) . unwrap ( ) ;
136
168
137
- init_git_repo ( Path :: new ( target_dir ) ) ;
169
+ init_git_repo ( & download_dir ) ;
138
170
139
171
// Cleanup
140
172
std:: fs:: remove_file ( archive_file) . unwrap ( ) ;
@@ -175,6 +207,10 @@ fn get_patches(source_dir: &Path, crate_name: &str) -> Vec<PathBuf> {
175
207
}
176
208
177
209
fn apply_patches ( crate_name : & str , target_dir : & Path ) {
210
+ if crate_name == "<none>" {
211
+ return ;
212
+ }
213
+
178
214
for patch in get_patches ( & std:: env:: current_dir ( ) . unwrap ( ) , crate_name) {
179
215
eprintln ! (
180
216
"[PATCH] {:?} <- {:?}" ,
0 commit comments