Skip to content

Commit a900a52

Browse files
committed
Download tarballs from github instead of cloning full repos
This saves 40-50s on CI as the repo history can be skipped
1 parent af008bd commit a900a52

File tree

1 file changed

+68
-23
lines changed

1 file changed

+68
-23
lines changed

build_system/prepare.rs

Lines changed: 68 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,33 @@ pub(crate) fn prepare() {
1414
eprintln!("[INSTALL] hyperfine");
1515
Command::new("cargo").arg("install").arg("hyperfine").spawn().unwrap().wait().unwrap();
1616

17-
// FIXME download source archives where possible instead
18-
clone_repo(
17+
clone_repo_shallow_github(
18+
"rand",
19+
"rust-random",
1920
"rand",
20-
"https://github.com/rust-random/rand.git",
2121
"0f933f9c7176e53b2a3c7952ded484e1783f0bf1",
2222
);
2323
apply_patches("rand", Path::new("rand"));
2424

25-
clone_repo(
25+
clone_repo_shallow_github(
26+
"regex",
27+
"rust-lang",
2628
"regex",
27-
"https://github.com/rust-lang/regex.git",
2829
"341f207c1071f7290e3f228c710817c280c8dca1",
2930
);
3031

31-
clone_repo(
32+
clone_repo_shallow_github(
33+
"portable-simd",
34+
"rust-lang",
3235
"portable-simd",
33-
"https://github.com/rust-lang/portable-simd",
3436
"b8d6b6844602f80af79cd96401339ec594d472d8",
3537
);
3638
apply_patches("portable-simd", Path::new("portable-simd"));
3739

38-
clone_repo(
40+
clone_repo_shallow_github(
41+
"simple-raytracer",
42+
"ebobby",
3943
"simple-raytracer",
40-
"https://github.com/ebobby/simple-raytracer",
4144
"804a7a21b9e673a482797aa289a18ed480e4d813",
4245
);
4346

@@ -75,29 +78,20 @@ fn prepare_sysroot() {
7578
git_init_cmd.arg("init").arg("-q").current_dir(&sysroot_src);
7679
spawn_and_wait(git_init_cmd);
7780

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);
9082

9183
apply_patches("sysroot", &sysroot_src);
9284

93-
clone_repo(
85+
clone_repo_shallow_github(
9486
"build_sysroot/compiler-builtins",
95-
"https://github.com/rust-lang/compiler-builtins.git",
87+
"rust-lang",
88+
"compiler-builtins",
9689
"0.1.70",
9790
);
9891
apply_patches("compiler-builtins", Path::new("build_sysroot/compiler-builtins"));
9992
}
10093

94+
#[allow(dead_code)]
10195
fn clone_repo(target_dir: &str, repo: &str, rev: &str) {
10296
eprintln!("[CLONE] {}", repo);
10397
// 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) {
112106
spawn_and_wait(checkout_cmd);
113107
}
114108

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+
115160
fn get_patches(crate_name: &str) -> Vec<OsString> {
116161
let mut patches: Vec<_> = fs::read_dir("patches")
117162
.unwrap()

0 commit comments

Comments
 (0)