Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ exclude = [
"/tests/ui",
]
edition = "2021"
# this allows PyO3 to forward build-config from `pyo3-ffi` to avoid downstream crates
# needing to depend on `pyo3-ffi` directly to use `pyo3-build-config` functionality.
links = "pyo3-python"
rust-version.workspace = true

[dependencies]
Expand Down Expand Up @@ -82,7 +85,7 @@ uuid = { version = "1.10.0", features = ["v4"] }
parking_lot = { version = "0.12.3", features = ["arc_lock"] }

[build-dependencies]
pyo3-build-config = { path = "pyo3-build-config", version = "=0.28.3", features = ["resolve-config"] }
pyo3-build-config = { path = "pyo3-build-config", version = "=0.28.3" }

[features]
default = ["macros"]
Expand All @@ -106,16 +109,16 @@ multiple-pymethods = ["inventory", "pyo3-macros/multiple-pymethods"]
extension-module = ["pyo3-ffi/extension-module"]

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

# With abi3, we can manually set the minimum Python version.
abi3-py38 = ["abi3-py39", "pyo3-build-config/abi3-py38", "pyo3-ffi/abi3-py38"]
abi3-py39 = ["abi3-py310", "pyo3-build-config/abi3-py39", "pyo3-ffi/abi3-py39"]
abi3-py310 = ["abi3-py311", "pyo3-build-config/abi3-py310", "pyo3-ffi/abi3-py310"]
abi3-py311 = ["abi3-py312", "pyo3-build-config/abi3-py311", "pyo3-ffi/abi3-py311"]
abi3-py312 = ["abi3-py313", "pyo3-build-config/abi3-py312", "pyo3-ffi/abi3-py312"]
abi3-py313 = ["abi3-py314", "pyo3-build-config/abi3-py313", "pyo3-ffi/abi3-py313"]
abi3-py314 = ["abi3", "pyo3-build-config/abi3-py314", "pyo3-ffi/abi3-py314"]
abi3-py38 = ["abi3-py39", "pyo3-ffi/abi3-py38"]
abi3-py39 = ["abi3-py310", "pyo3-ffi/abi3-py39"]
abi3-py310 = ["abi3-py311", "pyo3-ffi/abi3-py310"]
abi3-py311 = ["abi3-py312", "pyo3-ffi/abi3-py311"]
abi3-py312 = ["abi3-py313", "pyo3-ffi/abi3-py312"]
abi3-py313 = ["abi3-py314", "pyo3-ffi/abi3-py313"]
abi3-py314 = ["abi3", "pyo3-ffi/abi3-py314"]

