Skip to content

Build rustc and codegen backends with -Zembed-metadata=no - #151061

Open
bjorn3 wants to merge 1 commit into
rust-lang:mainfrom
bjorn3:rustc_no_embed_metadata
Open

Build rustc and codegen backends with -Zembed-metadata=no#151061
bjorn3 wants to merge 1 commit into
rust-lang:mainfrom
bjorn3:rustc_no_embed_metadata

Conversation

@bjorn3

@bjorn3 bjorn3 commented Jan 13, 2026

Copy link
Copy Markdown
Member

View all comments

While this won't change much for rustc and rustc-dev, it should make codegen backends a bit smaller by omitting their crate metadata. In addition it should reduce disk usage while compiling.

Follow up to #145343

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) labels Jan 13, 2026
@rustbot

rustbot commented Jan 13, 2026

Copy link
Copy Markdown
Collaborator

r? @jieyouxu

rustbot has assigned @jieyouxu.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@bjorn3

bjorn3 commented Jan 13, 2026

Copy link
Copy Markdown
Member Author

cc @Kobzol

@bors try

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Jan 13, 2026
Build rustc and codegen backends with -Zno-embed-metadata
Comment thread src/bootstrap/src/core/builder/cargo.rs
@rust-bors

rust-bors Bot commented Jan 13, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: d9668cf (d9668cf85dd8b3cac5d57f7b5b8b1508112db899, parent: b2a322beb29110e22a1782e2ce5ed2a0719b81ed)

@bjorn3

bjorn3 commented Jan 13, 2026

Copy link
Copy Markdown
Member Author

And the baseline to compare the disk space against for try builds:

@bors try

rust-bors Bot pushed a commit that referenced this pull request Jan 13, 2026
Build rustc and codegen backends with -Zno-embed-metadata
@rust-bors

This comment has been minimized.

@Kobzol

Kobzol commented Jan 13, 2026

Copy link
Copy Markdown
Member

r? @Kobzol

@rustbot rustbot assigned Kobzol and unassigned jieyouxu Jan 13, 2026
@rust-bors

rust-bors Bot commented Jan 13, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: db6fee5 (db6fee556e8bf32d307f378d2acbb52ba25b5a8b, parent: db1484bdee1cb065b322a5bd512b39c49dadc9e5)

@bjorn3
bjorn3 force-pushed the rustc_no_embed_metadata branch from 6e25c8e to b6605c3 Compare January 13, 2026 19:29
@bjorn3

bjorn3 commented Jan 13, 2026

Copy link
Copy Markdown
Member Author

For the try build it saves 2GB or 4% of the total space the build takes (46GB -> 44GB). Hoped it would be a bit more, but still not bad I think. And maybe it gives a higher relative saving when not collecting PGO profiles?

@rustbot ready

@Kobzol

Kobzol commented Jan 13, 2026

Copy link
Copy Markdown
Member

Let's do a full try build to see the codegen backend savings (we can compare them with the parent commit, should be enough), and also run perf., just in case.

@bors try jobs=dist-x86_64-linux @rust-timer queue

@rust-timer

This comment has been minimized.

@rust-bors

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jan 13, 2026
rust-bors Bot pushed a commit that referenced this pull request Jan 13, 2026
Build rustc and codegen backends with -Zno-embed-metadata


try-job: dist-x86_64-linux
@bjorn3

bjorn3 commented Jan 13, 2026

Copy link
Copy Markdown
Member Author

For cg_clif the .rmeta section of the codegen backend dylib when built from the cg_clif repo is almost 1MB out of the 15MB the full dylib uses. The savings from this PR should be near identical, though the full size of the dylib may be different due to different codegen options.

@rust-bors

rust-bors Bot commented Jan 13, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: 2cbe7f7 (2cbe7f7eda161d598e47752d03fc34a1539dad7c, parent: 9b81629631b382fd49ee3a20ac47797b1467e52d)

@rust-timer

This comment has been minimized.

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (2cbe7f7): comparison URL.

Overall result: no relevant changes - no action needed

Benchmarking this pull request means it may be perf-sensitive – we'll automatically label it not fit for rolling up. You can override this, but we strongly advise not to, due to possible changes in compiler perf.

@bors rollup=never
@rustbot label: -S-waiting-on-perf -perf-regression

Instruction count

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

Max RSS (memory usage)

