Skip to content

Commit 019040d

Browse files
authored
Merge pull request #1291 from bjorn3/build_system_rework2
Move downloaded test project to downloads/
2 parents e1a7791 + 24198ce commit 019040d

File tree

5 files changed

+136
-86
lines changed

5 files changed

+136
-86
lines changed

.gitignore

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,4 @@ perf.data.old
1515
/build_sysroot/compiler-builtins
1616
/build_sysroot/rustc_version
1717
/rust
18-
/rand
19-
/regex
20-
/simple-raytracer
21-
/portable-simd
22-
/abi-cafe
23-
/abi-checker
18+
/download

build_system/abi_cafe.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::path::Path;
33

44
use super::build_sysroot;
55
use super::config;
6+
use super::prepare;
67
use super::utils::{cargo_command, spawn_and_wait};
78
use super::SysrootKind;
89

@@ -35,9 +36,8 @@ pub(crate) fn run(
3536
);
3637

3738
eprintln!("Running abi-cafe");
38-
let mut abi_cafe_path = env::current_dir().unwrap();
39-
abi_cafe_path.push("abi-cafe");
40-
env::set_current_dir(&abi_cafe_path.clone()).unwrap();
39+
let abi_cafe_path = prepare::ABI_CAFE.source_dir();
40+
env::set_current_dir(abi_cafe_path.clone()).unwrap();
4141

4242
let pairs = ["rustc_calls_cgclif", "cgclif_calls_rustc", "cgclif_calls_cc", "cc_calls_cgclif"];
4343

build_system/prepare.rs

Lines changed: 103 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -7,56 +7,61 @@ use std::process::Command;
77
use super::rustc_info::{get_file_name, get_rustc_path, get_rustc_version};
88
use super::utils::{cargo_command, copy_dir_recursively, spawn_and_wait};
99

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+
1037
pub(crate) fn prepare() {
38+
if Path::new("download").exists() {
39+
std::fs::remove_dir_all(Path::new("download")).unwrap();
40+
}
41+
std::fs::create_dir_all(Path::new("download")).unwrap();
42+
1143
prepare_sysroot();
1244

45+
// FIXME maybe install this only locally?
1346
eprintln!("[INSTALL] hyperfine");
1447
Command::new("cargo").arg("install").arg("hyperfine").spawn().unwrap().wait().unwrap();
1548

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-
);
49+
ABI_CAFE.fetch();
50+
RAND.fetch();
51+
REGEX.fetch();
52+
PORTABLE_SIMD.fetch();
53+
SIMPLE_RAYTRACER.fetch();
5354

5455
eprintln!("[LLVM BUILD] simple-raytracer");
55-
let build_cmd = cargo_command("cargo", "build", None, Path::new("simple-raytracer"));
56+
let build_cmd = cargo_command("cargo", "build", None, &SIMPLE_RAYTRACER.source_dir());
5657
spawn_and_wait(build_cmd);
5758
fs::copy(
58-
Path::new("simple-raytracer/target/debug").join(get_file_name("main", "bin")),
59-
Path::new("simple-raytracer").join(get_file_name("raytracer_cg_llvm", "bin")),
59+
SIMPLE_RAYTRACER
60+
.source_dir()
61+
.join("target")
62+
.join("debug")
63+
.join(get_file_name("main", "bin")),
64+
SIMPLE_RAYTRACER.source_dir().join(get_file_name("raytracer_cg_llvm", "bin")),
6065
)
6166
.unwrap();
6267
}
@@ -88,38 +93,78 @@ fn prepare_sysroot() {
8893
apply_patches("sysroot", &sysroot_src);
8994
}
9095

