Add support for generating PyPy Windows import library

This commit is contained in:
messense 2022-07-14 13:16:06 +08:00
parent 402018e628
commit dfe223619a
No known key found for this signature in database
GPG Key ID: BB41A8A2C716CCA9
4 changed files with 24 additions and 6 deletions

View File

@ -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

View File

@ -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]

View File

@ -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<In
#[cfg(feature = "python3-dll-a")]
if lib_dir.is_none() {
let py_version = if abi3 { None } else { Some(version) };
lib_dir = self::import_lib::generate_import_lib(&cross_compile_config.target, py_version)?;
lib_dir = self::import_lib::generate_import_lib(
&cross_compile_config.target,
cross_compile_config
.implementation
.unwrap_or(PythonImplementation::CPython),
py_version,
)?;
}
Ok(InterpreterConfig {
@ -1765,7 +1772,11 @@ pub fn make_interpreter_config() -> Result<InterpreterConfig> {
} 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)

View File

@ -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<PythonVersion>,
) -> Result<Option<String>> {
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")?;