Skip to content

Commit 2f8a725

Browse files
committed
Replace extension-module feature with PYO3_MAKE_EXTENSION_MODULE
1 parent cfa5b2e commit 2f8a725

File tree

9 files changed

+12
-45
lines changed

9 files changed

+12
-45
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1212
- Correct FFI definitions `Py_SetProgramName` and `Py_SetPythonHome` to take `*const` argument instead of `*mut`. [#1021](https://github.com/PyO3/pyo3/pull/1021)
1313
- Rename `PyString::to_string` to `to_str`, change return type `Cow<str>` to `&str`. [#1023](https://github.com/PyO3/pyo3/pull/1023)
1414
- Correct FFI definition `_PyLong_AsByteArray` `*mut c_uchar` argument instead of `*const c_uchar`. [#1029](https://github.com/PyO3/pyo3/pull/1029)
15+
- Replace `extension-module` feature with `PYO3_MAKE_EXTENSION_MODULE` environment variable. See the migration guide for help with upgrading. [#1040](https://github.com/PyO3/pyo3/pull/1040)
1516

1617
### Removed
1718
- Remove `PyString::as_bytes`. [#1023](https://github.com/PyO3/pyo3/pull/1023)
1819
- Remove `Python::register_any`. [#1023](https://github.com/PyO3/pyo3/pull/1023)
20+
- Remove `extension-module` feature. [#1040](https://github.com/PyO3/pyo3/pull/1040)
1921

2022
### Fixed
2123
- Conversion from types with an `__index__` method to Rust BigInts. [#1027](https://github.com/PyO3/pyo3/pull/1027)

Cargo.toml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,6 @@ nightly = []
4444
# this is no longer needed internally, but setuptools-rust assumes this feature
4545
python3 = []
4646

47-
# Use this feature when building an extension module.
48-
# It tells the linker to keep the python symbols unresolved,
49-
# so that the module can also be used with statically linked python interpreters.
50-
extension-module = []
51-
5247
# The stable cpython abi as defined in PEP 384. Currently broken with
5348
# many compilation errors. Pull Requests working towards fixing that
5449
# are welcome.

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ crate-type = ["cdylib"]
4848

4949
[dependencies.pyo3]
5050
version = "0.11.1"
51-
features = ["extension-module"]
5251
```
5352

5453
**`src/lib.rs`**

build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ fn configure(interpreter_config: &InterpreterConfig) -> Result<String> {
485485

486486
check_target_architecture(interpreter_config)?;
487487

488-
let is_extension_module = env::var_os("CARGO_FEATURE_EXTENSION_MODULE").is_some();
488+
let is_extension_module = env::var_os("PYO3_MAKE_EXTENSION_MODULE").is_some();
489489
if !is_extension_module || cfg!(target_os = "windows") {
490490
println!("{}", get_rustc_link_lib(&interpreter_config)?);
491491
if let Some(libdir) = &interpreter_config.libdir {

examples/rustapi_module/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ edition = "2018"
99

1010
[dependencies.pyo3]
1111
path = "../../"
12-
features = ["extension-module"]
1312

1413
[lib]
1514
name = "rustapi_module"

examples/word-count/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ edition = "2018"
66

77
[dependencies]
88
rayon = "1.0.2"
9-
pyo3 = { path = "../..", features = ["extension-module"] }
9+
pyo3 = { path = "../.." }
1010

1111
[lib]
1212
name = "word_count"

guide/src/building_and_distribution.md

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,35 +8,15 @@ PyO3 uses a build script to determine the Python version and set the correct lin
88

99
Different linker arguments must be set for libraries/extension modules and binaries, which includes both standalone binaries and tests. (More specifically, binaries must be told where to find libpython and libraries must not link to libpython for [manylinux](https://www.python.org/dev/peps/pep-0513/) compliance).
1010

11-
Since PyO3's build script can't know whether you're building a binary or a library, you have to activate the `extension-module` feature to get the build options for a library, or it'll default to binary.
12-
13-
If you have e.g. a library crate and a profiling crate alongside, you need to use optional features. E.g. you put the following in the library crate:
14-
15-
```toml
16-
[dependencies]
17-
pyo3 = "0.6"
18-
19-
[lib]
20-
name = "hyperjson"
21-
crate-type = ["rlib", "cdylib"]
22-
23-
[features]
24-
default = ["pyo3/extension-module"]
25-
```
26-
27-
And this in the profiling crate:
28-
29-
```toml
30-
[dependencies]
31-
my_main_crate = { path = "..", default-features = false }
32-
pyo3 = "0.6"
33-
```
11+
Since PyO3's build script can't know whether you're building a binary or a library, it defaults to building for binaries. To build a library, you should set the `PYO3_MAKE_EXTENSION_MODULE` environment variable to a nonempty value.
3412

3513
On Linux/macOS you might have to change `LD_LIBRARY_PATH` to include libpython, while on windows you might need to set `LIB` to include `pythonxy.lib` (where x and y are major and minor version), which is normally either in the `libs` or `Lib` folder of a Python installation.
3614

3715
## Distribution
3816

39-
There are two ways to distribute your module as a Python package: The old, [setuptools-rust](https://github.com/PyO3/setuptools-rust), and the new, [maturin](https://github.com/pyo3/maturin). setuptools-rust needs several configuration files (`setup.py`, `MANIFEST.in`, `build-wheels.sh`, etc.). maturin doesn't need any configuration files, however it does not support some functionality of setuptools such as package data ([pyo3/maturin#258](https://github.com/PyO3/maturin/issues/258)) and requires a rigid project structure, while setuptools-rust allows (and sometimes requires) configuration with python code.
17+
There are two ways to distribute your module as a Python package:
18+
- [`maturin`](https://github.com/pyo3/maturin) is the typical way to build and package PyO3 extension modules. It is deliberately opinionated about project structure, which allows it to need minimal configuration.
19+
- [`setuptools-rust`](https://github.com/PyO3/setuptools-rust), in contrast, needs several configuration files (`setup.py`, `MANIFEST.in`, `build-wheels.sh`, etc.). This complexity comes at added flexibility, allowing configuration using python code.
4020

4121
## Cross Compiling
4222

guide/src/faq.md

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,4 @@ PyO3 provides a struct [`GILOnceCell`] which works equivalently to `OnceCell` bu
1717

1818
## I can't run `cargo test`: I'm having linker issues like "Symbol not found" or "Undefined reference to _PyExc_SystemError"!
1919

20-
Currently, [#341](https://github.com/PyO3/pyo3/issues/341) causes `cargo test` to fail with linking errors when the `extension-module` feature is activated. For now you can work around this by making the `extension-module` feature optional and running the tests with `cargo test --no-default-features`:
21-
22-
```toml
23-
[dependencies.pyo3]
24-
version = "*"
25-
26-
[features]
27-
extension-module = ["pyo3/extension-module"]
28-
default = ["extension-module"]
29-
```
20+
If `PYO3_MAKE_EXTENSION_MODULE` environment variable is non-empty, PyO3 will not link against libpython. This will lead to errors like the above at link time.

src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@
3737
//!
3838
//! ## Using Rust from Python
3939
//!
40-
//! PyO3 can be used to generate a native Python module.
40+
//! PyO3 can be used to generate a native Python module. For a zero-configuration
41+
//! package to aid with compiling and packaging the module, see
42+
//! [`maturin`](https://github.com/PyO3/maturin).
4143
//!
4244
//! **`Cargo.toml`**
4345
//!
@@ -53,7 +55,6 @@
5355
//!
5456
//! [dependencies.pyo3]
5557
//! version = "0.11.1"
56-
//! features = ["extension-module"]
5758
//! ```
5859
//!
5960
//! **`src/lib.rs`**

0 commit comments

Comments
 (0)