# deprecated: no longer needed, raw-dylib is used instead
generate-import-lib = ["pyo3-ffi/generate-import-lib"]
Expand Down
4 changes: 4 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ fn configure_pyo3() -> Result<()> {

print_feature_cfgs();

// Forwards interpreter config under the links = "pyo3-python" configuration,
// which allows consumers of `pyo3-build-config` APIs to depend on pyo3 instead of pyo3-ffi.
interpreter_config.to_cargo_dep_env()?;

// Make `cargo test` etc work on macOS with Xcode bundled Python
add_python_framework_link_args();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ To see a full reference of all the `#[cfg]` flags provided, see the [`pyo3-build

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

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

```toml
[build-dependencies]
pyo3-build-config = { {{#PYO3_CRATE_VERSION}}, features = ["resolve-config"] }
pyo3-build-config = {{#PYO3_CRATE_VERSION}}
```

2. Add a [`build.rs`](https://doc.rust-lang.org/cargo/reference/build-scripts.html) file to your crate with the following contents:
Expand Down
6 changes: 0 additions & 6 deletions guide/src/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,6 @@ See [the `#[pyclass]` implementation details](class.md#implementation-details) f
The `nightly` feature needs the nightly Rust compiler.
This allows PyO3 to use the `auto_traits` and `negative_impls` features to fix the `Python::detach` function.

### `resolve-config`

The `resolve-config` feature of the `pyo3-build-config` crate controls whether that crate's build script automatically resolves a Python interpreter / build configuration.
This feature is primarily useful when building PyO3 itself.
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.

## Optional Dependencies

These features enable conversions between Python types and types from other Rust crates, enabling easy access to the rest of the Rust ecosystem.
Expand Down
1 change: 1 addition & 0 deletions newsfragments/5862.changed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Deprecate `pyo3-build-config/resolve-config` feature.
2 changes: 1 addition & 1 deletion pyo3-benches/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ rust_decimal = { version = "1.0.0", default-features = false }
hashbrown = "0.16"

[features]
abi3 = ["pyo3-build-config/abi3"]
abi3 = ["pyo3/abi3"]

[[bench]]
name = "bench_any"
Expand Down
16 changes: 1 addition & 15 deletions pyo3-build-config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,11 @@ target-lexicon = "0.13.3"
[features]
default = []

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

# deprecated
extension-module = []

# deprecated: no longer needed, raw-dylib is used instead
generate-import-lib = []

# These features are enabled by pyo3 when building Stable ABI extension modules.
abi3 = []
abi3-py38 = ["abi3-py39"]
abi3-py39 = ["abi3-py310"]
abi3-py310 = ["abi3-py311"]
abi3-py311 = ["abi3-py312"]
abi3-py312 = ["abi3-py313"]
abi3-py313 = ["abi3-py314"]
abi3-py314 = ["abi3"]

[package.metadata.docs.rs]
features = ["resolve-config"]
58 changes: 0 additions & 58 deletions pyo3-build-config/build.rs

This file was deleted.

38 changes: 20 additions & 18 deletions pyo3-build-config/src/impl_.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
//! Main implementation module included in both the `pyo3-build-config` library crate
//! and its build script.

#[cfg(test)]
use std::cell::RefCell;
use std::{
Expand Down Expand Up @@ -61,9 +58,7 @@ pub fn cargo_env_var(var: &str) -> Option<String> {
/// Gets an external environment variable, and registers the build script to rerun if
/// the variable changes.
pub fn env_var(var: &str) -> Option<OsString> {
if cfg!(feature = "resolve-config") {
println!("cargo:rerun-if-env-changed={var}");
}
println!("cargo:rerun-if-env-changed={var}");
#[cfg(test)]
{
READ_ENV_VARS.with(|env_vars| {
Expand Down Expand Up @@ -490,7 +485,8 @@ print("gil_disabled", get_config_var("Py_GIL_DISABLED"))

#[doc(hidden)]
pub fn from_cargo_dep_env() -> Option<Result<Self>> {
cargo_env_var("DEP_PYTHON_PYO3_CONFIG")
cargo_env_var("DEP_PYTHON_PYO3_CONFIG") // from `pyo3-ffi`
.or_else(|| cargo_env_var("DEP_PYO3_PYTHON_PYO3_CONFIG")) // forwared by `pyo3`
.map(|buf| InterpreterConfig::from_reader(&*unescape(&buf)))
}

Expand Down Expand Up @@ -583,7 +579,6 @@ print("gil_disabled", get_config_var("Py_GIL_DISABLED"))
/// This requires knowledge of the final target, so cannot be done when the config file is
/// inlined into `pyo3-build-config` at build time and instead needs to be done when
/// resolving the build config for linking.
#[cfg(any(test, feature = "resolve-config"))]
pub(crate) fn apply_default_lib_name_to_config_file(&mut self, target: &Triple) {
if self.lib_name.is_none() {
self.lib_name = Some(default_lib_name_for_target(
Expand Down Expand Up @@ -1909,9 +1904,7 @@ pub fn make_cross_compile_config() -> Result<Option<InterpreterConfig>> {
Ok(interpreter_config)
}

/// Generates an interpreter config which will be hard-coded into the pyo3-build-config crate.
/// Only used by `pyo3-build-config` build script.
#[allow(dead_code, unused_mut)]
/// Generates an interpreter config suitable for the build host.
pub fn make_interpreter_config() -> Result<InterpreterConfig> {
let host = Triple::host();
let abi3_version = get_abi3_version();
Expand Down Expand Up @@ -2874,17 +2867,17 @@ mod tests {
}

#[test]
#[cfg(all(
target_os = "linux",
target_arch = "x86_64",
feature = "resolve-config"
))]
#[cfg(all(target_os = "linux", target_arch = "x86_64",))]
fn parse_sysconfigdata() {
// A best effort attempt to get test coverage for the sysconfigdata parsing.
// Might not complete successfully depending on host installation; that's ok as long as
// CI demonstrates this path is covered!

let interpreter_config = crate::get();
let Ok(interpreter_config) = make_interpreter_config() else {
// Couldn't get an interpreter config, won't be able to test a matching sysconfigdata,
// never mind. (This is intended for coverage, don't mind if it fails if it doesn't run.)
return;
};

let lib_dir = match &interpreter_config.lib_dir {
Some(lib_dir) => Path::new(lib_dir),
Expand All @@ -2910,7 +2903,16 @@ mod tests {
_ => return,
};
let sysconfigdata = super::parse_sysconfigdata(sysconfigdata_path).unwrap();
let parsed_config = InterpreterConfig::from_sysconfigdata(&sysconfigdata).unwrap();
let mut parsed_config = InterpreterConfig::from_sysconfigdata(&sysconfigdata).unwrap();

// Workaround case where empty `PYTHONFRAMEWORKPREFIX` is returned as empty string instead of None,
// which causes the assert_eq! below to fail.
//
// TODO: probably should deprecate using this variable at all, seemingly only used in `add_python_framework_link_args`
// which is probably a strictly worse version of `add_libpython_rpath_link_args`.
if parsed_config.python_framework_prefix.as_deref() == Some("") {
parsed_config.python_framework_prefix = None;
}

assert_eq!(
parsed_config,
Expand Down
Loading
Loading