From dfe223619ab9589e9fe45bab4a93414e1e99078d Mon Sep 17 00:00:00 2001 From: messense Date: Thu, 14 Jul 2022 13:16:06 +0800 Subject: [PATCH] Add support for generating PyPy Windows import library --- CHANGELOG.md | 1 + pyo3-build-config/Cargo.toml | 4 ++-- pyo3-build-config/src/impl_.rs | 17 ++++++++++++++--- pyo3-build-config/src/import_lib.rs | 8 +++++++- 4 files changed, 24 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4deb5f4e..ba768cb0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 Rust `std::cmp::Ordering` comparison. [#2460](https://github.com/PyO3/pyo3/pull/2460) - Supprt `#[pyo3(name)]` on enum variants [#2457](https://github.com/PyO3/pyo3/pull/2457) - Add `PySuper` object [#2049](https://github.com/PyO3/pyo3/issues/2049) +- Add support for generating PyPy Windows import library. [#2506](https://github.com/PyO3/pyo3/pull/2506) ### Changed diff --git a/pyo3-build-config/Cargo.toml b/pyo3-build-config/Cargo.toml index 4e05e4ce..22f2e78e 100644 --- a/pyo3-build-config/Cargo.toml +++ b/pyo3-build-config/Cargo.toml @@ -12,11 +12,11 @@ edition = "2018" [dependencies] once_cell = "1" -python3-dll-a = { version = "0.2.2", optional = true } +python3-dll-a = { version = "0.2.5", optional = true } target-lexicon = "0.12" [build-dependencies] -python3-dll-a = { version = "0.2.2", optional = true } +python3-dll-a = { version = "0.2.5", optional = true } target-lexicon = "0.12" [features] diff --git a/pyo3-build-config/src/impl_.rs b/pyo3-build-config/src/impl_.rs index 8fde0412..c94770b1 100644 --- a/pyo3-build-config/src/impl_.rs +++ b/pyo3-build-config/src/impl_.rs @@ -471,7 +471,8 @@ print("mingw", get_platform().startswith("mingw")) if self.lib_dir.is_none() { let target = target_triple_from_env(); let py_version = if self.abi3 { None } else { Some(self.version) }; - self.lib_dir = import_lib::generate_import_lib(&target, py_version)?; + self.lib_dir = + import_lib::generate_import_lib(&target, self.implementation, py_version)?; } Ok(()) } @@ -1427,7 +1428,13 @@ fn default_cross_compile(cross_compile_config: &CrossCompileConfig) -> Result Result { } else { Some(interpreter_config.version) }; - interpreter_config.lib_dir = self::import_lib::generate_import_lib(&host, py_version)?; + interpreter_config.lib_dir = self::import_lib::generate_import_lib( + &host, + interpreter_config.implementation, + py_version, + )?; } Ok(interpreter_config) diff --git a/pyo3-build-config/src/import_lib.rs b/pyo3-build-config/src/import_lib.rs index ef941542..5b50e250 100644 --- a/pyo3-build-config/src/import_lib.rs +++ b/pyo3-build-config/src/import_lib.rs @@ -7,7 +7,7 @@ use python3_dll_a::ImportLibraryGenerator; use crate::errors::{Context, Result}; -use super::{Architecture, OperatingSystem, PythonVersion, Triple}; +use super::{Architecture, OperatingSystem, PythonImplementation, PythonVersion, Triple}; /// Generates the `python3.dll` or `pythonXY.dll` import library for Windows targets. /// @@ -17,6 +17,7 @@ use super::{Architecture, OperatingSystem, PythonVersion, Triple}; /// Does nothing if the target OS is not Windows. pub(super) fn generate_import_lib( target: &Triple, + py_impl: PythonImplementation, py_version: Option, ) -> Result> { if target.operating_system != OperatingSystem::Windows { @@ -38,9 +39,14 @@ pub(super) fn generate_import_lib( }; let env = target.environment.to_string(); + let implementation = match py_impl { + PythonImplementation::CPython => python3_dll_a::PythonImplementation::CPython, + PythonImplementation::PyPy => python3_dll_a::PythonImplementation::PyPy, + }; ImportLibraryGenerator::new(&arch, &env) .version(py_version.map(|v| (v.major, v.minor))) + .implementation(implementation) .generate(&out_lib_dir) .context("failed to generate python3.dll import library")?;