Skip to content

Commit e14e5c2

Browse files
committed
Don't use hyperfine during testing
A new command ./y.rs bench is introduced for benchmarking. This change allows skipping hyperfine installation in ./y.rs prepare and thus avoids writing to ~/.cargo/bin.
1 parent da37e16 commit e14e5c2

File tree

10 files changed

+106
-110
lines changed

10 files changed

+106
-110
lines changed

.cirrus.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ task:
66
- pkg install -y curl git bash
77
- curl https://sh.rustup.rs -sSf --output rustup.sh
88
- sh rustup.sh --default-toolchain none -y --profile=minimal
9-
cargo_bin_cache:
10-
folder: ~/.cargo/bin
119
target_cache:
1210
folder: target
1311
prepare_script:

.github/workflows/main.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,6 @@ jobs:
6262
steps:
6363
- uses: actions/checkout@v3
6464

65-
- name: Cache cargo installed crates
66-
uses: actions/cache@v3
67-
with:
68-
path: ~/.cargo/bin
69-
key: ${{ runner.os }}-${{ matrix.env.TARGET_TRIPLE }}-cargo-installed-crates
70-
7165
- name: Cache cargo registry and index
7266
uses: actions/cache@v3
7367
with:

.github/workflows/nightly-cranelift.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,6 @@ jobs:
1313
steps:
1414
- uses: actions/checkout@v3
1515

16-
- name: Cache cargo installed crates
17-
uses: actions/cache@v3
18-
with:
19-
path: ~/.cargo/bin
20-
key: ubuntu-latest-cargo-installed-crates
21-
2216
- name: Prepare dependencies
2317
run: |
2418
git config --global user.email "[email protected]"

.github/workflows/rustc.yml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,6 @@ jobs:
1010
steps:
1111
- uses: actions/checkout@v3
1212

13-
- name: Cache cargo installed crates
14-
uses: actions/cache@v3
15-
with:
16-
path: ~/.cargo/bin
17-
key: ${{ runner.os }}-cargo-installed-crates
18-
1913
- name: Cache cargo registry and index
2014
uses: actions/cache@v3
2115
with:
@@ -44,12 +38,6 @@ jobs:
4438
steps:
4539
- uses: actions/checkout@v3
4640

