Skip to content

Commit

Permalink
pyo3-build-config: fix windows "cross-compile" panic
Browse files Browse the repository at this point in the history
  • Loading branch information
davidhewitt committed Mar 16, 2022
1 parent 9ef7987 commit 8e48955
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed

- Panic during compilation when `PYO3_CROSS_LIB_DIR` is set when compiling for 32-bit on 64-bit windows. [#2232](https://github.com/PyO3/pyo3/pull/2232)

## [0.16.2] - 2022-03-15

### Packaging
Expand Down
29 changes: 12 additions & 17 deletions pyo3-build-config/src/impl_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -577,17 +577,6 @@ pub fn any_cross_compiling_env_vars_set() -> bool {

fn cross_compiling_from_cargo_env() -> Result<Option<CrossCompileConfig>> {
let host = cargo_env_var("HOST").ok_or("expected HOST env var")?;
let target = cargo_env_var("TARGET").ok_or("expected TARGET env var")?;

if host == target {
// Definitely not cross compiling if the host matches the target
return Ok(None);
}

if target == "i686-pc-windows-msvc" && host == "x86_64-pc-windows-msvc" {
// Not cross-compiling to compile for 32-bit Python from windows 64-bit
return Ok(None);
}

let target_arch =
cargo_env_var("CARGO_CFG_TARGET_ARCH").ok_or("expected CARGO_CFG_TARGET_ARCH env var")?;
Expand Down Expand Up @@ -638,6 +627,18 @@ pub fn cross_compiling(
// No cross-compiling environment variables set; try to determine if this is a known case
// which is not cross-compilation.

if host.starts_with(&target_triple) {
// Not cross-compiling if arch-vendor-os is all the same
// e.g. x86_64-unknown-linux-musl on x86_64-unknown-linux-gnu host
// x86_64-pc-windows-gnu on x86_64-pc-windows-msvc host
return Ok(None);
}

if target_triple == "i686-pc-windows" && host.starts_with("x86_64-pc-windows") {
// Not cross-compiling to compile for 32-bit Python from windows 64-bit
return Ok(None);
}

if target_triple == "x86_64-apple-darwin" && host == "aarch64-apple-darwin" {
// Not cross-compiling to compile for x86-64 Python from macOS arm64
return Ok(None);
Expand All @@ -647,12 +648,6 @@ pub fn cross_compiling(
// Not cross-compiling to compile for arm64 Python from macOS x86_64
return Ok(None);
}

if host.starts_with(&target_triple) {
// Not cross-compiling if arch-vendor-os is all the same
// e.g. x86_64-unknown-linux-musl on x86_64-unknown-linux-gnu host
return Ok(None);
}
}

// At this point we assume that we are cross compiling.
Expand Down

0 comments on commit 8e48955

Please sign in to comment.