Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 24 additions & 9 deletions src/bootstrap/src/core/build_steps/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1185,13 +1185,15 @@ impl Step for Rustc {
{
// jemalloc_sys and rustc_public_bridge are not linked into librustc_driver.so,
// so we need to distribute them as rlib to be able to use them.
filename.ends_with(".rlib")
} else {
// Distribute the rest of the rustc crates as rmeta files only to reduce
// the tarball sizes by about 50%. The object files are linked into
// librustc_driver.so, so it is still possible to link against them.
filename.ends_with(".rmeta")
if filename.ends_with(".rlib") {
return true;
}
}

// Distribute the rest of the rustc crates as rmeta files only to reduce
// the tarball sizes by about 50%. The object files are linked into
// librustc_driver.so, so it is still possible to link against them.
filename.ends_with(".rmeta")
})),
);

Expand Down Expand Up @@ -1741,7 +1743,7 @@ impl Step for GccCodegenBackend {

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

GccCodegenBackendOutput {
stamp: write_codegen_backend_stamp(stamp, files, builder.config.dry_run()),
Expand Down Expand Up @@ -1817,7 +1819,7 @@ impl Step for CraneliftCodegenBackend {
build_compiler,
target,
);
let files = run_cargo(builder, cargo, vec![], &stamp, vec![], ArtifactKeepMode::OnlyRlib);
let files = run_cargo(builder, cargo, vec![], &stamp, vec![], ArtifactKeepMode::OnlyDylib);
write_codegen_backend_stamp(stamp, files, builder.config.dry_run())
}

Expand Down Expand Up @@ -2641,6 +2643,8 @@ pub fn add_to_sysroot(
/// build stamp, and thus be included in dist archives and copied into sysroots by default.
/// Note that some kinds of artifacts are copied automatically (e.g. native libraries).
pub enum ArtifactKeepMode {
/// Only keep .so files, ignore .rlib and .rmeta files
OnlyDylib,
/// Only keep .rlib files, ignore .rmeta files
OnlyRlib,
/// Only keep .rmeta files, ignore .rlib files
Expand All @@ -2656,7 +2660,7 @@ pub enum ArtifactKeepMode {

pub fn run_cargo(
builder: &Builder<'_>,
cargo: Cargo,
mut cargo: Cargo,
tail_args: Vec<String>,
stamp: &BuildStamp,
additional_target_deps: Vec<(PathBuf, DependencyType)>,
Expand All @@ -2674,6 +2678,16 @@ pub fn run_cargo(
.unwrap() // chop off `$target`
.join(target_root_dir.file_name().unwrap());

match artifact_keep_mode {
ArtifactKeepMode::OnlyDylib
| ArtifactKeepMode::OnlyRmeta
| ArtifactKeepMode::BothRlibAndRmeta
| ArtifactKeepMode::Custom(_) => {
cargo.arg("-Zno-embed-metadata");
}
ArtifactKeepMode::OnlyRlib => {}
}

// Spawn Cargo slurping up its JSON output. We'll start building up the
// `deps` array of all files it generated along with a `toplevel` array of
// files we need to probe for later.
Expand Down Expand Up @@ -2703,6 +2717,7 @@ pub fn run_cargo(
true
} else {
match &artifact_keep_mode {
ArtifactKeepMode::OnlyDylib => false,
ArtifactKeepMode::OnlyRlib => filename.ends_with(".rlib"),
ArtifactKeepMode::OnlyRmeta => filename.ends_with(".rmeta"),
ArtifactKeepMode::BothRlibAndRmeta => {
Expand Down
4 changes: 0 additions & 4 deletions src/bootstrap/src/core/builder/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1095,10 +1095,6 @@ impl Builder<'_> {
// Enable usage of unstable features
cargo.env("RUSTC_BOOTSTRAP", "1");

if matches!(mode, Mode::Std) {
cargo.arg("-Zno-embed-metadata");
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this looks like what I came up with while upgrading to 1.94.0 in alpinelinux https://git.alpinelinux.org/aports/commit/?id=e688d5dcba35af7386e9b9f24527ea98dad4040d

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

In this PR, the -Zno-embed-metadata is just moved and also enabled by rustc and codegen backends.

without this we would need to keep the lib*.rmeta files in the main rust
package and have it grow more than twice in size and there would be less
reason of keeping the then much smaller rustc-dev subpackage split

You only need to keep the .rmeta files for the standard library. Without -Zno-embed-metadata they are still present, just embedded in the .rlib and .so files. If anything removing -Zno-embed-metadata increases the size of the package you create as now both libstd.rlib and libstd.so contain a separate copy of the crate metadata rather than sharing a single .rmeta file.

if self.config.dump_bootstrap_shims {
prepare_behaviour_dump_dir(self.build);

Expand Down
Loading