From 523d0edfdcbe759789f54fa4885addecf0937807 Mon Sep 17 00:00:00 2001 From: messense Date: Fri, 19 Feb 2021 22:16:34 +0800 Subject: [PATCH] Set a more reasonable LC_ID_DYLIB entry on macOS --- Changelog.md | 1 + src/compile.rs | 22 +++++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/Changelog.md b/Changelog.md index 6ee59cdad..e5235224b 100644 --- a/Changelog.md +++ b/Changelog.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * Change manylinux default version based on target arch by messense in [#424](https://github.com/PyO3/maturin/pull/424) * Support local path dependencies in source distribution (i.e. you can now package a workspace into an sdist) + * Set a more reasonable LC_ID_DYLIB entry on macOS by messense [#433](https://github.com/PyO3/maturin/pull/433) ## 0.9.4 - 2021-02-18 diff --git a/src/compile.rs b/src/compile.rs index 4d2b99e30..9322657ba 100644 --- a/src/compile.rs +++ b/src/compile.rs @@ -133,10 +133,30 @@ fn compile_target( } } + let module_name = &context.module_name; + let so_filename = match python_interpreter { + Some(python_interpreter) => python_interpreter.get_library_name(module_name), + // abi3 + None => { + format!("{base}.abi3.so", base = module_name) + } + }; + // Change LC_ID_DYLIB to the finaly .so name for macOS targets to avoid linking with + // non-existent library. + // See https://github.com/PyO3/setuptools-rust/issues/106 for detail + let macos_dylib_install_name = format!("link-args=-Wl,-install_name,@rpath/{}", so_filename); + // https://github.com/PyO3/pyo3/issues/88#issuecomment-337744403 if context.target.is_macos() { if let BridgeModel::Bindings(_) | BridgeModel::BindingsAbi3(_, _) = bindings_crate { - let mac_args = &["-C", "link-arg=-undefined", "-C", "link-arg=dynamic_lookup"]; + let mac_args = &[ + "-C", + "link-arg=-undefined", + "-C", + "link-arg=dynamic_lookup", + "-C", + &macos_dylib_install_name, + ]; rustc_args.extend(mac_args); } }