47-
- name: Cache cargo installed crates
48-
uses: actions/cache@v3
49-
with:
50-
path: ~/.cargo/bin
51-
key: ${{ runner.os }}-cargo-installed-crates
52-
5341
- name: Cache cargo registry and index
5442
uses: actions/cache@v3
5543
with:

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
]
3131
},
3232
{
33-
"sysroot_src": "./build_sysroot/sysroot_src/library",
33+
"sysroot_src": "./download/sysroot/sysroot_src/library",
3434
"crates": [
3535
{
3636
"root_module": "./example/std_example.rs",

build_system/bench.rs

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
use std::env;
2+
use std::fs;
3+
use std::path::Path;
4+
5+
use super::path::{Dirs, RelPath};
6+
use super::prepare::GitRepo;
7+
use super::rustc_info::{get_file_name, get_wrapper_file_name};
8+
use super::utils::{hyperfine_command, is_ci, spawn_and_wait, CargoProject};
9+
10+
pub(crate) static SIMPLE_RAYTRACER_REPO: GitRepo = GitRepo::github(
11+
"ebobby",
12+
"simple-raytracer",
13+
"804a7a21b9e673a482797aa289a18ed480e4d813",
14+
"<none>",
15+
);
16+
17+
pub(crate) static SIMPLE_RAYTRACER: CargoProject =
18+
CargoProject::new(&SIMPLE_RAYTRACER_REPO.source_dir(), "simple_raytracer");
19+
20+
pub(crate) fn benchmark(dirs: &Dirs) {
21+
benchmark_simple_raytracer(dirs);
22+
}
23+
24+
fn benchmark_simple_raytracer(dirs: &Dirs) {
25+
if std::process::Command::new("hyperfine").output().is_err() {
26+
eprintln!("Hyperfine not installed");
27+
eprintln!("Hint: Try `cargo install hyperfine` to install hyperfine");
28+
std::process::exit(1);
29+
}
30+
31+
let run_runs = env::var("RUN_RUNS")
32+
.unwrap_or(if is_ci() { "2" } else { "10" }.to_string())
33+
.parse()
34+
.unwrap();
35+
36+
eprintln!("[BENCH COMPILE] ebobby/simple-raytracer");
37+
let cargo_clif = RelPath::DIST.to_path(dirs).join(get_wrapper_file_name("cargo-clif", "bin"));
38+
let manifest_path = SIMPLE_RAYTRACER.manifest_path(dirs);
39+
let target_dir = SIMPLE_RAYTRACER.target_dir(dirs);
40+
41+
let clean_cmd = format!(
42+
"cargo clean --manifest-path {manifest_path} --target-dir {target_dir}",
43+
manifest_path = manifest_path.display(),
44+
target_dir = target_dir.display(),
45+
);
46+
let llvm_build_cmd = format!(
47+
"cargo build --manifest-path {manifest_path} --target-dir {target_dir}",
48+
manifest_path = manifest_path.display(),
49+
target_dir = target_dir.display(),
50+
);
51+
let clif_build_cmd = format!(
52+
"{cargo_clif} build --manifest-path {manifest_path} --target-dir {target_dir}",
53+
cargo_clif = cargo_clif.display(),
54+
manifest_path = manifest_path.display(),
55+
target_dir = target_dir.display(),
56+
);
57+
58+
let bench_compile =
59+
hyperfine_command(1, run_runs, Some(&clean_cmd), &llvm_build_cmd, &clif_build_cmd);
60+
61+
spawn_and_wait(bench_compile);
62+
63+
eprintln!("[BENCH RUN] ebobby/simple-raytracer");
64+
fs::copy(
65+
target_dir.join("debug").join(get_file_name("main", "bin")),
66+
RelPath::BUILD.to_path(dirs).join(get_file_name("raytracer_cg_clif", "bin")),
67+
)
68+
.unwrap();
69+
70+
let mut bench_run = hyperfine_command(
71+
0,
72+
run_runs,
73+
None,
74+
Path::new(".").join(get_file_name("raytracer_cg_llvm", "bin")).to_str().unwrap(),
75+
Path::new(".").join(get_file_name("raytracer_cg_clif", "bin")).to_str().unwrap(),
76+
);
77+
bench_run.current_dir(RelPath::BUILD.to_path(dirs));
78+
spawn_and_wait(bench_run);
79+
}

build_system/mod.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::process;
55
use self::utils::is_ci;
66

77
mod abi_cafe;
8+
mod bench;
89
mod build_backend;
910
mod build_sysroot;
1011
mod config;
@@ -20,6 +21,7 @@ USAGE:
2021
./y.rs prepare [--out-dir DIR]
2122
./y.rs build [--debug] [--sysroot none|clif|llvm] [--out-dir DIR] [--no-unstable-features]
2223
./y.rs test [--debug] [--sysroot none|clif|llvm] [--out-dir DIR] [--no-unstable-features]
24+
./y.rs bench [--debug] [--sysroot none|clif|llvm] [--out-dir DIR] [--no-unstable-features]
2325
2426
OPTIONS:
2527
--sysroot none|clif|llvm
@@ -54,6 +56,7 @@ enum Command {
5456
Prepare,
5557
Build,
5658
Test,
59+
Bench,
5760
}
5861

5962
#[derive(Copy, Clone, Debug)]
@@ -67,7 +70,7 @@ pub fn main() {
6770
if env::var("RUST_BACKTRACE").is_err() {
6871
env::set_var("RUST_BACKTRACE", "1");
6972
}
70-
env::set_var("CG_CLIF_DISPLAY_CG_TIME", "1");
73+
env::set_var("CG_CLIF_DISPLAY_CG_TIME", "1"); // FIXME disable this by default
7174
env::set_var("CG_CLIF_DISABLE_INCR_CACHE", "1");
7275

7376
if is_ci() {
@@ -83,6 +86,7 @@ pub fn main() {
8386
Some("prepare") => Command::Prepare,
8487
Some("build") => Command::Build,
8588
Some("test") => Command::Test,
89+
Some("bench") => Command::Bench,
8690
Some(flag) if flag.starts_with('-') => arg_error!("Expected command found flag {}", flag),
8791
Some(command) => arg_error!("Unknown command {}", command),
8892
None => {
@@ -198,5 +202,16 @@ pub fn main() {
198202
&target_triple,
199203
);
200204
}
205+
Command::Bench => {
206+
build_sysroot::build_sysroot(
207+
&dirs,
208+
channel,
209+
sysroot_kind,
210+
&cg_clif_dylib,
211+
&host_triple,
212+
&target_triple,
213+
);
214+
bench::benchmark(&dirs);
215+
}
201216
}
202217
}

build_system/prepare.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ pub(crate) fn prepare(dirs: &Dirs) {
3333
super::tests::RAND_REPO.fetch(dirs);
3434
super::tests::REGEX_REPO.fetch(dirs);
3535
super::tests::PORTABLE_SIMD_REPO.fetch(dirs);
36-
super::tests::SIMPLE_RAYTRACER_REPO.fetch(dirs);
36+
super::bench::SIMPLE_RAYTRACER_REPO.fetch(dirs);
3737

3838
eprintln!("[LLVM BUILD] simple-raytracer");
3939
let host_compiler = Compiler::host();
40-
let build_cmd = super::tests::SIMPLE_RAYTRACER.build(&host_compiler, dirs);
40+
let build_cmd = super::bench::SIMPLE_RAYTRACER.build(&host_compiler, dirs);
4141
spawn_and_wait(build_cmd);
4242
fs::copy(
43-
super::tests::SIMPLE_RAYTRACER
43+
super::bench::SIMPLE_RAYTRACER
4444
.target_dir(dirs)
4545
.join(&host_compiler.triple)
4646
.join("debug")

build_system/tests.rs

Lines changed: 6 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
use crate::build_system::build_sysroot::SYSROOT_SRC;
2-
3-
use super::build_sysroot;
1+
use super::bench::SIMPLE_RAYTRACER;
2+
use super::build_sysroot::{self, SYSROOT_SRC};
43
use super::config;
54
use super::path::{Dirs, RelPath};
65
use super::prepare::GitRepo;
7-
use super::rustc_info::{get_file_name, get_wrapper_file_name};
8-
use super::utils::{
9-
hyperfine_command, is_ci, spawn_and_wait, spawn_and_wait_with_input, CargoProject, Compiler,
10-
};
6+
use super::utils::{spawn_and_wait, spawn_and_wait_with_input, CargoProject, Compiler};
117
use super::SysrootKind;
128
use std::env;
139
use std::ffi::OsStr;
@@ -253,16 +249,6 @@ pub(crate) static PORTABLE_SIMD_REPO: GitRepo = GitRepo::github(
253249
static PORTABLE_SIMD: CargoProject =
254250
CargoProject::new(&PORTABLE_SIMD_REPO.source_dir(), "portable_simd");
255251

256-
pub(crate) static SIMPLE_RAYTRACER_REPO: GitRepo = GitRepo::github(
257-
"ebobby",
258-
"simple-raytracer",
259-
"804a7a21b9e673a482797aa289a18ed480e4d813",
260-
"<none>",
261-
);
262-
263-
pub(crate) static SIMPLE_RAYTRACER: CargoProject =
264-
CargoProject::new(&SIMPLE_RAYTRACER_REPO.source_dir(), "simple_raytracer");
265-
266252
static LIBCORE_TESTS: CargoProject =
267253
CargoProject::new(&SYSROOT_SRC.join("library/core/tests"), "core_tests");
268254

@@ -282,67 +268,9 @@ const EXTENDED_SYSROOT_SUITE: &[TestCase] = &[
282268
spawn_and_wait(build_cmd);
283269
}
284270
}),
285-
TestCase::new("bench.simple-raytracer", &|runner| {
286-
let run_runs = env::var("RUN_RUNS")
287-
.unwrap_or(if is_ci() { "2" } else { "10" }.to_string())
288-
.parse()
289-
.unwrap();
290-
291-
if runner.is_native {
292-
eprintln!("[BENCH COMPILE] ebobby/simple-raytracer");
293-
let cargo_clif = RelPath::DIST
294-
.to_path(&runner.dirs)
295-
.join(get_wrapper_file_name("cargo-clif", "bin"));
296-
let manifest_path = SIMPLE_RAYTRACER.manifest_path(&runner.dirs);
297-
let target_dir = SIMPLE_RAYTRACER.target_dir(&runner.dirs);
298-
299-
let clean_cmd = format!(
300-
"cargo clean --manifest-path {manifest_path} --target-dir {target_dir}",
301-
manifest_path = manifest_path.display(),
302-
target_dir = target_dir.display(),
303-
);
304-
let llvm_build_cmd = format!(
305-
"cargo build --manifest-path {manifest_path} --target-dir {target_dir}",
306-
manifest_path = manifest_path.display(),
307-
target_dir = target_dir.display(),
308-
);
309-
let clif_build_cmd = format!(
310-
"{cargo_clif} build --manifest-path {manifest_path} --target-dir {target_dir}",
311-
cargo_clif = cargo_clif.display(),
312-
manifest_path = manifest_path.display(),
313-
target_dir = target_dir.display(),
314-
);
315-
316-
let bench_compile =
317-
hyperfine_command(1, run_runs, Some(&clean_cmd), &llvm_build_cmd, &clif_build_cmd);
318-
319-
spawn_and_wait(bench_compile);
320-
321-
eprintln!("[BENCH RUN] ebobby/simple-raytracer");
322-
fs::copy(
323-
target_dir.join("debug").join(get_file_name("main", "bin")),
324-
RelPath::BUILD
325-
.to_path(&runner.dirs)
326-
.join(get_file_name("raytracer_cg_clif", "bin")),
327-
)
328-
.unwrap();
329-
330-
let mut bench_run = hyperfine_command(
331-
0,
332-
run_runs,
333-
None,
334-
Path::new(".").join(get_file_name("raytracer_cg_llvm", "bin")).to_str().unwrap(),
335-
Path::new(".").join(get_file_name("raytracer_cg_clif", "bin")).to_str().unwrap(),
336-
);
337-
bench_run.current_dir(RelPath::BUILD.to_path(&runner.dirs));
338-
spawn_and_wait(bench_run);
339-
} else {
340-
spawn_and_wait(SIMPLE_RAYTRACER.clean(&runner.target_compiler.cargo, &runner.dirs));
341-
eprintln!("[BENCH COMPILE] ebobby/simple-raytracer (skipped)");
342-
eprintln!("[COMPILE] ebobby/simple-raytracer");
343-
spawn_and_wait(SIMPLE_RAYTRACER.build(&runner.target_compiler, &runner.dirs));
344-
eprintln!("[BENCH RUN] ebobby/simple-raytracer (skipped)");
345-
}
271+
TestCase::new("test.simple-raytracer", &|runner| {
272+
spawn_and_wait(SIMPLE_RAYTRACER.clean(&runner.host_compiler.cargo, &runner.dirs));
273+
spawn_and_wait(SIMPLE_RAYTRACER.build(&runner.target_compiler, &runner.dirs));
346274
}),
347275
TestCase::new("test.libcore", &|runner| {
348276
spawn_and_wait(LIBCORE_TESTS.clean(&runner.host_compiler.cargo, &runner.dirs));

config.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ aot.issue-72793
4444

4545
testsuite.extended_sysroot
4646
test.rust-random/rand
47-
bench.simple-raytracer
47+
test.simple-raytracer
4848
test.libcore
4949
test.regex-shootout-regex-dna
5050
test.regex

0 commit comments

Comments
 (0)