Skip to content

Commit 20429c0

Browse files
authored
Merge pull request rust-lang#1338 from bjorn3/build_system_rework5
Avoid clobbering build_system/ and ~/.cargo/bin
2 parents 571405d + e14e5c2 commit 20429c0

16 files changed

+130
-134
lines changed

.cirrus.yml

-2
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

-6
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

-6
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 "user@example.com"

.github/workflows/rustc.yml

-12
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:

.gitignore

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
target
1+
/target
22
**/*.rs.bk
33
*.rlib
44
*.o
@@ -11,9 +11,6 @@ perf.data.old
1111
/y.exe
1212
/y.pdb
1313
/build
14-
/build_sysroot/sysroot_src
15-
/build_sysroot/compiler-builtins
16-
/build_sysroot/rustc_version
1714
/dist
1815
/rust
1916
/download

.vscode/settings.json

+1-1
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

+79
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/build_sysroot.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,11 @@ pub(crate) fn build_sysroot(
146146
}
147147
}
148148

149-
// FIXME move to download/ or dist/
150-
pub(crate) static SYSROOT_RUSTC_VERSION: RelPath = RelPath::BUILD_SYSROOT.join("rustc_version");
151-
pub(crate) static SYSROOT_SRC: RelPath = RelPath::BUILD_SYSROOT.join("sysroot_src");
152-
static STANDARD_LIBRARY: CargoProject = CargoProject::new(&RelPath::BUILD_SYSROOT, "build_sysroot");
149+
pub(crate) static ORIG_BUILD_SYSROOT: RelPath = RelPath::SOURCE.join("build_sysroot");
150+
pub(crate) static BUILD_SYSROOT: RelPath = RelPath::DOWNLOAD.join("sysroot");
151+
pub(crate) static SYSROOT_RUSTC_VERSION: RelPath = BUILD_SYSROOT.join("rustc_version");
152+
pub(crate) static SYSROOT_SRC: RelPath = BUILD_SYSROOT.join("sysroot_src");
153+
static STANDARD_LIBRARY: CargoProject = CargoProject::new(&BUILD_SYSROOT, "build_sysroot");
153154

154155
fn build_clif_sysroot_for_triple(
155156
dirs: &Dirs,

build_system/mod.rs

+16-1
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/path.rs

-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ impl RelPath {
4242
pub(crate) const DIST: RelPath = RelPath::Base(PathBase::Dist);
4343

4444
pub(crate) const SCRIPTS: RelPath = RelPath::SOURCE.join("scripts");
45-
pub(crate) const BUILD_SYSROOT: RelPath = RelPath::SOURCE.join("build_sysroot");
4645
pub(crate) const PATCHES: RelPath = RelPath::SOURCE.join("patches");
4746

4847
pub(crate) const fn join(&'static self, suffix: &'static str) -> RelPath {

build_system/prepare.rs

+16-14
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ use std::fs;
33
use std::path::{Path, PathBuf};
44
use std::process::Command;
55

6-
use super::build_sysroot::{SYSROOT_RUSTC_VERSION, SYSROOT_SRC};
6+
use crate::build_system::rustc_info::get_default_sysroot;
7+
8+
use super::build_sysroot::{BUILD_SYSROOT, ORIG_BUILD_SYSROOT, SYSROOT_RUSTC_VERSION, SYSROOT_SRC};
79
use super::path::{Dirs, RelPath};
8-
use super::rustc_info::{get_file_name, get_rustc_path, get_rustc_version};
10+
use super::rustc_info::{get_file_name, get_rustc_version};
911
use super::utils::{copy_dir_recursively, spawn_and_wait, Compiler};
1012

1113
pub(crate) fn prepare(dirs: &Dirs) {
@@ -31,14 +33,14 @@ pub(crate) fn prepare(dirs: &Dirs) {
3133
super::tests::RAND_REPO.fetch(dirs);
3234
super::tests::REGEX_REPO.fetch(dirs);
3335
super::tests::PORTABLE_SIMD_REPO.fetch(dirs);
34-
super::tests::SIMPLE_RAYTRACER_REPO.fetch(dirs);
36+
super::bench::SIMPLE_RAYTRACER_REPO.fetch(dirs);
3537

3638
eprintln!("[LLVM BUILD] simple-raytracer");
3739
let host_compiler = Compiler::host();
38-
let build_cmd = super::tests::SIMPLE_RAYTRACER.build(&host_compiler, dirs);
40+
let build_cmd = super::bench::SIMPLE_RAYTRACER.build(&host_compiler, dirs);
3941
spawn_and_wait(build_cmd);
4042
fs::copy(
41-
super::tests::SIMPLE_RAYTRACER
43+
super::bench::SIMPLE_RAYTRACER
4244
.target_dir(dirs)
4345
.join(&host_compiler.triple)
4446
.join("debug")
@@ -49,27 +51,27 @@ pub(crate) fn prepare(dirs: &Dirs) {
4951
}
5052

5153
fn prepare_sysroot(dirs: &Dirs) {
52-
let rustc_path = get_rustc_path();
53-
let sysroot_src_orig = rustc_path.parent().unwrap().join("../lib/rustlib/src/rust");
54-
let sysroot_src = SYSROOT_SRC;
55-
54+
let sysroot_src_orig = get_default_sysroot().join("lib/rustlib/src/rust");
5655
assert!(sysroot_src_orig.exists());
5756

58-
sysroot_src.ensure_fresh(dirs);
59-
fs::create_dir_all(sysroot_src.to_path(dirs).join("library")).unwrap();
6057
eprintln!("[COPY] sysroot src");
58+
59+
BUILD_SYSROOT.ensure_fresh(dirs);
60+
copy_dir_recursively(&ORIG_BUILD_SYSROOT.to_path(dirs), &BUILD_SYSROOT.to_path(dirs));
61+
62+
fs::create_dir_all(SYSROOT_SRC.to_path(dirs).join("library")).unwrap();
6163
copy_dir_recursively(
6264
&sysroot_src_orig.join("library"),
63-
&sysroot_src.to_path(dirs).join("library"),
65+
&SYSROOT_SRC.to_path(dirs).join("library"),
6466
);
6567

6668
let rustc_version = get_rustc_version();
6769
fs::write(SYSROOT_RUSTC_VERSION.to_path(dirs), &rustc_version).unwrap();
6870

6971
eprintln!("[GIT] init");
70-
init_git_repo(&sysroot_src.to_path(dirs));
72+
init_git_repo(&SYSROOT_SRC.to_path(dirs));
7173

72-
apply_patches(dirs, "sysroot", &sysroot_src.to_path(dirs));
74+
apply_patches(dirs, "sysroot", &SYSROOT_SRC.to_path(dirs));
7375
}
7476

7577
pub(crate) struct GitRepo {

0 commit comments

Comments
 (0)