From 2503e61c65df638ce48b73215026fb0ba5b172b6 Mon Sep 17 00:00:00 2001 From: Sergey Kvachonok Date: Thu, 25 Mar 2021 08:14:07 +0300 Subject: [PATCH] Always use correct abi3 Python DLL name for MinGW Compiling an abi3 extension module for `x86_64-pc-windows-gnu` target links to `python3.dll` import library when `PYO3_NO_PYTHON` is set and to `python3.Y.dll` import library when `PYO3_NO_PYTHON` is not set. All abi3 extensions should link to `python3.dll` on Windows, as required by https://www.python.org/dev/peps/pep-0384/#linkage Update the code path for the case when `PYO3_NO_PYTHON` is not set to yield the same Python DLL import library name. --- build.rs | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/build.rs b/build.rs index b0c8c974..9ab5aab7 100644 --- a/build.rs +++ b/build.rs @@ -625,26 +625,23 @@ 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" { - if env::var("CARGO_CFG_TARGET_ENV").unwrap().as_str() == "gnu" { + if is_abi3() { + // 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. + "pythonXY:python3".to_owned() + } else if env::var("CARGO_CFG_TARGET_ENV").unwrap().as_str() == "gnu" { // https://packages.msys2.org/base/mingw-w64-python - // TODO: ABI3? format!( "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 is_abi3() { - "pythonXY:python3".to_owned() - } else { - format!( - "pythonXY:python{}{}", - config.version.major, config.version.minor - ) - } + format!( + "pythonXY:python{}{}", + config.version.major, config.version.minor + ) } } else { match config.implementation {