-
Notifications
You must be signed in to change notification settings - Fork 13.3k
[idea] Add an option put the metadata in a separate file #57076
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
Comments
If I understand this correctly, an another advantage is that we'd get a |
@Xanewok If I read rust-lang/cargo#3501 correctly, it is technically possible to do so already, but cargo doesn't support it. |
If this is accepted rust-lang/cargo#4831 could be done without invoking rustc twice. Just let rustc print a message when the metadata file is emitted and allow it to read |
Triage: no real changes; sort of a duplicate of the cargo ticket, kinda. |
Introduce -Zsplit-metadata option This will split the crate metadata out of library files. Instead only the svh and a bit of extra metadata is preserved to allow for loading the right rmeta file. This significantly reduces library size. In addition it allows for cheaper checks if different library files are the same crate. A fair amount of the complexity in this PR is to work around the fact that cargo doesn't directly support this option yet. Fixes rust-lang#23366 Fixes rust-lang#57076 Revives rust-lang#93945
Introduce `-Zembed-metadata` to allow omitting full metadata from rlibs and dylibs This is a continuation of rust-lang/rust#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 `-Zembed-metadata=[no|yes]`, with the default being `yes` (see rust-lang/rust#57076 for context). When set to `no`, 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](rust-lang/rust#120855 (comment)) shows an example of binary/artifact size wins that can be achieved using this approach. Contrary to rust-lang/rust#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). Fixes rust-lang/rust#23366 Closes rust-lang/rust#29511 Fixes rust-lang/rust#57076 Another attempt of rust-lang/rust#93945 and rust-lang/rust#120855. r? `@petrochenkov`
Detailed design
When
-Zsplit-metadata
is passed to rustc, it will put the metadata normally inside arlib
ordylib
in a separatermeta
file. Therlib
/dylib
will contain the SVH to prevent accidentally mixing thermeta
andrlib
/dylib
of different compilations.Advantages
This would make the increase in size of #56987 easily fixable by deleting the
rlib
files, while keeping thermeta
files. Those are not necessary anyway, becauserustc_driver.so
already contains the code.This will decrease
staticlib
,dylib
andcdylib
compilation time, because there is no need to copy all object files to a new archive to remove therust.metadata.bin
file from therlib
.rust/src/librustc_codegen_llvm/back/link.rs
Lines 1340 to 1342 in 6d9640b
Disadvantages
Rustc and cargo get a bit more complex.
The text was updated successfully, but these errors were encountered: