Skip to content

Commit 027dfe9

Browse files
committed
Build core crates before building std crates
1 parent 4e80235 commit 027dfe9

File tree

16 files changed

+120
-149
lines changed

16 files changed

+120
-149
lines changed

src/Cargo.lock

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,13 @@ version = "0.0.0"
2121
dependencies = [
2222
"build_helper 0.1.0",
2323
"cc 1.0.15 (registry+https://github.com/rust-lang/crates.io-index)",
24-
"compiler_builtins 0.0.0",
25-
"core 0.0.0",
2624
"libc 0.0.0",
2725
]
2826

2927
[[package]]
3028
name = "alloc_system"
3129
version = "0.0.0"
3230
dependencies = [
33-
"compiler_builtins 0.0.0",
34-
"core 0.0.0",
3531
"dlmalloc 0.0.0",
3632
"libc 0.0.0",
3733
]
@@ -598,10 +594,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
598594
[[package]]
599595
name = "dlmalloc"
600596
version = "0.0.0"
601-
dependencies = [
602-
"compiler_builtins 0.0.0",
603-
"core 0.0.0",
604-
]
605597

606598
[[package]]
607599
name = "dtoa"
@@ -1060,10 +1052,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
10601052
[[package]]
10611053
name = "libc"
10621054
version = "0.0.0"
1063-
dependencies = [
1064-
"compiler_builtins 0.0.0",
1065-
"core 0.0.0",
1066-
]
10671055

