Auto merge of #145343 - Kobzol:dogfood-z-no-embed-metadata, r=bjorn3
Dogfood `-Zno-embed-metadata` in the standard library This PR dogfoods the [`-Zno-embed-metadata`](https://github.com/rust-lang/cargo/issues/15495) flag in the standard library. This removes the .rmeta portion out of the `libstd.so` file, thus reducing its filesize on disk. Notably, this reduces the amount of MiB that we ship to people who download the standard library. I think that the only way to find out what this breaks is to try to run full CI, and then try to land it on nightly :) r? @ghost
This commit is contained in:
commit
b2a322beb2
11 changed files with 32 additions and 16 deletions
|
|
@ -299,7 +299,8 @@ impl Step for Std {
|
|||
if self.is_for_mir_opt_tests {
|
||||
ArtifactKeepMode::OnlyRmeta
|
||||
} else {
|
||||
ArtifactKeepMode::OnlyRlib
|
||||
// We use -Zno-embed-metadata for the standard library
|
||||
ArtifactKeepMode::BothRlibAndRmeta
|
||||
},
|
||||
);
|
||||
|
||||
|
|
@ -2645,6 +2646,10 @@ pub enum ArtifactKeepMode {
|
|||
OnlyRlib,
|
||||
/// Only keep .rmeta files, ignore .rlib files
|
||||
OnlyRmeta,
|
||||
/// Keep both .rlib and .rmeta files.
|
||||
/// This is essentially only useful when using `-Zno-embed-metadata`, in which case both the
|
||||
/// .rlib and .rmeta files are needed for compilation/linking.
|
||||
BothRlibAndRmeta,
|
||||
/// Custom logic for keeping an artifact
|
||||
/// It receives the filename of an artifact, and returns true if it should be kept.
|
||||
Custom(Box<dyn Fn(&str) -> bool>),
|
||||
|
|
@ -2701,6 +2706,9 @@ pub fn run_cargo(
|
|||
match &artifact_keep_mode {
|
||||
ArtifactKeepMode::OnlyRlib => filename.ends_with(".rlib"),
|
||||
ArtifactKeepMode::OnlyRmeta => filename.ends_with(".rmeta"),
|
||||
ArtifactKeepMode::BothRlibAndRmeta => {
|
||||
filename.ends_with(".rmeta") || filename.ends_with(".rlib")
|
||||
}
|
||||
ArtifactKeepMode::Custom(func) => func(&filename),
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1095,6 +1095,10 @@ impl Builder<'_> {
|
|||
// Enable usage of unstable features
|
||||
cargo.env("RUSTC_BOOTSTRAP", "1");
|
||||
|
||||
if matches!(mode, Mode::Std) {
|
||||
cargo.arg("-Zno-embed-metadata");
|
||||
}
|
||||
|
||||
if self.config.dump_bootstrap_shims {
|
||||
prepare_behaviour_dump_dir(self.build);
|
||||
|
||||
|
|
|
|||
|
|
@ -28,13 +28,17 @@ fn check_crate_is_unstable(cr: &Crate) {
|
|||
|
||||
print!("- Verifying that sysroot crate '{name}' is an unstable crate ...");
|
||||
|
||||
// Trying to use this crate from a user program should fail.
|
||||
let output = rustc()
|
||||
.crate_type("rlib")
|
||||
.extern_(name, path)
|
||||
.input("-")
|
||||
.stdin_buf(format!("extern crate {name};"))
|
||||
.run_fail();
|
||||
// Checking if rmeta path exists
|
||||
let rmeta_path = path.with_extension("rmeta");
|
||||
|
||||
let mut cmd = rustc();
|
||||
cmd.crate_type("rlib").extern_(name, path); // Pass the rlib
|
||||
|
||||
if rmeta_path.exists() {
|
||||
cmd.extern_(name, &rmeta_path);
|
||||
}
|
||||
|
||||
let output = cmd.input("-").stdin_buf(format!("extern crate {name};")).run_fail();
|
||||
|
||||
// Make sure it failed for the intended reason, not some other reason.
|
||||
// (The actual feature required varies between crates.)
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
//!
|
||||
//! Issue: <https://github.com/rust-lang/rust/issues/31788>
|
||||
|
||||
//@ normalize-stderr: "loaded from .*libstd-.*.rlib" -> "loaded from SYSROOT/libstd-*.rlib"
|
||||
//@ normalize-stderr: "loaded from .*libstd-.*.rmeta" -> "loaded from SYSROOT/libstd-*.rmeta"
|
||||
//@ dont-require-annotations: NOTE
|
||||
|
||||
#![feature(lang_items)]
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ LL | | }
|
|||
| |_^
|
||||
|
|
||||
= note: the lang item is first defined in crate `std` (which `E0152_duplicate_lang_items` depends on)
|
||||
= note: first definition in `std` loaded from SYSROOT/libstd-*.rlib
|
||||
= note: first definition in `std` loaded from SYSROOT/libstd-*.rmeta
|
||||
= note: second definition in the local crate (`E0152_duplicate_lang_items`)
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
//@ normalize-stderr: "loaded from .*liballoc-.*.rlib" -> "loaded from SYSROOT/liballoc-*.rlib"
|
||||
//@ normalize-stderr: "loaded from .*liballoc-.*.rmeta" -> "loaded from SYSROOT/liballoc-*.rmeta"
|
||||
#![feature(lang_items)]
|
||||
|
||||
#[lang = "owned_box"]
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ LL | struct Foo<T>(T);
|
|||
| ^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: the lang item is first defined in crate `alloc` (which `std` depends on)
|
||||
= note: first definition in `alloc` loaded from SYSROOT/liballoc-*.rlib
|
||||
= note: first definition in `alloc` loaded from SYSROOT/liballoc-*.rmeta
|
||||
= note: second definition in the local crate (`E0152`)
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
//@ normalize-stderr: "loaded from .*libcore-.*.rlib" -> "loaded from SYSROOT/libcore-*.rlib"
|
||||
//@ normalize-stderr: "loaded from .*libcore-.*.rmeta" -> "loaded from SYSROOT/libcore-*.rmeta"
|
||||
#![feature(lang_items)]
|
||||
|
||||
#[lang = "sized"]
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ LL | trait Sized {}
|
|||
| ^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: the lang item is first defined in crate `core` (which `std` depends on)
|
||||
= note: first definition in `core` loaded from SYSROOT/libcore-*.rlib
|
||||
= note: first definition in `core` loaded from SYSROOT/libcore-*.rmeta
|
||||
= note: second definition in the local crate (`duplicate`)
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
//@ normalize-stderr: "loaded from .*libstd-.*.rlib" -> "loaded from SYSROOT/libstd-*.rlib"
|
||||
//@ normalize-stderr: "loaded from .*libstd-.*.rmeta" -> "loaded from SYSROOT/libstd-*.rmeta"
|
||||
|
||||
extern crate core;
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ LL | | }
|
|||
| |_^
|
||||
|
|
||||
= note: the lang item is first defined in crate `std` (which `panic_handler_std` depends on)
|
||||
= note: first definition in `std` loaded from SYSROOT/libstd-*.rlib
|
||||
= note: first definition in `std` loaded from SYSROOT/libstd-*.rmeta
|
||||
= note: second definition in the local crate (`panic_handler_std`)
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue