From e067b32521d7f1ba36cca7fc1aba00cc6fce6abf Mon Sep 17 00:00:00 2001 From: Christoph Reiter Date: Fri, 12 Feb 2021 10:16:30 +0100 Subject: [PATCH] Support building with Mingw Python The DLL of the mingw Python in MSYS2 is named libpython3.8.dll: $ python3 -m sysconfig | grep LIBPYTHON LIBPYTHON = "-lpython3.8" Add another special case to in get_rustc_link_lib() to handle that case. Afaik the mingw build doesn't support the limited ABI, so skipt that as well. This makes all tests pass in an MSYS2 environment and lets us build python-cryptography. --- CHANGELOG.md | 1 + build.rs | 24 ++++++++++++++++-------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3ad83146169..5e057acd044 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Fix support for using `r#raw_idents` as argument names in pyfunctions. [#1383](https://github.com/PyO3/pyo3/pull/1383) - Fix unqualified `Result` usage in `pyobject_native_type_base`. [#1402](https://github.com/PyO3/pyo3/pull/1402) - Fix build on systems where the default Python encoding is not UTF-8. [#1405](https://github.com/PyO3/pyo3/pull/1405) +- Fix build on mingw / MSYS2. [#1423](https://github.com/PyO3/pyo3/pull/1423) ## [0.13.1] - 2021-01-10 ### Added diff --git a/build.rs b/build.rs index f0467dfe24e..aa3e474fec0 100644 --- a/build.rs +++ b/build.rs @@ -598,17 +598,25 @@ fn run_python_script(interpreter: &Path, script: &str) -> Result { fn get_rustc_link_lib(config: &InterpreterConfig) -> String { let link_name = if env::var("CARGO_CFG_TARGET_OS").unwrap().as_str() == "windows" { - // Link against python3.lib for the stable ABI on Windows. - // See https://www.python.org/dev/peps/pep-0384/#linkage - // - // This contains only the limited ABI symbols. - if env::var_os("CARGO_FEATURE_ABI3").is_some() { - "pythonXY:python3".to_owned() - } else { + if env::var("CARGO_CFG_TARGET_ENV").unwrap().as_str() == "gnu" { + // https://packages.msys2.org/base/mingw-w64-python format!( - "pythonXY:python{}{}", + "pythonXY:python{}.{}", config.version.major, config.version.minor ) + } else { + // Link against python3.lib for the stable ABI on Windows. + // See https://www.python.org/dev/peps/pep-0384/#linkage + // + // This contains only the limited ABI symbols. + if env::var_os("CARGO_FEATURE_ABI3").is_some() { + "pythonXY:python3".to_owned() + } else { + format!( + "pythonXY:python{}{}", + config.version.major, config.version.minor + ) + } } } else { match config.version.implementation {