Merge pull request #1302 from bjorn3/build_system_rework4
Allow specifying where build artifacts should be written to
This commit is contained in:
commit
f73b0b1349
12 changed files with 338 additions and 249 deletions
4
.github/workflows/main.yml
vendored
4
.github/workflows/main.yml
vendored
|
@ -63,7 +63,7 @@ jobs:
|
|||
- name: Cache cargo target dir
|
||||
uses: actions/cache@v3
|
||||
with:
|
||||
path: target
|
||||
path: build/cg_clif
|
||||
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('rust-toolchain', '**/Cargo.lock') }}
|
||||
|
||||
- name: Install MinGW toolchain and wine
|
||||
|
@ -164,7 +164,7 @@ jobs:
|
|||
- name: Cache cargo target dir
|
||||
uses: actions/cache@v3
|
||||
with:
|
||||
path: target
|
||||
path: build/cg_clif
|
||||
key: ${{ runner.os }}-${{ matrix.env.TARGET_TRIPLE }}-cargo-build-target-${{ hashFiles('rust-toolchain', '**/Cargo.lock') }}
|
||||
|
||||
- name: Set MinGW as the default toolchain
|
||||
|
|
4
.github/workflows/rustc.yml
vendored
4
.github/workflows/rustc.yml
vendored
|
@ -27,7 +27,7 @@ jobs:
|
|||
- name: Cache cargo target dir
|
||||
uses: actions/cache@v3
|
||||
with:
|
||||
path: target
|
||||
path: build/cg_clif
|
||||
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('rust-toolchain', '**/Cargo.lock') }}
|
||||
|
||||
- name: Prepare dependencies
|
||||
|
@ -65,7 +65,7 @@ jobs:
|
|||
- name: Cache cargo target dir
|
||||
uses: actions/cache@v3
|
||||
with:
|
||||
path: target
|
||||
path: build/cg_clif
|
||||
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('rust-toolchain', '**/Cargo.lock') }}
|
||||
|
||||
- name: Prepare dependencies
|
||||
|
|
|
@ -2,6 +2,7 @@ use std::path::Path;
|
|||
|
||||
use super::build_sysroot;
|
||||
use super::config;
|
||||
use super::path::Dirs;
|
||||
use super::prepare::GitRepo;
|
||||
use super::utils::{spawn_and_wait, CargoProject, Compiler};
|
||||
use super::SysrootKind;
|
||||
|
@ -9,12 +10,12 @@ use super::SysrootKind;
|
|||
pub(crate) static ABI_CAFE_REPO: GitRepo =
|
||||
GitRepo::github("Gankra", "abi-cafe", "4c6dc8c9c687e2b3a760ff2176ce236872b37212", "abi-cafe");
|
||||
|
||||
static ABI_CAFE: CargoProject = CargoProject::git(&ABI_CAFE_REPO, ".");
|
||||
static ABI_CAFE: CargoProject = CargoProject::new(&ABI_CAFE_REPO.source_dir(), "abi_cafe");
|
||||
|
||||
pub(crate) fn run(
|
||||
channel: &str,
|
||||
sysroot_kind: SysrootKind,
|
||||
dist_dir: &Path,
|
||||
dirs: &Dirs,
|
||||
cg_clif_dylib: &Path,
|
||||
host_triple: &str,
|
||||
target_triple: &str,
|
||||
|
@ -31,9 +32,9 @@ pub(crate) fn run(
|
|||
|
||||
eprintln!("Building sysroot for abi-cafe");
|
||||
build_sysroot::build_sysroot(
|
||||
dirs,
|
||||
channel,
|
||||
sysroot_kind,
|
||||
dist_dir,
|
||||
cg_clif_dylib,
|
||||
host_triple,
|
||||
target_triple,
|
||||
|
@ -43,13 +44,13 @@ pub(crate) fn run(
|
|||
|
||||
let pairs = ["rustc_calls_cgclif", "cgclif_calls_rustc", "cgclif_calls_cc", "cc_calls_cgclif"];
|
||||
|
||||
let mut cmd = ABI_CAFE.run(&Compiler::host());
|
||||
let mut cmd = ABI_CAFE.run(&Compiler::host(), dirs);
|
||||
cmd.arg("--");
|
||||
cmd.arg("--pairs");
|
||||
cmd.args(pairs);
|
||||
cmd.arg("--add-rustc-codegen-backend");
|
||||
cmd.arg(format!("cgclif:{}", cg_clif_dylib.display()));
|
||||
cmd.current_dir(ABI_CAFE.source_dir());
|
||||
cmd.current_dir(ABI_CAFE.source_dir(dirs));
|
||||
|
||||
spawn_and_wait(cmd);
|
||||
}
|
||||
|
|
|
@ -1,17 +1,19 @@
|
|||
use std::env;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use super::path::{Dirs, RelPath};
|
||||
use super::rustc_info::get_file_name;
|
||||
use super::utils::{is_ci, CargoProject, Compiler};
|
||||
|
||||
static CG_CLIF: CargoProject = CargoProject::local(".");
|
||||
static CG_CLIF: CargoProject = CargoProject::new(&RelPath::SOURCE, "cg_clif");
|
||||
|
||||
pub(crate) fn build_backend(
|
||||
dirs: &Dirs,
|
||||
channel: &str,
|
||||
host_triple: &str,
|
||||
use_unstable_features: bool,
|
||||
) -> PathBuf {
|
||||
let mut cmd = CG_CLIF.build(&Compiler::host());
|
||||
let mut cmd = CG_CLIF.build(&Compiler::host(), dirs);
|
||||
|
||||
cmd.env("CARGO_BUILD_INCREMENTAL", "true"); // Force incr comp even in release mode
|
||||
|
||||
|
@ -43,8 +45,7 @@ pub(crate) fn build_backend(
|
|||
super::utils::spawn_and_wait(cmd);
|
||||
|
||||
CG_CLIF
|
||||
.source_dir()
|
||||
.join("target")
|
||||
.target_dir(dirs)
|
||||
.join(host_triple)
|
||||
.join(channel)
|
||||
.join(get_file_name("rustc_codegen_cranelift", "dylib"))
|
||||
|
|
|
@ -1,36 +1,40 @@
|
|||
use std::fs;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::path::Path;
|
||||
use std::process::{self, Command};
|
||||
|
||||
use super::path::{Dirs, RelPath};
|
||||
use super::rustc_info::{get_file_name, get_rustc_version, get_wrapper_file_name};
|
||||
use super::utils::{spawn_and_wait, try_hard_link, CargoProject, Compiler};
|
||||
use super::SysrootKind;
|
||||
|
||||
static DIST_DIR: RelPath = RelPath::DIST;
|
||||
static BIN_DIR: RelPath = RelPath::DIST.join("bin");
|
||||
static LIB_DIR: RelPath = RelPath::DIST.join("lib");
|
||||
static RUSTLIB_DIR: RelPath = LIB_DIR.join("rustlib");
|
||||
|
||||
pub(crate) fn build_sysroot(
|
||||
dirs: &Dirs,
|
||||
channel: &str,
|
||||
sysroot_kind: SysrootKind,
|
||||
dist_dir: &Path,
|
||||
cg_clif_dylib_src: &Path,
|
||||
host_triple: &str,
|
||||
target_triple: &str,
|
||||
) {
|
||||
eprintln!("[BUILD] sysroot {:?}", sysroot_kind);
|
||||
|
||||
if dist_dir.exists() {
|
||||
fs::remove_dir_all(dist_dir).unwrap();
|
||||
}
|
||||
fs::create_dir_all(dist_dir.join("bin")).unwrap();
|
||||
fs::create_dir_all(dist_dir.join("lib")).unwrap();
|
||||
DIST_DIR.ensure_fresh(dirs);
|
||||
BIN_DIR.ensure_exists(dirs);
|
||||
LIB_DIR.ensure_exists(dirs);
|
||||
|
||||
// Copy the backend
|
||||
let cg_clif_dylib_path = dist_dir
|
||||
.join(if cfg!(windows) {
|
||||
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"
|
||||
BIN_DIR
|
||||
} else {
|
||||
"lib"
|
||||
})
|
||||
LIB_DIR
|
||||
}
|
||||
.to_path(dirs)
|
||||
.join(get_file_name("rustc_codegen_cranelift", "dylib"));
|
||||
try_hard_link(cg_clif_dylib_src, &cg_clif_dylib_path);
|
||||
|
||||
|
@ -40,18 +44,17 @@ pub(crate) fn build_sysroot(
|
|||
|
||||
let mut build_cargo_wrapper_cmd = Command::new("rustc");
|
||||
build_cargo_wrapper_cmd
|
||||
.arg(PathBuf::from("scripts").join(format!("{wrapper}.rs")))
|
||||
.arg(RelPath::SCRIPTS.to_path(dirs).join(&format!("{wrapper}.rs")))
|
||||
.arg("-o")
|
||||
.arg(dist_dir.join(wrapper_name))
|
||||
.arg(DIST_DIR.to_path(dirs).join(wrapper_name))
|
||||
.arg("-g");
|
||||
spawn_and_wait(build_cargo_wrapper_cmd);
|
||||
}
|
||||
|
||||
let default_sysroot = super::rustc_info::get_default_sysroot();
|
||||
|
||||
let rustlib = dist_dir.join("lib").join("rustlib");
|
||||
let host_rustlib_lib = rustlib.join(host_triple).join("lib");
|
||||
let target_rustlib_lib = rustlib.join(target_triple).join("lib");
|
||||
let host_rustlib_lib = RUSTLIB_DIR.to_path(dirs).join(host_triple).join("lib");
|
||||
let target_rustlib_lib = RUSTLIB_DIR.to_path(dirs).join(target_triple).join("lib");
|
||||
fs::create_dir_all(&host_rustlib_lib).unwrap();
|
||||
fs::create_dir_all(&target_rustlib_lib).unwrap();
|
||||
|
||||
|
@ -112,13 +115,7 @@ pub(crate) fn build_sysroot(
|
|||
}
|
||||
}
|
||||
SysrootKind::Clif => {
|
||||
build_clif_sysroot_for_triple(
|
||||
channel,
|
||||
dist_dir,
|
||||
host_triple,
|
||||
&cg_clif_dylib_path,
|
||||
None,
|
||||
);
|
||||
build_clif_sysroot_for_triple(dirs, channel, host_triple, &cg_clif_dylib_path, None);
|
||||
|
||||
if host_triple != target_triple {
|
||||
// When cross-compiling it is often necessary to manually pick the right linker
|
||||
|
@ -128,8 +125,8 @@ pub(crate) fn build_sysroot(
|
|||
None
|
||||
};
|
||||
build_clif_sysroot_for_triple(
|
||||
dirs,
|
||||
channel,
|
||||
dist_dir,
|
||||
target_triple,
|
||||
&cg_clif_dylib_path,
|
||||
linker,
|
||||
|
@ -142,23 +139,26 @@ pub(crate) fn build_sysroot(
|
|||
let file = file.unwrap().path();
|
||||
let filename = file.file_name().unwrap().to_str().unwrap();
|
||||
if filename.contains("std-") && !filename.contains(".rlib") {
|
||||
try_hard_link(&file, dist_dir.join("lib").join(file.file_name().unwrap()));
|
||||
try_hard_link(&file, LIB_DIR.to_path(dirs).join(file.file_name().unwrap()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static STANDARD_LIBRARY: CargoProject = CargoProject::local("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");
|
||||
|
||||
fn build_clif_sysroot_for_triple(
|
||||
dirs: &Dirs,
|
||||
channel: &str,
|
||||
dist_dir: &Path,
|
||||
triple: &str,
|
||||
cg_clif_dylib_path: &Path,
|
||||
linker: Option<&str>,
|
||||
) {
|
||||
match fs::read_to_string(Path::new("build_sysroot").join("rustc_version")) {
|
||||
match fs::read_to_string(SYSROOT_RUSTC_VERSION.to_path(dirs)) {
|
||||
Err(e) => {
|
||||
eprintln!("Failed to get rustc version for patched sysroot source: {}", e);
|
||||
eprintln!("Hint: Try `./y.rs prepare` to patch the sysroot source");
|
||||
|
@ -176,7 +176,7 @@ fn build_clif_sysroot_for_triple(
|
|||
}
|
||||
}
|
||||
|
||||
let build_dir = Path::new("build_sysroot").join("target").join(triple).join(channel);
|
||||
let build_dir = STANDARD_LIBRARY.target_dir(dirs).join(triple).join(channel);
|
||||
|
||||
if !super::config::get_bool("keep_sysroot") {
|
||||
// Cleanup the deps dir, but keep build scripts and the incremental cache for faster
|
||||
|
@ -189,7 +189,7 @@ fn build_clif_sysroot_for_triple(
|
|||
// Build sysroot
|
||||
let mut rustflags = "-Zforce-unstable-if-unmarked -Cpanic=abort".to_string();
|
||||
rustflags.push_str(&format!(" -Zcodegen-backend={}", cg_clif_dylib_path.to_str().unwrap()));
|
||||
rustflags.push_str(&format!(" --sysroot={}", dist_dir.to_str().unwrap()));
|
||||
rustflags.push_str(&format!(" --sysroot={}", DIST_DIR.to_path(dirs).to_str().unwrap()));
|
||||
if channel == "release" {
|
||||
rustflags.push_str(" -Zmir-opt-level=3");
|
||||
}
|
||||
|
@ -199,7 +199,7 @@ fn build_clif_sysroot_for_triple(
|
|||
}
|
||||
let mut compiler = Compiler::with_triple(triple.to_owned());
|
||||
compiler.rustflags = rustflags;
|
||||
let mut build_cmd = STANDARD_LIBRARY.build(&compiler);
|
||||
let mut build_cmd = STANDARD_LIBRARY.build(&compiler, dirs);
|
||||
if channel == "release" {
|
||||
build_cmd.arg("--release");
|
||||
}
|
||||
|
@ -207,10 +207,7 @@ fn build_clif_sysroot_for_triple(
|
|||
spawn_and_wait(build_cmd);
|
||||
|
||||
// Copy all relevant files to the sysroot
|
||||
for entry in
|
||||
fs::read_dir(Path::new("build_sysroot/target").join(triple).join(channel).join("deps"))
|
||||
.unwrap()
|
||||
{
|
||||
for entry in fs::read_dir(build_dir.join("deps")).unwrap() {
|
||||
let entry = entry.unwrap();
|
||||
if let Some(ext) = entry.path().extension() {
|
||||
if ext == "rmeta" || ext == "d" || ext == "dSYM" || ext == "clif" {
|
||||
|
@ -221,7 +218,7 @@ fn build_clif_sysroot_for_triple(
|
|||
};
|
||||
try_hard_link(
|
||||
entry.path(),
|
||||
dist_dir.join("lib").join("rustlib").join(triple).join("lib").join(entry.file_name()),
|
||||
RUSTLIB_DIR.to_path(dirs).join(triple).join("lib").join(entry.file_name()),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,20 +8,37 @@ mod abi_cafe;
|
|||
mod build_backend;
|
||||
mod build_sysroot;
|
||||
mod config;
|
||||
mod path;
|
||||
mod prepare;
|
||||
mod rustc_info;
|
||||
mod tests;
|
||||
mod utils;
|
||||
|
||||
const USAGE: &str = r#"The build system of cg_clif.
|
||||
|
||||
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]
|
||||
|
||||
OPTIONS:
|
||||
--sysroot none|clif|llvm
|
||||
Which sysroot libraries to use:
|
||||
`none` will not include any standard library in the sysroot.
|
||||
`clif` will build the standard library using Cranelift.
|
||||
`llvm` will use the pre-compiled standard library of rustc which is compiled with LLVM.
|
||||
|
||||
--out-dir DIR
|
||||
Specify the directory in which the download, build and dist directories are stored.
|
||||
By default this is the working directory.
|
||||
|
||||
--no-unstable-features
|
||||
fSome features are not yet ready for production usage. This option will disable these
|
||||
features. This includes the JIT mode and inline assembly support.
|
||||
"#;
|
||||
|
||||
fn usage() {
|
||||
eprintln!("Usage:");
|
||||
eprintln!(" ./y.rs prepare");
|
||||
eprintln!(
|
||||
" ./y.rs build [--debug] [--sysroot none|clif|llvm] [--dist-dir DIR] [--no-unstable-features]"
|
||||
);
|
||||
eprintln!(
|
||||
" ./y.rs test [--debug] [--sysroot none|clif|llvm] [--dist-dir DIR] [--no-unstable-features]"
|
||||
);
|
||||
eprintln!("{USAGE}");
|
||||
}
|
||||
|
||||
macro_rules! arg_error {
|
||||
|
@ -34,6 +51,7 @@ macro_rules! arg_error {
|
|||
|
||||
#[derive(PartialEq, Debug)]
|
||||
enum Command {
|
||||
Prepare,
|
||||
Build,
|
||||
Test,
|
||||
}
|
||||
|
@ -48,8 +66,6 @@ pub(crate) enum SysrootKind {
|
|||
pub fn main() {
|
||||
env::set_var("CG_CLIF_DISPLAY_CG_TIME", "1");
|
||||
env::set_var("CG_CLIF_DISABLE_INCR_CACHE", "1");
|
||||
// The target dir is expected in the default location. Guard against the user changing it.
|
||||
env::set_var("CARGO_TARGET_DIR", "target");
|
||||
|
||||
if is_ci() {
|
||||
// Disabling incr comp reduces cache size and incr comp doesn't save as much on CI anyway
|
||||
|
@ -58,13 +74,7 @@ pub fn main() {
|
|||
|
||||
let mut args = env::args().skip(1);
|
||||
let command = match args.next().as_deref() {
|
||||
Some("prepare") => {
|
||||
if args.next().is_some() {
|
||||
arg_error!("./y.rs prepare doesn't expect arguments");
|
||||
}
|
||||
prepare::prepare();
|
||||
process::exit(0);
|
||||
}
|
||||
Some("prepare") => Command::Prepare,
|
||||
Some("build") => Command::Build,
|
||||
Some("test") => Command::Test,
|
||||
Some(flag) if flag.starts_with('-') => arg_error!("Expected command found flag {}", flag),
|
||||
|
@ -75,15 +85,15 @@ pub fn main() {
|
|||
}
|
||||
};
|
||||
|
||||
let mut dist_dir = PathBuf::from("dist");
|
||||
let mut out_dir = PathBuf::from(".");
|
||||
let mut channel = "release";
|
||||
let mut sysroot_kind = SysrootKind::Clif;
|
||||
let mut use_unstable_features = true;
|
||||
while let Some(arg) = args.next().as_deref() {
|
||||
match arg {
|
||||
"--dist-dir" => {
|
||||
dist_dir = PathBuf::from(args.next().unwrap_or_else(|| {
|
||||
arg_error!("--dist-dir requires argument");
|
||||
"--out-dir" => {
|
||||
out_dir = PathBuf::from(args.next().unwrap_or_else(|| {
|
||||
arg_error!("--out-dir requires argument");
|
||||
}))
|
||||
}
|
||||
"--debug" => channel = "debug",
|
||||
|
@ -101,7 +111,6 @@ pub fn main() {
|
|||
arg => arg_error!("Unexpected argument {}", arg),
|
||||
}
|
||||
}
|
||||
dist_dir = std::env::current_dir().unwrap().join(dist_dir);
|
||||
|
||||
let host_triple = if let Ok(host_triple) = std::env::var("HOST_TRIPLE") {
|
||||
host_triple
|
||||
|
@ -122,13 +131,43 @@ pub fn main() {
|
|||
host_triple.clone()
|
||||
};
|
||||
|
||||
let cg_clif_dylib = build_backend::build_backend(channel, &host_triple, use_unstable_features);
|
||||
// FIXME allow changing the location of these dirs using cli arguments
|
||||
let current_dir = std::env::current_dir().unwrap();
|
||||
out_dir = current_dir.join(out_dir);
|
||||
let dirs = path::Dirs {
|
||||
source_dir: current_dir.clone(),
|
||||
download_dir: out_dir.join("download"),
|
||||
build_dir: out_dir.join("build"),
|
||||
dist_dir: out_dir.join("dist"),
|
||||
};
|
||||
|
||||
path::RelPath::BUILD.ensure_exists(&dirs);
|
||||
|
||||
{
|
||||
// Make sure we always explicitly specify the target dir
|
||||
let target =
|
||||
path::RelPath::BUILD.join("target_dir_should_be_set_explicitly").to_path(&dirs);
|
||||
env::set_var("CARGO_TARGET_DIR", &target);
|
||||
let _ = std::fs::remove_file(&target);
|
||||
std::fs::File::create(target).unwrap();
|
||||
}
|
||||
|
||||
if command == Command::Prepare {
|
||||
prepare::prepare(&dirs);
|
||||
process::exit(0);
|
||||
}
|
||||
|
||||
let cg_clif_dylib =
|
||||
build_backend::build_backend(&dirs, channel, &host_triple, use_unstable_features);
|
||||
match command {
|
||||
Command::Prepare => {
|
||||
// Handled above
|
||||
}
|
||||
Command::Test => {
|
||||
tests::run_tests(
|
||||
&dirs,
|
||||
channel,
|
||||
sysroot_kind,
|
||||
&dist_dir,
|
||||
&cg_clif_dylib,
|
||||
&host_triple,
|
||||
&target_triple,
|
||||
|
@ -137,7 +176,7 @@ pub fn main() {
|
|||
abi_cafe::run(
|
||||
channel,
|
||||
sysroot_kind,
|
||||
&dist_dir,
|
||||
&dirs,
|
||||
&cg_clif_dylib,
|
||||
&host_triple,
|
||||
&target_triple,
|
||||
|
@ -145,9 +184,9 @@ pub fn main() {
|
|||
}
|
||||
Command::Build => {
|
||||
build_sysroot::build_sysroot(
|
||||
&dirs,
|
||||
channel,
|
||||
sysroot_kind,
|
||||
&dist_dir,
|
||||
&cg_clif_dylib,
|
||||
&host_triple,
|
||||
&target_triple,
|
||||
|
|
70
build_system/path.rs
Normal file
70
build_system/path.rs
Normal file
|
@ -0,0 +1,70 @@
|
|||
use std::fs;
|
||||
use std::path::PathBuf;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub(crate) struct Dirs {
|
||||
pub(crate) source_dir: PathBuf,
|
||||
pub(crate) download_dir: PathBuf,
|
||||
pub(crate) build_dir: PathBuf,
|
||||
pub(crate) dist_dir: PathBuf,
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub(crate) enum PathBase {
|
||||
Source,
|
||||
Download,
|
||||
Build,
|
||||
Dist,
|
||||
}
|
||||
|
||||
impl PathBase {
|
||||
fn to_path(self, dirs: &Dirs) -> PathBuf {
|
||||
match self {
|
||||
PathBase::Source => dirs.source_dir.clone(),
|
||||
PathBase::Download => dirs.download_dir.clone(),
|
||||
PathBase::Build => dirs.build_dir.clone(),
|
||||
PathBase::Dist => dirs.dist_dir.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub(crate) enum RelPath {
|
||||
Base(PathBase),
|
||||
Join(&'static RelPath, &'static str),
|
||||
}
|
||||
|
||||
impl RelPath {
|
||||
pub(crate) const SOURCE: RelPath = RelPath::Base(PathBase::Source);
|
||||
pub(crate) const DOWNLOAD: RelPath = RelPath::Base(PathBase::Download);
|
||||
pub(crate) const BUILD: RelPath = RelPath::Base(PathBase::Build);
|
||||
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 {
|
||||
RelPath::Join(self, suffix)
|
||||
}
|
||||
|
||||
pub(crate) fn to_path(&self, dirs: &Dirs) -> PathBuf {
|
||||
match self {
|
||||
RelPath::Base(base) => base.to_path(dirs),
|
||||
RelPath::Join(base, suffix) => base.to_path(dirs).join(suffix),
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn ensure_exists(&self, dirs: &Dirs) {
|
||||
fs::create_dir_all(self.to_path(dirs)).unwrap();
|
||||
}
|
||||
|
||||
pub(crate) fn ensure_fresh(&self, dirs: &Dirs) {
|
||||
let path = self.to_path(dirs);
|
||||
if path.exists() {
|
||||
fs::remove_dir_all(&path).unwrap();
|
||||
}
|
||||
fs::create_dir_all(path).unwrap();
|
||||
}
|
||||
}
|
|
@ -1,72 +1,79 @@
|
|||
use std::env;
|
||||
use std::ffi::OsStr;
|
||||
use std::fs;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process::Command;
|
||||
|
||||
use super::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::utils::{copy_dir_recursively, spawn_and_wait, Compiler};
|
||||
|
||||
pub(crate) fn prepare() {
|
||||
if Path::new("download").exists() {
|
||||
std::fs::remove_dir_all(Path::new("download")).unwrap();
|
||||
pub(crate) fn prepare(dirs: &Dirs) {
|
||||
if RelPath::DOWNLOAD.to_path(dirs).exists() {
|
||||
std::fs::remove_dir_all(RelPath::DOWNLOAD.to_path(dirs)).unwrap();
|
||||
}
|
||||
std::fs::create_dir_all(Path::new("download")).unwrap();
|
||||
std::fs::create_dir_all(RelPath::DOWNLOAD.to_path(dirs)).unwrap();
|
||||
|
||||
prepare_sysroot();
|
||||
prepare_sysroot(dirs);
|
||||
|
||||
// FIXME maybe install this only locally?
|
||||
eprintln!("[INSTALL] hyperfine");
|
||||
Command::new("cargo").arg("install").arg("hyperfine").spawn().unwrap().wait().unwrap();
|
||||
Command::new("cargo")
|
||||
.arg("install")
|
||||
.arg("hyperfine")
|
||||
.env_remove("CARGO_TARGET_DIR")
|
||||
.spawn()
|
||||
.unwrap()
|
||||
.wait()
|
||||
.unwrap();
|
||||
|
||||
super::abi_cafe::ABI_CAFE_REPO.fetch();
|
||||
super::tests::RAND_REPO.fetch();
|
||||
super::tests::REGEX_REPO.fetch();
|
||||
super::tests::PORTABLE_SIMD_REPO.fetch();
|
||||
super::tests::SIMPLE_RAYTRACER_REPO.fetch();
|
||||
super::abi_cafe::ABI_CAFE_REPO.fetch(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);
|
||||
|
||||
eprintln!("[LLVM BUILD] simple-raytracer");
|
||||
let host_compiler = Compiler::host();
|
||||
let build_cmd = super::tests::SIMPLE_RAYTRACER.build(&host_compiler);
|
||||
let build_cmd = super::tests::SIMPLE_RAYTRACER.build(&host_compiler, dirs);
|
||||
spawn_and_wait(build_cmd);
|
||||
fs::copy(
|
||||
super::tests::SIMPLE_RAYTRACER
|
||||
.target_dir()
|
||||
.target_dir(dirs)
|
||||
.join(&host_compiler.triple)
|
||||
.join("debug")
|
||||
.join(get_file_name("main", "bin")),
|
||||
super::tests::SIMPLE_RAYTRACER_REPO
|
||||
.source_dir()
|
||||
.join(get_file_name("raytracer_cg_llvm", "bin")),
|
||||
RelPath::BUILD.to_path(dirs).join(get_file_name("raytracer_cg_llvm", "bin")),
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
fn prepare_sysroot() {
|
||||
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 = env::current_dir().unwrap().join("build_sysroot").join("sysroot_src");
|
||||
let sysroot_src = SYSROOT_SRC;
|
||||
|
||||
assert!(sysroot_src_orig.exists());
|
||||
|
||||
if sysroot_src.exists() {
|
||||
fs::remove_dir_all(&sysroot_src).unwrap();
|
||||
}
|
||||
fs::create_dir_all(sysroot_src.join("library")).unwrap();
|
||||
sysroot_src.ensure_fresh(dirs);
|
||||
fs::create_dir_all(sysroot_src.to_path(dirs).join("library")).unwrap();
|
||||
eprintln!("[COPY] sysroot src");
|
||||
copy_dir_recursively(&sysroot_src_orig.join("library"), &sysroot_src.join("library"));
|
||||
copy_dir_recursively(
|
||||
&sysroot_src_orig.join("library"),
|
||||
&sysroot_src.to_path(dirs).join("library"),
|
||||
);
|
||||
|
||||
let rustc_version = get_rustc_version();
|
||||
fs::write(Path::new("build_sysroot").join("rustc_version"), &rustc_version).unwrap();
|
||||
fs::write(SYSROOT_RUSTC_VERSION.to_path(dirs), &rustc_version).unwrap();
|
||||
|
||||
eprintln!("[GIT] init");
|
||||
let mut git_init_cmd = Command::new("git");
|
||||
git_init_cmd.arg("init").arg("-q").current_dir(&sysroot_src);
|
||||
git_init_cmd.arg("init").arg("-q").current_dir(sysroot_src.to_path(dirs));
|
||||
spawn_and_wait(git_init_cmd);
|
||||
|
||||
init_git_repo(&sysroot_src);
|
||||
init_git_repo(&sysroot_src.to_path(dirs));
|
||||
|
||||
apply_patches("sysroot", &sysroot_src);
|
||||
apply_patches(dirs, "sysroot", &sysroot_src.to_path(dirs));
|
||||
}
|
||||
|
||||
pub(crate) struct GitRepo {
|
||||
|
@ -89,21 +96,25 @@ impl GitRepo {
|
|||
GitRepo { url: GitRepoUrl::Github { user, repo }, rev, patch_name }
|
||||
}
|
||||
|
||||
pub(crate) fn source_dir(&self) -> PathBuf {
|
||||
pub(crate) const fn source_dir(&self) -> RelPath {
|
||||
match self.url {
|
||||
GitRepoUrl::Github { user: _, repo } => {
|
||||
std::env::current_dir().unwrap().join("download").join(repo)
|
||||
}
|
||||
GitRepoUrl::Github { user: _, repo } => RelPath::DOWNLOAD.join(repo),
|
||||
}
|
||||
}
|
||||
|
||||
fn fetch(&self) {
|
||||
fn fetch(&self, dirs: &Dirs) {
|
||||
match self.url {
|
||||
GitRepoUrl::Github { user, repo } => {
|
||||
clone_repo_shallow_github(&self.source_dir(), user, repo, self.rev);
|
||||
clone_repo_shallow_github(
|
||||
dirs,
|
||||
&self.source_dir().to_path(dirs),
|
||||
user,
|
||||
repo,
|
||||
self.rev,
|
||||
);
|
||||
}
|
||||
}
|
||||
apply_patches(self.patch_name, &self.source_dir());
|
||||
apply_patches(dirs, self.patch_name, &self.source_dir().to_path(dirs));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -122,18 +133,16 @@ fn clone_repo(download_dir: &Path, repo: &str, rev: &str) {
|
|||
spawn_and_wait(checkout_cmd);
|
||||
}
|
||||
|
||||
fn clone_repo_shallow_github(download_dir: &Path, user: &str, repo: &str, rev: &str) {
|
||||
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 downloads_dir = std::env::current_dir().unwrap().join("download");
|
||||
|
||||
let archive_url = format!("https://github.com/{}/{}/archive/{}.tar.gz", user, repo, rev);
|
||||
let archive_file = downloads_dir.join(format!("{}.tar.gz", rev));
|
||||
let archive_dir = downloads_dir.join(format!("{}-{}", 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);
|
||||
|
||||
|
@ -149,7 +158,7 @@ fn clone_repo_shallow_github(download_dir: &Path, user: &str, repo: &str, rev: &
|
|||
|
||||
// Unpack tar archive
|
||||
let mut unpack_cmd = Command::new("tar");
|
||||
unpack_cmd.arg("xf").arg(&archive_file).current_dir(downloads_dir);
|
||||
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
|
||||
|
@ -175,8 +184,8 @@ fn init_git_repo(repo_dir: &Path) {
|
|||
spawn_and_wait(git_commit_cmd);
|
||||
}
|
||||
|
||||
fn get_patches(source_dir: &Path, crate_name: &str) -> Vec<PathBuf> {
|
||||
let mut patches: Vec<_> = fs::read_dir(source_dir.join("patches"))
|
||||
fn get_patches(dirs: &Dirs, crate_name: &str) -> Vec<PathBuf> {
|
||||
let mut patches: Vec<_> = fs::read_dir(RelPath::PATCHES.to_path(dirs))
|
||||
.unwrap()
|
||||
.map(|entry| entry.unwrap().path())
|
||||
.filter(|path| path.extension() == Some(OsStr::new("patch")))
|
||||
|
@ -195,12 +204,12 @@ fn get_patches(source_dir: &Path, crate_name: &str) -> Vec<PathBuf> {
|
|||
patches
|
||||
}
|
||||
|
||||
fn apply_patches(crate_name: &str, target_dir: &Path) {
|
||||
fn apply_patches(dirs: &Dirs, crate_name: &str, target_dir: &Path) {
|
||||
if crate_name == "<none>" {
|
||||
return;
|
||||
}
|
||||
|
||||
for patch in get_patches(&std::env::current_dir().unwrap(), crate_name) {
|
||||
for patch in get_patches(dirs, crate_name) {
|
||||
eprintln!(
|
||||
"[PATCH] {:?} <- {:?}",
|
||||
target_dir.file_name().unwrap(),
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
use crate::build_system::rustc_info::get_cargo_path;
|
||||
|
||||
use super::build_sysroot;
|
||||
use super::config;
|
||||
use super::path::{Dirs, RelPath};
|
||||
use super::prepare::GitRepo;
|
||||
use super::rustc_info::get_wrapper_file_name;
|
||||
use super::rustc_info::{get_cargo_path, get_wrapper_file_name};
|
||||
use super::utils::{
|
||||
hyperfine_command, spawn_and_wait, spawn_and_wait_with_input, CargoProject, Compiler,
|
||||
};
|
||||
|
@ -11,9 +10,11 @@ use super::SysrootKind;
|
|||
use std::env;
|
||||
use std::ffi::OsStr;
|
||||
use std::fs;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::path::Path;
|
||||
use std::process::Command;
|
||||
|
||||
static BUILD_EXAMPLE_OUT_DIR: RelPath = RelPath::BUILD.join("example");
|
||||
|
||||
struct TestCase {
|
||||
config: &'static str,
|
||||
func: &'static dyn Fn(&TestRunner),
|
||||
|
@ -223,12 +224,12 @@ const BASE_SYSROOT_SUITE: &[TestCase] = &[
|
|||
pub(crate) static RAND_REPO: GitRepo =
|
||||
GitRepo::github("rust-random", "rand", "0f933f9c7176e53b2a3c7952ded484e1783f0bf1", "rand");
|
||||
|
||||
static RAND: CargoProject = CargoProject::git(&RAND_REPO, ".");
|
||||
static RAND: CargoProject = CargoProject::new(&RAND_REPO.source_dir(), "rand");
|
||||
|
||||
pub(crate) static REGEX_REPO: GitRepo =
|
||||
GitRepo::github("rust-lang", "regex", "341f207c1071f7290e3f228c710817c280c8dca1", "regex");
|
||||
|
||||
static REGEX: CargoProject = CargoProject::git(®EX_REPO, ".");
|
||||
static REGEX: CargoProject = CargoProject::new(®EX_REPO.source_dir(), "regex");
|
||||
|
||||
pub(crate) static PORTABLE_SIMD_REPO: GitRepo = GitRepo::github(
|
||||
"rust-lang",
|
||||
|
@ -237,7 +238,8 @@ pub(crate) static PORTABLE_SIMD_REPO: GitRepo = GitRepo::github(
|
|||
"portable-simd",
|
||||
);
|
||||
|
||||
static PORTABLE_SIMD: CargoProject = CargoProject::git(&PORTABLE_SIMD_REPO, ".");
|
||||
static PORTABLE_SIMD: CargoProject =
|
||||
CargoProject::new(&PORTABLE_SIMD_REPO.source_dir(), "portable_simd");
|
||||
|
||||
pub(crate) static SIMPLE_RAYTRACER_REPO: GitRepo = GitRepo::github(
|
||||
"ebobby",
|
||||
|
@ -246,23 +248,24 @@ pub(crate) static SIMPLE_RAYTRACER_REPO: GitRepo = GitRepo::github(
|
|||
"<none>",
|
||||
);
|
||||
|
||||
pub(crate) static SIMPLE_RAYTRACER: CargoProject = CargoProject::git(&SIMPLE_RAYTRACER_REPO, ".");
|
||||
pub(crate) static SIMPLE_RAYTRACER: CargoProject =
|
||||
CargoProject::new(&SIMPLE_RAYTRACER_REPO.source_dir(), "simple_raytracer");
|
||||
|
||||
static LIBCORE_TESTS: CargoProject =
|
||||
CargoProject::local("build_sysroot/sysroot_src/library/core/tests");
|
||||
CargoProject::new(&RelPath::BUILD_SYSROOT.join("sysroot_src/library/core/tests"), "core_tests");
|
||||
|
||||
const EXTENDED_SYSROOT_SUITE: &[TestCase] = &[
|
||||
TestCase::new("test.rust-random/rand", &|runner| {
|
||||
spawn_and_wait(RAND.clean(&runner.target_compiler.cargo));
|
||||
spawn_and_wait(RAND.clean(&runner.target_compiler.cargo, &runner.dirs));
|
||||
|
||||
if runner.is_native {
|
||||
eprintln!("[TEST] rust-random/rand");
|
||||
let mut test_cmd = RAND.test(&runner.target_compiler);
|
||||
let mut test_cmd = RAND.test(&runner.target_compiler, &runner.dirs);
|
||||
test_cmd.arg("--workspace");
|
||||
spawn_and_wait(test_cmd);
|
||||
} else {
|
||||
eprintln!("[AOT] rust-random/rand");
|
||||
let mut build_cmd = RAND.build(&runner.target_compiler);
|
||||
let mut build_cmd = RAND.build(&runner.target_compiler, &runner.dirs);
|
||||
build_cmd.arg("--workspace").arg("--tests");
|
||||
spawn_and_wait(build_cmd);
|
||||
}
|
||||
|
@ -272,13 +275,11 @@ const EXTENDED_SYSROOT_SUITE: &[TestCase] = &[
|
|||
|
||||
if runner.is_native {
|
||||
eprintln!("[BENCH COMPILE] ebobby/simple-raytracer");
|
||||
let cargo_clif = env::current_dir()
|
||||
.unwrap()
|
||||
.join("dist")
|
||||
let cargo_clif = RelPath::DIST
|
||||
.to_path(&runner.dirs)
|
||||
.join(get_wrapper_file_name("cargo-clif", "bin"));
|
||||
let source_dir = SIMPLE_RAYTRACER.source_dir();
|
||||
let manifest_path = SIMPLE_RAYTRACER.manifest_path();
|
||||
let target_dir = SIMPLE_RAYTRACER.target_dir();
|
||||
let manifest_path = SIMPLE_RAYTRACER.manifest_path(&runner.dirs);
|
||||
let target_dir = SIMPLE_RAYTRACER.target_dir(&runner.dirs);
|
||||
|
||||
let clean_cmd = format!(
|
||||
"cargo clean --manifest-path {manifest_path} --target-dir {target_dir}",
|
||||
|
@ -303,58 +304,58 @@ const EXTENDED_SYSROOT_SUITE: &[TestCase] = &[
|
|||
spawn_and_wait(bench_compile);
|
||||
|
||||
eprintln!("[BENCH RUN] ebobby/simple-raytracer");
|
||||
fs::copy(target_dir.join("debug").join("main"), source_dir.join("raytracer_cg_clif"))
|
||||
fs::copy(
|
||||
target_dir.join("debug").join("main"),
|
||||
RelPath::BUILD.to_path(&runner.dirs).join("raytracer_cg_clif"),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let mut bench_run = hyperfine_command(
|
||||
0,
|
||||
run_runs,
|
||||
None,
|
||||
&source_dir.join("raytracer_cg_llvm").display().to_string(),
|
||||
&source_dir.join("raytracer_cg_clif").display().to_string(),
|
||||
);
|
||||
bench_run.current_dir(SIMPLE_RAYTRACER.source_dir());
|
||||
let mut bench_run =
|
||||
hyperfine_command(0, run_runs, None, "./raytracer_cg_llvm", "./raytracer_cg_clif");
|
||||
bench_run.current_dir(RelPath::BUILD.to_path(&runner.dirs));
|
||||
spawn_and_wait(bench_run);
|
||||
} else {
|
||||
spawn_and_wait(SIMPLE_RAYTRACER.clean(&runner.target_compiler.cargo));
|
||||
spawn_and_wait(SIMPLE_RAYTRACER.clean(&runner.target_compiler.cargo, &runner.dirs));
|
||||
eprintln!("[BENCH COMPILE] ebobby/simple-raytracer (skipped)");
|
||||
eprintln!("[COMPILE] ebobby/simple-raytracer");
|
||||
spawn_and_wait(SIMPLE_RAYTRACER.build(&runner.target_compiler));
|
||||
spawn_and_wait(SIMPLE_RAYTRACER.build(&runner.target_compiler, &runner.dirs));
|
||||
eprintln!("[BENCH RUN] ebobby/simple-raytracer (skipped)");
|
||||
}
|
||||
}),
|
||||
TestCase::new("test.libcore", &|runner| {
|
||||
spawn_and_wait(LIBCORE_TESTS.clean(&runner.host_compiler.cargo));
|
||||
spawn_and_wait(LIBCORE_TESTS.clean(&runner.host_compiler.cargo, &runner.dirs));
|
||||
|
||||
if runner.is_native {
|
||||
spawn_and_wait(LIBCORE_TESTS.test(&runner.target_compiler));
|
||||
spawn_and_wait(LIBCORE_TESTS.test(&runner.target_compiler, &runner.dirs));
|
||||
} else {
|
||||
eprintln!("Cross-Compiling: Not running tests");
|
||||
let mut build_cmd = LIBCORE_TESTS.build(&runner.target_compiler);
|
||||
let mut build_cmd = LIBCORE_TESTS.build(&runner.target_compiler, &runner.dirs);
|
||||
build_cmd.arg("--tests");
|
||||
spawn_and_wait(build_cmd);
|
||||
}
|
||||
}),
|
||||
TestCase::new("test.regex-shootout-regex-dna", &|runner| {
|
||||
spawn_and_wait(REGEX.clean(&runner.target_compiler.cargo));
|
||||
spawn_and_wait(REGEX.clean(&runner.target_compiler.cargo, &runner.dirs));
|
||||
|
||||
// newer aho_corasick versions throw a deprecation warning
|
||||
let lint_rust_flags = format!("{} --cap-lints warn", runner.target_compiler.rustflags);
|
||||
|
||||
let mut build_cmd = REGEX.build(&runner.target_compiler);
|
||||
let mut build_cmd = REGEX.build(&runner.target_compiler, &runner.dirs);
|
||||
build_cmd.arg("--example").arg("shootout-regex-dna");
|
||||
build_cmd.env("RUSTFLAGS", lint_rust_flags.clone());
|
||||
spawn_and_wait(build_cmd);
|
||||
|
||||
if runner.is_native {
|
||||
let mut run_cmd = REGEX.run(&runner.target_compiler);
|
||||
let mut run_cmd = REGEX.run(&runner.target_compiler, &runner.dirs);
|
||||
run_cmd.arg("--example").arg("shootout-regex-dna");
|
||||
run_cmd.env("RUSTFLAGS", lint_rust_flags);
|
||||
|
||||
let input =
|
||||
fs::read_to_string(REGEX.source_dir().join("examples").join("regexdna-input.txt"))
|
||||
let input = fs::read_to_string(
|
||||
REGEX.source_dir(&runner.dirs).join("examples").join("regexdna-input.txt"),
|
||||
)
|
||||
.unwrap();
|
||||
let expected_path = REGEX.source_dir().join("examples").join("regexdna-output.txt");
|
||||
let expected_path =
|
||||
REGEX.source_dir(&runner.dirs).join("examples").join("regexdna-output.txt");
|
||||
let expected = fs::read_to_string(&expected_path).unwrap();
|
||||
|
||||
let output = spawn_and_wait_with_input(run_cmd, input);
|
||||
|
@ -368,7 +369,7 @@ const EXTENDED_SYSROOT_SUITE: &[TestCase] = &[
|
|||
|
||||
let output_matches = expected.lines().eq(output.lines());
|
||||
if !output_matches {
|
||||
let res_path = REGEX.source_dir().join("res.txt");
|
||||
let res_path = REGEX.source_dir(&runner.dirs).join("res.txt");
|
||||
fs::write(&res_path, &output).unwrap();
|
||||
|
||||
if cfg!(windows) {
|
||||
|
@ -388,13 +389,13 @@ const EXTENDED_SYSROOT_SUITE: &[TestCase] = &[
|
|||
}
|
||||
}),
|
||||
TestCase::new("test.regex", &|runner| {
|
||||
spawn_and_wait(REGEX.clean(&runner.host_compiler.cargo));
|
||||
spawn_and_wait(REGEX.clean(&runner.host_compiler.cargo, &runner.dirs));
|
||||
|
||||
// newer aho_corasick versions throw a deprecation warning
|
||||
let lint_rust_flags = format!("{} --cap-lints warn", runner.target_compiler.rustflags);
|
||||
|
||||
if runner.is_native {
|
||||
let mut run_cmd = REGEX.test(&runner.target_compiler);
|
||||
let mut run_cmd = REGEX.test(&runner.target_compiler, &runner.dirs);
|
||||
run_cmd.args([
|
||||
"--tests",
|
||||
"--",
|
||||
|
@ -408,21 +409,21 @@ const EXTENDED_SYSROOT_SUITE: &[TestCase] = &[
|
|||
spawn_and_wait(run_cmd);
|
||||
} else {
|
||||
eprintln!("Cross-Compiling: Not running tests");
|
||||
let mut build_cmd = REGEX.build(&runner.target_compiler);
|
||||
let mut build_cmd = REGEX.build(&runner.target_compiler, &runner.dirs);
|
||||
build_cmd.arg("--tests");
|
||||
build_cmd.env("RUSTFLAGS", lint_rust_flags.clone());
|
||||
spawn_and_wait(build_cmd);
|
||||
}
|
||||
}),
|
||||
TestCase::new("test.portable-simd", &|runner| {
|
||||
spawn_and_wait(PORTABLE_SIMD.clean(&runner.host_compiler.cargo));
|
||||
spawn_and_wait(PORTABLE_SIMD.clean(&runner.host_compiler.cargo, &runner.dirs));
|
||||
|
||||
let mut build_cmd = PORTABLE_SIMD.build(&runner.target_compiler);
|
||||
let mut build_cmd = PORTABLE_SIMD.build(&runner.target_compiler, &runner.dirs);
|
||||
build_cmd.arg("--all-targets");
|
||||
spawn_and_wait(build_cmd);
|
||||
|
||||
if runner.is_native {
|
||||
let mut test_cmd = PORTABLE_SIMD.test(&runner.target_compiler);
|
||||
let mut test_cmd = PORTABLE_SIMD.test(&runner.target_compiler, &runner.dirs);
|
||||
test_cmd.arg("-q");
|
||||
spawn_and_wait(test_cmd);
|
||||
}
|
||||
|
@ -430,26 +431,26 @@ const EXTENDED_SYSROOT_SUITE: &[TestCase] = &[
|
|||
];
|
||||
|
||||
pub(crate) fn run_tests(
|
||||
dirs: &Dirs,
|
||||
channel: &str,
|
||||
sysroot_kind: SysrootKind,
|
||||
dist_dir: &Path,
|
||||
cg_clif_dylib: &Path,
|
||||
host_triple: &str,
|
||||
target_triple: &str,
|
||||
) {
|
||||
let runner = TestRunner::new(host_triple.to_string(), target_triple.to_string());
|
||||
let runner = TestRunner::new(dirs.clone(), host_triple.to_string(), target_triple.to_string());
|
||||
|
||||
if config::get_bool("testsuite.no_sysroot") {
|
||||
build_sysroot::build_sysroot(
|
||||
dirs,
|
||||
channel,
|
||||
SysrootKind::None,
|
||||
&dist_dir,
|
||||
cg_clif_dylib,
|
||||
&host_triple,
|
||||
&target_triple,
|
||||
);
|
||||
|
||||
let _ = fs::remove_dir_all(Path::new("target").join("out"));
|
||||
BUILD_EXAMPLE_OUT_DIR.ensure_fresh(dirs);
|
||||
runner.run_testsuite(NO_SYSROOT_SUITE);
|
||||
} else {
|
||||
eprintln!("[SKIP] no_sysroot tests");
|
||||
|
@ -460,9 +461,9 @@ pub(crate) fn run_tests(
|
|||
|
||||
if run_base_sysroot || run_extended_sysroot {
|
||||
build_sysroot::build_sysroot(
|
||||
dirs,
|
||||
channel,
|
||||
sysroot_kind,
|
||||
&dist_dir,
|
||||
cg_clif_dylib,
|
||||
&host_triple,
|
||||
&target_triple,
|
||||
|
@ -483,32 +484,23 @@ pub(crate) fn run_tests(
|
|||
}
|
||||
|
||||
struct TestRunner {
|
||||
out_dir: PathBuf,
|
||||
is_native: bool,
|
||||
jit_supported: bool,
|
||||
dirs: Dirs,
|
||||
host_compiler: Compiler,
|
||||
target_compiler: Compiler,
|
||||
}
|
||||
|
||||
impl TestRunner {
|
||||
pub fn new(host_triple: String, target_triple: String) -> Self {
|
||||
let root_dir = env::current_dir().unwrap();
|
||||
|
||||
let mut out_dir = root_dir.clone();
|
||||
out_dir.push("target");
|
||||
out_dir.push("out");
|
||||
|
||||
pub fn new(dirs: Dirs, host_triple: String, target_triple: String) -> Self {
|
||||
let is_native = host_triple == target_triple;
|
||||
let jit_supported =
|
||||
target_triple.contains("x86_64") && is_native && !host_triple.contains("windows");
|
||||
|
||||
let mut rustc_clif = root_dir.clone();
|
||||
rustc_clif.push("dist");
|
||||
rustc_clif.push(get_wrapper_file_name("rustc-clif", "bin"));
|
||||
|
||||
let mut rustdoc_clif = root_dir.clone();
|
||||
rustdoc_clif.push("dist");
|
||||
rustdoc_clif.push(get_wrapper_file_name("rustdoc-clif", "bin"));
|
||||
let rustc_clif =
|
||||
RelPath::DIST.to_path(&dirs).join(get_wrapper_file_name("rustc-clif", "bin"));
|
||||
let rustdoc_clif =
|
||||
RelPath::DIST.to_path(&dirs).join(get_wrapper_file_name("rustdoc-clif", "bin"));
|
||||
|
||||
let mut rustflags = env::var("RUSTFLAGS").ok().unwrap_or("".to_string());
|
||||
let mut runner = vec![];
|
||||
|
@ -551,15 +543,15 @@ impl TestRunner {
|
|||
|
||||
let target_compiler = Compiler {
|
||||
cargo: get_cargo_path(),
|
||||
rustc: rustc_clif.clone(),
|
||||
rustdoc: rustdoc_clif.clone(),
|
||||
rustc: rustc_clif,
|
||||
rustdoc: rustdoc_clif,
|
||||
rustflags: rustflags.clone(),
|
||||
rustdocflags: rustflags,
|
||||
triple: target_triple,
|
||||
runner,
|
||||
};
|
||||
|
||||
Self { out_dir, is_native, jit_supported, host_compiler, target_compiler }
|
||||
Self { is_native, jit_supported, dirs, host_compiler, target_compiler }
|
||||
}
|
||||
|
||||
pub fn run_testsuite(&self, tests: &[TestCase]) {
|
||||
|
@ -588,9 +580,9 @@ impl TestRunner {
|
|||
let mut cmd = Command::new(&self.target_compiler.rustc);
|
||||
cmd.args(self.target_compiler.rustflags.split_whitespace());
|
||||
cmd.arg("-L");
|
||||
cmd.arg(format!("crate={}", self.out_dir.display()));
|
||||
cmd.arg(format!("crate={}", BUILD_EXAMPLE_OUT_DIR.to_path(&self.dirs).display()));
|
||||
cmd.arg("--out-dir");
|
||||
cmd.arg(format!("{}", self.out_dir.display()));
|
||||
cmd.arg(format!("{}", BUILD_EXAMPLE_OUT_DIR.to_path(&self.dirs).display()));
|
||||
cmd.arg("-Cdebuginfo=2");
|
||||
cmd.args(args);
|
||||
cmd
|
||||
|
@ -615,11 +607,9 @@ impl TestRunner {
|
|||
full_cmd.extend(self.target_compiler.runner.iter().cloned());
|
||||
}
|
||||
|
||||
full_cmd.push({
|
||||
let mut out_path = self.out_dir.clone();
|
||||
out_path.push(name);
|
||||
out_path.to_str().unwrap().to_string()
|
||||
});
|
||||
full_cmd.push(
|
||||
BUILD_EXAMPLE_OUT_DIR.to_path(&self.dirs).join(name).to_str().unwrap().to_string(),
|
||||
);
|
||||
|
||||
for arg in args.into_iter() {
|
||||
full_cmd.push(arg.to_string());
|
||||
|
|
|
@ -4,7 +4,7 @@ use std::io::Write;
|
|||
use std::path::{Path, PathBuf};
|
||||
use std::process::{self, Command, Stdio};
|
||||
|
||||
use super::prepare::GitRepo;
|
||||
use super::path::{Dirs, RelPath};
|
||||
use super::rustc_info::{get_cargo_path, get_host_triple, get_rustc_path, get_rustdoc_path};
|
||||
|
||||
pub(crate) struct Compiler {
|
||||
|
@ -43,60 +43,42 @@ impl Compiler {
|
|||
}
|
||||
}
|
||||
|
||||
enum CargoProjectSource {
|
||||
Local,
|
||||
GitRepo(&'static GitRepo),
|
||||
}
|
||||
|
||||
pub(crate) struct CargoProject {
|
||||
source: CargoProjectSource,
|
||||
path: &'static str,
|
||||
source: &'static RelPath,
|
||||
target: &'static str,
|
||||
}
|
||||
|
||||
impl CargoProject {
|
||||
pub(crate) const fn local(path: &'static str) -> CargoProject {
|
||||
CargoProject { source: CargoProjectSource::Local, path }
|
||||
pub(crate) const fn new(path: &'static RelPath, target: &'static str) -> CargoProject {
|
||||
CargoProject { source: path, target }
|
||||
}
|
||||
|
||||
pub(crate) const fn git(git_repo: &'static GitRepo, path: &'static str) -> CargoProject {
|
||||
CargoProject { source: CargoProjectSource::GitRepo(git_repo), path }
|
||||
pub(crate) fn source_dir(&self, dirs: &Dirs) -> PathBuf {
|
||||
self.source.to_path(dirs)
|
||||
}
|
||||
|
||||
pub(crate) fn source_dir(&self) -> PathBuf {
|
||||
match self.source {
|
||||
CargoProjectSource::Local => std::env::current_dir().unwrap(),
|
||||
CargoProjectSource::GitRepo(git_repo) => git_repo.source_dir(),
|
||||
}
|
||||
.join(self.path)
|
||||
pub(crate) fn manifest_path(&self, dirs: &Dirs) -> PathBuf {
|
||||
self.source_dir(dirs).join("Cargo.toml")
|
||||
}
|
||||
|
||||
pub(crate) fn manifest_path(&self) -> PathBuf {
|
||||
self.source_dir().join("Cargo.toml")
|
||||
pub(crate) fn target_dir(&self, dirs: &Dirs) -> PathBuf {
|
||||
RelPath::BUILD.join(self.target).to_path(dirs)
|
||||
}
|
||||
|
||||
pub(crate) fn target_dir(&self) -> PathBuf {
|
||||
match self.source {
|
||||
CargoProjectSource::Local => std::env::current_dir().unwrap(),
|
||||
CargoProjectSource::GitRepo(git_repo) => git_repo.source_dir(),
|
||||
}
|
||||
.join(self.path)
|
||||
.join("target")
|
||||
}
|
||||
|
||||
fn base_cmd(&self, command: &str, cargo: &Path) -> Command {
|
||||
fn base_cmd(&self, command: &str, cargo: &Path, dirs: &Dirs) -> Command {
|
||||
let mut cmd = Command::new(cargo);
|
||||
|
||||
cmd.arg(command)
|
||||
.arg("--manifest-path")
|
||||
.arg(self.manifest_path())
|
||||
.arg(self.manifest_path(dirs))
|
||||
.arg("--target-dir")
|
||||
.arg(self.target_dir());
|
||||
.arg(self.target_dir(dirs));
|
||||
|
||||
cmd
|
||||
}
|
||||
|
||||
fn build_cmd(&self, command: &str, compiler: &Compiler) -> Command {
|
||||
let mut cmd = self.base_cmd(command, &compiler.cargo);
|
||||
fn build_cmd(&self, command: &str, compiler: &Compiler, dirs: &Dirs) -> Command {
|
||||
let mut cmd = self.base_cmd(command, &compiler.cargo, dirs);
|
||||
|
||||
cmd.arg("--target").arg(&compiler.triple);
|
||||
|
||||
|
@ -115,32 +97,32 @@ impl CargoProject {
|
|||
}
|
||||
|
||||
#[must_use]
|
||||
pub(crate) fn fetch(&self, cargo: impl AsRef<Path>) -> Command {
|
||||
pub(crate) fn fetch(&self, cargo: impl AsRef<Path>, dirs: &Dirs) -> Command {
|
||||
let mut cmd = Command::new(cargo.as_ref());
|
||||
|
||||
cmd.arg("fetch").arg("--manifest-path").arg(self.manifest_path());
|
||||
cmd.arg("fetch").arg("--manifest-path").arg(self.manifest_path(dirs));
|
||||
|
||||
cmd
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub(crate) fn clean(&self, cargo: &Path) -> Command {
|
||||
self.base_cmd("clean", cargo)
|
||||
pub(crate) fn clean(&self, cargo: &Path, dirs: &Dirs) -> Command {
|
||||
self.base_cmd("clean", cargo, dirs)
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub(crate) fn build(&self, compiler: &Compiler) -> Command {
|
||||
self.build_cmd("build", compiler)
|
||||
pub(crate) fn build(&self, compiler: &Compiler, dirs: &Dirs) -> Command {
|
||||
self.build_cmd("build", compiler, dirs)
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub(crate) fn test(&self, compiler: &Compiler) -> Command {
|
||||
self.build_cmd("test", compiler)
|
||||
pub(crate) fn test(&self, compiler: &Compiler, dirs: &Dirs) -> Command {
|
||||
self.build_cmd("test", compiler, dirs)
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub(crate) fn run(&self, compiler: &Compiler) -> Command {
|
||||
self.build_cmd("run", compiler)
|
||||
pub(crate) fn run(&self, compiler: &Compiler, dirs: &Dirs) -> Command {
|
||||
self.build_cmd("run", compiler, dirs)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,9 +2,9 @@
|
|||
set -e
|
||||
|
||||
rm -rf build_sysroot/{sysroot_src/,target/,compiler-builtins/,rustc_version}
|
||||
rm -rf target/ dist/ perf.data{,.old} y.bin
|
||||
rm -rf target/ build/ dist/ perf.data{,.old} y.bin
|
||||
rm -rf download/
|
||||
|
||||
# Kept for now in case someone updates their checkout of cg_clif before running clean_all.sh
|
||||
# FIXME remove at some point in the future
|
||||
rm -rf rand/ regex/ simple-raytracer/ portable-simd/ abi-checker/ abi-cafe/ build/
|
||||
rm -rf rand/ regex/ simple-raytracer/ portable-simd/ abi-checker/ abi-cafe/
|
||||
|
|
2
test.sh
2
test.sh
|
@ -1,2 +1,2 @@
|
|||
#!/usr/bin/env bash
|
||||
exec ./y.rs test
|
||||
exec ./y.rs test "$@"
|
||||
|
|
Loading…
Add table
Reference in a new issue