Skip to content

Commit 8ad3827

Browse files
authored
Merge pull request #1514 from jameshilliard/cross-env-detection
Ensure we are cross compiling when any cross env variables are set.
2 parents 24b0000 + 2c3e8b1 commit 8ad3827

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
@@ -48,6 +48,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
4848
- Fix inability to use a named lifetime for `&PyTuple` of `*args` in `#[pyfunction]`. [#1440](https://github.com/PyO3/pyo3/pull/1440)
4949
- Fix inability to add `#[text_signature]` to some `#[pyproto]` methods. [#1483](https://github.com/PyO3/pyo3/pull/1483)
5050
- Fix use of Python argument for #[pymethods] inside macro expansions. [#1505](https://github.com/PyO3/pyo3/pull/1505)
51+
- Always use cross-compiling configuration if any of the environment variables are set. [#1514](https://github.com/PyO3/pyo3/pull/1514)
5152

5253
## [0.13.2] - 2021-02-12
5354
### Packaging

build.rs

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -142,36 +142,44 @@ impl CrossCompileConfig {
142142
}
143143

144144
fn cross_compiling() -> Result<Option<CrossCompileConfig>> {
145-
let target = env::var("TARGET")?;
146-
let host = env::var("HOST")?;
147-
if target == host {
148-
// Not cross-compiling
149-
return Ok(None);
150-
}
145+
if env::var_os("PYO3_CROSS").is_none()
146+
&& env::var_os("PYO3_CROSS_LIB_DIR").is_none()
147+
&& env::var_os("PYO3_CROSS_INCLUDE_DIR").is_none()
148+
&& env::var_os("PYO3_CROSS_VERSION").is_none()
149+
&& env::var_os("PYO3_CROSS_PYTHON_VERSION").is_none()
150+
{
151+
let target = env::var("TARGET")?;
152+
let host = env::var("HOST")?;
153+
if target == host {
154+
// Not cross-compiling
155+
return Ok(None);
156+
}
151157

152-
if target == "i686-pc-windows-msvc" && host == "x86_64-pc-windows-msvc" {
153-
// Not cross-compiling to compile for 32-bit Python from windows 64-bit
154-
return Ok(None);
155-
}
158+
if target == "i686-pc-windows-msvc" && host == "x86_64-pc-windows-msvc" {
159+
// Not cross-compiling to compile for 32-bit Python from windows 64-bit
160+
return Ok(None);
161+
}
156162

157-
if target == "x86_64-apple-darwin" && host == "aarch64-apple-darwin" {
158-
// Not cross-compiling to compile for x86-64 Python from macOS arm64
159-
return Ok(None);
160-
}
161-
if target == "aarch64-apple-darwin" && host == "x86_64-apple-darwin" {
162-
// Not cross-compiling to compile for arm64 Python from macOS x86_64
163-
return Ok(None);
164-
}
163+
if target == "x86_64-apple-darwin" && host == "aarch64-apple-darwin" {
164+
// Not cross-compiling to compile for x86-64 Python from macOS arm64
165+
return Ok(None);
166+
}
165167

166-
if host.starts_with(&format!(
167-
"{}-{}-{}",
168-
env::var("CARGO_CFG_TARGET_ARCH")?,
169-
env::var("CARGO_CFG_TARGET_VENDOR")?,
170-
env::var("CARGO_CFG_TARGET_OS")?
171-
)) {
172-
// Not cross-compiling if arch-vendor-os is all the same
173-
// e.g. x86_64-unknown-linux-musl on x86_64-unknown-linux-gnu host
174-
return Ok(None);
168+
if target == "aarch64-apple-darwin" && host == "x86_64-apple-darwin" {
169+
// Not cross-compiling to compile for arm64 Python from macOS x86_64
170+
return Ok(None);
171+
}
172+
173+
if host.starts_with(&format!(
174+
"{}-{}-{}",
175+
env::var("CARGO_CFG_TARGET_ARCH")?,
176+
env::var("CARGO_CFG_TARGET_VENDOR")?,
177+
env::var("CARGO_CFG_TARGET_OS")?
178+
)) {
179+
// Not cross-compiling if arch-vendor-os is all the same
180+
// e.g. x86_64-unknown-linux-musl on x86_64-unknown-linux-gnu host
181+
return Ok(None);
182+
}
175183
}
176184

177185
// Cross-compiling on any other platform

0 commit comments

Comments
 (0)