Skip to content

Commit

Permalink
Merge pull request #433 from messense/dylib-install-name
Browse files Browse the repository at this point in the history
Set a more reasonable LC_ID_DYLIB entry on macOS
  • Loading branch information
messense authored Feb 24, 2021
2 parents 0b8c340 + 523d0ed commit c39a595
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
22 changes: 21 additions & 1 deletion src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down

0 comments on commit c39a595

Please sign in to comment.