Repository navigation
fix(python-sdk): pass extension-module link args outside maturin - #58
Merged
Merged
Conversation
Building `merry-py` with plain Cargo (`cargo build`, `cargo test`) cannot link the `_merry` cdylib on macOS: the `pyo3/extension-module` feature stops PyO3 from linking `libpython`, so the module needs `-undefined dynamic_lookup` to leave the Python symbols for the host interpreter, and only a `maturin` build supplied those arguments. Emit them from the crate's own build script through `pyo3_build_config::add_extension_module_link_args()` so every Cargo path produces a loadable extension module. The call is a no-op on targets that do not need it, and the new `pyo3-build-config` workspace dependency is pinned to the same release as `pyo3`. Verification: - `cargo fmt --all --check` - `cargo clippy --locked --all-targets --all-features -- -D warnings` - `cargo test --locked --all` - `cargo build -p merry-py` (Linux keeps the previous link behavior)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Building
merry-pywith plain Cargo (cargo build,cargo test) cannot link the_merrycdylib on macOS. With thepyo3/extension-modulefeature PyO3 stops linkinglibpython, so the module needs-undefined dynamic_lookupto let the host interpreter resolve the Python symbols at import time. Only amaturinbuild added those arguments, so plain Cargo could not produce a loadable module.Change
crates/merry-py/build.rs, which callspyo3_build_config::add_extension_module_link_args(), the PyO3-owned helper that emits the requiredcargo:rustc-cdylib-link-argvalues.pyo3-build-configin[workspace.dependencies]to the same release aspyo3and use it as a build dependency ofmerry-py.The helper is a no-op where those arguments are not needed, so Linux and Windows link output is unchanged, and there is no production dependency, runtime state, or Python-visible behavior change. The extension-module contract stays with PyO3 instead of being re-hardcoded in the workspace.
Verification
cargo fmt --all --checkcargo clippy --locked --all-targets --all-features -- -D warningscargo test --locked --allcargo build -p merry-pylinks the cdylib on Linux with the build script activemacOS linking was not exercised in this environment. The
Python SDKworkflow matrix covers macOS, wherematurin developalready supplied the same arguments, so the new path is exercised by plaincargo build/cargo teston a macOS checkout.