Skip to content

Avoid clobbering build_system/ and ~/.cargo/bin #1338

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ task:
- pkg install -y curl git bash
- curl https://sh.rustup.rs -sSf --output rustup.sh
- sh rustup.sh --default-toolchain none -y --profile=minimal
cargo_bin_cache:
folder: ~/.cargo/bin
target_cache:
folder: target
prepare_script:
Expand Down
6 changes: 0 additions & 6 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,6 @@ jobs:
steps:
- uses: actions/checkout@v3

- name: Cache cargo installed crates
uses: actions/cache@v3
with:
path: ~/.cargo/bin
key: ${{ runner.os }}-${{ matrix.env.TARGET_TRIPLE }}-cargo-installed-crates

- name: Cache cargo registry and index
uses: actions/cache@v3
with:
Expand Down
6 changes: 0 additions & 6 deletions .github/workflows/nightly-cranelift.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@ jobs:
steps:
- uses: actions/checkout@v3

- name: Cache cargo installed crates
uses: actions/cache@v3
with:
path: ~/.cargo/bin
key: ubuntu-latest-cargo-installed-crates

- name: Prepare dependencies
run: |
git config --global user.email "[email protected]"
Expand Down
12 changes: 0 additions & 12 deletions .github/workflows/rustc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ jobs:
steps:
- uses: actions/checkout@v3

- name: Cache cargo installed crates
uses: actions/cache@v3
with:
path: ~/.cargo/bin
key: ${{ runner.os }}-cargo-installed-crates

- name: Cache cargo registry and index
uses: actions/cache@v3
with:
Expand Down Expand Up @@ -44,12 +38,6 @@ jobs:
steps:
- uses: actions/checkout@v3

- name: Cache cargo installed crates
uses: actions/cache@v3
with:
path: ~/.cargo/bin
key: ${{ runner.os }}-cargo-installed-crates

