Rust binaries cannot load relocatable libraries on macOS without -rpath
#127100
Labels
A-linkage
Area: linking into static, shared libraries and binaries
C-bug
Category: This is a bug.
O-macos
Operating system: macOS
T-cargo
Relevant to the cargo team, which will review and decide on the PR/issue.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Hi all,
I tried to link against a relocatable shared library on macOS with the following demo project: https://github.com/amyspark/rust-demo-rpath
The library
rpath-meson
is built with Ninja:The library at this point is relocatable, as described in "Dynamic Library Identification" over at the Apple Developer forums:
otool output
This library is made available to Cargo through
pkg-config
using:I expected to see this happen:
Instead, this happened:
This is because Cargo does not insert RPATH entries on its own. From searching older issues, a list of which is attached below, it seems that Cargo expects the environment to add the requisite flags. I have added such a flag through the pkg-config module; even though it is properly detected by
pkg-config
and forwarded as arustc-link-arg
entry,rustc-link-arg
flags are skipped by Cargo. This seems to be a known issue:-rpath
flags is disallowed)DEP_*
environment variables for that)Using
DEP_*
environment variables is very vaguely documented in rust-lang/cargo#7846 (comment) (there's no mention ifcargo:rustc-link-arg
s are exposed likecargo:include
entries). However, it does not scale because it needs the participation of all consumers of the relocatable library.Using a pkg-config module or other such tool would still need Cargo to support bubbling
rustc-link-arg
s up to those crates generating loadable binaries.Would it be possible for Rust/Cargo to consider bubbling up linker flags from
-sys
crates up to the apex consumer (shared library/executable), or insert them on its own?Meta
rustc --version --verbose
:Backtrace
The text was updated successfully, but these errors were encountered: