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

Support linking to rust dylib with --crate-type staticlib #106560

Merged
merged 6 commits into from
May 10, 2023

Conversation

bjorn3
Copy link
Member

@bjorn3 bjorn3 commented Jan 7, 2023

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.

@bjorn3 bjorn3 added A-linkage Area: linking into static, shared libraries and binaries T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jan 7, 2023
@rustbot
Copy link
Collaborator

rustbot commented Jan 7, 2023

r? @nagisa

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 7, 2023
@bjorn3 bjorn3 added the T-lang Relevant to the language team, which will review and decide on the PR/issue. label Jan 7, 2023
@rust-log-analyzer

This comment has been minimized.

@bjorn3 bjorn3 force-pushed the support_staticlib_dylib_linking branch from 1c48992 to 7efedaf Compare January 7, 2023 14:16
@nagisa
Copy link
Member

nagisa commented Jan 9, 2023

r? rust-lang/compiler

(I would've assigned petrochenkov, but IIRC they're busy too)

@rustbot rustbot assigned Noratrieb and unassigned nagisa Jan 9, 2023
@Noratrieb
Copy link
Member

r? compiler

@rustbot rustbot assigned eholk and unassigned Noratrieb Jan 10, 2023
@eholk
Copy link
Contributor

eholk commented Jan 14, 2023

r? compiler

@rustbot rustbot assigned Noratrieb and unassigned eholk Jan 14, 2023
@eholk
Copy link
Contributor

eholk commented Jan 14, 2023

r? compiler

(trying again since @Nilstrieb already rerolled)

@rustbot rustbot assigned jackh726 and unassigned Noratrieb Jan 14, 2023
@jackh726
Copy link
Member

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.

@jackh726 jackh726 added the I-compiler-nominated Nominated for discussion during a compiler team meeting. label Jan 29, 2023
@pnkfelix
Copy link
Member

pnkfelix commented Feb 2, 2023

self-assigning for both review and for bring up at T-lang meeting to find out if they want to weigh in on this feature.

r? @pnkfelix

@rustbot label: +I-lang-nominated -I-compiler-nominated

@rustbot rustbot assigned pnkfelix and unassigned jackh726 Feb 2, 2023
@rustbot rustbot added I-lang-nominated Nominated for discussion during a lang team meeting. and removed I-compiler-nominated Nominated for discussion during a compiler team meeting. labels Feb 2, 2023
@joshtriplett
Copy link
Member

I feel like this isn't a lang issue at all.

@joshtriplett
Copy link
Member

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.

@petrochenkov petrochenkov self-assigned this Feb 8, 2023
@bjorn3
Copy link
Member Author

bjorn3 commented Apr 27, 2023

Looks like the test doesn't work when cross-compiling. Disabled it for cross compiling just like a similar test for cdylib.

@bjorn3
Copy link
Member Author

bjorn3 commented May 9, 2023

@bors r=pnkfelix

The only change since the last review is a new ignore-cross-compile directive for a test that needs it.

@bors
Copy link
Contributor

bors commented May 9, 2023

📌 Commit 47be060 has been approved by pnkfelix

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 9, 2023
@bors
Copy link
Contributor

bors commented May 9, 2023

⌛ Testing commit 47be060 with merge d55a160f23727197173156b4dcd1b17712340a6c...

@rust-log-analyzer
Copy link
Collaborator

The job x86_64-gnu-tools failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
error: failed to push some refs to 'https://github.com/rust-lang-nursery/rust-toolstate'
Sleeping for 3 seconds before retrying push
From https://github.com/rust-lang-nursery/rust-toolstate
 * branch            master     -> FETCH_HEAD
thread 'main' panicked at 'Failed to update toolstate repository with new data', toolstate.rs:436:9
HEAD is now at 839b1a6 (windows CI update)
Build completed unsuccessfully in 0:00:53

@bors
Copy link
Contributor

bors commented May 9, 2023

💔 Test failed - checks-actions

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels May 9, 2023
@Dylan-DPC

This comment was marked as off-topic.

@Dylan-DPC
Copy link
Member

@bors retry
@bors treeclosed=1000

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 9, 2023
@bors
Copy link
Contributor

bors commented May 10, 2023

⌛ Testing commit 47be060 with merge 63fc57b...

@bors
Copy link
Contributor

bors commented May 10, 2023

☀️ Test successful - checks-actions
Approved by: pnkfelix
Pushing 63fc57b to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label May 10, 2023
@bors bors merged commit 63fc57b into rust-lang:master May 10, 2023
@rustbot rustbot added this to the 1.71.0 milestone May 10, 2023
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (63fc57b): comparison URL.

Overall result: no relevant changes - no action needed

@rustbot label: -perf-regression

Instruction count

This benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

Results

This 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.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.0% [-2.5%, -1.5%] 2
All ❌✅ (primary) - - 0

Cycles

This benchmark run did not return any relevant results for this metric.

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 657.481s -> 657.842s (0.05%)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-CLI Area: Command-line interface (CLI) to the compiler A-linkage Area: linking into static, shared libraries and binaries A-testsuite Area: The testsuite used to check the correctness of rustc merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-infra Relevant to the infrastructure team, which will review and decide on the PR/issue. T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.