Skip to content

Commit e75dfef

Browse files
committed
Put all temporary build artifacts in build/
1 parent 5e97a39 commit e75dfef

File tree

8 files changed

+42
-49
lines changed

8 files changed

+42
-49
lines changed

build_system/abi_cafe.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use super::SysrootKind;
99
pub(crate) static ABI_CAFE_REPO: GitRepo =
1010
GitRepo::github("Gankra", "abi-cafe", "4c6dc8c9c687e2b3a760ff2176ce236872b37212", "abi-cafe");
1111

12-
static ABI_CAFE: CargoProject = CargoProject::git(&ABI_CAFE_REPO, ".");
12+
static ABI_CAFE: CargoProject = CargoProject::git(&ABI_CAFE_REPO, ".", "abi_cafe");
1313

1414
pub(crate) fn run(
1515
channel: &str,

build_system/build_backend.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::path::PathBuf;
44
use super::rustc_info::get_file_name;
55
use super::utils::{is_ci, CargoProject, Compiler};
66

7-
static CG_CLIF: CargoProject = CargoProject::local(".");
7+
static CG_CLIF: CargoProject = CargoProject::local(".", "cg_clif");
88

99
pub(crate) fn build_backend(
1010
channel: &str,
@@ -43,8 +43,7 @@ pub(crate) fn build_backend(
4343
super::utils::spawn_and_wait(cmd);
4444

4545
CG_CLIF
46-
.source_dir()
47-
.join("target")
46+
.target_dir()
4847
.join(host_triple)
4948
.join(channel)
5049
.join(get_file_name("rustc_codegen_cranelift", "dylib"))

build_system/build_sysroot.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use std::fs;
2-
use std::path::{Path, PathBuf};
2+
use std::path::Path;
33
use std::process::{self, Command};
44

55
use super::rustc_info::{get_file_name, get_rustc_version, get_wrapper_file_name};
@@ -40,7 +40,7 @@ pub(crate) fn build_sysroot(
4040

4141
let mut build_cargo_wrapper_cmd = Command::new("rustc");
4242
build_cargo_wrapper_cmd
43-
.arg(PathBuf::from("scripts").join(format!("{wrapper}.rs")))
43+
.arg(Path::new("scripts").join(format!("{wrapper}.rs")))
4444
.arg("-o")
4545
.arg(dist_dir.join(wrapper_name))
4646
.arg("-g");
@@ -149,7 +149,7 @@ pub(crate) fn build_sysroot(
149149
}
150150
}
151151

152-
static STANDARD_LIBRARY: CargoProject = CargoProject::local("build_sysroot");
152+
static STANDARD_LIBRARY: CargoProject = CargoProject::local("build_sysroot", "build_sysroot");
153153

154154
fn build_clif_sysroot_for_triple(
155155
channel: &str,
@@ -176,7 +176,7 @@ fn build_clif_sysroot_for_triple(
176176
}
177177
}
178178

179-
let build_dir = Path::new("build_sysroot").join("target").join(triple).join(channel);
179+
let build_dir = STANDARD_LIBRARY.target_dir().join(triple).join(channel);
180180

181181
if !super::config::get_bool("keep_sysroot") {
182182
// Cleanup the deps dir, but keep build scripts and the incremental cache for faster
@@ -207,10 +207,7 @@ fn build_clif_sysroot_for_triple(
207207
spawn_and_wait(build_cmd);
208208

209209
// Copy all relevant files to the sysroot
210-
for entry in
211-
fs::read_dir(Path::new("build_sysroot/target").join(triple).join(channel).join("deps"))
212-
.unwrap()
213-
{
210+
for entry in fs::read_dir(build_dir.join("deps")).unwrap() {
214211
let entry = entry.unwrap();
215212
if let Some(ext) = entry.path().extension() {
216213
if ext == "rmeta" || ext == "d" || ext == "dSYM" || ext == "clif" {

build_system/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,14 @@ pub fn main() {
4949
env::set_var("CG_CLIF_DISPLAY_CG_TIME", "1");
5050
env::set_var("CG_CLIF_DISABLE_INCR_CACHE", "1");
5151

52+
std::fs::create_dir_all("build").unwrap();
53+
5254
{
5355
// Make sure we always explicitly specify the target dir
5456
let target = "build/target_dir_should_be_set_explicitly";
5557
env::set_var("CARGO_TARGET_DIR", target);
56-
std::fs::create_dir_all("build").unwrap();
5758
let _ = std::fs::remove_file(target);
58-
let file = std::fs::File::create(target).unwrap();
59+
std::fs::File::create(target).unwrap();
5960
}
6061

6162
if is_ci() {

build_system/prepare.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,7 @@ pub(crate) fn prepare() {
3535
.join(&host_compiler.triple)
3636
.join("debug")
3737
.join(get_file_name("main", "bin")),
38-
super::tests::SIMPLE_RAYTRACER_REPO
39-
.source_dir()
40-
.join(get_file_name("raytracer_cg_llvm", "bin")),
38+
Path::new("build").join(get_file_name("raytracer_cg_llvm", "bin")),
4139
)
4240
.unwrap();
4341
}

build_system/tests.rs

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -223,12 +223,12 @@ const BASE_SYSROOT_SUITE: &[TestCase] = &[
223223
pub(crate) static RAND_REPO: GitRepo =
224224
GitRepo::github("rust-random", "rand", "0f933f9c7176e53b2a3c7952ded484e1783f0bf1", "rand");
225225

226-
static RAND: CargoProject = CargoProject::git(&RAND_REPO, ".");
226+
static RAND: CargoProject = CargoProject::git(&RAND_REPO, ".", "rand");
227227

228228
pub(crate) static REGEX_REPO: GitRepo =
229229
GitRepo::github("rust-lang", "regex", "341f207c1071f7290e3f228c710817c280c8dca1", "regex");
230230

231-
static REGEX: CargoProject = CargoProject::git(&REGEX_REPO, ".");
231+
static REGEX: CargoProject = CargoProject::git(&REGEX_REPO, ".", "regex");
232232

233233
pub(crate) static PORTABLE_SIMD_REPO: GitRepo = GitRepo::github(
234234
"rust-lang",
@@ -237,7 +237,7 @@ pub(crate) static PORTABLE_SIMD_REPO: GitRepo = GitRepo::github(
237237
"portable-simd",
238238
);
239239

240-
static PORTABLE_SIMD: CargoProject = CargoProject::git(&PORTABLE_SIMD_REPO, ".");
240+
static PORTABLE_SIMD: CargoProject = CargoProject::git(&PORTABLE_SIMD_REPO, ".", "portable_simd");
241241

242242
pub(crate) static SIMPLE_RAYTRACER_REPO: GitRepo = GitRepo::github(
243243
"ebobby",
@@ -246,10 +246,11 @@ pub(crate) static SIMPLE_RAYTRACER_REPO: GitRepo = GitRepo::github(
246246
"<none>",
247247
);
248248

249-
pub(crate) static SIMPLE_RAYTRACER: CargoProject = CargoProject::git(&SIMPLE_RAYTRACER_REPO, ".");
249+
pub(crate) static SIMPLE_RAYTRACER: CargoProject =
250+
CargoProject::git(&SIMPLE_RAYTRACER_REPO, ".", "simple_raytracer");
250251

251252
static LIBCORE_TESTS: CargoProject =
252-
CargoProject::local("build_sysroot/sysroot_src/library/core/tests");
253+
CargoProject::local("build_sysroot/sysroot_src/library/core/tests", "core_tests");
253254

254255
const EXTENDED_SYSROOT_SUITE: &[TestCase] = &[
255256
TestCase::new("test.rust-random/rand", &|runner| {
@@ -276,7 +277,6 @@ const EXTENDED_SYSROOT_SUITE: &[TestCase] = &[
276277
.unwrap()
277278
.join("dist")
278279
.join(get_wrapper_file_name("cargo-clif", "bin"));
279-
let source_dir = SIMPLE_RAYTRACER.source_dir();
280280
let manifest_path = SIMPLE_RAYTRACER.manifest_path();
281281
let target_dir = SIMPLE_RAYTRACER.target_dir();
282282

@@ -303,17 +303,15 @@ const EXTENDED_SYSROOT_SUITE: &[TestCase] = &[
303303
spawn_and_wait(bench_compile);
304304

305305
eprintln!("[BENCH RUN] ebobby/simple-raytracer");
306-
fs::copy(target_dir.join("debug").join("main"), source_dir.join("raytracer_cg_clif"))
307-
.unwrap();
308-
309-
let mut bench_run = hyperfine_command(
310-
0,
311-
run_runs,
312-
None,
313-
&source_dir.join("raytracer_cg_llvm").display().to_string(),
314-
&source_dir.join("raytracer_cg_clif").display().to_string(),
315-
);
316-
bench_run.current_dir(SIMPLE_RAYTRACER.source_dir());
306+
fs::copy(
307+
target_dir.join("debug").join("main"),
308+
Path::new("build").join("raytracer_cg_clif"),
309+
)
310+
.unwrap();
311+
312+
let mut bench_run =
313+
hyperfine_command(0, run_runs, None, "./raytracer_cg_llvm", "./raytracer_cg_clif");
314+
bench_run.current_dir(Path::new("build"));
317315
spawn_and_wait(bench_run);
318316
} else {
319317
spawn_and_wait(SIMPLE_RAYTRACER.clean(&runner.target_compiler.cargo));
@@ -449,7 +447,7 @@ pub(crate) fn run_tests(
449447
&target_triple,
450448
);
451449

452-
let _ = fs::remove_dir_all(Path::new("target").join("out"));
450+
let _ = fs::remove_dir_all(Path::new("build").join("example"));
453451
runner.run_testsuite(NO_SYSROOT_SUITE);
454452
} else {
455453
eprintln!("[SKIP] no_sysroot tests");
@@ -495,8 +493,8 @@ impl TestRunner {
495493
let root_dir = env::current_dir().unwrap();
496494

497495
let mut out_dir = root_dir.clone();
498-
out_dir.push("target");
499-
out_dir.push("out");
496+
out_dir.push("build");
497+
out_dir.push("example");
500498

501499
let is_native = host_triple == target_triple;
502500
let jit_supported =

build_system/utils.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,20 @@ enum CargoProjectSource {
5151
pub(crate) struct CargoProject {
5252
source: CargoProjectSource,
5353
path: &'static str,
54+
target: &'static str,
5455
}
5556

5657
impl CargoProject {
57-
pub(crate) const fn local(path: &'static str) -> CargoProject {
58-
CargoProject { source: CargoProjectSource::Local, path }
58+
pub(crate) const fn local(path: &'static str, target: &'static str) -> CargoProject {
59+
CargoProject { source: CargoProjectSource::Local, path, target }
5960
}
6061

61-
pub(crate) const fn git(git_repo: &'static GitRepo, path: &'static str) -> CargoProject {
62-
CargoProject { source: CargoProjectSource::GitRepo(git_repo), path }
62+
pub(crate) const fn git(
63+
git_repo: &'static GitRepo,
64+
path: &'static str,
65+
target: &'static str,
66+
) -> CargoProject {
67+
CargoProject { source: CargoProjectSource::GitRepo(git_repo), path, target }
6368
}
6469

6570
pub(crate) fn source_dir(&self) -> PathBuf {
@@ -75,12 +80,7 @@ impl CargoProject {
7580
}
7681

7782
pub(crate) fn target_dir(&self) -> PathBuf {
78-
match self.source {
79-
CargoProjectSource::Local => std::env::current_dir().unwrap(),
80-
CargoProjectSource::GitRepo(git_repo) => git_repo.source_dir(),
81-
}
82-
.join(self.path)
83-
.join("target")
83+
std::env::current_dir().unwrap().join("build").join(self.target)
8484
}
8585

8686
fn base_cmd(&self, command: &str, cargo: &Path) -> Command {

clean_all.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
set -e
33

44
rm -rf build_sysroot/{sysroot_src/,target/,compiler-builtins/,rustc_version}
5-
rm -rf target/ dist/ perf.data{,.old} y.bin
5+
rm -rf target/ build/ dist/ perf.data{,.old} y.bin
66
rm -rf download/
77

88
# Kept for now in case someone updates their checkout of cg_clif before running clean_all.sh
99
# FIXME remove at some point in the future
10-
rm -rf rand/ regex/ simple-raytracer/ portable-simd/ abi-checker/ abi-cafe/ build/
10+
rm -rf rand/ regex/ simple-raytracer/ portable-simd/ abi-checker/ abi-cafe/

0 commit comments

Comments
 (0)