Skip to content

Commit 07093e9

Browse files
ngoldbaumdavidhewitt
authored andcommitted
Free-threaded build config fixes (#4719)
* update build config logic and library name generation * fix free-threaded windows clippy with --features=abi3 * use constant * add release note * apply my self-review comments * use ensure and error handling instead of panicking * skip abi3 fixup on free-threaded build * don't support PYO3_USE_ABI3_FORWARD_COMPATIBILITY on free-threaded build * don't panic in pyo3-ffi in abi3 check * document lack of limited API support * add is_free_threaded() method to InterpreterConfig * implement David's code review suggestions * remove unused imports
1 parent 02eb2a1 commit 07093e9

File tree

4 files changed

+245
-79
lines changed

4 files changed

+245
-79
lines changed

guide/src/free-threading.md

+27-1
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,15 @@ using single-phase initialization and the
108108
[`sequential`](https://github.com/PyO3/pyo3/tree/main/pyo3-ffi/examples/sequential)
109109
example for modules using multi-phase initialization.
110110

111+
If you would like to use conditional compilation to trigger different code paths
112+
under the free-threaded build, you can use the `Py_GIL_DISABLED` attribute once
113+
you have configured your crate to generate the necessary build configuration
114+
data. See [the guide
115+
section](./building-and-distribution/multiple-python-versions.md) for more
116+
details about supporting multiple different Python versions, including the
117+
free-threaded build.
118+
119+
111120
## Special considerations for the free-threaded build
112121

113122
The free-threaded interpreter does not have a GIL, and this can make interacting
@@ -234,7 +243,24 @@ needed. For now you should explicitly add locking, possibly using conditional
234243
compilation or using the critical section API to avoid creating deadlocks with
235244
the GIL.
236245

237-
## Thread-safe single initialization
246+
### Cannot build extensions using the limited API
247+
248+
The free-threaded build uses a completely new ABI and there is not yet an
249+
equivalent to the limited API for the free-threaded ABI. That means if your
250+
crate depends on PyO3 using the `abi3` feature or an an `abi3-pyxx` feature,
251+
PyO3 will print a warning and ignore that setting when building extensions using
252+
the free-threaded interpreter.
253+
254+
This means that if your package makes use of the ABI forward compatibility
255+
provided by the limited API to uploads only one wheel for each release of your
256+
package, you will need to update and tooling or instructions to also upload a
257+
version-specific free-threaded wheel.
258+
259+
See [the guide section](./building-and-distribution/multiple-python-versions.md)
260+
for more details about supporting multiple different Python versions, including
261+
the free-threaded build.
262+
263+
### Thread-safe single initialization
238264

239265
Until version 0.23, PyO3 provided only [`GILOnceCell`] to enable deadlock-free
240266
single initialization of data in contexts that might execute arbitrary Python

newsfragments/4719.fixed.md

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
* Fixed an issue that prevented building free-threaded extensions for crates
2+
that request a specific minimum limited API version.

0 commit comments

Comments
 (0)