Skip to content

Commit

Permalink
Use the compiler returned by build_sysroot for benchmarking
Browse files Browse the repository at this point in the history
Rather than trying to fish it out of the default target location dist/.
This reduces the amount of places where the presence of the dist dir is
hardcoded.
  • Loading branch information
bjorn3 committed Dec 18, 2024
1 parent 8521e70 commit cae568e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 28 deletions.
41 changes: 15 additions & 26 deletions build_system/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@ static SIMPLE_RAYTRACER_REPO: GitRepo = GitRepo::github(
"<none>",
);

pub(crate) fn benchmark(dirs: &Dirs, bootstrap_host_compiler: &Compiler) {
benchmark_simple_raytracer(dirs, bootstrap_host_compiler);
}

fn benchmark_simple_raytracer(dirs: &Dirs, bootstrap_host_compiler: &Compiler) {
pub(crate) fn benchmark(dirs: &Dirs, compiler: &Compiler) {
if std::process::Command::new("hyperfine").output().is_err() {
eprintln!("Hyperfine not installed");
eprintln!("Hint: Try `cargo install hyperfine` to install hyperfine");
Expand All @@ -39,9 +35,9 @@ fn benchmark_simple_raytracer(dirs: &Dirs, bootstrap_host_compiler: &Compiler) {
};

eprintln!("[BENCH COMPILE] ebobby/simple-raytracer");
let cargo_clif = dirs
.dist_dir
.join(get_file_name(&bootstrap_host_compiler.rustc, "cargo_clif", "bin").replace('_', "-"));
let cargo_clif = &compiler.cargo;
let rustc_clif = &compiler.rustc;
let rustflags = &compiler.rustflags.join("\x1f");
let manifest_path = SIMPLE_RAYTRACER_REPO.source_dir().to_path(dirs).join("Cargo.toml");
let target_dir = dirs.build_dir.join("simple_raytracer");

Expand All @@ -56,22 +52,24 @@ fn benchmark_simple_raytracer(dirs: &Dirs, bootstrap_host_compiler: &Compiler) {
target_dir = target_dir.display(),
);
let clif_build_cmd = format!(
"RUSTC=rustc {cargo_clif} build --manifest-path {manifest_path} --target-dir {target_dir} && (rm build/raytracer_cg_clif || true) && ln build/simple_raytracer/debug/main build/raytracer_cg_clif",
"RUSTC={rustc_clif} CARGO_ENCODED_RUSTFLAGS=\"{rustflags}\" {cargo_clif} build --manifest-path {manifest_path} --target-dir {target_dir} && (rm build/raytracer_cg_clif || true) && ln build/simple_raytracer/debug/main build/raytracer_cg_clif",
cargo_clif = cargo_clif.display(),
rustc_clif = rustc_clif.display(),
manifest_path = manifest_path.display(),
target_dir = target_dir.display(),
);
let clif_build_opt_cmd = format!(
"RUSTC=rustc {cargo_clif} build --manifest-path {manifest_path} --target-dir {target_dir} --release && (rm build/raytracer_cg_clif_opt || true) && ln build/simple_raytracer/release/main build/raytracer_cg_clif_opt",
"RUSTC={rustc_clif} CARGO_ENCODED_RUSTFLAGS=\"{rustflags}\" {cargo_clif} build --manifest-path {manifest_path} --target-dir {target_dir} --release && (rm build/raytracer_cg_clif_opt || true) && ln build/simple_raytracer/release/main build/raytracer_cg_clif_opt",
cargo_clif = cargo_clif.display(),
rustc_clif = rustc_clif.display(),
manifest_path = manifest_path.display(),
target_dir = target_dir.display(),
);

let bench_compile_markdown = dirs.dist_dir.join("bench_compile.md");

let bench_compile = hyperfine_command(
1,
0,
bench_runs,
Some(&clean_cmd),
&[
Expand All @@ -94,21 +92,12 @@ fn benchmark_simple_raytracer(dirs: &Dirs, bootstrap_host_compiler: &Compiler) {

let bench_run_markdown = dirs.dist_dir.join("bench_run.md");

let raytracer_cg_llvm = Path::new(".").join(get_file_name(
&bootstrap_host_compiler.rustc,
"raytracer_cg_llvm",
"bin",
));
let raytracer_cg_clif = Path::new(".").join(get_file_name(
&bootstrap_host_compiler.rustc,
"raytracer_cg_clif",
"bin",
));
let raytracer_cg_clif_opt = Path::new(".").join(get_file_name(
&bootstrap_host_compiler.rustc,
"raytracer_cg_clif_opt",
"bin",
));
let raytracer_cg_llvm =
Path::new(".").join(get_file_name(&compiler.rustc, "raytracer_cg_llvm", "bin"));
let raytracer_cg_clif =
Path::new(".").join(get_file_name(&compiler.rustc, "raytracer_cg_clif", "bin"));
let raytracer_cg_clif_opt =
Path::new(".").join(get_file_name(&compiler.rustc, "raytracer_cg_clif_opt", "bin"));
let mut bench_run = hyperfine_command(
0,
bench_runs,
Expand Down
4 changes: 2 additions & 2 deletions build_system/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,15 +247,15 @@ fn main() {
);
}
Command::Bench => {
build_sysroot::build_sysroot(
let compiler = build_sysroot::build_sysroot(
&dirs,
sysroot_kind,
&cg_clif_dylib,
&bootstrap_host_compiler,
rustup_toolchain_name.as_deref(),
target_triple,
);
bench::benchmark(&dirs, &bootstrap_host_compiler);
bench::benchmark(&dirs, &compiler);
}
}
}

0 comments on commit cae568e

Please sign in to comment.