Skip to content

Commit f0db7a6

Browse files
Fix cargo test linking: make extension-module a conditional feature
PyO3's extension-module feature skips linking against libpython, which is correct for building the .so/.pyd extension but breaks cargo test. Move extension-module behind a Cargo feature flag (enabled by default so maturin builds are unaffected) and use --no-default-features in CI for cargo test and clippy.
1 parent b7dfba6 commit f0db7a6

3 files changed

Lines changed: 8 additions & 4 deletions

File tree

.github/workflows/rust-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,4 @@ jobs:
4545
toolchain: ${{ matrix.rust }}
4646

4747
- name: Run cargo test
48-
run: cargo test
48+
run: cargo test --no-default-features

.github/workflows/static-checks.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,4 @@ jobs:
5454
run: cargo fmt --check
5555

5656
- name: Run clippy
57-
run: cargo clippy -- -D warnings
57+
run: cargo clippy --no-default-features -- -D warnings

Cargo.toml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,16 @@ name = "_core"
1010
crate-type = ["cdylib", "lib"]
1111

1212
[dependencies]
13-
# "extension-module" tells pyo3 we want to build an extension module (skips linking against libpython.so)
1413
# "abi3-py310" tells pyo3 (and maturin) to build using the stable ABI with minimum Python version 3.10
15-
pyo3 = { version = "0.27.1", features = ["extension-module", "abi3-py310"] }
14+
# "extension-module" is behind a feature flag so `cargo test` can link against libpython
15+
pyo3 = { version = "0.27.1", features = ["abi3-py310"] }
1616
yamlpath = "1"
1717
yamlpatch = "1"
1818
# NOTE: serde_yaml 0.9 is archived/unmaintained (dtolnay). No drop-in
1919
# replacement exists yet. Monitor for a successor or security advisories.
2020
serde_yaml = "0.9"
2121
indexmap = "2"
22+
23+
[features]
24+
default = ["extension-module"]
25+
extension-module = ["pyo3/extension-module"]

0 commit comments

Comments
 (0)