Skip to content

Commit

Permalink
Fix cargo test with extension-module feature.
Browse files Browse the repository at this point in the history
  • Loading branch information
aviramha committed Jan 31, 2022
1 parent bb0ae49 commit 0aa471a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

- Fix `cargo test` with `extension-module` feature. (Requires `cargo +nightly` for now.) #[2135](https://github.com/PyO3/pyo3/pull/2135)
- Fix undefined symbol for `PyObject_HasAttr` on PyPy. [#2025](https://github.com/PyO3/pyo3/pull/2025)
- Fix memory leak in `PyErr::into_value`. [#2026](https://github.com/PyO3/pyo3/pull/2026)
- Fix clippy warning `needless-option-as-deref` in code generated by `#[pyfunction]` and `#[pymethods]`. [#2040](https://github.com/PyO3/pyo3/pull/2040)
Expand Down
16 changes: 8 additions & 8 deletions guide/src/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ PyO3 provides a struct [`GILOnceCell`] which works equivalently to `OnceCell` bu

[`GILOnceCell`]: {{#PYO3_DOCS_URL}}/pyo3/once_cell/struct.GILOnceCell.html

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

Currently, [#340](https://github.com/PyO3/pyo3/issues/340) 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`:
On unix operating systems the `extension-module` feature is required to disable linking against libpython to meet criteria of how Python extension modules should be built.

```toml
[dependencies.pyo3]
{{#PYO3_CRATE_VERSION}}
PyO3 is able to re-enable linking for binaries and tests in the project, but it requires a nightly cargo. To use this feature, you must use nightly cargo, e.g.:

[features]
extension-module = ["pyo3/extension-module"]
default = ["extension-module"]
```
# For cargo test
cargo +nightly test
# For cargo run
cargo +nightly run
```

## I can't run `cargo test`: my crate cannot be found for tests in `tests/` directory!
Expand Down
8 changes: 8 additions & 0 deletions pyo3-build-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ fn _add_extension_module_link_args(target_os: &str, mut writer: impl std::io::Wr
writeln!(writer, "cargo:rustc-cdylib-link-arg=-undefined").unwrap();
writeln!(writer, "cargo:rustc-cdylib-link-arg=dynamic_lookup").unwrap();
}
if target_os != "windows" && target_os != "android" {
let interpreter_config = get();
let lib_name = interpreter_config.lib_name.as_ref().unwrap();
println!("cargo:rustc-link-arg-bins=-l{}", lib_name);
println!("cargo:rustc-link-arg-tests=-l{}", lib_name);
println!("cargo:rustc-link-arg-benches=-l{}", lib_name);
println!("cargo:rustc-link-arg-examples=-l{}", lib_name);
}
}

/// Loads the configuration determined from the build environment.
Expand Down

0 comments on commit 0aa471a

Please sign in to comment.