-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Support linking to rust dylib with --crate-type staticlib #106560
Support linking to rust dylib with --crate-type staticlib #106560
Conversation
r? @nagisa (rustbot has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
1c48992
to
7efedaf
Compare
r? rust-lang/compiler (I would've assigned petrochenkov, but IIRC they're busy too) |
r? compiler |
r? compiler |
r? compiler (trying again since @Nilstrieb already rerolled) |
Okay clearly we're just playing spin the bottle for review here. So let me nominate to make sure we can find the right person in a meeting. |
I feel like this isn't a lang issue at all. |
We discussed this in today's @rust-lang/lang meeting. We agreed that we're comfortable with T-compiler handling this issue. We also felt like, in general, we'd love to have some kind of Rust team whose purview directly encompasses linking and similar issues like this. |
Looks like the test doesn't work when cross-compiling. Disabled it for cross compiling just like a similar test for cdylib. |
@bors r=pnkfelix The only change since the last review is a new ignore-cross-compile directive for a test that needs it. |
⌛ Testing commit 47be060 with merge d55a160f23727197173156b4dcd1b17712340a6c... |
The job Click to see the possible cause of the failure (guessed by this bot)
|
💔 Test failed - checks-actions |
This comment was marked as off-topic.
This comment was marked as off-topic.
☀️ Test successful - checks-actions |
Finished benchmarking commit (63fc57b): comparison URL. Overall result: no relevant changes - no action needed@rustbot label: -perf-regression Instruction countThis benchmark run did not return any relevant results for this metric. Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesThis benchmark run did not return any relevant results for this metric. Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 657.481s -> 657.842s (0.05%) |
This allows for example dynamically linking libstd, while statically linking the user crate into an executable or C dynamic library. For this two unstable flags (
-Z staticlib-allow-rdylib-deps
and-Z staticlib-prefer-dynamic
) are introduced. Without the former you get an error. The latter is the equivalent to-C prefer-dynamic
for the staticlib crate type to indicate that dynamically linking is preferred when both options are available, like for libstd. Care must be taken to ensure that no crate ends up being merged into two distinct staticlibs that are linked together. Doing so will cause a linker error at best and undefined behavior at worst. In addition two distinct staticlibs compiled by different rustc may not be combined under any circumstances due to some rustc private symbols not being mangled.To successfully link a staticlib,
--print native-static-libs
can be used while compiling to ask rustc for the linker flags necessary when linking the staticlib. This is an existing flag which previously only listed native libraries. It has been extended to list rust dylibs too. Trying to locate libstd yourself to link against it is not supported and may break if for example the libstd of multiple rustc versions are put in the same directory.For an example on how to use this see the
src/test/run-make-fulldeps/staticlib-dylib-linkage/
test.