Skip to content

Commit

Permalink
Merge pull request #1529 from ravenexp/fix-cargo-target-parsing
Browse files Browse the repository at this point in the history
Clean up CARGO_CFG_TARGET_FAMILY variable parsing
  • Loading branch information
davidhewitt authored Mar 29, 2021
2 parents f97aac6 + ccaabe3 commit 2939bf1
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,6 @@ impl CrossCompileConfig {
fn cross_compiling() -> Result<Option<CrossCompileConfig>> {
if env::var_os("PYO3_CROSS").is_none()
&& env::var_os("PYO3_CROSS_LIB_DIR").is_none()
&& env::var_os("PYO3_CROSS_INCLUDE_DIR").is_none()
&& env::var_os("PYO3_CROSS_VERSION").is_none()
&& env::var_os("PYO3_CROSS_PYTHON_VERSION").is_none()
{
let target = env::var("TARGET")?;
Expand Down Expand Up @@ -489,7 +487,7 @@ fn windows_hardcoded_cross_compile(
) {
(Some(major), Some(minor), None) => (major, minor),
_ => bail!(
"Expected major.minor version (e.g. 3.9) for PYO3_CROSS_VERSION, got `{}`",
"Expected major.minor version (e.g. 3.9) for PYO3_CROSS_PYTHON_VERSION, got `{}`",
version
),
}
Expand Down Expand Up @@ -518,13 +516,18 @@ fn windows_hardcoded_cross_compile(
fn load_cross_compile_info(
cross_compile_config: CrossCompileConfig,
) -> Result<(InterpreterConfig, BuildFlags)> {
let target_family = env::var("CARGO_CFG_TARGET_FAMILY")?;
// Because compiling for windows on linux still includes the unix target family
if target_family == "unix" {
match env::var_os("CARGO_CFG_TARGET_FAMILY") {
// Configure for unix platforms using the sysconfigdata file
load_cross_compile_from_sysconfigdata(cross_compile_config)
} else {
windows_hardcoded_cross_compile(cross_compile_config)
Some(os) if os == "unix" => load_cross_compile_from_sysconfigdata(cross_compile_config),
// Use hardcoded interpreter config when targeting Windows
Some(os) if os == "windows" => windows_hardcoded_cross_compile(cross_compile_config),
// Waiting for users to tell us what they expect on their target platform
Some(os) => bail!(
"Unsupported target OS family for cross-compilation: {:?}",
os
),
// Unknown os family - try to do something useful
None => load_cross_compile_from_sysconfigdata(cross_compile_config),
}
}

Expand Down

0 comments on commit 2939bf1

Please sign in to comment.