Skip to content

Commit c37c2a7

Browse files
authored
stop inlining config into pyo3-build-config; generate directly in pyo3-ffi (#5862)
* stop inlining config into `pyo3-build-config`; generate directly in `pyo3-ffi` * enable `pyo3-ffi-check` macro to see pyo3 config * fixup benches `abi3` dependency * fix `pyo3-build-config` test * correct path * fixup call * fix linux-only use of `resolve_build_config` * add newsfragment * fixup ordering * directly resolve host config in test * more fixups * workaround sysconfig pain point * migration notes, bump coverage * fix typo in migration guide * review feedback
1 parent 526c690 commit c37c2a7

15 files changed

Lines changed: 157 additions & 265 deletions

File tree

Cargo.toml

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ exclude = [
2222
"/tests/ui",
2323
]
2424
edition = "2021"
25+
# This allows PyO3 to forward build-config from `pyo3-ffi` to avoid downstream crates
26+
# needing to depend on `pyo3-ffi` directly to use `pyo3-build-config` functionality.
27+
#
28+
# See also https://github.com/rust-lang/cargo/issues/3544 and
29+
# https://github.com/rust-lang/cargo/pull/16436 which may allow this to be
30+
# reverted in the future.
31+
links = "pyo3-python"
2532
rust-version.workspace = true
2633

2734
[dependencies]
@@ -82,7 +89,7 @@ uuid = { version = "1.10.0", features = ["v4"] }
8289
parking_lot = { version = "0.12.3", features = ["arc_lock"] }
8390

8491
[build-dependencies]
85-
pyo3-build-config = { path = "pyo3-build-config", version = "=0.28.3", features = ["resolve-config"] }
92+
pyo3-build-config = { path = "pyo3-build-config", version = "=0.28.3" }
8693

8794
[features]
8895
default = ["macros"]
@@ -106,16 +113,16 @@ multiple-pymethods = ["inventory", "pyo3-macros/multiple-pymethods"]
106113
extension-module = ["pyo3-ffi/extension-module"]
107114

108115
# Use the Python limited API. See https://www.python.org/dev/peps/pep-0384/ for more.
109-
abi3 = ["pyo3-build-config/abi3", "pyo3-ffi/abi3"]
116+
abi3 = ["pyo3-ffi/abi3"]
110117

111118
# With abi3, we can manually set the minimum Python version.
112-
abi3-py38 = ["abi3-py39", "pyo3-build-config/abi3-py38", "pyo3-ffi/abi3-py38"]
113-
abi3-py39 = ["abi3-py310", "pyo3-build-config/abi3-py39", "pyo3-ffi/abi3-py39"]
114-
abi3-py310 = ["abi3-py311", "pyo3-build-config/abi3-py310", "pyo3-ffi/abi3-py310"]
115-
abi3-py311 = ["abi3-py312", "pyo3-build-config/abi3-py311", "pyo3-ffi/abi3-py311"]
116-
abi3-py312 = ["abi3-py313", "pyo3-build-config/abi3-py312", "pyo3-ffi/abi3-py312"]
117-
abi3-py313 = ["abi3-py314", "pyo3-build-config/abi3-py313", "pyo3-ffi/abi3-py313"]
118-
abi3-py314 = ["abi3", "pyo3-build-config/abi3-py314", "pyo3-ffi/abi3-py314"]
119+
abi3-py38 = ["abi3-py39", "pyo3-ffi/abi3-py38"]
120+
abi3-py39 = ["abi3-py310", "pyo3-ffi/abi3-py39"]
121+
abi3-py310 = ["abi3-py311", "pyo3-ffi/abi3-py310"]
122+
abi3-py311 = ["abi3-py312", "pyo3-ffi/abi3-py311"]
123+
abi3-py312 = ["abi3-py313", "pyo3-ffi/abi3-py312"]
124+
abi3-py313 = ["abi3-py314", "pyo3-ffi/abi3-py313"]
125+
abi3-py314 = ["abi3", "pyo3-ffi/abi3-py314"]
119126

120127
# deprecated: no longer needed, raw-dylib is used instead
121128
generate-import-lib = ["pyo3-ffi/generate-import-lib"]

build.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ fn configure_pyo3() -> Result<()> {
4343

4444
print_feature_cfgs();
4545

46+
// Forwards interpreter config under the links = "pyo3-python" configuration,
47+
// which allows consumers of `pyo3-build-config` APIs to depend on pyo3 instead of pyo3-ffi.
48+
interpreter_config.to_cargo_dep_env()?;
49+
4650
// Make `cargo test` etc work on macOS with Xcode bundled Python
4751
add_python_framework_link_args();
4852

guide/src/building-and-distribution/multiple-python-versions.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ To see a full reference of all the `#[cfg]` flags provided, see the [`pyo3-build
3636

3737
You can use the `#[cfg]` flags in just two steps:
3838

39-
1. Add `pyo3-build-config` with the [`resolve-config`](../features.md#resolve-config) feature enabled to your crate's build dependencies in `Cargo.toml`:
39+
1. Add `pyo3-build-config` to your crate's build dependencies in `Cargo.toml`:
4040

4141
```toml
4242
[build-dependencies]
43-
pyo3-build-config = { {{#PYO3_CRATE_VERSION}}, features = ["resolve-config"] }
43+
pyo3-build-config = {{#PYO3_CRATE_VERSION}}
4444
```
4545

4646
2. Add a [`build.rs`](https://doc.rust-lang.org/cargo/reference/build-scripts.html) file to your crate with the following contents:

guide/src/features.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,6 @@ See [the `#[pyclass]` implementation details](class.md#implementation-details) f
105105
The `nightly` feature needs the nightly Rust compiler.
106106
This allows PyO3 to use the `auto_traits` and `negative_impls` features to fix the `Python::detach` function.
107107

108-
### `resolve-config`
109-
110-
The `resolve-config` feature of the `pyo3-build-config` crate controls whether that crate's build script automatically resolves a Python interpreter / build configuration.
111-
This feature is primarily useful when building PyO3 itself.
112-
By default this feature is not enabled, meaning you can freely use `pyo3-build-config` as a standalone library to read or write PyO3 build configuration files or resolve metadata about a Python interpreter.
113-
114108
## Optional Dependencies
115109

116110
These features enable conversions between Python types and types from other Rust crates, enabling easy access to the rest of the Rust ecosystem.

guide/src/migration.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,17 @@ fn bytes_to_str<'a>(py: Python<'_>, bytes: &'a [u8]) -> PyResult<&'a str> {
3636
For `string::FromUtf16Error` and `char::DecodeUtf16Error` the Rust error types do not contain any of the information required to construct a `UnicodeDecodeError`.
3737
To raise a Python `UnicodeDecodeError` a new error should be manually constructed by calling `PyUnicodeDecodeError::new_err(...)`.
3838

39+
### `pyo3_build_config` APIs now require a direct dependency on `pyo3` or `pyo3-ffi`
40+
41+
Prior to PyO3 0.29, `pyo3-build-config` would inline part of the build configuration into the crate in its own build script.
42+
This worked for simple builds but not for cross-compiling; `pyo3-ffi`'s build script would need to re-implement a lot of the same machinery to correctly configure the build for cross-compilation.
43+
There were also edge cases where `pyo3-build-config` would use this inlined configuration incorrectly and misconfigure the build - e.g. [when cross compiling with `buck` or `bazel` build systems](https://github.com/PyO3/pyo3/issues/4579).
44+
45+
In PyO3 0.29, `pyo3-build-config` no longer inlines any configuration into itself and instead requires a direct dependency on either `pyo3-ffi` or `pyo3` to load the configuration resolved from `pyo3-ffi`'s build script.
46+
47+
This has upside of faster compilation - `pyo3-build-config` no longer has a build script and never recompiles when changing Python version.
48+
It also guarantees that all builds are based on the single fully-configured build configuration resolved by `pyo3-ffi`.
49+
3950
## from 0.27.* to 0.28
4051

4152
### Default to supporting free-threaded Python

newsfragments/5862.changed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Deprecate `pyo3-build-config/resolve-config` feature.

pyo3-benches/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ rust_decimal = { version = "1.0.0", default-features = false }
2020
hashbrown = "0.17"
2121

2222
[features]
23-
abi3 = ["pyo3-build-config/abi3"]
23+
abi3 = ["pyo3/abi3"]
2424

2525
[[bench]]
2626
name = "bench_any"

pyo3-build-config/Cargo.toml

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,11 @@ target-lexicon = "0.13.3"
2020
[features]
2121
default = []
2222

23-
# Attempt to resolve a Python interpreter config for building in the build
24-
# script. If this feature isn't enabled, the build script no-ops.
23+
# deprecated
2524
resolve-config = []
2625

2726
# deprecated
2827
extension-module = []
2928

3029
# deprecated: no longer needed, raw-dylib is used instead
3130
generate-import-lib = []
32-
33-
# These features are enabled by pyo3 when building Stable ABI extension modules.
34-
abi3 = []
35-
abi3-py38 = ["abi3-py39"]
36-
abi3-py39 = ["abi3-py310"]
37-
abi3-py310 = ["abi3-py311"]
38-
abi3-py311 = ["abi3-py312"]
39-
abi3-py312 = ["abi3-py313"]
40-
abi3-py313 = ["abi3-py314"]
41-
abi3-py314 = ["abi3"]
42-
43-
[package.metadata.docs.rs]
44-
features = ["resolve-config"]

pyo3-build-config/build.rs

Lines changed: 0 additions & 58 deletions
This file was deleted.

0 commit comments

Comments
 (0)