1
Fork 0

Merge commit '918acafef6' into sync_cg_clif-2025-01-05

This commit is contained in:
bjorn3 2025-01-05 15:44:46 +00:00
commit a94e2d513b
16 changed files with 119 additions and 248 deletions

View file

@ -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");
@ -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");
@ -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_markdown = dirs.build_dir.join("bench_compile.md");
let bench_compile = hyperfine_command(
1,
0,
bench_runs,
Some(&clean_cmd),
&[
@ -92,23 +90,14 @@ fn benchmark_simple_raytracer(dirs: &Dirs, bootstrap_host_compiler: &Compiler) {
eprintln!("[BENCH RUN] ebobby/simple-raytracer");
let bench_run_markdown = dirs.dist_dir.join("bench_run.md");
let bench_run_markdown = dirs.build_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,

View file

@ -33,23 +33,3 @@ pub(crate) fn get_bool(name: &str) -> bool {
true
}
}
pub(crate) fn get_value(name: &str) -> Option<String> {
let values = load_config_file()
.into_iter()
.filter(|(key, _)| key == name)
.map(|(_, val)| val)
.collect::<Vec<_>>();
if values.is_empty() {
None
} else if values.len() == 1 {
if values[0].is_none() {
eprintln!("Config `{}` missing value", name);
process::exit(1);
}
values.into_iter().next().unwrap()
} else {
eprintln!("Config `{}` given multiple values: {:?}", name, values);
process::exit(1);
}
}

View file

@ -156,10 +156,8 @@ fn main() {
let cargo = rustc_info::get_cargo_path();
let rustc = rustc_info::get_rustc_path();
let rustdoc = rustc_info::get_rustdoc_path();
let triple = std::env::var("HOST_TRIPLE")
.ok()
.or_else(|| config::get_value("host"))
.unwrap_or_else(|| rustc_info::get_host_triple(&rustc));
let triple =
std::env::var("HOST_TRIPLE").unwrap_or_else(|_| rustc_info::get_host_triple(&rustc));
Compiler {
cargo,
rustc,
@ -170,10 +168,8 @@ fn main() {
runner: vec![],
}
};
let target_triple = std::env::var("TARGET_TRIPLE")
.ok()
.or_else(|| config::get_value("target"))
.unwrap_or_else(|| bootstrap_host_compiler.triple.clone());
let target_triple =
std::env::var("TARGET_TRIPLE").unwrap_or_else(|_| bootstrap_host_compiler.triple.clone());
let dirs = path::Dirs {
source_dir: current_dir.clone(),
@ -247,7 +243,7 @@ fn main() {
);
}
Command::Bench => {
build_sysroot::build_sysroot(
let compiler = build_sysroot::build_sysroot(
&dirs,
sysroot_kind,
&cg_clif_dylib,
@ -255,7 +251,7 @@ fn main() {
rustup_toolchain_name.as_deref(),
target_triple,
);
bench::benchmark(&dirs, &bootstrap_host_compiler);
bench::benchmark(&dirs, &compiler);
}
}
}

View file

@ -11,20 +11,11 @@ pub(crate) struct Dirs {
#[doc(hidden)]
#[derive(Debug, Copy, Clone)]
pub(crate) enum PathBase {
enum PathBase {
Source,
Build,
}
impl PathBase {
fn to_path(self, dirs: &Dirs) -> PathBuf {
match self {
PathBase::Source => dirs.source_dir.clone(),
PathBase::Build => dirs.build_dir.clone(),
}
}
}
#[derive(Debug, Copy, Clone)]
pub(crate) struct RelPath {
base: PathBase,
@ -41,6 +32,9 @@ impl RelPath {
}
pub(crate) fn to_path(&self, dirs: &Dirs) -> PathBuf {
self.base.to_path(dirs).join(self.suffix)
match self.base {
PathBase::Source => dirs.source_dir.join(self.suffix),
PathBase::Build => dirs.build_dir.join(self.suffix),
}
}
}