@@ -14,30 +14,33 @@ pub(crate) fn prepare() {
14
14
eprintln ! ( "[INSTALL] hyperfine" ) ;
15
15
Command :: new ( "cargo" ) . arg ( "install" ) . arg ( "hyperfine" ) . spawn ( ) . unwrap ( ) . wait ( ) . unwrap ( ) ;
16
16
17
- // FIXME download source archives where possible instead
18
- clone_repo (
17
+ clone_repo_shallow_github (
18
+ "rand" ,
19
+ "rust-random" ,
19
20
"rand" ,
20
- "https://github.com/rust-random/rand.git" ,
21
21
"0f933f9c7176e53b2a3c7952ded484e1783f0bf1" ,
22
22
) ;
23
23
apply_patches ( "rand" , Path :: new ( "rand" ) ) ;
24
24
25
- clone_repo (
25
+ clone_repo_shallow_github (
26
+ "regex" ,
27
+ "rust-lang" ,
26
28
"regex" ,
27
- "https://github.com/rust-lang/regex.git" ,
28
29
"341f207c1071f7290e3f228c710817c280c8dca1" ,
29
30
) ;
30
31
31
- clone_repo (
32
+ clone_repo_shallow_github (
33
+ "portable-simd" ,
34
+ "rust-lang" ,
32
35
"portable-simd" ,
33
- "https://github.com/rust-lang/portable-simd" ,
34
36
"b8d6b6844602f80af79cd96401339ec594d472d8" ,
35
37
) ;
36
38
apply_patches ( "portable-simd" , Path :: new ( "portable-simd" ) ) ;
37
39
38
- clone_repo (
40
+ clone_repo_shallow_github (
41
+ "simple-raytracer" ,
42
+ "ebobby" ,
39
43
"simple-raytracer" ,
40
- "https://github.com/ebobby/simple-raytracer" ,
41
44
"804a7a21b9e673a482797aa289a18ed480e4d813" ,
42
45
) ;
43
46
@@ -75,29 +78,20 @@ fn prepare_sysroot() {
75
78
git_init_cmd. arg ( "init" ) . arg ( "-q" ) . current_dir ( & sysroot_src) ;
76
79
spawn_and_wait ( git_init_cmd) ;
77
80
78
- let mut git_add_cmd = Command :: new ( "git" ) ;
79
- git_add_cmd. arg ( "add" ) . arg ( "." ) . current_dir ( & sysroot_src) ;
80
- spawn_and_wait ( git_add_cmd) ;
81
-
82
- let mut git_commit_cmd = Command :: new ( "git" ) ;
83
- git_commit_cmd
84
- . arg ( "commit" )
85
- . arg ( "-m" )
86
- . arg ( "Initial commit" )
87
- . arg ( "-q" )
88
- . current_dir ( & sysroot_src) ;
89
- spawn_and_wait ( git_commit_cmd) ;
81
+ init_git_repo ( & sysroot_src) ;
90
82
91
83
apply_patches ( "sysroot" , & sysroot_src) ;
92
84
93
- clone_repo (
85
+ clone_repo_shallow_github (
94
86
"build_sysroot/compiler-builtins" ,
95
- "https://github.com/rust-lang/compiler-builtins.git" ,
87
+ "rust-lang" ,
88
+ "compiler-builtins" ,
96
89
"0.1.70" ,
97
90
) ;
98
91
apply_patches ( "compiler-builtins" , Path :: new ( "build_sysroot/compiler-builtins" ) ) ;
99
92
}
100
93
94
+ #[ allow( dead_code) ]
101
95
fn clone_repo ( target_dir : & str , repo : & str , rev : & str ) {
102
96
eprintln ! ( "[CLONE] {}" , repo) ;
103
97
// Ignore exit code as the repo may already have been checked out
@@ -112,6 +106,57 @@ fn clone_repo(target_dir: &str, repo: &str, rev: &str) {
112
106
spawn_and_wait ( checkout_cmd) ;
113
107
}
114
108
109
+ fn clone_repo_shallow_github ( target_dir : & str , username : & str , repo : & str , rev : & str ) {
110
+ if cfg ! ( windows) {
111
+ // Older windows doesn't have tar or curl by default. Fall back to using git.
112
+ clone_repo ( target_dir, & format ! ( "https://github.com/{}/{}.git" , username, repo) , rev) ;
113
+ return ;
114
+ }
115
+
116
+ let archive_url = format ! ( "https://github.com/{}/{}/archive/{}.tar.gz" , username, repo, rev) ;
117
+ let archive_file = format ! ( "{}.tar.gz" , rev) ;
118
+ let archive_dir = format ! ( "{}-{}" , repo, rev) ;
119
+
120
+ eprintln ! ( "[DOWNLOAD] {}/{} from {}" , username, repo, archive_url) ;
121
+
122
+ // Remove previous results if they exists
123
+ let _ = std:: fs:: remove_file ( & archive_file) ;
124
+ let _ = std:: fs:: remove_dir_all ( & archive_dir) ;
125
+ let _ = std:: fs:: remove_dir_all ( target_dir) ;
126
+
127
+ // Download zip archive
128
+ let mut download_cmd = Command :: new ( "curl" ) ;
129
+ download_cmd. arg ( "--location" ) . arg ( "--output" ) . arg ( & archive_file) . arg ( archive_url) ;
130
+ spawn_and_wait ( download_cmd) ;
131
+
132
+ // Unpack tar archive
133
+ let mut unpack_cmd = Command :: new ( "tar" ) ;
134
+ unpack_cmd. arg ( "xf" ) . arg ( & archive_file) ;
135
+ spawn_and_wait ( unpack_cmd) ;
136
+
137
+ // Rename unpacked dir to the expected name
138
+ std:: fs:: rename ( archive_dir, target_dir) . unwrap ( ) ;
139
+
140
+ init_git_repo ( Path :: new ( target_dir) ) ;
141
+
142
+ // Cleanup
143
+ std:: fs:: remove_file ( archive_file) . unwrap ( ) ;
144
+ }
145
+
146
+ fn init_git_repo ( repo_dir : & Path ) {
147
+ let mut git_init_cmd = Command :: new ( "git" ) ;
148
+ git_init_cmd. arg ( "init" ) . arg ( "-q" ) . current_dir ( repo_dir) ;
149
+ spawn_and_wait ( git_init_cmd) ;
150
+
151
+ let mut git_add_cmd = Command :: new ( "git" ) ;
152
+ git_add_cmd. arg ( "add" ) . arg ( "." ) . current_dir ( repo_dir) ;
153
+ spawn_and_wait ( git_add_cmd) ;
154
+
155
+ let mut git_commit_cmd = Command :: new ( "git" ) ;
156
+ git_commit_cmd. arg ( "commit" ) . arg ( "-m" ) . arg ( "Initial commit" ) . arg ( "-q" ) . current_dir ( repo_dir) ;
157
+ spawn_and_wait ( git_commit_cmd) ;
158
+ }
159
+
115
160
fn get_patches ( crate_name : & str ) -> Vec < OsString > {
116
161
let mut patches: Vec < _ > = fs:: read_dir ( "patches" )
117
162
. unwrap ( )
0 commit comments