mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-27 09:14:20 +00:00
Use get_file_name everywhere for better cross compilation support
This commit is contained in:
parent
d0599350a7
commit
437b441ff5
@ -23,7 +23,7 @@ pub(crate) fn build_sysroot(
|
||||
fs::create_dir_all(target_dir.join("lib")).unwrap();
|
||||
|
||||
// Copy the backend
|
||||
let cg_clif_dylib = get_file_name("rustc_codegen_cranelift", "dylib");
|
||||
let cg_clif_dylib = get_file_name("rustc_codegen_cranelift", "dylib", target_triple);
|
||||
let cg_clif_dylib_path = target_dir
|
||||
.join(if cfg!(windows) {
|
||||
// Windows doesn't have rpath support, so the cg_clif dylib needs to be next to the
|
||||
@ -37,11 +37,10 @@ pub(crate) fn build_sysroot(
|
||||
|
||||
// Build and copy rustc and cargo wrappers
|
||||
for wrapper in ["rustc-clif", "cargo-clif"] {
|
||||
let wrapper_name = if cfg!(windows) {
|
||||
format!("{wrapper}.exe")
|
||||
} else {
|
||||
wrapper.to_string()
|
||||
};
|
||||
let crate_name = wrapper.replace('-', "_");
|
||||
let wrapper_name = get_file_name(&crate_name, "bin", target_triple);
|
||||
let wrapper_name = wrapper_name.replace('_', "-");
|
||||
|
||||
|
||||
let mut build_cargo_wrapper_cmd = Command::new("rustc");
|
||||
build_cargo_wrapper_cmd
|
||||
|
@ -48,13 +48,42 @@ pub fn main() {
|
||||
// The target dir is expected in the default location. Guard against the user changing it.
|
||||
env::set_var("CARGO_TARGET_DIR", "target");
|
||||
|
||||
|
||||
let host_triple = if let Ok(host_triple) = std::env::var("HOST_TRIPLE") {
|
||||
host_triple
|
||||
} else if let Some(host_triple) = config::get_value("host") {
|
||||
host_triple
|
||||
} else {
|
||||
rustc_info::get_host_triple()
|
||||
};
|
||||
let target_triple = if let Ok(target_triple) = std::env::var("TARGET_TRIPLE") {
|
||||
if target_triple != "" {
|
||||
target_triple
|
||||
} else {
|
||||
host_triple.clone() // Empty target triple can happen on GHA
|
||||
}
|
||||
} else if let Some(target_triple) = config::get_value("target") {
|
||||
target_triple
|
||||
} else {
|
||||
host_triple.clone()
|
||||
};
|
||||
|
||||
if target_triple.ends_with("-msvc") {
|
||||
eprintln!("The MSVC toolchain is not yet supported by rustc_codegen_cranelift.");
|
||||
eprintln!("Switch to the MinGW toolchain for Windows support.");
|
||||
eprintln!("Hint: You can use `rustup set default-host x86_64-pc-windows-gnu` to");
|
||||
eprintln!("set the global default target to MinGW");
|
||||
// process::exit(1);
|
||||
}
|
||||
|
||||
|
||||
let mut args = env::args().skip(1);
|
||||
let command = match args.next().as_deref() {
|
||||
Some("prepare") => {
|
||||
if args.next().is_some() {
|
||||
arg_error!("./x.rs prepare doesn't expect arguments");
|
||||
arg_error!("./y.rs prepare doesn't expect arguments");
|
||||
}
|
||||
prepare::prepare();
|
||||
prepare::prepare(&target_triple);
|
||||
process::exit(0);
|
||||
}
|
||||
Some("build") => Command::Build,
|
||||
@ -95,35 +124,7 @@ pub fn main() {
|
||||
}
|
||||
target_dir = std::env::current_dir().unwrap().join(target_dir);
|
||||
|
||||
let host_triple = if let Ok(host_triple) = std::env::var("HOST_TRIPLE") {
|
||||
host_triple
|
||||
} else if let Some(host_triple) = config::get_value("host") {
|
||||
host_triple
|
||||
} else {
|
||||
rustc_info::get_host_triple()
|
||||
};
|
||||
let target_triple = if let Ok(target_triple) = std::env::var("TARGET_TRIPLE") {
|
||||
if target_triple != "" {
|
||||
target_triple
|
||||
} else {
|
||||
host_triple.clone() // Empty target triple can happen on GHA
|
||||
}
|
||||
} else if let Some(target_triple) = config::get_value("target") {
|
||||
target_triple
|
||||
} else {
|
||||
host_triple.clone()
|
||||
};
|
||||
|
||||
if target_triple.ends_with("-msvc") {
|
||||
eprintln!("The MSVC toolchain is not yet supported by rustc_codegen_cranelift.");
|
||||
eprintln!("Switch to the MinGW toolchain for Windows support.");
|
||||
eprintln!("Hint: You can use `rustup set default-host x86_64-pc-windows-gnu` to");
|
||||
eprintln!("set the global default target to MinGW");
|
||||
process::exit(1);
|
||||
}
|
||||
|
||||
let cg_clif_build_dir = build_backend::build_backend(channel, &host_triple, use_unstable_features);
|
||||
|
||||
match command {
|
||||
Command::Test => {
|
||||
tests::run_tests(
|
||||
|
@ -8,7 +8,7 @@ use std::process::Command;
|
||||
use super::rustc_info::{get_file_name, get_rustc_path, get_rustc_version};
|
||||
use super::utils::{copy_dir_recursively, spawn_and_wait};
|
||||
|
||||
pub(crate) fn prepare() {
|
||||
pub(crate) fn prepare(target_triple: &str) {
|
||||
prepare_sysroot();
|
||||
|
||||
eprintln!("[INSTALL] hyperfine");
|
||||
@ -49,8 +49,8 @@ pub(crate) fn prepare() {
|
||||
build_cmd.arg("build").env_remove("CARGO_TARGET_DIR").current_dir("simple-raytracer");
|
||||
spawn_and_wait(build_cmd);
|
||||
fs::copy(
|
||||
Path::new("simple-raytracer/target/debug").join(get_file_name("main", "bin")),
|
||||
Path::new("simple-raytracer").join(get_file_name("raytracer_cg_llvm", "bin")),
|
||||
Path::new("simple-raytracer/target/debug").join(get_file_name("main", "bin", target_triple)),
|
||||
Path::new("simple-raytracer").join(get_file_name("raytracer_cg_llvm", "bin", target_triple)),
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ pub(crate) fn get_default_sysroot() -> PathBuf {
|
||||
Path::new(String::from_utf8(default_sysroot).unwrap().trim()).to_owned()
|
||||
}
|
||||
|
||||
pub(crate) fn get_file_name(crate_name: &str, crate_type: &str) -> String {
|
||||
pub(crate) fn get_file_name(crate_name: &str, crate_type: &str, target: &str) -> String {
|
||||
let file_name = Command::new("rustc")
|
||||
.stderr(Stdio::inherit())
|
||||
.args(&[
|
||||
@ -51,6 +51,8 @@ pub(crate) fn get_file_name(crate_name: &str, crate_type: &str) -> String {
|
||||
crate_name,
|
||||
"--crate-type",
|
||||
crate_type,
|
||||
"--target",
|
||||
target,
|
||||
"--print",
|
||||
"file-names",
|
||||
"-",
|
||||
|
Loading…
Reference in New Issue
Block a user