From 5af835daed5cc0f5a95506a6c1714123a9d5f511 Mon Sep 17 00:00:00 2001 From: David Hewitt <1939362+davidhewitt@users.noreply.github.com> Date: Thu, 5 Aug 2021 23:23:23 +0100 Subject: [PATCH] pyo3-build-config: fix build for windows gnu targets --- CHANGELOG.md | 1 + pyo3-build-config/src/impl_.rs | 23 ++++++++++------------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 87f50f59..ba7b1886 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Fix regression in 0.14.0 leading to incorrect code coverage being computed for `#[pyfunction]`s. [#1726](https://github.com/PyO3/pyo3/pull/1726) - Fix incorrect FFI definition of `Py_Buffer` on PyPy. [#1737](https://github.com/PyO3/pyo3/pull/1737) - Fix incorrect calculation of `dictoffset` on 32-bit Windows. [#1475](https://github.com/PyO3/pyo3/pull/1475) +- Fix regression in 0.13.2 leading to linking to incorrect Python library on Windows "gnu" targets. [#1759](https://github.com/PyO3/pyo3/pull/1759) ## [0.14.1] - 2021-07-04 diff --git a/pyo3-build-config/src/impl_.rs b/pyo3-build-config/src/impl_.rs index 729476ce..66c18d53 100644 --- a/pyo3-build-config/src/impl_.rs +++ b/pyo3-build-config/src/impl_.rs @@ -94,7 +94,7 @@ import os.path import platform import struct import sys -from sysconfig import get_config_var +from sysconfig import get_config_var, get_platform PYPY = platform.python_implementation() == "PyPy" @@ -132,6 +132,7 @@ print_if_set("libdir", get_config_var("LIBDIR")) print_if_set("base_prefix", base_prefix) print("executable", sys.executable) print("calcsize_pointer", struct.calcsize("P")) +print("mingw", get_platform() == "mingw") "#; let output = run_python_script(interpreter.as_ref(), SCRIPT)?; let map: HashMap = parse_script_output(&output); @@ -150,11 +151,7 @@ print("calcsize_pointer", struct.calcsize("P")) let implementation = map["implementation"].parse()?; let lib_name = if cfg!(windows) { - default_lib_name_windows( - version, - abi3, - &cargo_env_var("CARGO_CFG_TARGET_ENV").unwrap(), - ) + default_lib_name_windows(version, abi3, map["mingw"].as_str() == "True") } else { default_lib_name_unix( version, @@ -899,7 +896,7 @@ fn windows_hardcoded_cross_compile( version, shared: true, abi3: is_abi3(), - lib_name: Some(default_lib_name_windows(version, false, "msvc")), + lib_name: Some(default_lib_name_windows(version, false, false)), lib_dir: cross_compile_config.lib_dir.to_str().map(String::from), executable: None, pointer_width: None, @@ -936,10 +933,10 @@ fn load_cross_compile_config( // This contains only the limited ABI symbols. const WINDOWS_ABI3_LIB_NAME: &str = "python3"; -fn default_lib_name_windows(version: PythonVersion, abi3: bool, target_env: &str) -> String { +fn default_lib_name_windows(version: PythonVersion, abi3: bool, mingw: bool) -> String { if abi3 { WINDOWS_ABI3_LIB_NAME.to_owned() - } else if target_env == "gnu" { + } else if mingw { // https://packages.msys2.org/base/mingw-w64-python format!("python{}.{}", version.major, version.minor) } else { @@ -1278,19 +1275,19 @@ mod tests { #[test] fn default_lib_name_windows() { assert_eq!( - super::default_lib_name_windows(PythonVersion { major: 3, minor: 6 }, false, "mvsc"), + super::default_lib_name_windows(PythonVersion { major: 3, minor: 6 }, false, false), "python36", ); assert_eq!( - super::default_lib_name_windows(PythonVersion { major: 3, minor: 6 }, true, "mvsc"), + super::default_lib_name_windows(PythonVersion { major: 3, minor: 6 }, true, false), "python3", ); assert_eq!( - super::default_lib_name_windows(PythonVersion { major: 3, minor: 6 }, false, "gnu"), + super::default_lib_name_windows(PythonVersion { major: 3, minor: 6 }, false, true), "python3.6", ); assert_eq!( - super::default_lib_name_windows(PythonVersion { major: 3, minor: 6 }, true, "gnu"), + super::default_lib_name_windows(PythonVersion { major: 3, minor: 6 }, true, true), "python3", ); }