Skip to content

fix(python-sdk): pass extension-module link args outside maturin - #58

Merged
locez merged 1 commit into
mainfrom
fix/merry-py-extension-module-link-args
Sep 16, 2026
Merged

locez merged 1 commit into
mainfrom
fix/merry-py-extension-module-link-args

Conversation

@locez

@locez locez commented Sep 16, 2026

Copy link
Copy Markdown
Owner

Problem

Building merry-py with plain Cargo (cargo build, cargo test) cannot link the _merry cdylib on macOS. With the pyo3/extension-module feature PyO3 stops linking libpython, so the module needs -undefined dynamic_lookup to let the host interpreter resolve the Python symbols at import time. Only a maturin build added those arguments, so plain Cargo could not produce a loadable module.

Change

  • Add crates/merry-py/build.rs, which calls pyo3_build_config::add_extension_module_link_args(), the PyO3-owned helper that emits the required cargo:rustc-cdylib-link-arg values.
  • Pin pyo3-build-config in [workspace.dependencies] to the same release as pyo3 and use it as a build dependency of merry-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 --check
  • cargo clippy --locked --all-targets --all-features -- -D warnings
  • cargo test --locked --all
  • cargo build -p merry-py links the cdylib on Linux with the build script active

macOS linking was not exercised in this environment. The Python SDK workflow matrix covers macOS, where maturin develop already supplied the same arguments, so the new path is exercised by plain cargo build/cargo test on a macOS checkout.

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)
@locez
locez merged commit 6a1b855 into main Sep 16, 2026
8 checks passed
@locez
locez deleted the fix/merry-py-extension-module-link-args branch September 16, 2026 05:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant