Share cross-compilation code between building and testing
This commit is contained in:
parent
70a1cb9e62
commit
f311ef5a2e
@ -120,26 +120,19 @@ pub(crate) fn build_sysroot(
|
|||||||
channel,
|
channel,
|
||||||
host_compiler.clone(),
|
host_compiler.clone(),
|
||||||
&cg_clif_dylib_path,
|
&cg_clif_dylib_path,
|
||||||
None,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
if host_compiler.triple != target_triple {
|
if host_compiler.triple != target_triple {
|
||||||
// When cross-compiling it is often necessary to manually pick the right linker
|
|
||||||
let linker = match target_triple {
|
|
||||||
"aarch64-unknown-linux-gnu" => Some("aarch64-linux-gnu-gcc"),
|
|
||||||
"s390x-unknown-linux-gnu" => Some("s390x-linux-gnu-gcc"),
|
|
||||||
_ => None,
|
|
||||||
};
|
|
||||||
build_clif_sysroot_for_triple(
|
build_clif_sysroot_for_triple(
|
||||||
dirs,
|
dirs,
|
||||||
channel,
|
channel,
|
||||||
{
|
{
|
||||||
let mut target_compiler = host_compiler.clone();
|
let mut target_compiler = host_compiler.clone();
|
||||||
target_compiler.triple = target_triple.to_owned();
|
target_compiler.triple = target_triple.to_owned();
|
||||||
|
target_compiler.set_cross_linker_and_runner();
|
||||||
target_compiler
|
target_compiler
|
||||||
},
|
},
|
||||||
&cg_clif_dylib_path,
|
&cg_clif_dylib_path,
|
||||||
linker,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -167,7 +160,6 @@ fn build_clif_sysroot_for_triple(
|
|||||||
channel: &str,
|
channel: &str,
|
||||||
mut compiler: Compiler,
|
mut compiler: Compiler,
|
||||||
cg_clif_dylib_path: &Path,
|
cg_clif_dylib_path: &Path,
|
||||||
linker: Option<&str>,
|
|
||||||
) {
|
) {
|
||||||
match fs::read_to_string(SYSROOT_RUSTC_VERSION.to_path(dirs)) {
|
match fs::read_to_string(SYSROOT_RUSTC_VERSION.to_path(dirs)) {
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
@ -204,10 +196,6 @@ fn build_clif_sysroot_for_triple(
|
|||||||
if channel == "release" {
|
if channel == "release" {
|
||||||
rustflags.push_str(" -Zmir-opt-level=3");
|
rustflags.push_str(" -Zmir-opt-level=3");
|
||||||
}
|
}
|
||||||
if let Some(linker) = linker {
|
|
||||||
use std::fmt::Write;
|
|
||||||
write!(rustflags, " -Clinker={}", linker).unwrap();
|
|
||||||
}
|
|
||||||
compiler.rustflags += &rustflags;
|
compiler.rustflags += &rustflags;
|
||||||
let mut build_cmd = STANDARD_LIBRARY.build(&compiler, dirs);
|
let mut build_cmd = STANDARD_LIBRARY.build(&compiler, dirs);
|
||||||
if channel == "release" {
|
if channel == "release" {
|
||||||
|
@ -448,50 +448,25 @@ impl TestRunner {
|
|||||||
let jit_supported =
|
let jit_supported =
|
||||||
is_native && host_triple.contains("x86_64") && !host_triple.contains("windows");
|
is_native && host_triple.contains("x86_64") && !host_triple.contains("windows");
|
||||||
|
|
||||||
let mut rustflags = env::var("RUSTFLAGS").ok().unwrap_or("".to_string());
|
|
||||||
let mut runner = vec![];
|
|
||||||
|
|
||||||
if !is_native {
|
|
||||||
match target_triple.as_str() {
|
|
||||||
"aarch64-unknown-linux-gnu" => {
|
|
||||||
// We are cross-compiling for aarch64. Use the correct linker and run tests in qemu.
|
|
||||||
rustflags = format!("-Clinker=aarch64-linux-gnu-gcc{}", rustflags);
|
|
||||||
runner = vec![
|
|
||||||
"qemu-aarch64".to_owned(),
|
|
||||||
"-L".to_owned(),
|
|
||||||
"/usr/aarch64-linux-gnu".to_owned(),
|
|
||||||
];
|
|
||||||
}
|
|
||||||
"s390x-unknown-linux-gnu" => {
|
|
||||||
// We are cross-compiling for s390x. Use the correct linker and run tests in qemu.
|
|
||||||
rustflags = format!("-Clinker=s390x-linux-gnu-gcc{}", rustflags);
|
|
||||||
runner = vec![
|
|
||||||
"qemu-s390x".to_owned(),
|
|
||||||
"-L".to_owned(),
|
|
||||||
"/usr/s390x-linux-gnu".to_owned(),
|
|
||||||
];
|
|
||||||
}
|
|
||||||
"x86_64-pc-windows-gnu" => {
|
|
||||||
// We are cross-compiling for Windows. Run tests in wine.
|
|
||||||
runner = vec!["wine".to_owned()];
|
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
println!("Unknown non-native platform");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// FIXME fix `#[linkage = "extern_weak"]` without this
|
|
||||||
if target_triple.contains("darwin") {
|
|
||||||
rustflags = format!("{} -Clink-arg=-undefined -Clink-arg=dynamic_lookup", rustflags);
|
|
||||||
}
|
|
||||||
|
|
||||||
let host_compiler = Compiler::clif_with_triple(&dirs, host_triple);
|
let host_compiler = Compiler::clif_with_triple(&dirs, host_triple);
|
||||||
|
|
||||||
let mut target_compiler = Compiler::clif_with_triple(&dirs, target_triple);
|
let mut target_compiler = Compiler::clif_with_triple(&dirs, target_triple);
|
||||||
target_compiler.rustflags = rustflags.clone();
|
if !is_native {
|
||||||
target_compiler.rustdocflags = rustflags;
|
target_compiler.set_cross_linker_and_runner();
|
||||||
target_compiler.runner = runner;
|
}
|
||||||
|
if let Ok(rustflags) = env::var("RUSTFLAGS") {
|
||||||
|
target_compiler.rustflags.push(' ');
|
||||||
|
target_compiler.rustflags.push_str(&rustflags);
|
||||||
|
}
|
||||||
|
if let Ok(rustdocflags) = env::var("RUSTDOCFLAGS") {
|
||||||
|
target_compiler.rustdocflags.push(' ');
|
||||||
|
target_compiler.rustdocflags.push_str(&rustdocflags);
|
||||||
|
}
|
||||||
|
|
||||||
|
// FIXME fix `#[linkage = "extern_weak"]` without this
|
||||||
|
if target_compiler.triple.contains("darwin") {
|
||||||
|
target_compiler.rustflags.push_str(" -Clink-arg=-undefined -Clink-arg=dynamic_lookup");
|
||||||
|
}
|
||||||
|
|
||||||
Self { is_native, jit_supported, dirs, host_compiler, target_compiler }
|
Self { is_native, jit_supported, dirs, host_compiler, target_compiler }
|
||||||
}
|
}
|
||||||
|
@ -47,6 +47,38 @@ impl Compiler {
|
|||||||
runner: vec![],
|
runner: vec![],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn set_cross_linker_and_runner(&mut self) {
|
||||||
|
match self.triple.as_str() {
|
||||||
|
"aarch64-unknown-linux-gnu" => {
|
||||||
|
// We are cross-compiling for aarch64. Use the correct linker and run tests in qemu.
|
||||||
|
self.rustflags += " -Clinker=aarch64-linux-gnu-gcc";
|
||||||
|
self.rustdocflags += " -Clinker=aarch64-linux-gnu-gcc";
|
||||||
|
self.runner = vec![
|
||||||
|
"qemu-aarch64".to_owned(),
|
||||||
|
"-L".to_owned(),
|
||||||
|
"/usr/aarch64-linux-gnu".to_owned(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
"s390x-unknown-linux-gnu" => {
|
||||||
|
// We are cross-compiling for s390x. Use the correct linker and run tests in qemu.
|
||||||
|
self.rustflags += " -Clinker=s390x-linux-gnu-gcc";
|
||||||
|
self.rustdocflags += " -Clinker=s390x-linux-gnu-gcc";
|
||||||
|
self.runner = vec![
|
||||||
|
"qemu-s390x".to_owned(),
|
||||||
|
"-L".to_owned(),
|
||||||
|
"/usr/s390x-linux-gnu".to_owned(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
"x86_64-pc-windows-gnu" => {
|
||||||
|
// We are cross-compiling for Windows. Run tests in wine.
|
||||||
|
self.runner = vec!["wine".to_owned()];
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
println!("Unknown non-native platform");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) struct CargoProject {
|
pub(crate) struct CargoProject {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user