@@ -14,29 +14,33 @@ pub(crate) fn prepare() {
1414 eprintln ! ( "[INSTALL] hyperfine" ) ;
1515 Command :: new ( "cargo" ) . arg ( "install" ) . arg ( "hyperfine" ) . spawn ( ) . unwrap ( ) . wait ( ) . unwrap ( ) ;
1616
17- clone_repo (
17+ clone_repo_shallow_github (
18+ "rand" ,
19+ "rust-random" ,
1820 "rand" ,
19- "https://github.com/rust-random/rand.git" ,
2021 "0f933f9c7176e53b2a3c7952ded484e1783f0bf1" ,
2122 ) ;
2223 apply_patches ( "rand" , Path :: new ( "rand" ) ) ;
2324
24- clone_repo (
25+ clone_repo_shallow_github (
26+ "regex" ,
27+ "rust-lang" ,
2528 "regex" ,
26- "https://github.com/rust-lang/regex.git" ,
2729 "341f207c1071f7290e3f228c710817c280c8dca1" ,
2830 ) ;
2931
30- clone_repo (
32+ clone_repo_shallow_github (
33+ "portable-simd" ,
34+ "rust-lang" ,
3135 "portable-simd" ,
32- "https://github.com/rust-lang/portable-simd" ,
3336 "b8d6b6844602f80af79cd96401339ec594d472d8" ,
3437 ) ;
3538 apply_patches ( "portable-simd" , Path :: new ( "portable-simd" ) ) ;
3639
37- clone_repo (
40+ clone_repo_shallow_github (
41+ "simple-raytracer" ,
42+ "ebobby" ,
3843 "simple-raytracer" ,
39- "https://github.com/ebobby/simple-raytracer" ,
4044 "804a7a21b9e673a482797aa289a18ed480e4d813" ,
4145 ) ;
4246
@@ -74,29 +78,12 @@ fn prepare_sysroot() {
7478 git_init_cmd. arg ( "init" ) . arg ( "-q" ) . current_dir ( & sysroot_src) ;
7579 spawn_and_wait ( git_init_cmd) ;
7680
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) ;
8982
9083 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" ) ) ;
9884}
9985
86+ #[ allow( dead_code) ]
10087fn clone_repo ( target_dir : & str , repo : & str , rev : & str ) {
10188 eprintln ! ( "[CLONE] {}" , repo) ;
10289 // 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) {
11198 spawn_and_wait ( checkout_cmd) ;
11299}
113100
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+
114152fn get_patches ( crate_name : & str ) -> Vec < OsString > {
115153 let mut patches: Vec < _ > = fs:: read_dir ( "patches" )
116154 . unwrap ( )
0 commit comments