Is there a way to disable the extensions of a dependency that uses PyO3? #2798
-
Following my question on insight-platform/Similari#87, I am looking for a way to disable as much as possible of a library's Python bindings to avoid relying on having Python available at build and run time. Following the features reference page of the doc, I have tried adding the following to the dependency's Cargo.toml: pyo3 = { version = "0.16", default-features = false, features = ["abi3"] } But the build still fails with:
Is there any built in way to achieve this? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
You can make python binding deps optional via cargo features. [dependencies.pyo3]
version = "0.16"
features = ["extension-module"]
optional = true
[build-dependencies]
pyo3-build-config = { version = "0.16", optional = true }
[features]
python = ["pyo3", "pyo3-build-config"] and #[cfg(feature = "python")]
mod python {
// your python binding code
} And add [tool.maturin]
features = ["python"] |
Beta Was this translation helpful? Give feedback.
-
Additionally, if the above to invasive a change for your dependency, maybe you could try |
Beta Was this translation helpful? Give feedback.
Additionally, if the above to invasive a change for your dependency, maybe you could try
features = ["abi-py37", "generate-abi3-import-lib"]
which means we link against a prebuilt library and should work without a Python interpreter being present.