96+
pub(crate) struct GitRepo {
97+
url: GitRepoUrl,
98+
rev: &'static str,
99+
patch_name: &'static str,
100+
}
101+
102+
enum GitRepoUrl {
103+
Github { user: &'static str, repo: &'static str },
104+
}
105+
106+
impl GitRepo {
107+
const fn github(
108+
user: &'static str,
109+
repo: &'static str,
110+
rev: &'static str,
111+
patch_name: &'static str,
112+
) -> GitRepo {
113+
GitRepo { url: GitRepoUrl::Github { user, repo }, rev, patch_name }
114+
}
115+
116+
pub(crate) fn source_dir(&self) -> PathBuf {
117+
match self.url {
118+
GitRepoUrl::Github { user: _, repo } => {
119+
std::env::current_dir().unwrap().join("download").join(repo)
120+
}
121+
}
122+
}
123+
124+
fn fetch(&self) {
125+
match self.url {
126+
GitRepoUrl::Github { user, repo } => {
127+
clone_repo_shallow_github(&self.source_dir(), user, repo, self.rev);
128+
}
129+
}
130+
apply_patches(self.patch_name, &self.source_dir());
131+
}
132+
}
133+
91134
#[allow(dead_code)]
92-
fn clone_repo(target_dir: &str, repo: &str, rev: &str) {
135+
fn clone_repo(download_dir: &Path, repo: &str, rev: &str) {
93136
eprintln!("[CLONE] {}", repo);
94137
// 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();
138+
Command::new("git").arg("clone").arg(repo).arg(&download_dir).spawn().unwrap().wait().unwrap();
96139

97140
let mut clean_cmd = Command::new("git");
98-
clean_cmd.arg("checkout").arg("--").arg(".").current_dir(target_dir);
141+
clean_cmd.arg("checkout").arg("--").arg(".").current_dir(&download_dir);
99142
spawn_and_wait(clean_cmd);
100143

101144
let mut checkout_cmd = Command::new("git");
102-
checkout_cmd.arg("checkout").arg("-q").arg(rev).current_dir(target_dir);
145+
checkout_cmd.arg("checkout").arg("-q").arg(rev).current_dir(download_dir);
103146
spawn_and_wait(checkout_cmd);
104147
}
105148

106-
fn clone_repo_shallow_github(target_dir: &str, username: &str, repo: &str, rev: &str) {
149+
fn clone_repo_shallow_github(download_dir: &Path, user: &str, repo: &str, rev: &str) {
107150
if cfg!(windows) {
108151
// 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);
152+
clone_repo(download_dir, &format!("https://github.com/{}/{}.git", user, repo), rev);
110153
return;
111154
}
112155

113-
let archive_url = format!("https://github.com/{}/{}/archive/{}.tar.gz", username, repo, rev);
114-
let archive_file = format!("{}.tar.gz", rev);
115-
let archive_dir = format!("{}-{}", repo, rev);
156+
let downloads_dir = std::env::current_dir().unwrap().join("download");
116157

117-
eprintln!("[DOWNLOAD] {}/{} from {}", username, repo, archive_url);
158+
let archive_url = format!("https://github.com/{}/{}/archive/{}.tar.gz", user, repo, rev);
159+
let archive_file = downloads_dir.join(format!("{}.tar.gz", rev));
160+
let archive_dir = downloads_dir.join(format!("{}-{}", repo, rev));
161+
162+
eprintln!("[DOWNLOAD] {}/{} from {}", user, repo, archive_url);
118163

119164
// Remove previous results if they exists
120165
let _ = std::fs::remove_file(&archive_file);
121166
let _ = std::fs::remove_dir_all(&archive_dir);
122-
let _ = std::fs::remove_dir_all(target_dir);
167+
let _ = std::fs::remove_dir_all(&download_dir);
123168

124169
// Download zip archive
125170
let mut download_cmd = Command::new("curl");
@@ -128,13 +173,13 @@ fn clone_repo_shallow_github(target_dir: &str, username: &str, repo: &str, rev:
128173

129174
// Unpack tar archive
130175
let mut unpack_cmd = Command::new("tar");
131-
unpack_cmd.arg("xf").arg(&archive_file);
176+
unpack_cmd.arg("xf").arg(&archive_file).current_dir(downloads_dir);
132177
spawn_and_wait(unpack_cmd);
133178

134179
// Rename unpacked dir to the expected name
135-
std::fs::rename(archive_dir, target_dir).unwrap();
180+
std::fs::rename(archive_dir, &download_dir).unwrap();
136181

137-
init_git_repo(Path::new(target_dir));
182+
init_git_repo(&download_dir);
138183

139184
// Cleanup
140185
std::fs::remove_file(archive_file).unwrap();
@@ -175,6 +220,10 @@ fn get_patches(source_dir: &Path, crate_name: &str) -> Vec<PathBuf> {
175220
}
176221

177222
fn apply_patches(crate_name: &str, target_dir: &Path) {
223+
if crate_name == "<none>" {
224+
return;
225+
}
226+
178227
for patch in get_patches(&std::env::current_dir().unwrap(), crate_name) {
179228
eprintln!(
180229
"[PATCH] {:?} <- {:?}",

build_system/tests.rs

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use super::build_sysroot;
22
use super::config;
3+
use super::prepare;
34
use super::rustc_info::get_wrapper_file_name;
45
use super::utils::{cargo_command, hyperfine_command, spawn_and_wait, spawn_and_wait_with_input};
56
use build_system::SysrootKind;
@@ -217,7 +218,7 @@ const BASE_SYSROOT_SUITE: &[TestCase] = &[
217218

218219
const EXTENDED_SYSROOT_SUITE: &[TestCase] = &[
219220
TestCase::new("test.rust-random/rand", &|runner| {
220-
runner.in_dir(["rand"], |runner| {
221+
runner.in_dir(prepare::RAND.source_dir(), |runner| {
221222
runner.run_cargo("clean", []);
222223

223224
if runner.host_triple == runner.target_triple {
@@ -230,7 +231,7 @@ const EXTENDED_SYSROOT_SUITE: &[TestCase] = &[
230231
});
231232
}),
232233
TestCase::new("bench.simple-raytracer", &|runner| {
233-
runner.in_dir(["simple-raytracer"], |runner| {
234+
runner.in_dir(prepare::SIMPLE_RAYTRACER.source_dir(), |runner| {
234235
let run_runs = env::var("RUN_RUNS").unwrap_or("10".to_string()).parse().unwrap();
235236

236237
if runner.host_triple == runner.target_triple {
@@ -273,19 +274,28 @@ const EXTENDED_SYSROOT_SUITE: &[TestCase] = &[
273274
});
274275
}),
275276
TestCase::new("test.libcore", &|runner| {
276-
runner.in_dir(["build_sysroot", "sysroot_src", "library", "core", "tests"], |runner| {
277-
runner.run_cargo("clean", []);
277+
runner.in_dir(
278+
std::env::current_dir()
279+
.unwrap()
280+
.join("build_sysroot")
281+
.join("sysroot_src")
282+
.join("library")
283+
.join("core")
284+
.join("tests"),
285+
|runner| {
286+
runner.run_cargo("clean", []);
278287

279-
if runner.host_triple == runner.target_triple {
280-
runner.run_cargo("test", []);
281-
} else {
282-
eprintln!("Cross-Compiling: Not running tests");
283-
runner.run_cargo("build", ["--tests"]);
284-
}
285-
});
288+
if runner.host_triple == runner.target_triple {
289+
runner.run_cargo("test", []);
290+
} else {
291+
eprintln!("Cross-Compiling: Not running tests");
292+
runner.run_cargo("build", ["--tests"]);
293+
}
294+
},
295+
);
286296
}),
287297
TestCase::new("test.regex-shootout-regex-dna", &|runner| {
288-
runner.in_dir(["regex"], |runner| {
298+
runner.in_dir(prepare::REGEX.source_dir(), |runner| {
289299
runner.run_cargo("clean", []);
290300

291301
// newer aho_corasick versions throw a deprecation warning
@@ -336,7 +346,7 @@ const EXTENDED_SYSROOT_SUITE: &[TestCase] = &[
336346
});
337347
}),
338348
TestCase::new("test.regex", &|runner| {
339-
runner.in_dir(["regex"], |runner| {
349+
runner.in_dir(prepare::REGEX.source_dir(), |runner| {
340350
runner.run_cargo("clean", []);
341351

342352
// newer aho_corasick versions throw a deprecation warning
@@ -367,7 +377,7 @@ const EXTENDED_SYSROOT_SUITE: &[TestCase] = &[
367377
});
368378
}),
369379
TestCase::new("test.portable-simd", &|runner| {
370-
runner.in_dir(["portable-simd"], |runner| {
380+
runner.in_dir(prepare::PORTABLE_SIMD.source_dir(), |runner| {
371381
runner.run_cargo("clean", []);
372382
runner.run_cargo("build", ["--all-targets", "--target", &runner.target_triple]);
373383

@@ -506,16 +516,8 @@ impl TestRunner {
506516
}
507517
}
508518

509-
fn in_dir<'a, I, F>(&self, dir: I, callback: F)
510-
where
511-
I: IntoIterator<Item = &'a str>,
512-
F: FnOnce(&TestRunner),
513-
{
519+
fn in_dir(&self, new: impl AsRef<Path>, callback: impl FnOnce(&TestRunner)) {
514520
let current = env::current_dir().unwrap();
515-
let mut new = current.clone();
516-
for d in dir {
517-
new.push(d);
518-
}
519521

520522
env::set_current_dir(new).unwrap();
521523
callback(self);

clean_all.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,8 @@ set -e
33

44
rm -rf build_sysroot/{sysroot_src/,target/,compiler-builtins/,rustc_version}
55
rm -rf target/ build/ perf.data{,.old} y.bin
6+
rm -rf download/
7+
8+
# Kept for now in case someone updates their checkout of cg_clif before running clean_all.sh
9+
# FIXME remove at some point in the future
610
rm -rf rand/ regex/ simple-raytracer/ portable-simd/ abi-checker/ abi-cafe/

0 commit comments

Comments
 (0)