rust/compiler/rustc_metadata
bors 8c35f4a85e Auto merge of #137535 - Kobzol:split-metadata, r=petrochenkov
Introduce `-Zembed-metadata` to allow omitting full metadata from rlibs and dylibs

This is a continuation of https://github.com/rust-lang/rust/pull/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 https://github.com/rust-lang/rust/issues/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](https://github.com/rust-lang/rust/pull/120855#issuecomment-1937018169) shows an example of binary/artifact size wins that can be achieved using this approach.

Contrary to https://github.com/rust-lang/rust/pull/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 https://github.com/rust-lang/rust/issues/23366
Closes https://github.com/rust-lang/rust/issues/29511
Fixes https://github.com/rust-lang/rust/issues/57076

Another attempt of https://github.com/rust-lang/rust/pull/93945 and https://github.com/rust-lang/rust/pull/120855.

r? `@petrochenkov`
2025-04-01 10:40:06 +00:00
..
src Auto merge of #137535 - Kobzol:split-metadata, r=petrochenkov 2025-04-01 10:40:06 +00:00
Cargo.toml Use -Wunused_crate_dependencies for compiler crates. 2025-03-20 08:59:43 +11:00
messages.ftl Add an error when full metadata was not found 2025-03-31 09:44:41 +02:00