Skip to content

Commit 2c3e8b1

Browse files
committed
Ensure we are cross compiling when any cross env variables are set.
1 parent 6e49ba3 commit 2c3e8b1

File tree

2 files changed

+36
-27
lines changed

2 files changed

+36
-27
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
4646
- Fix inability to use a named lifetime for `&PyTuple` of `*args` in `#[pyfunction]`. [#1440](https://github.com/PyO3/pyo3/pull/1440)
4747
- Fix inability to add `#[text_signature]` to some `#[pyproto]` methods. [#1483](https://github.com/PyO3/pyo3/pull/1483)
4848
- Fix use of Python argument for #[pymethods] inside macro expansions. [#1505](https://github.com/PyO3/pyo3/pull/1505)
49+
- Always use cross-compiling configuration if any of the environment variables are set. [#1514](https://github.com/PyO3/pyo3/pull/1514)
4950

5051
## [0.13.2] - 2021-02-12
5152
### Packaging

build.rs

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -151,36 +151,44 @@ impl CrossCompileConfig {
151151
}
152152

153153
fn cross_compiling() -> Result<Option<CrossCompileConfig>> {
154-
let target = env::var("TARGET")?;
155-
let host = env::var("HOST")?;
156-
if target == host {
157-
// Not cross-compiling
158-
return Ok(None);
159-
}
154+
if env::var_os("PYO3_CROSS").is_none()
155+
&& env::var_os("PYO3_CROSS_LIB_DIR").is_none()
156+
&& env::var_os("PYO3_CROSS_INCLUDE_DIR").is_none()
157+
&& env::var_os("PYO3_CROSS_VERSION").is_none()
158+
&& env::var_os("PYO3_CROSS_PYTHON_VERSION").is_none()
159+
{
160+
let target = env::var("TARGET")?;
161+
let host = env::var("HOST")?;
162+
if target == host {
163+
// Not cross-compiling
164+
return Ok(None);
165+
}
160166

161-
if target == "i686-pc-windows-msvc" && host == "x86_64-pc-windows-msvc" {
162-
// Not cross-compiling to compile for 32-bit Python from windows 64-bit
163-
return Ok(None);
164-
}
167+
if target == "i686-pc-windows-msvc" && host == "x86_64-pc-windows-msvc" {
168+
// Not cross-compiling to compile for 32-bit Python from windows 64-bit
169+
return Ok(None);
170+
}
165171

166-
if target == "x86_64-apple-darwin" && host == "aarch64-apple-darwin" {
167-
// Not cross-compiling to compile for x86-64 Python from macOS arm64
168-
return Ok(None);
169-
}
170-
if target == "aarch64-apple-darwin" && host == "x86_64-apple-darwin" {
171-
// Not cross-compiling to compile for arm64 Python from macOS x86_64
172-
return Ok(None);
173-
}
172+
if target == "x86_64-apple-darwin" && host == "aarch64-apple-darwin" {
173+
// Not cross-compiling to compile for x86-64 Python from macOS arm64
174+
return Ok(None);
175+
}
174176

175-
if host.starts_with(&format!(
176-
"{}-{}-{}",
177-
env::var("CARGO_CFG_TARGET_ARCH")?,
178-
env::var("CARGO_CFG_TARGET_VENDOR")?,
179-
env::var("CARGO_CFG_TARGET_OS")?
180-
)) {
181-
// Not cross-compiling if arch-vendor-os is all the same
182-
// e.g. x86_64-unknown-linux-musl on x86_64-unknown-linux-gnu host
183-
return Ok(None);
177+
if target == "aarch64-apple-darwin" && host == "x86_64-apple-darwin" {
178+
// Not cross-compiling to compile for arm64 Python from macOS x86_64
179+
return Ok(None);
180+
}
181+
182+
if host.starts_with(&format!(
183+
"{}-{}-{}",
184+
env::var("CARGO_CFG_TARGET_ARCH")?,
185+
env::var("CARGO_CFG_TARGET_VENDOR")?,
186+
env::var("CARGO_CFG_TARGET_OS")?
187+
)) {
188+
// Not cross-compiling if arch-vendor-os is all the same
189+
// e.g. x86_64-unknown-linux-musl on x86_64-unknown-linux-gnu host
190+
return Ok(None);
191+
}
184192
}
185193

186194
if env::var("CARGO_CFG_TARGET_FAMILY")? == "windows" {

0 commit comments

Comments
 (0)