Allow building and testing without rustup
This can be done by installing the nightly specified in rust-toolchain.toml and then pointing the CARGO, RUSTC and RUSTDOC env vars to the right executables.
This commit is contained in:
parent
22befab611
commit
a2f720d9fe
@ -16,6 +16,7 @@ pub(crate) fn run(
|
||||
sysroot_kind: SysrootKind,
|
||||
dirs: &Dirs,
|
||||
cg_clif_dylib: &Path,
|
||||
rustup_toolchain_name: Option<&str>,
|
||||
bootstrap_host_compiler: &Compiler,
|
||||
) {
|
||||
ABI_CAFE_REPO.fetch(dirs);
|
||||
@ -27,6 +28,7 @@ pub(crate) fn run(
|
||||
sysroot_kind,
|
||||
cg_clif_dylib,
|
||||
bootstrap_host_compiler,
|
||||
rustup_toolchain_name,
|
||||
bootstrap_host_compiler.triple.clone(),
|
||||
);
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
use std::process::{self, Command};
|
||||
|
||||
use super::path::{Dirs, RelPath};
|
||||
use super::rustc_info::{get_file_name, get_rustc_version, get_toolchain_name};
|
||||
use super::rustc_info::{get_file_name, get_rustc_version};
|
||||
use super::utils::{remove_dir_if_exists, spawn_and_wait, try_hard_link, CargoProject, Compiler};
|
||||
use super::SysrootKind;
|
||||
|
||||
@ -17,6 +17,7 @@ pub(crate) fn build_sysroot(
|
||||
sysroot_kind: SysrootKind,
|
||||
cg_clif_dylib_src: &Path,
|
||||
bootstrap_host_compiler: &Compiler,
|
||||
rustup_toolchain_name: Option<&str>,
|
||||
target_triple: String,
|
||||
) -> Compiler {
|
||||
eprintln!("[BUILD] sysroot {:?}", sysroot_kind);
|
||||
@ -41,18 +42,29 @@ pub(crate) fn build_sysroot(
|
||||
|
||||
// Build and copy rustc and cargo wrappers
|
||||
let wrapper_base_name = get_file_name(&bootstrap_host_compiler.rustc, "____", "bin");
|
||||
let toolchain_name = get_toolchain_name();
|
||||
for wrapper in ["rustc-clif", "rustdoc-clif", "cargo-clif"] {
|
||||
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);
|
||||
build_cargo_wrapper_cmd
|
||||
.env("TOOLCHAIN_NAME", toolchain_name.clone())
|
||||
.arg(RelPath::SCRIPTS.to_path(dirs).join(&format!("{wrapper}.rs")))
|
||||
.arg("-o")
|
||||
.arg(&wrapper_path)
|
||||
.arg("-Cstrip=debuginfo");
|
||||
if let Some(rustup_toolchain_name) = &rustup_toolchain_name {
|
||||
build_cargo_wrapper_cmd
|
||||
.env("TOOLCHAIN_NAME", rustup_toolchain_name)
|
||||
.env_remove("CARGO")
|
||||
.env_remove("RUSTC")
|
||||
.env_remove("RUSTDOC");
|
||||
} else {
|
||||
build_cargo_wrapper_cmd
|
||||
.env_remove("TOOLCHAIN_NAME")
|
||||
.env("CARGO", &bootstrap_host_compiler.cargo)
|
||||
.env("RUSTC", &bootstrap_host_compiler.rustc)
|
||||
.env("RUSTDOC", &bootstrap_host_compiler.rustdoc);
|
||||
}
|
||||
spawn_and_wait(build_cargo_wrapper_cmd);
|
||||
try_hard_link(wrapper_path, BIN_DIR.to_path(dirs).join(wrapper_name));
|
||||
}
|
||||
|
@ -103,6 +103,14 @@ pub(crate) fn main() {
|
||||
}
|
||||
}
|
||||
|
||||
let rustup_toolchain_name = match (env::var("CARGO"), env::var("RUSTC"), env::var("RUSTDOC")) {
|
||||
(Ok(_), Ok(_), Ok(_)) => None,
|
||||
(Err(_), Err(_), Err(_)) => Some(rustc_info::get_toolchain_name()),
|
||||
_ => {
|
||||
eprintln!("All of CARGO, RUSTC and RUSTDOC need to be set or none must be set");
|
||||
process::exit(1);
|
||||
}
|
||||
};
|
||||
let bootstrap_host_compiler = {
|
||||
let cargo = rustc_info::get_cargo_path();
|
||||
let rustc = rustc_info::get_rustc_path();
|
||||
@ -173,6 +181,7 @@ pub(crate) fn main() {
|
||||
sysroot_kind,
|
||||
&cg_clif_dylib,
|
||||
&bootstrap_host_compiler,
|
||||
rustup_toolchain_name.as_deref(),
|
||||
target_triple.clone(),
|
||||
);
|
||||
}
|
||||
@ -181,7 +190,14 @@ pub(crate) fn main() {
|
||||
eprintln!("Abi-cafe doesn't support cross-compilation");
|
||||
process::exit(1);
|
||||
}
|
||||
abi_cafe::run(channel, sysroot_kind, &dirs, &cg_clif_dylib, &bootstrap_host_compiler);
|
||||
abi_cafe::run(
|
||||
channel,
|
||||
sysroot_kind,
|
||||
&dirs,
|
||||
&cg_clif_dylib,
|
||||
rustup_toolchain_name.as_deref(),
|
||||
&bootstrap_host_compiler,
|
||||
);
|
||||
}
|
||||
Command::Build => {
|
||||
build_sysroot::build_sysroot(
|
||||
@ -190,6 +206,7 @@ pub(crate) fn main() {
|
||||
sysroot_kind,
|
||||
&cg_clif_dylib,
|
||||
&bootstrap_host_compiler,
|
||||
rustup_toolchain_name.as_deref(),
|
||||
target_triple,
|
||||
);
|
||||
}
|
||||
@ -200,6 +217,7 @@ pub(crate) fn main() {
|
||||
sysroot_kind,
|
||||
&cg_clif_dylib,
|
||||
&bootstrap_host_compiler,
|
||||
rustup_toolchain_name.as_deref(),
|
||||
target_triple,
|
||||
);
|
||||
bench::benchmark(&dirs, &bootstrap_host_compiler);
|
||||
|
@ -34,6 +34,9 @@ pub(crate) fn get_toolchain_name() -> String {
|
||||
}
|
||||
|
||||
pub(crate) fn get_cargo_path() -> PathBuf {
|
||||
if let Ok(cargo) = std::env::var("CARGO") {
|
||||
return PathBuf::from(cargo);
|
||||
}
|
||||
let cargo_path = Command::new("rustup")
|
||||
.stderr(Stdio::inherit())
|
||||
.args(&["which", "cargo"])
|
||||
@ -44,6 +47,9 @@ pub(crate) fn get_cargo_path() -> PathBuf {
|
||||
}
|
||||
|
||||
pub(crate) fn get_rustc_path() -> PathBuf {
|
||||
if let Ok(rustc) = std::env::var("RUSTC") {
|
||||
return PathBuf::from(rustc);
|
||||
}
|
||||
let rustc_path = Command::new("rustup")
|
||||
.stderr(Stdio::inherit())
|
||||
.args(&["which", "rustc"])
|
||||
@ -54,6 +60,9 @@ pub(crate) fn get_rustc_path() -> PathBuf {
|
||||
}
|
||||
|
||||
pub(crate) fn get_rustdoc_path() -> PathBuf {
|
||||
if let Ok(rustdoc) = std::env::var("RUSTDOC") {
|
||||
return PathBuf::from(rustdoc);
|
||||
}
|
||||
let rustc_path = Command::new("rustup")
|
||||
.stderr(Stdio::inherit())
|
||||
.args(&["which", "rustdoc"])
|
||||
|
@ -217,6 +217,7 @@ pub(crate) fn run_tests(
|
||||
sysroot_kind: SysrootKind,
|
||||
cg_clif_dylib: &Path,
|
||||
bootstrap_host_compiler: &Compiler,
|
||||
rustup_toolchain_name: Option<&str>,
|
||||
target_triple: String,
|
||||
) {
|
||||
if config::get_bool("testsuite.no_sysroot") {
|
||||
@ -226,6 +227,7 @@ pub(crate) fn run_tests(
|
||||
SysrootKind::None,
|
||||
cg_clif_dylib,
|
||||
bootstrap_host_compiler,
|
||||
rustup_toolchain_name,
|
||||
target_triple.clone(),
|
||||
);
|
||||
|
||||
@ -251,6 +253,7 @@ pub(crate) fn run_tests(
|
||||
sysroot_kind,
|
||||
cg_clif_dylib,
|
||||
bootstrap_host_compiler,
|
||||
rustup_toolchain_name,
|
||||
target_triple.clone(),
|
||||
);
|
||||
// Rust's build system denies a couple of lints that trigger on several of the test
|
||||
|
@ -30,8 +30,9 @@ OPTIONS:
|
||||
Require Cargo.lock and cache are up to date
|
||||
|
||||
REQUIREMENTS:
|
||||
* Rustup: The build system has a hard coded dependency on rustup to install the right nightly
|
||||
version and make sure it is used where necessary.
|
||||
* 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: `./y.rs prepare` uses git for applying patches and on Windows for downloading test repos.
|
||||
* Curl and tar (non-Windows only): Used by `./y.rs prepare` to download a single commit for
|
||||
repos. Git will be used to clone the whole repo when using Windows.
|
||||
|
@ -28,8 +28,13 @@ fn main() {
|
||||
env::set_var("RUSTFLAGS", env::var("RUSTFLAGS").unwrap_or(String::new()) + &rustflags);
|
||||
env::set_var("RUSTDOCFLAGS", env::var("RUSTDOCFLAGS").unwrap_or(String::new()) + &rustflags);
|
||||
|
||||
// Ensure that the right toolchain is used
|
||||
env::set_var("RUSTUP_TOOLCHAIN", env!("TOOLCHAIN_NAME"));
|
||||
let cargo = if let Some(cargo) = option_env!("CARGO") {
|
||||
cargo
|
||||
} else {
|
||||
// Ensure that the right toolchain is used
|
||||
env::set_var("RUSTUP_TOOLCHAIN", option_env!("TOOLCHAIN_NAME").expect("TOOLCHAIN_NAME"));
|
||||
"cargo"
|
||||
};
|
||||
|
||||
let args: Vec<_> = match env::args().nth(1).as_deref() {
|
||||
Some("jit") => {
|
||||
@ -64,10 +69,10 @@ fn main() {
|
||||
};
|
||||
|
||||
#[cfg(unix)]
|
||||
panic!("Failed to spawn cargo: {}", Command::new("cargo").args(args).exec());
|
||||
panic!("Failed to spawn cargo: {}", Command::new(cargo).args(args).exec());
|
||||
|
||||
#[cfg(not(unix))]
|
||||
std::process::exit(
|
||||
Command::new("cargo").args(args).spawn().unwrap().wait().unwrap().code().unwrap_or(1),
|
||||
Command::new(cargo).args(args).spawn().unwrap().wait().unwrap().code().unwrap_or(1),
|
||||
);
|
||||
}
|
||||
|
@ -30,14 +30,19 @@ fn main() {
|
||||
}
|
||||
args.extend(passed_args);
|
||||
|
||||
// Ensure that the right toolchain is used
|
||||
env::set_var("RUSTUP_TOOLCHAIN", env!("TOOLCHAIN_NAME"));
|
||||
let rustc = if let Some(rustc) = option_env!("RUSTC") {
|
||||
rustc
|
||||
} else {
|
||||
// Ensure that the right toolchain is used
|
||||
env::set_var("RUSTUP_TOOLCHAIN", option_env!("TOOLCHAIN_NAME").expect("TOOLCHAIN_NAME"));
|
||||
"rustc"
|
||||
};
|
||||
|
||||
#[cfg(unix)]
|
||||
panic!("Failed to spawn rustc: {}", Command::new("rustc").args(args).exec());
|
||||
panic!("Failed to spawn rustc: {}", Command::new(rustc).args(args).exec());
|
||||
|
||||
#[cfg(not(unix))]
|
||||
std::process::exit(
|
||||
Command::new("rustc").args(args).spawn().unwrap().wait().unwrap().code().unwrap_or(1),
|
||||
Command::new(rustc).args(args).spawn().unwrap().wait().unwrap().code().unwrap_or(1),
|
||||
);
|
||||
}
|
||||
|
@ -30,14 +30,19 @@ fn main() {
|
||||
}
|
||||
args.extend(passed_args);
|
||||
|
||||
// Ensure that the right toolchain is used
|
||||
env::set_var("RUSTUP_TOOLCHAIN", env!("TOOLCHAIN_NAME"));
|
||||
let rustdoc = if let Some(rustdoc) = option_env!("RUSTDOC") {
|
||||
rustdoc
|
||||
} else {
|
||||
// Ensure that the right toolchain is used
|
||||
env::set_var("RUSTUP_TOOLCHAIN", option_env!("TOOLCHAIN_NAME").expect("TOOLCHAIN_NAME"));
|
||||
"rustdoc"
|
||||
};
|
||||
|
||||
#[cfg(unix)]
|
||||
panic!("Failed to spawn rustdoc: {}", Command::new("rustdoc").args(args).exec());
|
||||
panic!("Failed to spawn rustdoc: {}", Command::new(rustdoc).args(args).exec());
|
||||
|
||||
#[cfg(not(unix))]
|
||||
std::process::exit(
|
||||
Command::new("rustdoc").args(args).spawn().unwrap().wait().unwrap().code().unwrap_or(1),
|
||||
Command::new(rustdoc).args(args).spawn().unwrap().wait().unwrap().code().unwrap_or(1),
|
||||
);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user