Skip to content

Commit

Permalink
fix: cross-compilation compatibility checks for Windows (#4800)
Browse files Browse the repository at this point in the history
* fix: cross-compilation compatibility checks for Windows

* add newsfragments

* add simple test
  • Loading branch information
kahojyun authored and davidhewitt committed Jan 11, 2025
1 parent 81eabed commit f2915f5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions newsfragments/4800.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fix: cross-compilation compatibility checks for Windows
16 changes: 14 additions & 2 deletions pyo3-build-config/src/impl_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use std::{

pub use target_lexicon::Triple;

use target_lexicon::{Environment, OperatingSystem};
use target_lexicon::{Architecture, Environment, OperatingSystem};

use crate::{
bail, ensure,
Expand Down Expand Up @@ -944,7 +944,9 @@ impl CrossCompileConfig {

// Not cross-compiling to compile for 32-bit Python from windows 64-bit
compatible |= target.operating_system == OperatingSystem::Windows
&& host.operating_system == OperatingSystem::Windows;
&& host.operating_system == OperatingSystem::Windows
&& matches!(target.architecture, Architecture::X86_32(_))
&& host.architecture == Architecture::X86_64;

// Not cross-compiling to compile for x86-64 Python from macOS arm64 and vice versa
compatible |= target.operating_system == OperatingSystem::Darwin
Expand Down Expand Up @@ -2955,6 +2957,16 @@ mod tests {
.is_none());
}

#[test]
fn test_is_cross_compiling_from_to() {
assert!(cross_compiling_from_to(
&triple!("x86_64-pc-windows-msvc"),
&triple!("aarch64-pc-windows-msvc")
)
.unwrap()
.is_some());
}

#[test]
fn test_run_python_script() {
// as above, this should be okay in CI where Python is presumed installed
Expand Down

0 comments on commit f2915f5

Please sign in to comment.