Skip to content

Commit b6605c3

Browse files
committed
Build rustc and codegen backends with -Zno-embed-metadata
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.
1 parent b2a322b commit b6605c3

2 files changed

Lines changed: 14 additions & 9 deletions

File tree

src/bootstrap/src/core/build_steps/compile.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,13 +1185,15 @@ impl Step for Rustc {
11851185
{
11861186
// jemalloc_sys and rustc_public_bridge are not linked into librustc_driver.so,
11871187
// so we need to distribute them as rlib to be able to use them.
1188-
filename.ends_with(".rlib")
1189-
} else {
1190-
// Distribute the rest of the rustc crates as rmeta files only to reduce
1191-
// the tarball sizes by about 50%. The object files are linked into
1192-
// librustc_driver.so, so it is still possible to link against them.
1193-
filename.ends_with(".rmeta")
1188+
if filename.ends_with(".rlib") {
1189+
return true;
1190+
}
11941191
}
1192+
1193+
// Distribute the rest of the rustc crates as rmeta files only to reduce
1194+
// the tarball sizes by about 50%. The object files are linked into
1195+
// librustc_driver.so, so it is still possible to link against them.
1196+
filename.ends_with(".rmeta")
11951197
})),
11961198
);
11971199

@@ -1732,7 +1734,7 @@ impl Step for GccCodegenBackend {
17321734

17331735
let _guard =
17341736
builder.msg(Kind::Build, "codegen backend gcc", Mode::Codegen, build_compiler, host);
1735-
let files = run_cargo(builder, cargo, vec![], &stamp, vec![], ArtifactKeepMode::OnlyRlib);
1737+
let files = run_cargo(builder, cargo, vec![], &stamp, vec![], ArtifactKeepMode::OnlyDylib);
17361738

17371739
GccCodegenBackendOutput {
17381740
stamp: write_codegen_backend_stamp(stamp, files, builder.config.dry_run()),
@@ -1808,7 +1810,7 @@ impl Step for CraneliftCodegenBackend {
18081810
build_compiler,
18091811
target,
18101812
);
1811-
let files = run_cargo(builder, cargo, vec![], &stamp, vec![], ArtifactKeepMode::OnlyRlib);
1813+
let files = run_cargo(builder, cargo, vec![], &stamp, vec![], ArtifactKeepMode::OnlyDylib);
18121814
write_codegen_backend_stamp(stamp, files, builder.config.dry_run())
18131815
}
18141816

@@ -2642,6 +2644,8 @@ pub fn add_to_sysroot(
26422644
/// build stamp, and thus be included in dist archives and copied into sysroots by default.
26432645
/// Note that some kinds of artifacts are copied automatically (e.g. native libraries).
26442646
pub enum ArtifactKeepMode {
2647+
/// Only keep .so files, ignore .rlib and .rmeta files
2648+
OnlyDylib,
26452649
/// Only keep .rlib files, ignore .rmeta files
26462650
OnlyRlib,
26472651
/// Only keep .rmeta files, ignore .rlib files
@@ -2704,6 +2708,7 @@ pub fn run_cargo(
27042708
true
27052709
} else {
27062710
match &artifact_keep_mode {
2711+
ArtifactKeepMode::OnlyDylib => false,
27072712
ArtifactKeepMode::OnlyRlib => filename.ends_with(".rlib"),
27082713
ArtifactKeepMode::OnlyRmeta => filename.ends_with(".rmeta"),
27092714
ArtifactKeepMode::BothRlibAndRmeta => {

src/bootstrap/src/core/builder/cargo.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1095,7 +1095,7 @@ impl Builder<'_> {
10951095
// Enable usage of unstable features
10961096
cargo.env("RUSTC_BOOTSTRAP", "1");
10971097

1098-
if matches!(mode, Mode::Std) {
1098+
if matches!(mode, Mode::Std | Mode::Rustc | Mode::Codegen) {
10991099
cargo.arg("-Zno-embed-metadata");
11001100
}
11011101

0 commit comments

Comments
 (0)