From 39fe13becf56df1a6a9ec4342492475586e9827e Mon Sep 17 00:00:00 2001 From: David Hewitt Date: Mon, 2 Dec 2024 04:32:26 +0000 Subject: [PATCH] support python3-dll-a free-threaded generation (#4749) --- newsfragments/4749.fixed.md | 1 + newsfragments/4749.packaging.md | 1 + pyo3-build-config/Cargo.toml | 4 ++-- pyo3-build-config/src/impl_.rs | 15 +++++++++++++-- pyo3-build-config/src/import_lib.rs | 2 ++ 5 files changed, 19 insertions(+), 4 deletions(-) create mode 100644 newsfragments/4749.fixed.md create mode 100644 newsfragments/4749.packaging.md diff --git a/newsfragments/4749.fixed.md b/newsfragments/4749.fixed.md new file mode 100644 index 00000000000..8d8923075f3 --- /dev/null +++ b/newsfragments/4749.fixed.md @@ -0,0 +1 @@ +Fix failure to link on Windows free-threaded Python when using the `generate-import-lib` feature. diff --git a/newsfragments/4749.packaging.md b/newsfragments/4749.packaging.md new file mode 100644 index 00000000000..a87524431d8 --- /dev/null +++ b/newsfragments/4749.packaging.md @@ -0,0 +1 @@ +Bump optional `python3-dll-a` dependency to 0.2.11. diff --git a/pyo3-build-config/Cargo.toml b/pyo3-build-config/Cargo.toml index bcf8b1de2a6..61478dc4d18 100644 --- a/pyo3-build-config/Cargo.toml +++ b/pyo3-build-config/Cargo.toml @@ -13,11 +13,11 @@ rust-version = "1.63" [dependencies] once_cell = "1" -python3-dll-a = { version = "0.2.6", optional = true } +python3-dll-a = { version = "0.2.11", optional = true } target-lexicon = "0.12.14" [build-dependencies] -python3-dll-a = { version = "0.2.6", optional = true } +python3-dll-a = { version = "0.2.11", optional = true } target-lexicon = "0.12.14" [features] diff --git a/pyo3-build-config/src/impl_.rs b/pyo3-build-config/src/impl_.rs index 30684344e39..bc97460a795 100644 --- a/pyo3-build-config/src/impl_.rs +++ b/pyo3-build-config/src/impl_.rs @@ -554,8 +554,17 @@ print("gil_disabled", get_config_var("Py_GIL_DISABLED")) 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, self.implementation, py_version)?; + let abiflags = if self.is_free_threaded() { + Some("t") + } else { + None + }; + self.lib_dir = import_lib::generate_import_lib( + &target, + self.implementation, + py_version, + abiflags, + )?; } Ok(()) } @@ -1521,6 +1530,7 @@ fn default_cross_compile(cross_compile_config: &CrossCompileConfig) -> Result Result { &host, interpreter_config.implementation, py_version, + None, )?; } diff --git a/pyo3-build-config/src/import_lib.rs b/pyo3-build-config/src/import_lib.rs index 0925a861b5b..ee934441f77 100644 --- a/pyo3-build-config/src/import_lib.rs +++ b/pyo3-build-config/src/import_lib.rs @@ -19,6 +19,7 @@ pub(super) fn generate_import_lib( target: &Triple, py_impl: PythonImplementation, py_version: Option, + abiflags: Option<&str>, ) -> Result> { if target.operating_system != OperatingSystem::Windows { return Ok(None); @@ -50,6 +51,7 @@ pub(super) fn generate_import_lib( ImportLibraryGenerator::new(&arch, &env) .version(py_version.map(|v| (v.major, v.minor))) .implementation(implementation) + .abiflags(abiflags) .generate(&out_lib_dir) .context("failed to generate python3.dll import library")?;