10681056
[[package]]
10691057
name = "libc"
@@ -1350,18 +1338,13 @@ dependencies = [
13501338
name = "panic_abort"
13511339
version = "0.0.0"
13521340
dependencies = [
1353-
"compiler_builtins 0.0.0",
1354-
"core 0.0.0",
13551341
"libc 0.0.0",
13561342
]
13571343

13581344
[[package]]
13591345
name = "panic_unwind"
13601346
version = "0.0.0"
13611347
dependencies = [
1362-
"alloc 0.0.0",
1363-
"compiler_builtins 0.0.0",
1364-
"core 0.0.0",
13651348
"libc 0.0.0",
13661349
"unwind 0.0.0",
13671350
]
@@ -1501,8 +1484,6 @@ name = "profiler_builtins"
15011484
version = "0.0.0"
15021485
dependencies = [
15031486
"cc 1.0.15 (registry+https://github.com/rust-lang/crates.io-index)",
1504-
"compiler_builtins 0.0.0",
1505-
"core 0.0.0",
15061487
]
15071488

15081489
[[package]]
@@ -2054,12 +2035,9 @@ dependencies = [
20542035
name = "rustc_asan"
20552036
version = "0.0.0"
20562037
dependencies = [
2057-
"alloc 0.0.0",
20582038
"alloc_system 0.0.0",
20592039
"build_helper 0.1.0",
20602040
"cmake 0.1.30 (registry+https://github.com/rust-lang/crates.io-index)",
2061-
"compiler_builtins 0.0.0",
2062-
"core 0.0.0",
20632041
]
20642042

20652043
[[package]]
@@ -2235,12 +2213,9 @@ dependencies = [
22352213
name = "rustc_lsan"
22362214
version = "0.0.0"
22372215
dependencies = [
2238-
"alloc 0.0.0",
22392216
"alloc_system 0.0.0",
22402217
"build_helper 0.1.0",
22412218
"cmake 0.1.30 (registry+https://github.com/rust-lang/crates.io-index)",
2242-
"compiler_builtins 0.0.0",
2243-
"core 0.0.0",
22442219
]
22452220

22462221
[[package]]
@@ -2286,12 +2261,9 @@ dependencies = [
22862261
name = "rustc_msan"
22872262
version = "0.0.0"
22882263
dependencies = [
2289-
"alloc 0.0.0",
22902264
"alloc_system 0.0.0",
22912265
"build_helper 0.1.0",
22922266
"cmake 0.1.30 (registry+https://github.com/rust-lang/crates.io-index)",
2293-
"compiler_builtins 0.0.0",
2294-
"core 0.0.0",
22952267
]
22962268

22972269
[[package]]
@@ -2390,12 +2362,9 @@ dependencies = [
23902362
name = "rustc_tsan"
23912363
version = "0.0.0"
23922364
dependencies = [
2393-
"alloc 0.0.0",
23942365
"alloc_system 0.0.0",
23952366
"build_helper 0.1.0",
23962367
"cmake 0.1.30 (registry+https://github.com/rust-lang/crates.io-index)",
2397-
"compiler_builtins 0.0.0",
2398-
"core 0.0.0",
23992368
]
24002369

24012370
[[package]]
@@ -2632,13 +2601,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
26322601
name = "std"
26332602
version = "0.0.0"
26342603
dependencies = [
2635-
"alloc 0.0.0",
26362604
"alloc_jemalloc 0.0.0",
26372605
"alloc_system 0.0.0",
26382606
"build_helper 0.1.0",
26392607
"cc 1.0.15 (registry+https://github.com/rust-lang/crates.io-index)",
2640-
"compiler_builtins 0.0.0",
2641-
"core 0.0.0",
26422608
"libc 0.0.0",
26432609
"panic_abort 0.0.0",
26442610
"panic_unwind 0.0.0",
@@ -2648,7 +2614,6 @@ dependencies = [
26482614
"rustc_lsan 0.0.0",
26492615
"rustc_msan 0.0.0",
26502616
"rustc_tsan 0.0.0",
2651-
"std_unicode 0.0.0",
26522617
"unwind 0.0.0",
26532618
]
26542619

@@ -3037,8 +3002,6 @@ dependencies = [
30373002
name = "unwind"
30383003
version = "0.0.0"
30393004
dependencies = [
3040-
"compiler_builtins 0.0.0",
3041-
"core 0.0.0",
30423005
"libc 0.0.0",
30433006
]
30443007

src/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
[workspace]
22
members = [
33
"bootstrap",
4+
"libcore",
5+
"libstd_unicode",
6+
"liballoc",
47
"rustc",
58
"libstd",
69
"libtest",

src/bootstrap/compile.rs

Lines changed: 117 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -100,22 +100,45 @@ impl Step for Std {
100100

101101
let out_dir = builder.cargo_out(compiler, Mode::Std, target);
102102
builder.clear_if_dirty(&out_dir, &builder.rustc(compiler));
103-
let mut cargo = builder.cargo(compiler, Mode::Std, target, "build");
104-
std_cargo(builder, &compiler, target, &mut cargo);
103+
let mut core_cargo_invoc = builder.cargo(compiler, Mode::Std, target, "build");
104+
core_cargo(builder, &compiler, target, &mut core_cargo_invoc);
105+
let std_cargo_invoc = if builder.no_std(target) != Some(true) {
106+
let mut std_cargo_invoc = builder.cargo(compiler, Mode::Std, target, "build");
107+
std_cargo(builder, &compiler, target, &mut std_cargo_invoc);
108+
Some(std_cargo_invoc)
109+
} else {
110+
None
111+
};
105112

106113
let _folder = builder.fold_output(|| format!("stage{}-std", compiler.stage));
107114
builder.info(&format!("Building stage{} std artifacts ({} -> {})", compiler.stage,
108115
&compiler.host, target));
109116
run_cargo(builder,
110-
&mut cargo,
117+
&mut core_cargo_invoc,
111118
&libstd_stamp(builder, compiler, target),
112119
false);
113-
114-
builder.ensure(StdLink {
120+
builder.ensure(CoreLink {
115121
compiler: builder.compiler(compiler.stage, builder.config.build),
116122
target_compiler: compiler,
117123
target,
118124
});
125+
if let Some(mut std_cargo_invoc) = std_cargo_invoc {
126+
run_cargo(builder,
127+
&mut std_cargo_invoc,
128+
&libstd_stamp(builder, compiler, target),
129+
false);
130+
builder.ensure(StdLink {
131+
compiler: builder.compiler(compiler.stage, builder.config.build),
132+
target_compiler: compiler,
133+
target,
134+
});
135+
}
136+
137+
builder.ensure(tool::CleanTools {
138+
compiler,
139+
target,
140+
cause: Mode::Std,
141+
});
119142
}
120143
}
121144

@@ -139,6 +162,23 @@ fn mac_os_deployment_env_var(cargo: &mut Command) {
139162
}
140163
}
141164

165+
/// Configure cargo to compile a few no_std crates like core,
166+
/// adding appropriate env vars and such.
167+
pub fn core_cargo(builder: &Builder,
168+
_compiler: &Compiler,
169+
_target: Interned<String>,
170+
cargo: &mut Command) {
171+
mac_os_deployment_env_var(cargo);
172+
173+
// for no-std targets we only compile a few no_std crates
174+
cargo.arg("--features").arg("c mem")
175+
.args(&["-p", "alloc"])
176+
.args(&["-p", "compiler_builtins"])
177+
.args(&["-p", "std_unicode"])
178+
.arg("--manifest-path")
179+
.arg(builder.src.join("src/rustc/compiler_builtins_shim/Cargo.toml"));
180+
}
181+
142182
/// Configure cargo to compile the standard library, adding appropriate env vars
143183
/// and such.
144184
pub fn std_cargo(builder: &Builder,
@@ -147,58 +187,85 @@ pub fn std_cargo(builder: &Builder,
147187
cargo: &mut Command) {
148188
mac_os_deployment_env_var(cargo);
149189

150-
if builder.no_std(target) == Some(true) {
151-
// for no-std targets we only compile a few no_std crates
152-
cargo.arg("--features").arg("c mem")
153-
.args(&["-p", "alloc"])
154-
.args(&["-p", "compiler_builtins"])
155-
.args(&["-p", "std_unicode"])
156-
.arg("--manifest-path")
157-
.arg(builder.src.join("src/rustc/compiler_builtins_shim/Cargo.toml"));
158-
} else {
159-
let mut features = builder.std_features();
160-
161-
// When doing a local rebuild we tell cargo that we're stage1 rather than
162-
// stage0. This works fine if the local rust and being-built rust have the
163-
// same view of what the default allocator is, but fails otherwise. Since
164-
// we don't have a way to express an allocator preference yet, work
165-
// around the issue in the case of a local rebuild with jemalloc disabled.
166-
if compiler.stage == 0 && builder.local_rebuild && !builder.config.use_jemalloc {
167-
features.push_str(" force_alloc_system");
168-
}
190+
let mut features = builder.std_features();
169191

170-
if compiler.stage != 0 && builder.config.sanitizers {
171-
// This variable is used by the sanitizer runtime crates, e.g.
172-
// rustc_lsan, to build the sanitizer runtime from C code
173-
// When this variable is missing, those crates won't compile the C code,
174-
// so we don't set this variable during stage0 where llvm-config is
175-
// missing
176-
// We also only build the runtimes when --enable-sanitizers (or its
177-
// config.toml equivalent) is used
178-
let llvm_config = builder.ensure(native::Llvm {
179-
target: builder.config.build,
180-
emscripten: false,
181-
});
182-
cargo.env("LLVM_CONFIG", llvm_config);
183-
}
192+
// When doing a local rebuild we tell cargo that we're stage1 rather than
193+
// stage0. This works fine if the local rust and being-built rust have the
194+
// same view of what the default allocator is, but fails otherwise. Since
195+
// we don't have a way to express an allocator preference yet, work
196+
// around the issue in the case of a local rebuild with jemalloc disabled.
197+
if compiler.stage == 0 && builder.local_rebuild && !builder.config.use_jemalloc {
198+
features.push_str(" force_alloc_system");
199+
}
184200

185-
cargo.arg("--features").arg(features)
186-
.arg("--manifest-path")
187-
.arg(builder.src.join("src/libstd/Cargo.toml"));
201+
if compiler.stage != 0 && builder.config.sanitizers {
202+
// This variable is used by the sanitizer runtime crates, e.g.
203+
// rustc_lsan, to build the sanitizer runtime from C code
204+
// When this variable is missing, those crates won't compile the C code,
205+
// so we don't set this variable during stage0 where llvm-config is
206+
// missing
207+
// We also only build the runtimes when --enable-sanitizers (or its
208+
// config.toml equivalent) is used
209+
let llvm_config = builder.ensure(native::Llvm {
210+
target: builder.config.build,
211+
emscripten: false,
212+
});
213+
cargo.env("LLVM_CONFIG", llvm_config);
214+
}
188215

189-
if let Some(target) = builder.config.target_config.get(&target) {
190-
if let Some(ref jemalloc) = target.jemalloc {
191-
cargo.env("JEMALLOC_OVERRIDE", jemalloc);
192-
}
216+
cargo.arg("--features").arg(features)
217+
.arg("--manifest-path")
218+
.arg(builder.src.join("src/libstd/Cargo.toml"));
219+
220+
if let Some(target) = builder.config.target_config.get(&target) {
221+
if let Some(ref jemalloc) = target.jemalloc {
222+
cargo.env("JEMALLOC_OVERRIDE", jemalloc);
193223
}
194-
if target.contains("musl") {
195-
if let Some(p) = builder.musl_root(target) {
196-
cargo.env("MUSL_ROOT", p);
197-
}
224+
}
225+
if target.contains("musl") {
226+
if let Some(p) = builder.musl_root(target) {
227+
cargo.env("MUSL_ROOT", p);
198228
}
199229
}
200230
}
201231

232+
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
233+
struct CoreLink {
234+
pub compiler: Compiler,
235+
pub target_compiler: Compiler,
236+
pub target: Interned<String>,
237+
}
238+
239+
impl Step for CoreLink {
240+
type Output = ();
241+
242+
fn should_run(run: ShouldRun) -> ShouldRun {
243+
run.never()
244+
}
245+
246+
/// Link all libcore rlibs/dylibs into the sysroot location.
247+
///
248+
/// Links those artifacts generated by `compiler` to a the `stage` compiler's
249+
/// sysroot for the specified `host` and `target`.
250+
///
251+
/// Note that this assumes that `compiler` has already generated the
252+
/// libraries for `target`, and this method will find them in the relevant
253+
/// output directory.
254+
fn run(self, builder: &Builder) {
255+
let compiler = self.compiler;
256+
let target_compiler = self.target_compiler;
257+
let target = self.target;
258+
builder.info(&format!("Copying stage{} core from stage{} ({} -> {} / {})",
259+
target_compiler.stage,
260+
compiler.stage,
261+
&compiler.host,
262+
target_compiler.host,
263+
target));
264+
let libdir = builder.sysroot_libdir(target_compiler, target);
265+
add_to_sysroot(builder, &libdir, &libstd_stamp(builder, compiler, target));
266+
}
267+
}
268+
202269
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
203270
struct StdLink {
204271
pub compiler: Compiler,
@@ -240,12 +307,6 @@ impl Step for StdLink {
240307
// for reason why the sanitizers are not built in stage0.
241308
copy_apple_sanitizer_dylibs(builder, &builder.native_dir(target), "osx", &libdir);
242309
}
243-
244-
builder.ensure(tool::CleanTools {
245-
compiler: target_compiler,
246-
target,
247-
cause: Mode::Std,
248-
});
249310
}
250311
}
251312

@@ -923,6 +984,7 @@ impl Step for Assemble {
923984
for stage in 0..min(target_compiler.stage, builder.config.keep_stage.unwrap()) {
924985
let target_compiler = builder.compiler(stage, target_compiler.host);
925986
let target = target_compiler.host;
987+
builder.ensure(CoreLink { compiler, target_compiler, target });
926988
builder.ensure(StdLink { compiler, target_compiler, target });
927989
builder.ensure(TestLink { compiler, target_compiler, target });
928990
builder.ensure(RustcLink { compiler, target_compiler, target });

src/liballoc_jemalloc/Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ test = false
1212
doc = false
1313

1414
[dependencies]
15-
core = { path = "../libcore" }
1615
libc = { path = "../rustc/libc_shim" }
17-
compiler_builtins = { path = "../rustc/compiler_builtins_shim" }
1816

1917
[build-dependencies]
2018
build_helper = { path = "../build_helper" }

0 commit comments

Comments
 (0)