Merge commit '6d35b4c9a0' into sync_cg_clif-2024-09-22

This commit is contained in:
bjorn3 2024-09-23 11:20:46 +00:00
commit b40fe1ee28
31 changed files with 487 additions and 347 deletions

View file

@ -14,7 +14,6 @@ static ABI_CAFE_REPO: GitRepo = GitRepo::github(
static ABI_CAFE: CargoProject = CargoProject::new(&ABI_CAFE_REPO.source_dir(), "abi_cafe_target");
pub(crate) fn run(
channel: &str,
sysroot_kind: SysrootKind,
dirs: &Dirs,
cg_clif_dylib: &CodegenBackend,
@ -28,7 +27,6 @@ pub(crate) fn run(
eprintln!("Building sysroot for abi-cafe");
build_sysroot::build_sysroot(
dirs,
channel,
sysroot_kind,
cg_clif_dylib,
bootstrap_host_compiler,
@ -38,12 +36,11 @@ pub(crate) fn run(
eprintln!("Running abi-cafe");
let pairs = ["rustc_calls_cgclif", "cgclif_calls_rustc", "cgclif_calls_cc", "cc_calls_cgclif"];
let pairs =
let pairs: &[_] =
if cfg!(not(any(target_os = "macos", all(target_os = "windows", target_env = "msvc")))) {
&pairs[..]
&["rustc_calls_cgclif", "cgclif_calls_rustc", "cgclif_calls_cc", "cc_calls_cgclif"]
} else {
&pairs[..2]
&["rustc_calls_cgclif", "cgclif_calls_rustc"]
};
let mut cmd = ABI_CAFE.run(bootstrap_host_compiler, dirs);

View file

@ -1,11 +1,12 @@
use std::env;
use std::io::Write;
use std::path::Path;
use std::process::Command;
use crate::path::{Dirs, RelPath};
use crate::prepare::GitRepo;
use crate::rustc_info::get_file_name;
use crate::utils::{Compiler, hyperfine_command, spawn_and_wait};
use crate::utils::{Compiler, spawn_and_wait};
static SIMPLE_RAYTRACER_REPO: GitRepo = GitRepo::github(
"ebobby",
@ -128,3 +129,37 @@ fn benchmark_simple_raytracer(dirs: &Dirs, bootstrap_host_compiler: &Compiler) {
gha_step_summary.write_all(b"\n").unwrap();
}
}
#[must_use]
fn hyperfine_command(
warmup: u64,
runs: u64,
prepare: Option<&str>,
cmds: &[(&str, &str)],
markdown_export: &Path,
) -> Command {
let mut bench = Command::new("hyperfine");
bench.arg("--export-markdown").arg(markdown_export);
if warmup != 0 {
bench.arg("--warmup").arg(warmup.to_string());
}
if runs != 0 {
bench.arg("--runs").arg(runs.to_string());
}
if let Some(prepare) = prepare {
bench.arg("--prepare").arg(prepare);
}
for &(name, cmd) in cmds {
if name != "" {
bench.arg("-n").arg(name);
}
bench.arg(cmd);
}
bench
}

View file

@ -6,11 +6,10 @@ use crate::rustc_info::get_file_name;
use crate::shared_utils::{rustflags_from_env, rustflags_to_cmd_env};
use crate::utils::{CargoProject, Compiler, LogGroup};
pub(crate) static CG_CLIF: CargoProject = CargoProject::new(&RelPath::SOURCE, "cg_clif");
static CG_CLIF: CargoProject = CargoProject::new(&RelPath::SOURCE, "cg_clif");
pub(crate) fn build_backend(
dirs: &Dirs,
channel: &str,
bootstrap_host_compiler: &Compiler,
use_unstable_features: bool,
) -> PathBuf {
@ -19,8 +18,8 @@ pub(crate) fn build_backend(
let mut cmd = CG_CLIF.build(&bootstrap_host_compiler, dirs);
let mut rustflags = rustflags_from_env("RUSTFLAGS");
rustflags.push("-Zallow-features=rustc_private".to_owned());
rustflags_to_cmd_env(&mut cmd, "RUSTFLAGS", &rustflags);
if env::var("CG_CLIF_EXPENSIVE_CHECKS").is_ok() {
// Enabling debug assertions implicitly enables the clif ir verifier
@ -32,15 +31,7 @@ pub(crate) fn build_backend(
cmd.arg("--features").arg("unstable-features");
}
match channel {
"debug" => {}
"release" => {
cmd.arg("--release");
}
_ => unreachable!(),
}
rustflags_to_cmd_env(&mut cmd, "RUSTFLAGS", &rustflags);
cmd.arg("--release");
eprintln!("[BUILD] rustc_codegen_cranelift");
crate::utils::spawn_and_wait(cmd);
@ -48,6 +39,6 @@ pub(crate) fn build_backend(
CG_CLIF
.target_dir(dirs)
.join(&bootstrap_host_compiler.triple)
.join(channel)
.join("release")
.join(get_file_name(&bootstrap_host_compiler.rustc, "rustc_codegen_cranelift", "dylib"))
}

View file

@ -3,19 +3,15 @@ use std::process::Command;
use std::{env, fs};
use crate::path::{Dirs, RelPath};
use crate::rustc_info::get_file_name;
use crate::prepare::apply_patches;
use crate::rustc_info::{get_default_sysroot, get_file_name};
use crate::utils::{
CargoProject, Compiler, LogGroup, remove_dir_if_exists, spawn_and_wait, try_hard_link,
ensure_empty_dir, spawn_and_wait, try_hard_link, CargoProject, Compiler, LogGroup,
};
use crate::{CodegenBackend, SysrootKind, config};
static DIST_DIR: RelPath = RelPath::DIST;
static BIN_DIR: RelPath = RelPath::DIST.join("bin");
static LIB_DIR: RelPath = RelPath::DIST.join("lib");
use crate::{config, CodegenBackend, SysrootKind};
pub(crate) fn build_sysroot(
dirs: &Dirs,
channel: &str,
sysroot_kind: SysrootKind,
cg_clif_dylib_src: &CodegenBackend,
bootstrap_host_compiler: &Compiler,
@ -26,9 +22,11 @@ pub(crate) fn build_sysroot(
eprintln!("[BUILD] sysroot {:?}", sysroot_kind);
DIST_DIR.ensure_fresh(dirs);
BIN_DIR.ensure_exists(dirs);
LIB_DIR.ensure_exists(dirs);
let dist_dir = RelPath::DIST.to_path(dirs);
ensure_empty_dir(&dist_dir);
fs::create_dir_all(dist_dir.join("bin")).unwrap();
fs::create_dir_all(dist_dir.join("lib")).unwrap();
let is_native = bootstrap_host_compiler.triple == target_triple;
@ -38,11 +36,10 @@ pub(crate) fn build_sysroot(
let cg_clif_dylib_path = if cfg!(windows) {
// Windows doesn't have rpath support, so the cg_clif dylib needs to be next to the
// binaries.
BIN_DIR
dist_dir.join("bin")
} else {
LIB_DIR
dist_dir.join("lib")
}
.to_path(dirs)
.join(src_path.file_name().unwrap());
try_hard_link(src_path, &cg_clif_dylib_path);
CodegenBackend::Local(cg_clif_dylib_path)
@ -56,7 +53,7 @@ pub(crate) fn build_sysroot(
let wrapper_name = wrapper_base_name.replace("____", wrapper);
let mut build_cargo_wrapper_cmd = Command::new(&bootstrap_host_compiler.rustc);
let wrapper_path = DIST_DIR.to_path(dirs).join(&wrapper_name);
let wrapper_path = dist_dir.join(&wrapper_name);
build_cargo_wrapper_cmd
.arg(RelPath::SCRIPTS.to_path(dirs).join(&format!("{wrapper}.rs")))
.arg("-o")
@ -79,22 +76,20 @@ pub(crate) fn build_sysroot(
build_cargo_wrapper_cmd.env("BUILTIN_BACKEND", name);
}
spawn_and_wait(build_cargo_wrapper_cmd);
try_hard_link(wrapper_path, BIN_DIR.to_path(dirs).join(wrapper_name));
try_hard_link(wrapper_path, dist_dir.join("bin").join(wrapper_name));
}
let host = build_sysroot_for_triple(
dirs,
channel,
bootstrap_host_compiler.clone(),
&cg_clif_dylib_path,
sysroot_kind,
);
host.install_into_sysroot(&DIST_DIR.to_path(dirs));
host.install_into_sysroot(&dist_dir);
if !is_native {
build_sysroot_for_triple(
dirs,
channel,
{
let mut bootstrap_target_compiler = bootstrap_host_compiler.clone();
bootstrap_target_compiler.triple = target_triple.clone();
@ -104,7 +99,7 @@ pub(crate) fn build_sysroot(
&cg_clif_dylib_path,
sysroot_kind,
)
.install_into_sysroot(&DIST_DIR.to_path(dirs));
.install_into_sysroot(&dist_dir);
}
// Copy std for the host to the lib dir. This is necessary for the jit mode to find
@ -112,16 +107,13 @@ pub(crate) fn build_sysroot(
for lib in host.libs {
let filename = lib.file_name().unwrap().to_str().unwrap();
if filename.contains("std-") && !filename.contains(".rlib") {
try_hard_link(&lib, LIB_DIR.to_path(dirs).join(lib.file_name().unwrap()));
try_hard_link(&lib, dist_dir.join("lib").join(lib.file_name().unwrap()));
}
}
let mut target_compiler = {
let dirs: &Dirs = &dirs;
let rustc_clif =
RelPath::DIST.to_path(&dirs).join(wrapper_base_name.replace("____", "rustc-clif"));
let rustdoc_clif =
RelPath::DIST.to_path(&dirs).join(wrapper_base_name.replace("____", "rustdoc-clif"));
let rustc_clif = dist_dir.join(wrapper_base_name.replace("____", "rustc-clif"));
let rustdoc_clif = dist_dir.join(wrapper_base_name.replace("____", "rustdoc-clif"));
Compiler {
cargo: bootstrap_host_compiler.cargo.clone(),
@ -139,6 +131,7 @@ pub(crate) fn build_sysroot(
target_compiler
}
#[must_use]
struct SysrootTarget {
triple: String,
libs: Vec<PathBuf>,
@ -159,15 +152,13 @@ impl SysrootTarget {
}
}
pub(crate) static STDLIB_SRC: RelPath = RelPath::BUILD.join("stdlib");
pub(crate) static STANDARD_LIBRARY: CargoProject =
static STDLIB_SRC: RelPath = RelPath::BUILD.join("stdlib");
static STANDARD_LIBRARY: CargoProject =
CargoProject::new(&STDLIB_SRC.join("library/sysroot"), "stdlib_target");
pub(crate) static RTSTARTUP_SYSROOT: RelPath = RelPath::BUILD.join("rtstartup");
static RTSTARTUP_SYSROOT: RelPath = RelPath::BUILD.join("rtstartup");
#[must_use]
fn build_sysroot_for_triple(
dirs: &Dirs,
channel: &str,
compiler: Compiler,
cg_clif_dylib_path: &CodegenBackend,
sysroot_kind: SysrootKind,
@ -176,13 +167,10 @@ fn build_sysroot_for_triple(
SysrootKind::None => build_rtstartup(dirs, &compiler)
.unwrap_or(SysrootTarget { triple: compiler.triple, libs: vec![] }),
SysrootKind::Llvm => build_llvm_sysroot_for_triple(compiler),
SysrootKind::Clif => {
build_clif_sysroot_for_triple(dirs, channel, compiler, cg_clif_dylib_path)
}
SysrootKind::Clif => build_clif_sysroot_for_triple(dirs, compiler, cg_clif_dylib_path),
}
}
#[must_use]
fn build_llvm_sysroot_for_triple(compiler: Compiler) -> SysrootTarget {
let default_sysroot = crate::rustc_info::get_default_sysroot(&compiler.rustc);
@ -216,10 +204,8 @@ fn build_llvm_sysroot_for_triple(compiler: Compiler) -> SysrootTarget {
target_libs
}
#[must_use]
fn build_clif_sysroot_for_triple(
dirs: &Dirs,
channel: &str,
mut compiler: Compiler,
cg_clif_dylib_path: &CodegenBackend,
) -> SysrootTarget {
@ -231,12 +217,12 @@ fn build_clif_sysroot_for_triple(
target_libs.libs.extend(rtstartup_target_libs.libs);
}
let build_dir = STANDARD_LIBRARY.target_dir(dirs).join(&compiler.triple).join(channel);
let build_dir = STANDARD_LIBRARY.target_dir(dirs).join(&compiler.triple).join("release");
if !config::get_bool("keep_sysroot") {
// Cleanup the deps dir, but keep build scripts and the incremental cache for faster
// recompilation as they are not affected by changes in cg_clif.
remove_dir_if_exists(&build_dir.join("deps"));
ensure_empty_dir(&build_dir.join("deps"));
}
// Build sysroot
@ -252,12 +238,12 @@ fn build_clif_sysroot_for_triple(
// Necessary for MinGW to find rsbegin.o and rsend.o
rustflags.push("--sysroot".to_owned());
rustflags.push(RTSTARTUP_SYSROOT.to_path(dirs).to_str().unwrap().to_owned());
if channel == "release" {
// Incremental compilation by default disables mir inlining. This leads to both a decent
// compile perf and a significant runtime perf regression. As such forcefully enable mir
// inlining.
rustflags.push("-Zinline-mir".to_owned());
}
// Incremental compilation by default disables mir inlining. This leads to both a decent
// compile perf and a significant runtime perf regression. As such forcefully enable mir
// inlining.
rustflags.push("-Zinline-mir".to_owned());
if let Some(prefix) = env::var_os("CG_CLIF_STDLIB_REMAP_PATH_PREFIX") {
rustflags.push("--remap-path-prefix".to_owned());
rustflags.push(format!(
@ -268,9 +254,7 @@ fn build_clif_sysroot_for_triple(
}
compiler.rustflags.extend(rustflags);
let mut build_cmd = STANDARD_LIBRARY.build(&compiler, dirs);
if channel == "release" {
build_cmd.arg("--release");
}
build_cmd.arg("--release");
build_cmd.arg("--features").arg("backtrace panic-unwind compiler-builtins-no-f16-f128");
build_cmd.env("CARGO_PROFILE_RELEASE_DEBUG", "true");
build_cmd.env("__CARGO_DEFAULT_LIB_METADATA", "cg_clif");
@ -296,7 +280,10 @@ fn build_clif_sysroot_for_triple(
fn build_rtstartup(dirs: &Dirs, compiler: &Compiler) -> Option<SysrootTarget> {
if !config::get_bool("keep_sysroot") {
crate::prepare::prepare_stdlib(dirs, &compiler.rustc);
let sysroot_src_orig = get_default_sysroot(&compiler.rustc).join("lib/rustlib/src/rust");
assert!(sysroot_src_orig.exists());
apply_patches(dirs, "stdlib", &sysroot_src_orig, &STDLIB_SRC.to_path(dirs));
}
if !compiler.triple.ends_with("windows-gnu") {

View file

@ -81,7 +81,6 @@ fn main() {
let mut out_dir = PathBuf::from(".");
let mut download_dir = None;
let mut channel = "release";
let mut sysroot_kind = SysrootKind::Clif;
let mut use_unstable_features = true;
let mut frozen = false;
@ -99,7 +98,6 @@ fn main() {
arg_error!("--download-dir requires argument");
})));
}
"--debug" => channel = "debug",
"--sysroot" => {
sysroot_kind = match args.next().as_deref() {
Some("none") => SysrootKind::None,
@ -206,7 +204,6 @@ fn main() {
} else {
CodegenBackend::Local(build_backend::build_backend(
&dirs,
channel,
&bootstrap_host_compiler,
use_unstable_features,
))
@ -218,7 +215,6 @@ fn main() {
Command::Test => {
tests::run_tests(
&dirs,
channel,
sysroot_kind,
use_unstable_features,
&skip_tests.iter().map(|test| &**test).collect::<Vec<_>>(),
@ -234,7 +230,6 @@ fn main() {
process::exit(1);
}
abi_cafe::run(
channel,
sysroot_kind,
&dirs,
&cg_clif_dylib,
@ -245,7 +240,6 @@ fn main() {
Command::Build => {
build_sysroot::build_sysroot(
&dirs,
channel,
sysroot_kind,
&cg_clif_dylib,
&bootstrap_host_compiler,
@ -256,7 +250,6 @@ fn main() {
Command::Bench => {
build_sysroot::build_sysroot(
&dirs,
channel,
sysroot_kind,
&cg_clif_dylib,
&bootstrap_host_compiler,

View file

@ -1,7 +1,7 @@
use std::fs;
use std::path::PathBuf;
use crate::utils::remove_dir_if_exists;
use crate::utils::ensure_empty_dir;
#[derive(Debug, Clone)]
pub(crate) struct Dirs {
@ -64,7 +64,6 @@ impl RelPath {
pub(crate) fn ensure_fresh(&self, dirs: &Dirs) {
let path = self.to_path(dirs);
remove_dir_if_exists(&path);
fs::create_dir_all(path).unwrap();
ensure_empty_dir(&path);
}
}

View file

@ -4,12 +4,8 @@ use std::hash::{Hash, Hasher};
use std::path::{Path, PathBuf};
use std::process::Command;
use crate::build_sysroot::STDLIB_SRC;
use crate::path::{Dirs, RelPath};
use crate::rustc_info::get_default_sysroot;
use crate::utils::{
copy_dir_recursively, git_command, remove_dir_if_exists, retry_spawn_and_wait, spawn_and_wait,
};
use crate::utils::{copy_dir_recursively, ensure_empty_dir, spawn_and_wait};
pub(crate) fn prepare(dirs: &Dirs) {
RelPath::DOWNLOAD.ensure_exists(dirs);
@ -17,13 +13,6 @@ pub(crate) fn prepare(dirs: &Dirs) {
crate::tests::REGEX_REPO.fetch(dirs);
}
pub(crate) fn prepare_stdlib(dirs: &Dirs, rustc: &Path) {
let sysroot_src_orig = get_default_sysroot(rustc).join("lib/rustlib/src/rust");
assert!(sysroot_src_orig.exists());
apply_patches(dirs, "stdlib", &sysroot_src_orig, &STDLIB_SRC.to_path(dirs));
}
pub(crate) struct GitRepo {
url: GitRepoUrl,
rev: &'static str,
@ -119,7 +108,11 @@ impl GitRepo {
match self.url {
GitRepoUrl::Github { user, repo } => {
clone_repo_shallow_github(dirs, &download_dir, user, repo, self.rev);
clone_repo(
&download_dir,
&format!("https://github.com/{}/{}.git", user, repo),
self.rev,
);
}
}
@ -154,7 +147,6 @@ impl GitRepo {
}
}
#[allow(dead_code)]
fn clone_repo(download_dir: &Path, repo: &str, rev: &str) {
eprintln!("[CLONE] {}", repo);
// Ignore exit code as the repo may already have been checked out
@ -171,55 +163,6 @@ fn clone_repo(download_dir: &Path, repo: &str, rev: &str) {
std::fs::remove_dir_all(download_dir.join(".git")).unwrap();
}
fn clone_repo_shallow_github(dirs: &Dirs, download_dir: &Path, user: &str, repo: &str, rev: &str) {
if cfg!(windows) {
// Older windows doesn't have tar or curl by default. Fall back to using git.
clone_repo(download_dir, &format!("https://github.com/{}/{}.git", user, repo), rev);
return;
}
let archive_url = format!("https://github.com/{}/{}/archive/{}.tar.gz", user, repo, rev);
let archive_file = RelPath::DOWNLOAD.to_path(dirs).join(format!("{}.tar.gz", rev));
let archive_dir = RelPath::DOWNLOAD.to_path(dirs).join(format!("{}-{}", repo, rev));
eprintln!("[DOWNLOAD] {}/{} from {}", user, repo, archive_url);
// Remove previous results if they exists
let _ = std::fs::remove_file(&archive_file);
let _ = std::fs::remove_dir_all(&archive_dir);
let _ = std::fs::remove_dir_all(&download_dir);
// Download zip archive
let mut download_cmd = Command::new("curl");
download_cmd
.arg("--max-time")
.arg("600")
.arg("-y")
.arg("30")
.arg("-Y")
.arg("10")
.arg("--connect-timeout")
.arg("30")
.arg("--continue-at")
.arg("-")
.arg("--location")
.arg("--output")
.arg(&archive_file)
.arg(archive_url);
retry_spawn_and_wait(5, download_cmd);
// Unpack tar archive
let mut unpack_cmd = Command::new("tar");
unpack_cmd.arg("xf").arg(&archive_file).current_dir(RelPath::DOWNLOAD.to_path(dirs));
spawn_and_wait(unpack_cmd);
// Rename unpacked dir to the expected name
std::fs::rename(archive_dir, &download_dir).unwrap();
// Cleanup
std::fs::remove_file(archive_file).unwrap();
}
fn init_git_repo(repo_dir: &Path) {
let mut git_init_cmd = git_command(repo_dir, "init");
git_init_cmd.arg("-q");
@ -259,14 +202,8 @@ pub(crate) fn apply_patches(dirs: &Dirs, crate_name: &str, source_dir: &Path, ta
eprintln!("[COPY] {crate_name} source");
remove_dir_if_exists(target_dir);
fs::create_dir_all(target_dir).unwrap();
if crate_name == "stdlib" {
fs::create_dir(target_dir.join("library")).unwrap();
copy_dir_recursively(&source_dir.join("library"), &target_dir.join("library"));
} else {
copy_dir_recursively(source_dir, target_dir);
}
ensure_empty_dir(target_dir);
copy_dir_recursively(source_dir, target_dir);
init_git_repo(target_dir);
@ -285,3 +222,22 @@ pub(crate) fn apply_patches(dirs: &Dirs, crate_name: &str, source_dir: &Path, ta
spawn_and_wait(apply_patch_cmd);
}
}
#[must_use]
fn git_command<'a>(repo_dir: impl Into<Option<&'a Path>>, cmd: &str) -> Command {
let mut git_cmd = Command::new("git");
git_cmd
.arg("-c")
.arg("user.name=Dummy")
.arg("-c")
.arg("user.email=dummy@example.com")
.arg("-c")
.arg("core.autocrlf=false")
.arg("-c")
.arg("commit.gpgSign=false")
.arg(cmd);
if let Some(repo_dir) = repo_dir.into() {
git_cmd.current_dir(repo_dir);
}
git_cmd
}

View file

@ -117,7 +117,7 @@ pub(crate) static RAND_REPO: GitRepo = GitRepo::github(
"rand",
);
pub(crate) static RAND: CargoProject = CargoProject::new(&RAND_REPO.source_dir(), "rand_target");
static RAND: CargoProject = CargoProject::new(&RAND_REPO.source_dir(), "rand_target");
pub(crate) static REGEX_REPO: GitRepo = GitRepo::github(
"rust-lang",
@ -127,12 +127,11 @@ pub(crate) static REGEX_REPO: GitRepo = GitRepo::github(
"regex",
);
pub(crate) static REGEX: CargoProject = CargoProject::new(&REGEX_REPO.source_dir(), "regex_target");
static REGEX: CargoProject = CargoProject::new(&REGEX_REPO.source_dir(), "regex_target");
pub(crate) static PORTABLE_SIMD_SRC: RelPath = RelPath::BUILD.join("coretests");
static PORTABLE_SIMD_SRC: RelPath = RelPath::BUILD.join("portable-simd");
pub(crate) static PORTABLE_SIMD: CargoProject =
CargoProject::new(&PORTABLE_SIMD_SRC, "portable-simd_target");
static PORTABLE_SIMD: CargoProject = CargoProject::new(&PORTABLE_SIMD_SRC, "portable-simd_target");
static LIBCORE_TESTS_SRC: RelPath = RelPath::BUILD.join("coretests");
@ -230,13 +229,6 @@ const EXTENDED_SYSROOT_SUITE: &[TestCase] = &[
if runner.is_native {
let mut test_cmd = PORTABLE_SIMD.test(&runner.target_compiler, &runner.dirs);
test_cmd.arg("-q");
// FIXME remove after portable-simd update
test_cmd
.arg("--")
.arg("--skip")
.arg("core_simd::swizzle::simd_swizzle")
.arg("--skip")
.arg("core_simd::vector::Simd<T,N>::lanes");
spawn_and_wait(test_cmd);
}
}),
@ -244,7 +236,6 @@ const EXTENDED_SYSROOT_SUITE: &[TestCase] = &[
pub(crate) fn run_tests(
dirs: &Dirs,
channel: &str,
sysroot_kind: SysrootKind,
use_unstable_features: bool,
skip_tests: &[&str],
@ -260,7 +251,6 @@ pub(crate) fn run_tests(
if config::get_bool("testsuite.no_sysroot") && !skip_tests.contains(&"testsuite.no_sysroot") {
let target_compiler = build_sysroot::build_sysroot(
dirs,
channel,
SysrootKind::None,
cg_clif_dylib,
bootstrap_host_compiler,
@ -291,7 +281,6 @@ pub(crate) fn run_tests(
if run_base_sysroot || run_extended_sysroot {
let target_compiler = build_sysroot::build_sysroot(
dirs,
channel,
sysroot_kind,
cg_clif_dylib,
bootstrap_host_compiler,
@ -443,7 +432,6 @@ impl<'a> TestRunner<'a> {
cmd.arg("--target");
cmd.arg(&self.target_compiler.triple);
cmd.arg("-Cpanic=abort");
cmd.arg("-Zunstable-options");
cmd.arg("--check-cfg=cfg(jit)");
cmd.args(args);
cmd
@ -458,26 +446,11 @@ impl<'a> TestRunner<'a> {
}
fn run_out_command(&self, name: &str, args: &[&str]) {
let mut full_cmd = vec![];
let mut cmd = self
.target_compiler
.run_with_runner(BUILD_EXAMPLE_OUT_DIR.to_path(&self.dirs).join(name));
// Prepend the RUN_WRAPPER's
if !self.target_compiler.runner.is_empty() {
full_cmd.extend(self.target_compiler.runner.iter().cloned());
}
full_cmd.push(
BUILD_EXAMPLE_OUT_DIR.to_path(&self.dirs).join(name).to_str().unwrap().to_string(),
);
for arg in args {
full_cmd.push(arg.to_string());
}
let mut cmd_iter = full_cmd.into_iter();
let first = cmd_iter.next().unwrap();
let mut cmd = Command::new(first);
cmd.args(cmd_iter);
cmd.args(args);
spawn_and_wait(cmd);
}

View file

@ -2,16 +2,12 @@ The build system of cg_clif.
USAGE:
./y.sh prepare [--out-dir DIR] [--download-dir DIR]
./y.sh build [--debug] [--sysroot none|clif|llvm] [--out-dir DIR] [--download-dir DIR] [--no-unstable-features] [--frozen]
./y.sh test [--debug] [--sysroot none|clif|llvm] [--out-dir DIR] [--download-dir DIR] [--no-unstable-features] [--frozen] [--skip-test TESTNAME]
./y.sh abi-cafe [--debug] [--sysroot none|clif|llvm] [--out-dir DIR] [--download-dir DIR] [--no-unstable-features] [--frozen]
./y.sh bench [--debug] [--sysroot none|clif|llvm] [--out-dir DIR] [--download-dir DIR] [--no-unstable-features] [--frozen]
./y.sh build [--sysroot none|clif|llvm] [--out-dir DIR] [--download-dir DIR] [--no-unstable-features] [--frozen]
./y.sh test [--sysroot none|clif|llvm] [--out-dir DIR] [--download-dir DIR] [--no-unstable-features] [--frozen] [--skip-test TESTNAME]
./y.sh abi-cafe [--sysroot none|clif|llvm] [--out-dir DIR] [--download-dir DIR] [--no-unstable-features] [--frozen]
./y.sh bench [--sysroot none|clif|llvm] [--out-dir DIR] [--download-dir DIR] [--no-unstable-features] [--frozen]
OPTIONS:
--debug
Build cg_clif and the standard library in debug mode rather than release mode.
Warning: An unoptimized cg_clif is very slow.
--sysroot none|clif|llvm
Which sysroot libraries to use:
`none` will not include any standard library in the sysroot.
@ -43,7 +39,5 @@ REQUIREMENTS:
* Rustup: By default rustup is used to install the right nightly version. If you don't want to
use rustup, you can manually install the nightly version indicated by rust-toolchain.toml and
point the CARGO, RUSTC and RUSTDOC env vars to the right executables.
* Git: Git is used for applying patches and on Windows for downloading test repos.
* Curl and tar (non-Windows only): Used by `./y.sh prepare` to download a single commit for
repos. Git will be used to clone the whole repo when using Windows.
* Git: Git is used for downloading test repos and applying patches.
* [Hyperfine](https://github.com/sharkdp/hyperfine/): Used for benchmarking with `./y.sh bench`.

View file

@ -1,3 +1,4 @@
use std::ffi::OsStr;
use std::path::{Path, PathBuf};
use std::process::{self, Command};
use std::sync::atomic::{AtomicBool, Ordering};
@ -59,6 +60,18 @@ impl Compiler {
}
}
}
pub(crate) fn run_with_runner(&self, program: impl AsRef<OsStr>) -> Command {
if self.runner.is_empty() {
Command::new(program)
} else {
let mut runner_iter = self.runner.iter();
let mut cmd = Command::new(runner_iter.next().unwrap());
cmd.args(runner_iter);
cmd.arg(program);
cmd
}
}
}
pub(crate) struct CargoProject {
@ -141,59 +154,6 @@ impl CargoProject {
}
}
#[must_use]
pub(crate) fn hyperfine_command(
warmup: u64,
runs: u64,
prepare: Option<&str>,
cmds: &[(&str, &str)],
markdown_export: &Path,
) -> Command {
let mut bench = Command::new("hyperfine");
bench.arg("--export-markdown").arg(markdown_export);
if warmup != 0 {
bench.arg("--warmup").arg(warmup.to_string());
}
if runs != 0 {
bench.arg("--runs").arg(runs.to_string());
}
if let Some(prepare) = prepare {
bench.arg("--prepare").arg(prepare);
}
for &(name, cmd) in cmds {
if name != "" {
bench.arg("-n").arg(name);
}
bench.arg(cmd);
}
bench
}
#[must_use]
pub(crate) fn git_command<'a>(repo_dir: impl Into<Option<&'a Path>>, cmd: &str) -> Command {
let mut git_cmd = Command::new("git");
git_cmd
.arg("-c")
.arg("user.name=Dummy")
.arg("-c")
.arg("user.email=dummy@example.com")
.arg("-c")
.arg("core.autocrlf=false")
.arg("-c")
.arg("commit.gpgSign=false")
.arg(cmd);
if let Some(repo_dir) = repo_dir.into() {
git_cmd.current_dir(repo_dir);
}
git_cmd
}
#[track_caller]
pub(crate) fn try_hard_link(src: impl AsRef<Path>, dst: impl AsRef<Path>) {
let src = src.as_ref();
@ -212,27 +172,33 @@ pub(crate) fn spawn_and_wait(mut cmd: Command) {
}
}
// Based on the retry function in rust's src/ci/shared.sh
#[track_caller]
pub(crate) fn retry_spawn_and_wait(tries: u64, mut cmd: Command) {
for i in 1..tries + 1 {
if i != 1 {
eprintln!("Command failed. Attempt {i}/{tries}:");
}
if cmd.spawn().unwrap().wait().unwrap().success() {
/// Create the specified directory if it doesn't exist yet and delete all contents.
pub(crate) fn ensure_empty_dir(path: &Path) {
fs::create_dir_all(path).unwrap();
let read_dir = match fs::read_dir(&path) {
Ok(read_dir) => read_dir,
Err(err) if err.kind() == io::ErrorKind::NotFound => {
return;
}
std::thread::sleep(std::time::Duration::from_secs(i * 5));
}
eprintln!("The command has failed after {tries} attempts.");
process::exit(1);
}
pub(crate) fn remove_dir_if_exists(path: &Path) {
match fs::remove_dir_all(&path) {
Ok(()) => {}
Err(err) if err.kind() == io::ErrorKind::NotFound => {}
Err(err) => panic!("Failed to remove {path}: {err}", path = path.display()),
Err(err) => {
panic!("Failed to read contents of {path}: {err}", path = path.display())
}
};
for entry in read_dir {
let entry = entry.unwrap();
if entry.file_type().unwrap().is_dir() {
match fs::remove_dir_all(entry.path()) {
Ok(()) => {}
Err(err) if err.kind() == io::ErrorKind::NotFound => {}
Err(err) => panic!("Failed to remove {path}: {err}", path = entry.path().display()),
}
} else {
match fs::remove_file(entry.path()) {
Ok(()) => {}
Err(err) if err.kind() == io::ErrorKind::NotFound => {}
Err(err) => panic!("Failed to remove {path}: {err}", path = entry.path().display()),
}
}
}
}