Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for generating PyPy Windows import library #2506

Merged
merged 1 commit into from Jul 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions pyo3-build-config/Cargo.toml
Expand Up @@ -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]
Expand Down
17 changes: 14 additions & 3 deletions pyo3-build-config/src/impl_.rs
Expand Up @@ -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(())
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 7 additions & 1 deletion pyo3-build-config/src/import_lib.rs
Expand Up @@ -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.
///
Expand All @@ -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 {
Expand All @@ -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")?;

Expand Down