Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rust: allow linking with dynamic libstd #14224

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

bonzini
Copy link
Collaborator

@bonzini bonzini commented Feb 5, 2025

As a first step towards fixing #8828, allow linking Rust bin crates with dynamic libstd.

staticlib and cdylib crates cannot yet do this, but this can be extended later on; in the meanwhile, this PR creates the API with a minimal implementation.

@bonzini bonzini force-pushed the rust-dynamic-std branch 3 times, most recently from df1552f to daf6d4a Compare February 5, 2025 10:37
@bonzini bonzini marked this pull request as ready for review February 5, 2025 12:22
@bonzini bonzini force-pushed the rust-dynamic-std branch 2 times, most recently from 8f12ae2 to 273198e Compare February 5, 2025 15:55
Allow adding extra directories to the rpath.  Rust needs this when Rustup
is in use.

Signed-off-by: Paolo Bonzini <[email protected]>
RustCompiler.build_rpath_args works by appending the directory to the
arguments computed by self.linker.build_rpath_args.  This does not
work if there is no argument to begin with, which happens for example
in program crates.

Use the new extra_paths argument to force inclusion of the libdir into
the rpath of the binary, even in that case.

Signed-off-by: Paolo Bonzini <[email protected]>
As an initial implementation, simply adding "-C prefer-dynamic" works
for binary crates (as well as dylib and proc-macro that already used it).
In the future this could be extended to other crate types.  For more
information see the comment in the changed file, as well as
mesonbuild#8828 and
mesonbuild#14215.

Signed-off-by: Paolo Bonzini <[email protected]>
Comment on lines +2124 to +2127
# -Z staticlib-prefer-dynamic) are not yet stable; alternatively,
# one could use "--emit obj" (implemented in the pull request at
# https://github.com/mesonbuild/meson/pull/11213) or "--emit rlib"
# (officially not recommended for linking with C programs).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cdylibs should be okay for this i think?

-Cprefer-dynamic just works on cdylibs today.

Comment on lines 212 to +214
for arg in args:
rustc_rpath_args.append('-C')
rustc_rpath_args.append(f'link-arg={arg}:{self.get_target_libdir()}')
rustc_rpath_args.append('link-arg=' + arg)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

quasi related, btw: meson currently doesn't have a unified way to specifically pass link args for rust, only these ad-hoc spots #13537

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants