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:
bjorn3 2023-02-13 10:11:45 +00:00
parent 22befab611
commit a2f720d9fe
9 changed files with 78 additions and 18 deletions

View File

@ -16,6 +16,7 @@ pub(crate) fn run(
sysroot_kind: SysrootKind, sysroot_kind: SysrootKind,
dirs: &Dirs, dirs: &Dirs,
cg_clif_dylib: &Path, cg_clif_dylib: &Path,
rustup_toolchain_name: Option<&str>,
bootstrap_host_compiler: &Compiler, bootstrap_host_compiler: &Compiler,
) { ) {
ABI_CAFE_REPO.fetch(dirs); ABI_CAFE_REPO.fetch(dirs);
@ -27,6 +28,7 @@ pub(crate) fn run(
sysroot_kind, sysroot_kind,
cg_clif_dylib, cg_clif_dylib,
bootstrap_host_compiler, bootstrap_host_compiler,
rustup_toolchain_name,
bootstrap_host_compiler.triple.clone(), bootstrap_host_compiler.triple.clone(),
); );

View File

@ -3,7 +3,7 @@
use std::process::{self, Command}; use std::process::{self, Command};
use super::path::{Dirs, RelPath}; 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::utils::{remove_dir_if_exists, spawn_and_wait, try_hard_link, CargoProject, Compiler};
use super::SysrootKind; use super::SysrootKind;
@ -17,6 +17,7 @@ pub(crate) fn build_sysroot(
sysroot_kind: SysrootKind, sysroot_kind: SysrootKind,
cg_clif_dylib_src: &Path, cg_clif_dylib_src: &Path,
bootstrap_host_compiler: &Compiler, bootstrap_host_compiler: &Compiler,
rustup_toolchain_name: Option<&str>,
target_triple: String, target_triple: String,
) -> Compiler { ) -> Compiler {
eprintln!("[BUILD] sysroot {:?}", sysroot_kind); eprintln!("[BUILD] sysroot {:?}", sysroot_kind);
@ -41,18 +42,29 @@ pub(crate) fn build_sysroot(
// Build and copy rustc and cargo wrappers // Build and copy rustc and cargo wrappers
let wrapper_base_name = get_file_name(&bootstrap_host_compiler.rustc, "____", "bin"); 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"] { for wrapper in ["rustc-clif", "rustdoc-clif", "cargo-clif"] {
let wrapper_name = wrapper_base_name.replace("____", wrapper); let wrapper_name = wrapper_base_name.replace("____", wrapper);
let mut build_cargo_wrapper_cmd = Command::new(&bootstrap_host_compiler.rustc); 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.to_path(dirs).join(&wrapper_name);
build_cargo_wrapper_cmd build_cargo_wrapper_cmd
.env("TOOLCHAIN_NAME", toolchain_name.clone())
.arg(RelPath::SCRIPTS.to_path(dirs).join(&format!("{wrapper}.rs"))) .arg(RelPath::SCRIPTS.to_path(dirs).join(&format!("{wrapper}.rs")))
.arg("-o") .arg("-o")
.arg(&wrapper_path) .arg(&wrapper_path)
.arg("-Cstrip=debuginfo"); .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); 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, BIN_DIR.to_path(dirs).join(wrapper_name));
} }

View File

@ -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 bootstrap_host_compiler = {
let cargo = rustc_info::get_cargo_path(); let cargo = rustc_info::get_cargo_path();
let rustc = rustc_info::get_rustc_path(); let rustc = rustc_info::get_rustc_path();
@ -173,6 +181,7 @@ pub(crate) fn main() {
sysroot_kind, sysroot_kind,
&cg_clif_dylib, &cg_clif_dylib,
&bootstrap_host_compiler, &bootstrap_host_compiler,
rustup_toolchain_name.as_deref(),
target_triple.clone(), target_triple.clone(),
); );
} }
@ -181,7 +190,14 @@ pub(crate) fn main() {
eprintln!("Abi-cafe doesn't support cross-compilation"); eprintln!("Abi-cafe doesn't support cross-compilation");
process::exit(1); 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 => { Command::Build => {
build_sysroot::build_sysroot( build_sysroot::build_sysroot(
@ -190,6 +206,7 @@ pub(crate) fn main() {
sysroot_kind, sysroot_kind,
&cg_clif_dylib, &cg_clif_dylib,
&bootstrap_host_compiler, &bootstrap_host_compiler,
rustup_toolchain_name.as_deref(),
target_triple, target_triple,
); );
} }
@ -200,6 +217,7 @@ pub(crate) fn main() {
sysroot_kind, sysroot_kind,
&cg_clif_dylib, &cg_clif_dylib,
&bootstrap_host_compiler, &bootstrap_host_compiler,
rustup_toolchain_name.as_deref(),
target_triple, target_triple,
); );
bench::benchmark(&dirs, &bootstrap_host_compiler); bench::benchmark(&dirs, &bootstrap_host_compiler);

View File

@ -34,6 +34,9 @@ pub(crate) fn get_toolchain_name() -> String {
} }
pub(crate) fn get_cargo_path() -> PathBuf { 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") let cargo_path = Command::new("rustup")
.stderr(Stdio::inherit()) .stderr(Stdio::inherit())
.args(&["which", "cargo"]) .args(&["which", "cargo"])
@ -44,6 +47,9 @@ pub(crate) fn get_cargo_path() -> PathBuf {
} }
pub(crate) fn get_rustc_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") let rustc_path = Command::new("rustup")
.stderr(Stdio::inherit()) .stderr(Stdio::inherit())
.args(&["which", "rustc"]) .args(&["which", "rustc"])
@ -54,6 +60,9 @@ pub(crate) fn get_rustc_path() -> PathBuf {
} }
pub(crate) fn get_rustdoc_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") let rustc_path = Command::new("rustup")
.stderr(Stdio::inherit()) .stderr(Stdio::inherit())
.args(&["which", "rustdoc"]) .args(&["which", "rustdoc"])

