Merge pull request #1856 from indygreg/build-config-feature

pyo3-build-config: add a crate feature to control build script
This commit is contained in:
David Hewitt 2021-09-02 21:45:34 +01:00 committed by GitHub
commit afd4d46bdb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 23 additions and 6 deletions

View File

@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Add implementation of `std::ops::Index<usize>` for `PyList`, `PyTuple` and `PySequence`. [#1825](https://github.com/PyO3/pyo3/pull/1825)
- Add range indexing implementations of `std::ops::Index` for `PyList`, `PyTuple` and `PySequence`. [#1829](https://github.com/PyO3/pyo3/pull/1829)
- Add commonly-used sequence methods to `PyList` and `PyTuple`. [#1849](https://github.com/PyO3/pyo3/pull/1849)
- The `pyo3-build-config` crate now has a `resolve-config` feature to control whether its build script does anything. [#1856](https://github.com/PyO3/pyo3/pull/1856)
### Changed

View File

@ -43,7 +43,7 @@ pyo3 = { path = ".", default-features = false, features = ["macros", "auto-initi
serde_json = "1.0.61"
[build-dependencies]
pyo3-build-config = { path = "pyo3-build-config", version = "0.14.4" }
pyo3-build-config = { path = "pyo3-build-config", version = "0.14.4", features = ["resolve-config"] }
[features]
default = ["macros"]

View File

@ -69,6 +69,14 @@ The `nightly` feature needs the nightly Rust compiler. This allows PyO3 to use R
- `FromPyObject` for `Vec` and `[T;N]` can perform a `memcpy` when the object supports the Python buffer protocol.
- `ToBorrowedObject` can skip a reference count increase when the provided object is a Python native type.
### `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. Disabling
this feature enables this crate to be used in *library mode*. This may be desirable for
use cases where you want 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.

View File

@ -14,7 +14,11 @@ edition = "2018"
once_cell = "1"
[features]
default = []
default = ["resolve-config"]
# Attempt to resolve a Python interpreter config for building in the build
# script. If this feature isn't enabled, the build script no-ops.
resolve-config = []
abi3 = []
abi3-py36 = ["abi3-py37"]

View File

@ -91,8 +91,12 @@ fn generate_build_configs() -> Result<()> {
}
fn main() {
if let Err(e) = generate_build_configs() {
eprintln!("error: {}", e.report());
std::process::exit(1)
if std::env::var("CARGO_FEATURE_RESOLVE_CONFIG").is_ok() {
if let Err(e) = generate_build_configs() {
eprintln!("error: {}", e.report());
std::process::exit(1)
}
} else {
eprintln!("resolve-config feature not enabled; build script in no-op mode");
}
}

View File

@ -16,7 +16,7 @@ edition = "2018"
[dependencies]
quote = { version = "1", default-features = false }
proc-macro2 = { version = "1", default-features = false }
pyo3-build-config = { path = "../pyo3-build-config", version = "0.14.4" }
pyo3-build-config = { path = "../pyo3-build-config", version = "0.14.4", features = ["resolve-config"] }
[dependencies.syn]
version = "1"