Results (secondary -1.4%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
2.6% [2.5%, 2.7%] 2
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-4.1% [-6.1%, -2.2%] 3
All ❌✅ (primary) - - 0

Cycles

Results (secondary 2.7%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
2.7% [2.1%, 3.1%] 6
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Binary size

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

Bootstrap: 476.337s -> 475.884s (-0.10%)
Artifact size: 383.08 MiB -> 383.14 MiB (0.02%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jan 13, 2026
@Kobzol

Kobzol commented Jan 14, 2026

Copy link
Copy Markdown
Member

Before:

2026-01-13T17:34:05.4564183Z -rw-r--r-- 1 root root  2.5M Jan 13 16:45 rustc-codegen-cranelift-nightly-x86_64-unknown-linux-gnu.tar.xz
2026-01-13T17:34:05.4565056Z -rw-r--r-- 1 root root  1.1M Jan 13 17:19 rustc-codegen-gcc-nightly-x86_64-unknown-linux-gnu.tar.xz

After:

2026-01-13T22:55:02.7071176Z -rw-r--r-- 1 root root  2.3M Jan 13 22:07 rustc-codegen-cranelift-nightly-x86_64-unknown-linux-gnu.tar.xz
2026-01-13T22:55:02.7072077Z -rw-r--r-- 1 root root  827K Jan 13 22:40 rustc-codegen-gcc-nightly-x86_64-unknown-linux-gnu.tar.xz

And no other components seem to have changed their size. Yeah, pretty nice, a solid ~10%!

Comment thread src/bootstrap/src/core/build_steps/compile.rs
Comment thread src/bootstrap/src/core/builder/cargo.rs
@bjorn3
bjorn3 force-pushed the rustc_no_embed_metadata branch from 158bff0 to 14dbf7e Compare August 13, 2026 13:12
@rustbot

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@bjorn3 bjorn3 changed the title Build rustc and codegen backends with -Zno-embed-metadata Build rustc and codegen backends with -Zembed-metadata=no Aug 14, 2026
@rustbot rustbot added the A-testsuite Area: The testsuite used to check the correctness of rustc label Aug 14, 2026
@bjorn3

bjorn3 commented Aug 14, 2026

Copy link
Copy Markdown
Member Author

Managed to reproduce it locally. Seems to be working now. I wasn't able to unconditionally pass -Zembed-metadata=no though because of rust-lang/cargo#17359.

@bjorn3
bjorn3 force-pushed the rustc_no_embed_metadata branch from cb2e7ce to b61abad Compare August 14, 2026 13:49
@bjorn3

bjorn3 commented Aug 14, 2026

Copy link
Copy Markdown
Member Author

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Aug 14, 2026

@Kobzol Kobzol left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit confused by the move from Builder::cargo to run_cargo. So there were some places that use Builder::cargo, but not run_cargo, for which this broke?

View changes since this review

Comment thread src/bootstrap/src/core/build_steps/compile.rs Outdated
@bjorn3

bjorn3 commented Aug 14, 2026

Copy link
Copy Markdown
Member Author

So there were some places that use Builder::cargo, but not run_cargo, for which this broke?

The run-make-support build code doesn't use run_cargo. Previously this would be skipped by the Mode::Std check, but with that check gone, run-make-support would be built using -Zembed-metadata=no, which breaks compiletest.

@bjorn3
bjorn3 force-pushed the rustc_no_embed_metadata branch from b61abad to 5e75882 Compare August 14, 2026 14:05
@Kobzol

Kobzol commented Aug 14, 2026

Copy link
Copy Markdown
Member

Hmm, it's not just compiletest, rustdoc also breaks if we apply this everywhere:

error: only metadata stub found for `rlib` dependency `rustc_public` please provide path to the corresponding .rmeta file with full metadata
  --> src/librustdoc/lib.rs:35:1
   |
35 | extern crate rustc_driver;
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^

error: could not compile `rustdoc` (lib) due to 1 previous error

@bjorn3

bjorn3 commented Aug 14, 2026

Copy link
Copy Markdown
Member Author

Looks like someone decided to add a dependency on rustc_public to rustc_driver. That would have to be the other way around for rustc_public to function without manually linking in rustc_driver as user of rustc_public. That said, I don't understand how that error you got would be triggered. Both librustc_public.rmeta and librustc_public.rlib should be included in the sysroot.

@Kobzol

Kobzol commented Aug 14, 2026

Copy link
Copy Markdown
Member

Sorry, I tried this in a fresh checkout and didn't port your rustc_public allowlist changed over. Nevermind.

JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Aug 15, 2026
…ough, r=jieyouxu

Explicitly pass run_make_support rlib/rmeta paths to compiletest

This should unblock rust-lang#151061, and helps with rust-lang/cargo#17359 from the side of run-make-support.

I tested this with `-Zembed-metadata=no` applied to everything (in `Builder::cargo`), it works now both with and without it (that's not to say that applying `-Zembed-metadata=no` won't break something else, ofc).

CC @bjorn3

r? jieyouxu

---

try-job: aarch64-apple-1
try-job: x86_64-msvc-1
try-job: i686-msvc-1
try-job: aarch64-msvc-1
try-job: x86_64-mingw-1
try-job: armhf-gnu
rust-bors Bot pushed a commit that referenced this pull request Aug 15, 2026
Rollup merge of #161102 - Kobzol:compiletest-runmake-passthrough, r=jieyouxu

Explicitly pass run_make_support rlib/rmeta paths to compiletest

This should unblock #151061, and helps with rust-lang/cargo#17359 from the side of run-make-support.

I tested this with `-Zembed-metadata=no` applied to everything (in `Builder::cargo`), it works now both with and without it (that's not to say that applying `-Zembed-metadata=no` won't break something else, ofc).

CC @bjorn3

r? jieyouxu

---

try-job: aarch64-apple-1
try-job: x86_64-msvc-1
try-job: i686-msvc-1
try-job: aarch64-msvc-1
try-job: x86_64-mingw-1
try-job: armhf-gnu
rust-timer added a commit that referenced this pull request Aug 15, 2026
Rollup merge of #161102 - Kobzol:compiletest-runmake-passthrough, r=jieyouxu

Explicitly pass run_make_support rlib/rmeta paths to compiletest

This should unblock #151061, and helps with rust-lang/cargo#17359 from the side of run-make-support.

I tested this with `-Zembed-metadata=no` applied to everything (in `Builder::cargo`), it works now both with and without it (that's not to say that applying `-Zembed-metadata=no` won't break something else, ofc).

CC @bjorn3

r? jieyouxu

---

try-job: aarch64-apple-1
try-job: x86_64-msvc-1
try-job: i686-msvc-1
try-job: aarch64-msvc-1
try-job: x86_64-mingw-1
try-job: armhf-gnu
@Kobzol

Kobzol commented Aug 15, 2026

Copy link
Copy Markdown
Member

Could you please rebase this onto #161102, and apply it to everything in Builder::cargo?

While this won't change much for rustc and rustc-dev, it should make
codegen backends a bit smaller by omitting their crate metadata. In
addition it should reduce disk usage while compiling.
@bjorn3
bjorn3 force-pushed the rustc_no_embed_metadata branch from 5e75882 to 005f20e Compare August 16, 2026 12:09
@rustbot

rustbot commented Aug 16, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@Kobzol

Kobzol commented Aug 16, 2026

Copy link
Copy Markdown
Member

You can r=me if CI passes.

@rust-log-analyzer

Copy link
Copy Markdown
Collaborator

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

Click to see the possible cause of the failure (guessed by this bot)
WARNING: Ignoring `RUSTC_WRAPPER` environment variable, Miri does not support wrapping.
error: unknown `-Z` flag specified: no-embed-metadata

For available unstable features, see https://doc.rust-lang.org/nightly/cargo/reference/unstable.html
If you intended to use an unstable rustc feature, try setting `RUSTFLAGS="-Zno-embed-metadata"`
Command `/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/cargo-miri miri test --target x86_64-unknown-linux-gnu -Zbinary-dep-depinfo -j 4 -Zroot-dir=/checkout -Zno-embed-metadata --locked --color=always --manifest-path /checkout/src/tools/miri/test-cargo-miri/Cargo.toml --workspace -- [workdir=/checkout]` failed with exit code 101
Created at: src/bootstrap/src/core/builder/mod.rs:1446:23
Executed at: src/bootstrap/src/core/build_steps/test.rs:857:19

Command has failed. Rerun with -v to see more details.
Bootstrap failed while executing `test --stage 2 miri cargo-miri`
Currently active steps:
test::CargoMiri { target: x86_64-unknown-linux-gnu } at src/bootstrap/src/core/build_steps/test.rs:791
Build completed unsuccessfully in 0:52:47
  local time: Sun Aug 16 13:06:08 UTC 2026

@Kobzol

Kobzol commented Aug 16, 2026

Copy link
Copy Markdown
Member

Hmm, there are some steps that run with in-tree Cargo even without self.local_rebuild. I guess that it will be better to wait for the beta bump, which should happen soon, and then use -Zembed-metadata=no unconditionally.

@bjorn3

bjorn3 commented Aug 16, 2026

Copy link
Copy Markdown
Member Author

@rustbot blocked

@rustbot rustbot added S-blocked Status: Blocked on something else such as an RFC or other implementation work. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-testsuite Area: The testsuite used to check the correctness of rustc S-blocked Status: Blocked on something else such as an RFC or other implementation work. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants