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