View File

@ -217,6 +217,7 @@ pub(crate) fn run_tests(
sysroot_kind: SysrootKind, sysroot_kind: SysrootKind,
cg_clif_dylib: &Path, cg_clif_dylib: &Path,
bootstrap_host_compiler: &Compiler, bootstrap_host_compiler: &Compiler,
rustup_toolchain_name: Option<&str>,
target_triple: String, target_triple: String,
) { ) {
if config::get_bool("testsuite.no_sysroot") { if config::get_bool("testsuite.no_sysroot") {
@ -226,6 +227,7 @@ pub(crate) fn run_tests(
SysrootKind::None, SysrootKind::None,
cg_clif_dylib, cg_clif_dylib,
bootstrap_host_compiler, bootstrap_host_compiler,
rustup_toolchain_name,
target_triple.clone(), target_triple.clone(),
); );
@ -251,6 +253,7 @@ pub(crate) fn run_tests(
sysroot_kind, sysroot_kind,
cg_clif_dylib, cg_clif_dylib,
bootstrap_host_compiler, bootstrap_host_compiler,
rustup_toolchain_name,
target_triple.clone(), target_triple.clone(),
); );
// Rust's build system denies a couple of lints that trigger on several of the test // Rust's build system denies a couple of lints that trigger on several of the test

View File

@ -30,8 +30,9 @@ OPTIONS:
Require Cargo.lock and cache are up to date Require Cargo.lock and cache are up to date
REQUIREMENTS: REQUIREMENTS:
* Rustup: The build system has a hard coded dependency on rustup to install the right nightly * Rustup: By default rustup is used to install the right nightly version. If you don't want to
version and make sure it is used where necessary. 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. * 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 * 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. repos. Git will be used to clone the whole repo when using Windows.

View File

@ -28,8 +28,13 @@ fn main() {
env::set_var("RUSTFLAGS", env::var("RUSTFLAGS").unwrap_or(String::new()) + &rustflags); env::set_var("RUSTFLAGS", env::var("RUSTFLAGS").unwrap_or(String::new()) + &rustflags);
env::set_var("RUSTDOCFLAGS", env::var("RUSTDOCFLAGS").unwrap_or(String::new()) + &rustflags); env::set_var("RUSTDOCFLAGS", env::var("RUSTDOCFLAGS").unwrap_or(String::new()) + &rustflags);
let cargo = if let Some(cargo) = option_env!("CARGO") {
cargo
} else {
// Ensure that the right toolchain is used // Ensure that the right toolchain is used
env::set_var("RUSTUP_TOOLCHAIN", env!("TOOLCHAIN_NAME")); env::set_var("RUSTUP_TOOLCHAIN", option_env!("TOOLCHAIN_NAME").expect("TOOLCHAIN_NAME"));
"cargo"
};
let args: Vec<_> = match env::args().nth(1).as_deref() { let args: Vec<_> = match env::args().nth(1).as_deref() {
Some("jit") => { Some("jit") => {
@ -64,10 +69,10 @@ fn main() {
}; };
#[cfg(unix)] #[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))] #[cfg(not(unix))]
std::process::exit( 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),
); );
} }

View File

@ -30,14 +30,19 @@ fn main() {
} }
args.extend(passed_args); args.extend(passed_args);
let rustc = if let Some(rustc) = option_env!("RUSTC") {
rustc
} else {
// Ensure that the right toolchain is used // Ensure that the right toolchain is used
env::set_var("RUSTUP_TOOLCHAIN", env!("TOOLCHAIN_NAME")); env::set_var("RUSTUP_TOOLCHAIN", option_env!("TOOLCHAIN_NAME").expect("TOOLCHAIN_NAME"));
"rustc"
};
#[cfg(unix)] #[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))] #[cfg(not(unix))]
std::process::exit( 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),
); );
} }

View File

@ -30,14 +30,19 @@ fn main() {
} }
args.extend(passed_args); args.extend(passed_args);
let rustdoc = if let Some(rustdoc) = option_env!("RUSTDOC") {
rustdoc
} else {
// Ensure that the right toolchain is used // Ensure that the right toolchain is used
env::set_var("RUSTUP_TOOLCHAIN", env!("TOOLCHAIN_NAME")); env::set_var("RUSTUP_TOOLCHAIN", option_env!("TOOLCHAIN_NAME").expect("TOOLCHAIN_NAME"));
"rustdoc"
};
#[cfg(unix)] #[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))] #[cfg(not(unix))]
std::process::exit( 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),
); );
} }