Skip to content

Commit 3b1c8a9

Browse files
committed
Auto merge of #105609 - bjorn3:shrink_rustc_dev, r=jyn514
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. Fixes #103538
2 parents 442f997 + 8c000a6 commit 3b1c8a9

21 files changed

+181
-12
lines changed

compiler/rustc_error_messages/locales/en-US/metadata.ftl

+5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ metadata_rlib_required =
44
metadata_lib_required =
55
crate `{$crate_name}` required to be available in {$kind} format, but was not found in this form
66
7+
metadata_rustc_lib_required =
8+
crate `{$crate_name}` required to be available in {$kind} format, but was not found in this form
9+
.note = only .rmeta files are distributed for `rustc_private` crates other than `rustc_driver`
10+
.help = try adding `extern crate rustc_driver;` at the top level of this crate
11+
712
metadata_crate_dep_multiple =
813
cannot satisfy dependencies so `{$crate_name}` only shows up once
914
.help = having upstream crates all available in one format will likely make this go away

compiler/rustc_metadata/src/dependency_format.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
use crate::creader::CStore;
5555
use crate::errors::{
5656
BadPanicStrategy, CrateDepMultiple, IncompatiblePanicInDropStrategy, LibRequired,
57-
RequiredPanicStrategy, RlibRequired, TwoPanicRuntimes,
57+
RequiredPanicStrategy, RlibRequired, RustcLibRequired, TwoPanicRuntimes,
5858
};
5959

6060
use rustc_data_structures::fx::FxHashMap;
@@ -224,7 +224,12 @@ fn calculate_type(tcx: TyCtxt<'_>, ty: CrateType) -> DependencyList {
224224
Linkage::Static => "rlib",
225225
_ => "dylib",
226226
};
227-
sess.emit_err(LibRequired { crate_name: tcx.crate_name(cnum), kind: kind });
227+
let crate_name = tcx.crate_name(cnum);
228+
if crate_name.as_str().starts_with("rustc_") {
229+
sess.emit_err(RustcLibRequired { crate_name, kind });
230+
} else {
231+
sess.emit_err(LibRequired { crate_name, kind });
232+
}
228233
}
229234
}
230235
}

compiler/rustc_metadata/src/errors.rs

+8
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ pub struct LibRequired<'a> {
2424
pub kind: &'a str,
2525
}
2626

27+
#[derive(Diagnostic)]
28+
#[diag(metadata_rustc_lib_required)]
29+
#[help]
30+
pub struct RustcLibRequired<'a> {
31+
pub crate_name: Symbol,
32+
pub kind: &'a str,
33+
}
34+
2735
#[derive(Diagnostic)]
2836
#[diag(metadata_crate_dep_multiple)]
2937
#[help]

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

src/test/run-make-fulldeps/save-analysis/foo.rs

+5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
extern crate rustc_graphviz;
66
// A simple rust project
77

8+
// Necessary to pull in object code as the rest of the rustc crates are shipped only as rmeta
9+
// files.
10+
#[allow(unused_extern_crates)]
11+
extern crate rustc_driver;
12+
813
extern crate krate2;
914
extern crate krate2 as krate3;
1015

src/test/ui-fulldeps/deriving-encodable-decodable-box.rs

+5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
extern crate rustc_macros;
77
extern crate rustc_serialize;
88

9+
// Necessary to pull in object code as the rest of the rustc crates are shipped only as rmeta
10+
// files.
11+
#[allow(unused_extern_crates)]
12+
extern crate rustc_driver;
13+
914
use rustc_macros::{Decodable, Encodable};
1015
use rustc_serialize::opaque::{MemDecoder, MemEncoder};
1116
use rustc_serialize::{Decodable, Encodable, Encoder};

src/test/ui-fulldeps/deriving-encodable-decodable-cell-refcell.rs

+5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88
extern crate rustc_macros;
99
extern crate rustc_serialize;
1010

11+
// Necessary to pull in object code as the rest of the rustc crates are shipped only as rmeta
12+
// files.
13+
#[allow(unused_extern_crates)]
14+
extern crate rustc_driver;
15+
1116
use rustc_macros::{Decodable, Encodable};
1217
use rustc_serialize::opaque::{MemDecoder, MemEncoder};
1318
use rustc_serialize::{Decodable, Encodable, Encoder};

src/test/ui-fulldeps/deriving-global.rs

+5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
extern crate rustc_macros;
66
extern crate rustc_serialize;
77

8+
// Necessary to pull in object code as the rest of the rustc crates are shipped only as rmeta
9+
// files.
10+
#[allow(unused_extern_crates)]
11+
extern crate rustc_driver;
12+
813
mod submod {
914
use rustc_macros::{Decodable, Encodable};
1015

src/test/ui-fulldeps/deriving-hygiene.rs

+5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ extern crate rustc_serialize;
77

88
use rustc_macros::{Decodable, Encodable};
99

10+
// Necessary to pull in object code as the rest of the rustc crates are shipped only as rmeta
11+
// files.
12+
#[allow(unused_extern_crates)]
13+
extern crate rustc_driver;
14+
1015
pub const other: u8 = 1;
1116
pub const f: u8 = 1;
1217
pub const d: u8 = 1;

src/test/ui-fulldeps/dropck_tarena_sound_drop.rs

+5
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414

1515
extern crate rustc_arena;
1616

17+
// Necessary to pull in object code as the rest of the rustc crates are shipped only as rmeta
18+
// files.
19+
#[allow(unused_extern_crates)]
20+
extern crate rustc_driver;
21+
1722
use rustc_arena::TypedArena;
1823

1924
trait HasId { fn count(&self) -> usize; }

src/test/ui-fulldeps/empty-struct-braces-derive.rs

+5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
extern crate rustc_macros;
77
extern crate rustc_serialize;
88

9+
// Necessary to pull in object code as the rest of the rustc crates are shipped only as rmeta
10+
// files.
11+
#[allow(unused_extern_crates)]
12+
extern crate rustc_driver;
13+
914
use rustc_macros::{Decodable, Encodable};
1015

1116
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default, Debug, Encodable, Decodable)]

src/test/ui-fulldeps/issue-14021.rs

+5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
extern crate rustc_macros;
88
extern crate rustc_serialize;
99

10+
// Necessary to pull in object code as the rest of the rustc crates are shipped only as rmeta
11+
// files.
12+
#[allow(unused_extern_crates)]
13+
extern crate rustc_driver;
14+
1015
use rustc_macros::{Decodable, Encodable};
1116
use rustc_serialize::opaque::{MemDecoder, MemEncoder};
1217
use rustc_serialize::{Decodable, Encodable, Encoder};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Test that we get the following hint when trying to use a compiler crate without rustc_driver.
2+
// error-pattern: try adding `extern crate rustc_driver;` at the top level of this crate
3+
// compile-flags: --emit link
4+
// The exactly list of required crates depends on the target. as such only test Unix targets.
5+
// only-unix
6+
7+
#![feature(rustc_private)]
8+
9+
extern crate rustc_serialize;
10+
11+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
error: crate `rustc_serialize` required to be available in rlib format, but was not found in this form
2+
|
3+
= help: try adding `extern crate rustc_driver;` at the top level of this crate
4+
5+
error: crate `smallvec` required to be available in rlib format, but was not found in this form
6+
7+
error: crate `thin_vec` required to be available in rlib format, but was not found in this form
8+
9+
error: crate `indexmap` required to be available in rlib format, but was not found in this form
10+
11+
error: crate `hashbrown` required to be available in rlib format, but was not found in this form
12+
13+
error: crate `ahash` required to be available in rlib format, but was not found in this form
14+
15+
error: crate `once_cell` required to be available in rlib format, but was not found in this form
16+
17+
error: crate `getrandom` required to be available in rlib format, but was not found in this form
18+
19+
error: crate `cfg_if` required to be available in rlib format, but was not found in this form
20+
21+
error: crate `libc` required to be available in rlib format, but was not found in this form
22+
23+
error: aborting due to 10 previous errors
24+

src/test/ui-fulldeps/mod_dir_path_canonicalized.rs

+5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ extern crate rustc_parse;
1010
extern crate rustc_session;
1111
extern crate rustc_span;
1212

13+
// Necessary to pull in object code as the rest of the rustc crates are shipped only as rmeta
14+
// files.
15+
#[allow(unused_extern_crates)]
16+
extern crate rustc_driver;
17+
1318
use rustc_parse::new_parser_from_file;
1419
use rustc_session::parse::ParseSess;
1520
use rustc_span::source_map::FilePathMapping;

src/test/ui-fulldeps/pprust-expr-roundtrip.rs

+5
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ extern crate rustc_session;
2727
extern crate rustc_span;
2828
extern crate thin_vec;
2929

30+
// Necessary to pull in object code as the rest of the rustc crates are shipped only as rmeta
31+
// files.
32+
#[allow(unused_extern_crates)]
33+
extern crate rustc_driver;
34+
3035
use rustc_ast::mut_visit::{self, visit_clobber, MutVisitor};
3136
use rustc_ast::ptr::P;
3237
use rustc_ast::*;

src/test/ui-fulldeps/regions-mock-tcx.rs

+5
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
extern crate rustc_arena;
1515
extern crate libc;
1616

17+
// Necessary to pull in object code as the rest of the rustc crates are shipped only as rmeta
18+
// files.
19+
#[allow(unused_extern_crates)]
20+
extern crate rustc_driver;
21+
1722
use TypeStructure::{TypeInt, TypeFunction};
1823
use AstKind::{ExprInt, ExprVar, ExprLambda};
1924
use rustc_arena::TypedArena;

src/test/ui-fulldeps/rustc_encodable_hygiene.rs

+5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ extern crate rustc_macros;
66
#[allow(dead_code)]
77
extern crate rustc_serialize;
88

9+
// Necessary to pull in object code as the rest of the rustc crates are shipped only as rmeta
10+
// files.
11+
#[allow(unused_extern_crates)]
12+
extern crate rustc_driver;
13+
914
use rustc_macros::{Decodable, Encodable};
1015

1116
#[derive(Decodable, Encodable, Debug)]

src/tools/miri/src/lib.rs

+5
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ extern crate rustc_session;
5454
extern crate rustc_span;
5555
extern crate rustc_target;
5656

57+
// Necessary to pull in object code as the rest of the rustc crates are shipped only as rmeta
58+
// files.
59+
#[allow(unused_extern_crates)]
60+
extern crate rustc_driver;
61+
5762
mod borrow_tracker;
5863
mod clock;
5964
mod concurrency;

0 commit comments

Comments
 (0)