From f01595163c3411d92704bc796e8ec4da7a06ed07 Mon Sep 17 00:00:00 2001 From: messense Date: Mon, 15 Nov 2021 13:24:29 +0800 Subject: [PATCH] Don't link to python3.lib for PyPy on Windows --- pyo3-build-config/src/impl_.rs | 61 +++++++++++++++++++++++++++++----- 1 file changed, 53 insertions(+), 8 deletions(-) diff --git a/pyo3-build-config/src/impl_.rs b/pyo3-build-config/src/impl_.rs index 191a70bdd33..6a73b3b97d6 100644 --- a/pyo3-build-config/src/impl_.rs +++ b/pyo3-build-config/src/impl_.rs @@ -219,7 +219,12 @@ print("mingw", get_platform().startswith("mingw")) let implementation = map["implementation"].parse()?; let lib_name = if cfg!(windows) { - default_lib_name_windows(version, abi3, map["mingw"].as_str() == "True") + default_lib_name_windows( + version, + implementation, + abi3, + map["mingw"].as_str() == "True", + ) } else { default_lib_name_unix( version, @@ -987,7 +992,12 @@ fn windows_hardcoded_cross_compile( version, shared: true, abi3, - lib_name: Some(default_lib_name_windows(version, abi3, false)), + lib_name: Some(default_lib_name_windows( + version, + PythonImplementation::CPython, + abi3, + false, + )), lib_dir: cross_compile_config.lib_dir.to_str().map(String::from), executable: None, pointer_width: None, @@ -1026,8 +1036,13 @@ 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, mingw: bool) -> String { - if abi3 { +fn default_lib_name_windows( + version: PythonVersion, + implementation: PythonImplementation, + abi3: bool, + mingw: bool, +) -> String { + if abi3 && !implementation.is_pypy() { WINDOWS_ABI3_LIB_NAME.to_owned() } else if mingw { // https://packages.msys2.org/base/mingw-w64-python @@ -1387,22 +1402,52 @@ mod tests { #[test] fn default_lib_name_windows() { + use PythonImplementation::*; assert_eq!( - super::default_lib_name_windows(PythonVersion { major: 3, minor: 6 }, false, false), + super::default_lib_name_windows( + PythonVersion { major: 3, minor: 6 }, + CPython, + false, + false + ), "python36", ); assert_eq!( - super::default_lib_name_windows(PythonVersion { major: 3, minor: 6 }, true, false), + super::default_lib_name_windows( + PythonVersion { major: 3, minor: 6 }, + CPython, + true, + false + ), "python3", ); assert_eq!( - super::default_lib_name_windows(PythonVersion { major: 3, minor: 6 }, false, true), + super::default_lib_name_windows( + PythonVersion { major: 3, minor: 6 }, + CPython, + false, + true + ), "python3.6", ); assert_eq!( - super::default_lib_name_windows(PythonVersion { major: 3, minor: 6 }, true, true), + super::default_lib_name_windows( + PythonVersion { major: 3, minor: 6 }, + CPython, + true, + true + ), "python3", ); + assert_eq!( + super::default_lib_name_windows( + PythonVersion { major: 3, minor: 6 }, + PyPy, + true, + false + ), + "python36", + ); } #[test]