Skip to content

Commit 5c84f76

Browse files
committed
Only include metadata for non-dynamic libraries in rustc-dev
The actual object code should be linked from librustc_driver.so, which is still included in rustc-dev. This saves on download time and disk usage.
1 parent 96c1f33 commit 5c84f76

File tree

2 files changed

+56
-10
lines changed

2 files changed

+56
-10
lines changed

src/bootstrap/check.rs

+13-4
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ impl Step for Std {
105105
"Checking stage{} library artifacts ({} -> {})",
106106
builder.top_stage, &compiler.host, target
107107
));
108-
run_cargo(builder, cargo, &libstd_stamp(builder, compiler, target), vec![], true);
108+
run_cargo(builder, cargo, &libstd_stamp(builder, compiler, target), vec![], true, false);
109109

110110
// We skip populating the sysroot in non-zero stage because that'll lead
111111
// to rlib/rmeta conflicts if std gets built during this session.
@@ -155,7 +155,14 @@ impl Step for Std {
155155
"Checking stage{} library test/bench/example targets ({} -> {})",
156156
builder.top_stage, &compiler.host, target
157157
));
158-
run_cargo(builder, cargo, &libstd_test_stamp(builder, compiler, target), vec![], true);
158+
run_cargo(
159+
builder,
160+
cargo,
161+
&libstd_test_stamp(builder, compiler, target),
162+
vec![],
163+
true,
164+
false,
165+
);
159166
}
160167
}
161168

@@ -225,7 +232,7 @@ impl Step for Rustc {
225232
"Checking stage{} compiler artifacts ({} -> {})",
226233
builder.top_stage, &compiler.host, target
227234
));
228-
run_cargo(builder, cargo, &librustc_stamp(builder, compiler, target), vec![], true);
235+
run_cargo(builder, cargo, &librustc_stamp(builder, compiler, target), vec![], true, false);
229236

230237
let libdir = builder.sysroot_libdir(compiler, target);
231238
let hostdir = builder.sysroot_libdir(compiler, compiler.host);
@@ -285,6 +292,7 @@ impl Step for CodegenBackend {
285292
&codegen_backend_stamp(builder, compiler, target, backend),
286293
vec![],
287294
true,
295+
false,
288296
);
289297
}
290298
}
@@ -343,7 +351,7 @@ impl Step for RustAnalyzer {
343351
"Checking stage{} {} artifacts ({} -> {})",
344352
compiler.stage, "rust-analyzer", &compiler.host.triple, target.triple
345353
));
346-
run_cargo(builder, cargo, &stamp(builder, compiler, target), vec![], true);
354+
run_cargo(builder, cargo, &stamp(builder, compiler, target), vec![], true, false);
347355

348356
/// Cargo's output path in a given stage, compiled by a particular
349357
/// compiler for the specified target.
@@ -417,6 +425,7 @@ macro_rules! tool_check_step {
417425
&stamp(builder, compiler, target),
418426
vec![],
419427
true,
428+
false,
420429
);
421430

422431
/// Cargo's output path in a given stage, compiled by a particular

src/bootstrap/compile.rs

+43-6
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,14 @@ impl Step for Std {
141141
&compiler.host,
142142
target,
143143
));
144-
run_cargo(builder, cargo, &libstd_stamp(builder, compiler, target), target_deps, false);
144+
run_cargo(
145+
builder,
146+
cargo,
147+
&libstd_stamp(builder, compiler, target),
148+
target_deps,
149+
false,
150+
false,
151+
);
145152

146153
builder.ensure(StdLink::from_std(
147154
self,
@@ -728,7 +735,14 @@ impl Step for Rustc {
728735
&compiler.host,
729736
target,
730737
));
731-
run_cargo(builder, cargo, &librustc_stamp(builder, compiler, target), vec![], false);
738+
run_cargo(
739+
builder,
740+
cargo,
741+
&librustc_stamp(builder, compiler, target),
742+
vec![],
743+
false,
744+
true, // Only ship rustc_driver.so and .rmeta files, not all intermediate .rlib files.
745+
);
732746

733747
builder.ensure(RustcLink::from_rustc(
734748
self,
@@ -984,7 +998,7 @@ impl Step for CodegenBackend {
984998
"Building stage{} codegen backend {} ({} -> {})",
985999
compiler.stage, backend, &compiler.host, target
9861000
));
987-
let files = run_cargo(builder, cargo, &tmp_stamp, vec![], false);
1001+
let files = run_cargo(builder, cargo, &tmp_stamp, vec![], false, false);
9881002
if builder.config.dry_run() {
9891003
return;
9901004
}
@@ -1411,6 +1425,7 @@ pub fn run_cargo(
14111425
stamp: &Path,
14121426
additional_target_deps: Vec<(PathBuf, DependencyType)>,
14131427
is_check: bool,
1428+
rlib_only_metadata: bool,
14141429
) -> Vec<PathBuf> {
14151430
if builder.config.dry_run() {
14161431
return Vec::new();
@@ -1444,13 +1459,35 @@ pub fn run_cargo(
14441459
};
14451460
for filename in filenames {
14461461
// Skip files like executables
1447-
if !(filename.ends_with(".rlib")
1448-
|| filename.ends_with(".lib")
1462+
let mut keep = false;
1463+
if filename.ends_with(".lib")
14491464
|| filename.ends_with(".a")
14501465
|| is_debug_info(&filename)
14511466
|| is_dylib(&filename)
1452-
|| (is_check && filename.ends_with(".rmeta")))
14531467
{
1468+
// Always keep native libraries, rust dylibs and debuginfo
1469+
keep = true;
1470+
}
1471+
if is_check && filename.ends_with(".rmeta") {
1472+
// During check builds we need to keep crate metadata
1473+
keep = true;
1474+
} else if rlib_only_metadata {
1475+
if filename.contains("jemalloc_sys") || filename.contains("rustc_smir") {
1476+
// jemalloc_sys and rustc_smir are not linked into librustc_driver.so,
1477+
// so we need to distribute them as rlib to be able to use them.
1478+
keep |= filename.ends_with(".rlib");
1479+
} else {
1480+
// Distribute the rest of the rustc crates as rmeta files only to reduce
1481+
// the tarball sizes by about 50%. The object files are linked into
1482+
// librustc_driver.so, so it is still possible to link against them.
1483+
keep |= filename.ends_with(".rmeta");
1484+
}
1485+
} else {
1486+
// In all other cases keep all rlibs
1487+
keep |= filename.ends_with(".rlib");
1488+
}
1489+
1490+
if !keep {
14541491
continue;
14551492
}
14561493

0 commit comments

Comments
 (0)