Skip to content

Conversation

@bjorn3
Copy link
Member

@bjorn3 bjorn3 commented Jan 13, 2026

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

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.
@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
Copy link
Collaborator

rustbot commented Jan 13, 2026

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
Copy link
Member Author

bjorn3 commented Jan 13, 2026

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
if matches!(mode, Mode::Std) {
if matches!(mode, Mode::Std | Mode::Rustc | Mode::Codegen) {
cargo.arg("-Zno-embed-metadata");
}
Copy link
Member Author

@bjorn3 bjorn3 Jan 13, 2026

Choose a reason for hiding this comment

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

Maybe we could move this into run_cargo as that is the only function which supports -Zno-embed-metadata currently?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, it would be nice, we could then do some asserts, e.g. that you are not using OnlyRlib (although it's tricky - OnlyDylib is in theory also not valid for -Zno-embed-metadata, but it works if the thing you build doesn't need to be linked to through normal Rust means).

Copy link
Member Author

Choose a reason for hiding this comment

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

OnlyDylib is only used for codegen backends, which don't need the crate metadata. I've moved the -Zno-embed-metadata to run_cargo.

@rust-bors
Copy link
Contributor

rust-bors bot commented Jan 13, 2026

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

@bjorn3
Copy link
Member Author

bjorn3 commented Jan 13, 2026

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
Copy link
Member

Kobzol commented Jan 13, 2026

r? @Kobzol

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

rust-bors bot commented Jan 13, 2026

☀️ 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
Copy link
Member Author

bjorn3 commented Jan 13, 2026

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
Copy link
Member

Kobzol commented Jan 13, 2026

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
Copy link
Member Author

bjorn3 commented Jan 13, 2026

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
Copy link
Contributor

rust-bors bot commented Jan 13, 2026

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

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
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
Copy link
Member

Kobzol commented Jan 14, 2026

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%!

if matches!(mode, Mode::Std) {
if matches!(mode, Mode::Std | Mode::Rustc | Mode::Codegen) {
cargo.arg("-Zno-embed-metadata");
}
Copy link
Member

Choose a reason for hiding this comment

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

Yeah, it would be nice, we could then do some asserts, e.g. that you are not using OnlyRlib (although it's tricky - OnlyDylib is in theory also not valid for -Zno-embed-metadata, but it works if the thing you build doesn't need to be linked to through normal Rust means).

@rust-log-analyzer
Copy link
Collaborator

The job pr-check-1 failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
   |
69 | extern crate proc_macro2;
   | ^^^^^^^^^^^^^^^^^^^^^^^^^

error: only metadata stub found for `rlib` dependency `quote`
       please provide path to the corresponding .rmeta file with full metadata
  --> /cargo/registry/src/index.crates.io-1949cf8c6b5b557f/serde_derive-1.0.228/src/lib.rs:70:1
   |
70 | extern crate quote;
   | ^^^^^^^^^^^^^^^^^^^

error: only metadata stub found for `rlib` dependency `syn`
       please provide path to the corresponding .rmeta file with full metadata
  --> /cargo/registry/src/index.crates.io-1949cf8c6b5b557f/serde_derive-1.0.228/src/lib.rs:71:1
   |
71 | extern crate syn;
   | ^^^^^^^^^^^^^^^^^

error[E0432]: unresolved imports `quote::quote_spanned`, `quote::ToTokens`, `quote::quote_spanned`, `quote::quote_spanned`, `quote::quote_spanned`, `quote::ToTokens`, `quote::quote_spanned`, `quote::quote_spanned`, `quote::format_ident`, `quote::quote_spanned`
  --> /cargo/registry/src/index.crates.io-1949cf8c6b5b557f/serde_derive-1.0.228/src/de.rs:8:20
   |
 8 | use quote::{quote, quote_spanned, ToTokens};
   |                    ^^^^^^^^^^^^^  ^^^^^^^^
   |
  ::: /cargo/registry/src/index.crates.io-1949cf8c6b5b557f/serde_derive-1.0.228/src/de/enum_adjacently.rs:15:20
   |
15 | use quote::{quote, quote_spanned};
   |                    ^^^^^^^^^^^^^
   |
  ::: /cargo/registry/src/index.crates.io-1949cf8c6b5b557f/serde_derive-1.0.228/src/de/enum_externally.rs:19:20
   |
19 | use quote::{quote, quote_spanned};
   |                    ^^^^^^^^^^^^^
   |
  ::: /cargo/registry/src/index.crates.io-1949cf8c6b5b557f/serde_derive-1.0.228/src/de/enum_untagged.rs:18:20
   |
18 | use quote::{quote, quote_spanned};
   |                    ^^^^^^^^^^^^^
   |
  ::: /cargo/registry/src/index.crates.io-1949cf8c6b5b557f/serde_derive-1.0.228/src/de/identifier.rs:10:20
   |
10 | use quote::{quote, ToTokens};
   |                    ^^^^^^^^
   |
  ::: /cargo/registry/src/index.crates.io-1949cf8c6b5b557f/serde_derive-1.0.228/src/de/struct_.rs:13:20
   |
13 | use quote::{quote, quote_spanned};
   |                    ^^^^^^^^^^^^^
   |
  ::: /cargo/registry/src/index.crates.io-1949cf8c6b5b557f/serde_derive-1.0.228/src/de/tuple.rs:9:20
   |
 9 | use quote::{quote, quote_spanned};
   |                    ^^^^^^^^^^^^^
   |
  ::: /cargo/registry/src/index.crates.io-1949cf8c6b5b557f/serde_derive-1.0.228/src/pretend.rs:4:13
   |
 4 | use quote::{format_ident, quote};
   |             ^^^^^^^^^^^^
   |
  ::: /cargo/registry/src/index.crates.io-1949cf8c6b5b557f/serde_derive-1.0.228/src/ser.rs:8:20
   |
 8 | use quote::{quote, quote_spanned};
   |                    ^^^^^^^^^^^^^

For more information about this error, try `rustc --explain E0432`.
[RUSTC-TIMING] serde_derive test:false 0.125
error: could not compile `serde_derive` (lib) due to 4 previous errors

@bjorn3
Copy link
Member Author

bjorn3 commented Jan 14, 2026

I can't reproduce the CI failure locally. Could it be related to rust-lang/cargo#16503?

@Kobzol
Copy link
Member

Kobzol commented Jan 14, 2026

Possibly, although my first guess is that we are not copying rustc .rmeta files somewhere in bootstrap.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants