Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix aarch64 Windows cross compilation #2359

Merged
merged 1 commit into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 31 additions & 15 deletions src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,24 +287,40 @@ fn cargo_build_command(
.extend(["-C".to_string(), "strip=symbols".to_string()]);
}

let mut build_command = if target.is_msvc()
&& (target.cross_compiling() || env::var("MATURIN_USE_XWIN").ok().as_deref() == Some("1"))
{
let mut build_command = if target.is_msvc() && target.cross_compiling() {
#[cfg(feature = "xwin")]
{
println!("🛠️ Using xwin for cross-compiling to {target_triple}");
let xwin_options = {
use clap::Parser;

// This will populate the default values for the options
// and then override them with cargo-xwin environment variables.
cargo_xwin::XWinOptions::parse_from(Vec::<&str>::new())
};
// Don't use xwin if the Windows MSVC compiler can compile to the target
let native_compile = cc::Build::new()
.opt_level(0)
.host(target.host_triple())
.target(target_triple)
.cargo_metadata(false)
.cargo_warnings(false)
.cargo_output(false)
.try_get_compiler()
.is_ok();
let force_xwin = env::var("MATURIN_USE_XWIN").ok().as_deref() == Some("1");
if !native_compile || force_xwin {
println!("🛠️ Using xwin for cross-compiling to {target_triple}");
let xwin_options = {
use clap::Parser;

// This will populate the default values for the options
// and then override them with cargo-xwin environment variables.
cargo_xwin::XWinOptions::parse_from(Vec::<&str>::new())
};

let mut build = cargo_xwin::Rustc::from(cargo_rustc);
build.target = vec![target_triple.to_string()];
build.xwin = xwin_options;
build.build_command()?
let mut build = cargo_xwin::Rustc::from(cargo_rustc);
build.target = vec![target_triple.to_string()];
build.xwin = xwin_options;
build.build_command()?
} else {
if target.user_specified {
cargo_rustc.target = vec![target_triple.to_string()];
}
cargo_rustc.command()
}
}
#[cfg(not(feature = "xwin"))]
{
Expand Down
15 changes: 0 additions & 15 deletions src/cross_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,6 @@ pub fn is_cross_compiling(target: &Target) -> Result<bool> {
// Not cross-compiling to compile for 32-bit Python from windows 64-bit
return Ok(false);
}
if (target_triple == "aarch64-pc-windows-msvc" && host == "x86_64-pc-windows-msvc")
|| (target_triple == "x86_64-pc-windows-msvc" && host == "aarch64-pc-windows-msvc")
{
// Not cross-compiling if the Windows MSVC compiler can compile to the target
let native_compile = cc::Build::new()
.opt_level(0)
.host(host)
.target(target_triple)
.cargo_metadata(false)
.cargo_warnings(false)
.cargo_output(false)
.try_get_compiler()
.is_ok();
return Ok(!native_compile);
}
if target_triple.ends_with("windows-gnu") && host.ends_with("windows-msvc") {
// Not cross-compiling to compile for Windows GNU from Windows MSVC host
return Ok(false);
Expand Down
4 changes: 2 additions & 2 deletions test-crates/pyo3-mixed/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading