1
Fork 0

Merge pull request #1374 from bjorn3/non_rustup_build3

Allow building and testing without rustup
This commit is contained in:
bjorn3 2023-05-22 20:58:07 +02:00 committed by GitHub
commit a684753a68
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 146 additions and 92 deletions

View file

@ -16,10 +16,10 @@ 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);
spawn_and_wait(ABI_CAFE.fetch("cargo", &bootstrap_host_compiler.rustc, dirs));
eprintln!("Building sysroot for abi-cafe"); eprintln!("Building sysroot for abi-cafe");
build_sysroot::build_sysroot( build_sysroot::build_sysroot(
@ -28,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

@ -4,7 +4,7 @@ use std::path::Path;
use super::path::{Dirs, RelPath}; use super::path::{Dirs, RelPath};
use super::prepare::GitRepo; use super::prepare::GitRepo;
use super::rustc_info::get_file_name; use super::rustc_info::get_file_name;
use super::utils::{hyperfine_command, spawn_and_wait}; use super::utils::{hyperfine_command, spawn_and_wait, Compiler};
static SIMPLE_RAYTRACER_REPO: GitRepo = GitRepo::github( static SIMPLE_RAYTRACER_REPO: GitRepo = GitRepo::github(
"ebobby", "ebobby",
@ -13,11 +13,11 @@ static SIMPLE_RAYTRACER_REPO: GitRepo = GitRepo::github(
"<none>", "<none>",
); );
pub(crate) fn benchmark(dirs: &Dirs) { pub(crate) fn benchmark(dirs: &Dirs, bootstrap_host_compiler: &Compiler) {
benchmark_simple_raytracer(dirs); benchmark_simple_raytracer(dirs, bootstrap_host_compiler);
} }
fn benchmark_simple_raytracer(dirs: &Dirs) { fn benchmark_simple_raytracer(dirs: &Dirs, bootstrap_host_compiler: &Compiler) {
if std::process::Command::new("hyperfine").output().is_err() { if std::process::Command::new("hyperfine").output().is_err() {
eprintln!("Hyperfine not installed"); eprintln!("Hyperfine not installed");
eprintln!("Hint: Try `cargo install hyperfine` to install hyperfine"); eprintln!("Hint: Try `cargo install hyperfine` to install hyperfine");
@ -31,8 +31,9 @@ fn benchmark_simple_raytracer(dirs: &Dirs) {
let bench_runs = env::var("BENCH_RUNS").unwrap_or_else(|_| "10".to_string()).parse().unwrap(); let bench_runs = env::var("BENCH_RUNS").unwrap_or_else(|_| "10".to_string()).parse().unwrap();
eprintln!("[BENCH COMPILE] ebobby/simple-raytracer"); eprintln!("[BENCH COMPILE] ebobby/simple-raytracer");
let cargo_clif = let cargo_clif = RelPath::DIST
RelPath::DIST.to_path(dirs).join(get_file_name("cargo_clif", "bin").replace('_', "-")); .to_path(dirs)
.join(get_file_name(&bootstrap_host_compiler.rustc, "cargo_clif", "bin").replace('_', "-"));
let manifest_path = SIMPLE_RAYTRACER_REPO.source_dir().to_path(dirs).join("Cargo.toml"); let manifest_path = SIMPLE_RAYTRACER_REPO.source_dir().to_path(dirs).join("Cargo.toml");
let target_dir = RelPath::BUILD.join("simple_raytracer").to_path(dirs); let target_dir = RelPath::BUILD.join("simple_raytracer").to_path(dirs);
@ -75,9 +76,18 @@ fn benchmark_simple_raytracer(dirs: &Dirs) {
bench_runs, bench_runs,
None, None,
&[ &[
Path::new(".").join(get_file_name("raytracer_cg_llvm", "bin")).to_str().unwrap(), Path::new(".")
Path::new(".").join(get_file_name("raytracer_cg_clif", "bin")).to_str().unwrap(), .join(get_file_name(&bootstrap_host_compiler.rustc, "raytracer_cg_llvm", "bin"))
Path::new(".").join(get_file_name("raytracer_cg_clif_opt", "bin")).to_str().unwrap(), .to_str()
.unwrap(),
Path::new(".")
.join(get_file_name(&bootstrap_host_compiler.rustc, "raytracer_cg_clif", "bin"))
.to_str()
.unwrap(),
Path::new(".")
.join(get_file_name(&bootstrap_host_compiler.rustc, "raytracer_cg_clif_opt", "bin"))
.to_str()
.unwrap(),
], ],
); );
bench_run.current_dir(RelPath::BUILD.to_path(dirs)); bench_run.current_dir(RelPath::BUILD.to_path(dirs));

View file

@ -53,5 +53,5 @@ pub(crate) fn build_backend(
.target_dir(dirs) .target_dir(dirs)
.join(&bootstrap_host_compiler.triple) .join(&bootstrap_host_compiler.triple)
.join(channel) .join(channel)
.join(get_file_name("rustc_codegen_cranelift", "dylib")) .join(get_file_name(&bootstrap_host_compiler.rustc, "rustc_codegen_cranelift", "dylib"))
} }

View file

@ -3,7 +3,7 @@ use std::path::{Path, PathBuf};
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);
@ -40,19 +41,30 @@ pub(crate) fn build_sysroot(
try_hard_link(cg_clif_dylib_src, &cg_clif_dylib_path); try_hard_link(cg_clif_dylib_src, &cg_clif_dylib_path);
// Build and copy rustc and cargo wrappers // Build and copy rustc and cargo wrappers
let wrapper_base_name = get_file_name("____", "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

@ -78,6 +78,7 @@ pub(crate) fn main() {
let mut channel = "release"; let mut channel = "release";
let mut sysroot_kind = SysrootKind::Clif; let mut sysroot_kind = SysrootKind::Clif;
let mut use_unstable_features = true; let mut use_unstable_features = true;
let mut frozen = false;
while let Some(arg) = args.next().as_deref() { while let Some(arg) = args.next().as_deref() {
match arg { match arg {
"--out-dir" => { "--out-dir" => {
@ -96,17 +97,38 @@ pub(crate) fn main() {
} }
} }
"--no-unstable-features" => use_unstable_features = false, "--no-unstable-features" => use_unstable_features = false,
"--frozen" => frozen = true,
flag if flag.starts_with("-") => arg_error!("Unknown flag {}", flag), flag if flag.starts_with("-") => arg_error!("Unknown flag {}", flag),
arg => arg_error!("Unexpected argument {}", arg), arg => arg_error!("Unexpected argument {}", arg),
} }
} }
let bootstrap_host_compiler = Compiler::bootstrap_with_triple( let rustup_toolchain_name = match (env::var("CARGO"), env::var("RUSTC"), env::var("RUSTDOC")) {
std::env::var("HOST_TRIPLE") (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();
let rustdoc = rustc_info::get_rustdoc_path();
let triple = std::env::var("HOST_TRIPLE")
.ok() .ok()
.or_else(|| config::get_value("host")) .or_else(|| config::get_value("host"))
.unwrap_or_else(|| rustc_info::get_host_triple()), .unwrap_or_else(|| rustc_info::get_host_triple(&rustc));
); Compiler {
cargo,
rustc,
rustdoc,
rustflags: String::new(),
rustdocflags: String::new(),
triple,
runner: vec![],
}
};
let target_triple = std::env::var("TARGET_TRIPLE") let target_triple = std::env::var("TARGET_TRIPLE")
.ok() .ok()
.or_else(|| config::get_value("target")) .or_else(|| config::get_value("target"))
@ -120,6 +142,7 @@ pub(crate) fn main() {
download_dir: out_dir.join("download"), download_dir: out_dir.join("download"),
build_dir: out_dir.join("build"), build_dir: out_dir.join("build"),
dist_dir: out_dir.join("dist"), dist_dir: out_dir.join("dist"),
frozen,
}; };
path::RelPath::BUILD.ensure_exists(&dirs); path::RelPath::BUILD.ensure_exists(&dirs);
@ -134,7 +157,7 @@ pub(crate) fn main() {
} }
if command == Command::Prepare { if command == Command::Prepare {
prepare::prepare(&dirs); prepare::prepare(&dirs, &bootstrap_host_compiler.rustc);
process::exit(0); process::exit(0);
} }
@ -158,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(),
); );
} }
@ -166,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(
@ -175,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,
); );
} }
@ -185,9 +217,10 @@ 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); bench::benchmark(&dirs, &bootstrap_host_compiler);
} }
} }
} }

