From 66e044a5a994d9567db8d8e3423ec52792854f46 Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Wed, 20 Aug 2025 18:17:09 -0400 Subject: [PATCH] fixes #5202 -- treat the `PYO3_BUILD_EXTENSION_MODULE` env var the same as teh extension-module feature --- newsfragments/5343.added.md | 1 + pyo3-build-config/src/impl_.rs | 5 +++++ pytests/Cargo.toml | 2 +- pytests/pyproject.toml | 2 +- 4 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 newsfragments/5343.added.md diff --git a/newsfragments/5343.added.md b/newsfragments/5343.added.md new file mode 100644 index 00000000000..358d3c8fbad --- /dev/null +++ b/newsfragments/5343.added.md @@ -0,0 +1 @@ +When building pyo3, setting the `PYO3_BUILD_EXTENSION_MODULE` causes the same effect as the `extension-module` feature. Eventually we expect maturin and setuptools-rust to set this environment variable automatically. Users with their own build systems will need to do the same. diff --git a/pyo3-build-config/src/impl_.rs b/pyo3-build-config/src/impl_.rs index aae49026a41..f0d37416b1e 100644 --- a/pyo3-build-config/src/impl_.rs +++ b/pyo3-build-config/src/impl_.rs @@ -862,9 +862,14 @@ pub fn get_abi3_version() -> Option { /// Checks if the `extension-module` feature is enabled for the PyO3 crate. /// +/// This can be triggered either by: +/// - The `extension-module` Cargo feature +/// - Setting the `PYO3_BUILD_EXTENSION_MODULE` environment variable +/// /// Must be called from a PyO3 crate build script. pub fn is_extension_module() -> bool { cargo_env_var("CARGO_FEATURE_EXTENSION_MODULE").is_some() + || env_var("PYO3_BUILD_EXTENSION_MODULE").is_some() } /// Checks if we need to link to `libpython` for the current build target. diff --git a/pytests/Cargo.toml b/pytests/Cargo.toml index b744c6e16cc..0b8dfe5d5ba 100644 --- a/pytests/Cargo.toml +++ b/pytests/Cargo.toml @@ -8,7 +8,7 @@ publish = false rust-version = "1.74" [dependencies] -pyo3 = { path = "../", features = ["extension-module", "experimental-inspect"] } +pyo3 = { path = "../", features = ["experimental-inspect"] } [build-dependencies] pyo3-build-config = { path = "../pyo3-build-config" } diff --git a/pytests/pyproject.toml b/pytests/pyproject.toml index 5f78a573124..12a5fdf1e91 100644 --- a/pytests/pyproject.toml +++ b/pytests/pyproject.toml @@ -1,5 +1,5 @@ [build-system] -requires = ["maturin>=1,<2"] +requires = ["maturin>=1.9.4,<2"] build-backend = "maturin" [tool.pytest.ini_options]