- name: Cache cargo registry and index
uses: actions/cache@v3
with:
Expand Down
5 changes: 1 addition & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
target
/target
**/*.rs.bk
*.rlib
*.o
Expand All @@ -11,9 +11,6 @@ perf.data.old
/y.exe
/y.pdb
/build
/build_sysroot/sysroot_src
/build_sysroot/compiler-builtins
/build_sysroot/rustc_version
/dist
/rust
/download
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
]
},
{
"sysroot_src": "./build_sysroot/sysroot_src/library",
"sysroot_src": "./download/sysroot/sysroot_src/library",
"crates": [
{
"root_module": "./example/std_example.rs",
Expand Down
79 changes: 79 additions & 0 deletions build_system/bench.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
use std::env;
use std::fs;
use std::path::Path;

use super::path::{Dirs, RelPath};
use super::prepare::GitRepo;
use super::rustc_info::{get_file_name, get_wrapper_file_name};
use super::utils::{hyperfine_command, is_ci, spawn_and_wait, CargoProject};

pub(crate) static SIMPLE_RAYTRACER_REPO: GitRepo = GitRepo::github(
"ebobby",
"simple-raytracer",
"804a7a21b9e673a482797aa289a18ed480e4d813",
"<none>",
);

pub(crate) static SIMPLE_RAYTRACER: CargoProject =
CargoProject::new(&SIMPLE_RAYTRACER_REPO.source_dir(), "simple_raytracer");

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

fn benchmark_simple_raytracer(dirs: &Dirs) {
if std::process::Command::new("hyperfine").output().is_err() {
eprintln!("Hyperfine not installed");
eprintln!("Hint: Try `cargo install hyperfine` to install hyperfine");
std::process::exit(1);
}

let run_runs = env::var("RUN_RUNS")
.unwrap_or(if is_ci() { "2" } else { "10" }.to_string())
.parse()
.unwrap();

eprintln!("[BENCH COMPILE] ebobby/simple-raytracer");
let cargo_clif = RelPath::DIST.to_path(dirs).join(get_wrapper_file_name("cargo-clif", "bin"));
let manifest_path = SIMPLE_RAYTRACER.manifest_path(dirs);
let target_dir = SIMPLE_RAYTRACER.target_dir(dirs);

let clean_cmd = format!(
"cargo clean --manifest-path {manifest_path} --target-dir {target_dir}",
manifest_path = manifest_path.display(),
target_dir = target_dir.display(),
);
let llvm_build_cmd = format!(
"cargo build --manifest-path {manifest_path} --target-dir {target_dir}",
manifest_path = manifest_path.display(),
target_dir = target_dir.display(),
);
let clif_build_cmd = format!(
"{cargo_clif} build --manifest-path {manifest_path} --target-dir {target_dir}",
cargo_clif = cargo_clif.display(),
manifest_path = manifest_path.display(),
target_dir = target_dir.display(),
);

let bench_compile =
hyperfine_command(1, run_runs, Some(&clean_cmd), &llvm_build_cmd, &clif_build_cmd);

spawn_and_wait(bench_compile);

eprintln!("[BENCH RUN] ebobby/simple-raytracer");
fs::copy(
target_dir.join("debug").join(get_file_name("main", "bin")),
RelPath::BUILD.to_path(dirs).join(get_file_name("raytracer_cg_clif", "bin")),
)
.unwrap();

let mut bench_run = hyperfine_command(
0,
run_runs,
None,
Path::new(".").join(get_file_name("raytracer_cg_llvm", "bin")).to_str().unwrap(),
Path::new(".").join(get_file_name("raytracer_cg_clif", "bin")).to_str().unwrap(),
);
bench_run.current_dir(RelPath::BUILD.to_path(dirs));
spawn_and_wait(bench_run);
}
9 changes: 5 additions & 4 deletions build_system/build_sysroot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,11 @@ pub(crate) fn build_sysroot(
}
}

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

fn build_clif_sysroot_for_triple(
dirs: &Dirs,
Expand Down
17 changes: 16 additions & 1 deletion build_system/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::process;
use self::utils::is_ci;

mod abi_cafe;
mod bench;
mod build_backend;
mod build_sysroot;
mod config;
Expand All @@ -20,6 +21,7 @@ USAGE:
./y.rs prepare [--out-dir DIR]
./y.rs build [--debug] [--sysroot none|clif|llvm] [--out-dir DIR] [--no-unstable-features]
./y.rs test [--debug] [--sysroot none|clif|llvm] [--out-dir DIR] [--no-unstable-features]
./y.rs bench [--debug] [--sysroot none|clif|llvm] [--out-dir DIR] [--no-unstable-features]

OPTIONS:
--sysroot none|clif|llvm
Expand Down Expand Up @@ -54,6 +56,7 @@ enum Command {
Prepare,
Build,
Test,
Bench,
}

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

if is_ci() {
Expand All @@ -83,6 +86,7 @@ pub fn main() {
Some("prepare") => Command::Prepare,
Some("build") => Command::Build,
Some("test") => Command::Test,
Some("bench") => Command::Bench,
Some(flag) if flag.starts_with('-') => arg_error!("Expected command found flag {}", flag),
Some(command) => arg_error!("Unknown command {}", command),
None => {
Expand Down Expand Up @@ -198,5 +202,16 @@ pub fn main() {
&target_triple,
);
}
Command::Bench => {
build_sysroot::build_sysroot(
&dirs,
channel,
sysroot_kind,
&cg_clif_dylib,
&host_triple,
&target_triple,
);
bench::benchmark(&dirs);
}
}
}
1 change: 0 additions & 1 deletion build_system/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ impl RelPath {
pub(crate) const DIST: RelPath = RelPath::Base(PathBase::Dist);

pub(crate) const SCRIPTS: RelPath = RelPath::SOURCE.join("scripts");
pub(crate) const BUILD_SYSROOT: RelPath = RelPath::SOURCE.join("build_sysroot");
pub(crate) const PATCHES: RelPath = RelPath::SOURCE.join("patches");

pub(crate) const fn join(&'static self, suffix: &'static str) -> RelPath {
Expand Down
30 changes: 16 additions & 14 deletions build_system/prepare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ use std::fs;
use std::path::{Path, PathBuf};
use std::process::Command;

use super::build_sysroot::{SYSROOT_RUSTC_VERSION, SYSROOT_SRC};
use crate::build_system::rustc_info::get_default_sysroot;

use super::build_sysroot::{BUILD_SYSROOT, ORIG_BUILD_SYSROOT, SYSROOT_RUSTC_VERSION, SYSROOT_SRC};
use super::path::{Dirs, RelPath};
use super::rustc_info::{get_file_name, get_rustc_path, get_rustc_version};
use super::rustc_info::{get_file_name, get_rustc_version};
use super::utils::{copy_dir_recursively, spawn_and_wait, Compiler};

pub(crate) fn prepare(dirs: &Dirs) {
Expand All @@ -31,14 +33,14 @@ pub(crate) fn prepare(dirs: &Dirs) {
super::tests::RAND_REPO.fetch(dirs);
super::tests::REGEX_REPO.fetch(dirs);
super::tests::PORTABLE_SIMD_REPO.fetch(dirs);
super::tests::SIMPLE_RAYTRACER_REPO.fetch(dirs);
super::bench::SIMPLE_RAYTRACER_REPO.fetch(dirs);

eprintln!("[LLVM BUILD] simple-raytracer");
let host_compiler = Compiler::host();
let build_cmd = super::tests::SIMPLE_RAYTRACER.build(&host_compiler, dirs);
let build_cmd = super::bench::SIMPLE_RAYTRACER.build(&host_compiler, dirs);
spawn_and_wait(build_cmd);
fs::copy(
super::tests::SIMPLE_RAYTRACER
super::bench::SIMPLE_RAYTRACER
.target_dir(dirs)
.join(&host_compiler.triple)
.join("debug")
Expand All @@ -49,27 +51,27 @@ pub(crate) fn prepare(dirs: &Dirs) {
}

fn prepare_sysroot(dirs: &Dirs) {
let rustc_path = get_rustc_path();
let sysroot_src_orig = rustc_path.parent().unwrap().join("../lib/rustlib/src/rust");
let sysroot_src = SYSROOT_SRC;

let sysroot_src_orig = get_default_sysroot().join("lib/rustlib/src/rust");
assert!(sysroot_src_orig.exists());

sysroot_src.ensure_fresh(dirs);
fs::create_dir_all(sysroot_src.to_path(dirs).join("library")).unwrap();
eprintln!("[COPY] sysroot src");

BUILD_SYSROOT.ensure_fresh(dirs);
copy_dir_recursively(&ORIG_BUILD_SYSROOT.to_path(dirs), &BUILD_SYSROOT.to_path(dirs));

fs::create_dir_all(SYSROOT_SRC.to_path(dirs).join("library")).unwrap();
copy_dir_recursively(
&sysroot_src_orig.join("library"),
&sysroot_src.to_path(dirs).join("library"),
&SYSROOT_SRC.to_path(dirs).join("library"),
);

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

eprintln!("[GIT] init");
init_git_repo(&sysroot_src.to_path(dirs));
init_git_repo(&SYSROOT_SRC.to_path(dirs));

apply_patches(dirs, "sysroot", &sysroot_src.to_path(dirs));
apply_patches(dirs, "sysroot", &SYSROOT_SRC.to_path(dirs));
}

pub(crate) struct GitRepo {
Expand Down
Loading