View file

@ -9,6 +9,7 @@ pub(crate) struct Dirs {
pub(crate) download_dir: PathBuf, pub(crate) download_dir: PathBuf,
pub(crate) build_dir: PathBuf, pub(crate) build_dir: PathBuf,
pub(crate) dist_dir: PathBuf, pub(crate) dist_dir: PathBuf,
pub(crate) frozen: bool,
} }
#[doc(hidden)] #[doc(hidden)]

View file

@ -9,27 +9,19 @@ use super::rustc_info::{get_default_sysroot, get_rustc_version};
use super::tests::LIBCORE_TESTS_SRC; use super::tests::LIBCORE_TESTS_SRC;
use super::utils::{copy_dir_recursively, git_command, retry_spawn_and_wait, spawn_and_wait}; use super::utils::{copy_dir_recursively, git_command, retry_spawn_and_wait, spawn_and_wait};
pub(crate) fn prepare(dirs: &Dirs) { pub(crate) fn prepare(dirs: &Dirs, rustc: &Path) {
RelPath::DOWNLOAD.ensure_fresh(dirs); RelPath::DOWNLOAD.ensure_fresh(dirs);
spawn_and_wait(super::build_backend::CG_CLIF.fetch("cargo", "rustc", dirs)); prepare_stdlib(dirs, rustc);
prepare_coretests(dirs, rustc);
prepare_stdlib(dirs);
spawn_and_wait(super::build_sysroot::STANDARD_LIBRARY.fetch("cargo", "rustc", dirs));
prepare_coretests(dirs);
spawn_and_wait(super::tests::LIBCORE_TESTS.fetch("cargo", "rustc", dirs));
super::tests::RAND_REPO.fetch(dirs); super::tests::RAND_REPO.fetch(dirs);
spawn_and_wait(super::tests::RAND.fetch("cargo", "rustc", dirs));
super::tests::REGEX_REPO.fetch(dirs); super::tests::REGEX_REPO.fetch(dirs);
spawn_and_wait(super::tests::REGEX.fetch("cargo", "rustc", dirs));
super::tests::PORTABLE_SIMD_REPO.fetch(dirs); super::tests::PORTABLE_SIMD_REPO.fetch(dirs);
spawn_and_wait(super::tests::PORTABLE_SIMD.fetch("cargo", "rustc", dirs));
} }
fn prepare_stdlib(dirs: &Dirs) { fn prepare_stdlib(dirs: &Dirs, rustc: &Path) {
let sysroot_src_orig = get_default_sysroot(Path::new("rustc")).join("lib/rustlib/src/rust"); let sysroot_src_orig = get_default_sysroot(rustc).join("lib/rustlib/src/rust");
assert!(sysroot_src_orig.exists()); assert!(sysroot_src_orig.exists());
eprintln!("[COPY] stdlib src"); eprintln!("[COPY] stdlib src");
@ -44,7 +36,7 @@ fn prepare_stdlib(dirs: &Dirs) {
&SYSROOT_SRC.to_path(dirs).join("library"), &SYSROOT_SRC.to_path(dirs).join("library"),
); );
let rustc_version = get_rustc_version(Path::new("rustc")); let rustc_version = get_rustc_version(rustc);
fs::write(SYSROOT_RUSTC_VERSION.to_path(dirs), &rustc_version).unwrap(); fs::write(SYSROOT_RUSTC_VERSION.to_path(dirs), &rustc_version).unwrap();
eprintln!("[GIT] init"); eprintln!("[GIT] init");
@ -53,8 +45,8 @@ fn prepare_stdlib(dirs: &Dirs) {
apply_patches(dirs, "stdlib", &SYSROOT_SRC.to_path(dirs)); apply_patches(dirs, "stdlib", &SYSROOT_SRC.to_path(dirs));
} }
fn prepare_coretests(dirs: &Dirs) { fn prepare_coretests(dirs: &Dirs, rustc: &Path) {
let sysroot_src_orig = get_default_sysroot(Path::new("rustc")).join("lib/rustlib/src/rust"); let sysroot_src_orig = get_default_sysroot(rustc).join("lib/rustlib/src/rust");
assert!(sysroot_src_orig.exists()); assert!(sysroot_src_orig.exists());
eprintln!("[COPY] coretests src"); eprintln!("[COPY] coretests src");

View file

@ -7,9 +7,9 @@ pub(crate) fn get_rustc_version(rustc: &Path) -> String {
String::from_utf8(version_info).unwrap() String::from_utf8(version_info).unwrap()
} }
pub(crate) fn get_host_triple() -> String { pub(crate) fn get_host_triple(rustc: &Path) -> String {
let version_info = let version_info =
Command::new("rustc").stderr(Stdio::inherit()).args(&["-vV"]).output().unwrap().stdout; Command::new(rustc).stderr(Stdio::inherit()).args(&["-vV"]).output().unwrap().stdout;
String::from_utf8(version_info) String::from_utf8(version_info)
.unwrap() .unwrap()
.lines() .lines()
@ -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"])
@ -73,8 +82,9 @@ pub(crate) fn get_default_sysroot(rustc: &Path) -> PathBuf {
Path::new(String::from_utf8(default_sysroot).unwrap().trim()).to_owned() Path::new(String::from_utf8(default_sysroot).unwrap().trim()).to_owned()
} }
pub(crate) fn get_file_name(crate_name: &str, crate_type: &str) -> String { // FIXME call once for each target and pass result around in struct
let file_name = Command::new("rustc") pub(crate) fn get_file_name(rustc: &Path, crate_name: &str, crate_type: &str) -> String {
let file_name = Command::new(rustc)
.stderr(Stdio::inherit()) .stderr(Stdio::inherit())
.args(&[ .args(&[
"--crate-name", "--crate-name",

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

@ -2,10 +2,10 @@ The build system of cg_clif.
USAGE: USAGE:
./y.rs prepare [--out-dir DIR] ./y.rs prepare [--out-dir DIR]
./y.rs build [--debug] [--sysroot none|clif|llvm] [--out-dir DIR] [--no-unstable-features] ./y.rs build [--debug] [--sysroot none|clif|llvm] [--out-dir DIR] [--no-unstable-features] [--frozen]
./y.rs test [--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] [--frozen]
./y.rs abi-cafe [--debug] [--sysroot none|clif|llvm] [--out-dir DIR] [--no-unstable-features] ./y.rs abi-cafe [--debug] [--sysroot none|clif|llvm] [--out-dir DIR] [--no-unstable-features] [--frozen]
./y.rs bench [--debug] [--sysroot none|clif|llvm] [--out-dir DIR] [--no-unstable-features] ./y.rs bench [--debug] [--sysroot none|clif|llvm] [--out-dir DIR] [--no-unstable-features] [--frozen]
OPTIONS: OPTIONS:
--debug --debug
@ -26,9 +26,13 @@ OPTIONS:
Some features are not yet ready for production usage. This option will disable these Some features are not yet ready for production usage. This option will disable these
features. This includes the JIT mode and inline assembly support. features. This includes the JIT mode and inline assembly support.
--frozen
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

@ -5,7 +5,6 @@ use std::path::{Path, PathBuf};
use std::process::{self, Command, Stdio}; use std::process::{self, Command, Stdio};
use super::path::{Dirs, RelPath}; use super::path::{Dirs, RelPath};
use super::rustc_info::{get_cargo_path, get_rustc_path, get_rustdoc_path};
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub(crate) struct Compiler { pub(crate) struct Compiler {
@ -19,18 +18,6 @@ pub(crate) struct Compiler {
} }
impl Compiler { impl Compiler {
pub(crate) fn bootstrap_with_triple(triple: String) -> Compiler {
Compiler {
cargo: get_cargo_path(),
rustc: get_rustc_path(),
rustdoc: get_rustdoc_path(),
rustflags: String::new(),
rustdocflags: String::new(),
triple,
runner: vec![],
}
}
pub(crate) fn set_cross_linker_and_runner(&mut self) { pub(crate) fn set_cross_linker_and_runner(&mut self) {
match self.triple.as_str() { match self.triple.as_str() {
"aarch64-unknown-linux-gnu" => { "aarch64-unknown-linux-gnu" => {
@ -94,8 +81,11 @@ impl CargoProject {
.arg("--manifest-path") .arg("--manifest-path")
.arg(self.manifest_path(dirs)) .arg(self.manifest_path(dirs))
.arg("--target-dir") .arg("--target-dir")
.arg(self.target_dir(dirs)) .arg(self.target_dir(dirs));
.arg("--frozen");
if dirs.frozen {
cmd.arg("--frozen");
}
cmd cmd
} }
@ -120,23 +110,6 @@ impl CargoProject {
cmd cmd
} }
#[must_use]
pub(crate) fn fetch(
&self,
cargo: impl AsRef<Path>,
rustc: impl AsRef<Path>,
dirs: &Dirs,
) -> Command {
let mut cmd = Command::new(cargo.as_ref());
cmd.env("RUSTC", rustc.as_ref())
.arg("fetch")
.arg("--manifest-path")
.arg(self.manifest_path(dirs));
cmd
}
pub(crate) fn clean(&self, dirs: &Dirs) { pub(crate) fn clean(&self, dirs: &Dirs) {
let _ = fs::remove_dir_all(self.target_dir(dirs)); let _ = fs::remove_dir_all(self.target_dir(dirs));
} }

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);
// Ensure that the right toolchain is used let cargo = if let Some(cargo) = option_env!("CARGO") {
env::set_var("RUSTUP_TOOLCHAIN", env!("TOOLCHAIN_NAME")); 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() { 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);
// Ensure that the right toolchain is used let rustc = if let Some(rustc) = option_env!("RUSTC") {
env::set_var("RUSTUP_TOOLCHAIN", env!("TOOLCHAIN_NAME")); rustc
} else {
// Ensure that the right toolchain is used
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);
// Ensure that the right toolchain is used let rustdoc = if let Some(rustdoc) = option_env!("RUSTDOC") {
env::set_var("RUSTUP_TOOLCHAIN", env!("TOOLCHAIN_NAME")); rustdoc
} else {
// Ensure that the right toolchain is used
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),
); );
} }