-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Introduce -Zsplit-metadata
to split metadata out of rlibs/dylibs
#137535
Open
Kobzol
wants to merge
6
commits into
rust-lang:master
Choose a base branch
from
Kobzol:split-metadata
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+248
−54
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The job Click to see the possible cause of the failure (guessed by this bot)
|
(The test failure is the one situation not yet implemented, which is described in the PR description - |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
A-run-make
Area: port run-make Makefiles to rmake.rs
S-waiting-on-review
Status: Awaiting review from the assignee but also interested parties.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a continuation of #120855 (I was mentored by @bjorn3 to move it forward). Most of the original code was written by bjorn3, I tried to clean it up a bit and add some documentation and tests.
This PR introduces a new unstable compiler flag called
-Zsplit-metadata
(see #57076 for context). When used, rustc will only store a small metadata stub inside rlibs/dylibs instead of the full metadata, to keep their size smaller. It should be used in combination with--emit=metadata
, so that the users of such a compiled library can still read the metadata from the corresponding.rmeta
file. This comment shows an example of binary/artifact size wins that can be achieved using this approach.Contrary to #120855, this PR only introduces the new flag, along with a couple of run-make tests and documentation, but does not yet use it in bootstrap to actually compile rustc. I plan to do that as a follow-up step (along with integration in Cargo, which should ideally just always pass this flag to reduce the size of target directories).
There is one unresolved thing that I wanted to discuss with the reviewer(s) first, and one smaller nit.
Lookup of
.rmeta
filesWith
-Zsplit-metadata
, when rustc tries to link against a rlib/dylib that only has the stub metadata, it needs to be able to find the corresponding .rmeta file somehow. Currently, there are two codepaths taken in rustc regarding this dependency lookup:If you don't specify
--extern
, the usual list of possible dependency locations is searched (including-L
). The compiler already does this and finds the corresponding .rmeta files. This already works out of the box also with-Zsplit-metadata
in this PR.If you do specify
--extern
, the step above is skipped, and the--extern
paths are searched instead. This is not fully supported yet in this PR. What we do now is add a simple heuristic that tries to add a.rmeta
file path located in the same directory as the corresponding rlib/dylib file to the search paths. This will probably work for the majority of use-cases, but is not a fully general solution. If the.rmeta
file is not found at this location, we should probably invoke the general library search path lookup linked above. However, the locator code is currently structured in a way where this is not completely trivial. So I wanted to ask which approach do you consider to be better:find_commandline_library
, and store the information whether we only found a stub or not. Then, if we only found a stub, but no.rmeta
file, invokefind_library_crate
to try to find a corresponding.rmeta
file, and use it instead (if found).find_commandline_library
is not exclusive withfind_library_crate
, so that the library search paths and the--extern
paths are first combined together (with--extern
probably taking priority), and only then is the final SVH/metadata lookup performed. This would pretty much make this work also with split metadata. I found it quite surprising that when--extern
is passed, the-L
search logic is completely skipped, so this also looks like a nice cleanup. I'm not sure if it wouldn't have some unexpected behavior change though.Note that currently it is not possible to pass a full path to the corresponding
.rmeta
file explicitly, outside of using-L
, but I don't think that it should be needed. In theory, we could also literally store the (relative) path to the.rmeta
file on disk in the stub metadata header, but that's probably also not ideal, because the.rmeta
/rlib/dylib file could move independently of one another.Interaction with
--emit=metadata
Currently, if the user does not use
--emit=metadata
with-Zsplit-metadata
, no metadata will be emitted (there will be no.rmeta
file, and the rlib/dylib will only contain a stub). This is most likely a usage error, but in theory it could be a valid use-case (same as we e.g. allow--emit=metadata
for binaries, which just produces an empty.rmeta
file without any warning). As an alternative, we could emit a warning/error about this, or automatically fill in--emit=metadata
when-Zsplit-metadata
is used if no--emit
flag was specified.Fixes #23366
Closes #29511
Fixes #57076
Another attempt of #93945 and #120855.
r? @petrochenkov