Skip to content

Commit 00b824a

Browse files
committed
Do not add external libraries to libstd stamp file
They are already copied before libstd is built. Copying them again when reading stamp file is unnecessary.
1 parent ee6c0da commit 00b824a

File tree

2 files changed

+13
-41
lines changed

2 files changed

+13
-41
lines changed

src/bootstrap/check.rs

-3
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ impl Step for Std {
5353
cargo,
5454
args(builder.kind),
5555
&libstd_stamp(builder, compiler, target),
56-
vec![],
5756
true,
5857
);
5958

@@ -102,7 +101,6 @@ impl Step for Rustc {
102101
cargo,
103102
args(builder.kind),
104103
&librustc_stamp(builder, compiler, target),
105-
vec![],
106104
true,
107105
);
108106

@@ -160,7 +158,6 @@ macro_rules! tool_check_step {
160158
cargo,
161159
args(builder.kind),
162160
&stamp(builder, compiler, target),
163-
vec![],
164161
true,
165162
);
166163

src/bootstrap/compile.rs

+13-38
Original file line numberDiff line numberDiff line change
@@ -64,17 +64,13 @@ impl Step for Std {
6464
return;
6565
}
6666

67-
let mut target_deps = builder.ensure(StartupObjects { compiler, target });
67+
builder.ensure(StartupObjects { compiler, target });
68+
copy_third_party_objects(builder, &compiler, target);
6869

6970
let compiler_to_use = builder.compiler_for(compiler.stage, compiler.host, target);
7071
if compiler_to_use != compiler {
7172
builder.ensure(Std { compiler: compiler_to_use, target });
7273
builder.info(&format!("Uplifting stage1 std ({} -> {})", compiler_to_use.host, target));
73-
74-
// Even if we're not building std this stage, the new sysroot must
75-
// still contain the third party objects needed by various targets.
76-
copy_third_party_objects(builder, &compiler, target);
77-
7874
builder.ensure(StdLink {
7975
compiler: compiler_to_use,
8076
target_compiler: compiler,
@@ -83,7 +79,6 @@ impl Step for Std {
8379
return;
8480
}
8581

86-
target_deps.extend(copy_third_party_objects(builder, &compiler, target).into_iter());
8782

8883
let mut cargo = builder.cargo(compiler, Mode::Std, target, "build");
8984
std_cargo(builder, target, compiler.stage, &mut cargo);
@@ -97,7 +92,6 @@ impl Step for Std {
9792
cargo,
9893
vec![],
9994
&libstd_stamp(builder, compiler, target),
100-
target_deps,
10195
false,
10296
);
10397

@@ -114,15 +108,12 @@ fn copy_third_party_objects(
114108
builder: &Builder<'_>,
115109
compiler: &Compiler,
116110
target: Interned<String>,
117-
) -> Vec<PathBuf> {
111+
) {
118112
let libdir = builder.sysroot_libdir(*compiler, target);
119113

120-
let mut target_deps = vec![];
121-
122-
let mut copy_and_stamp = |sourcedir: &Path, name: &str| {
114+
let copy = |sourcedir: &Path, name: &str| {
123115
let target = libdir.join(name);
124116
builder.copy(&sourcedir.join(name), &target);
125-
target_deps.push(target);
126117
};
127118

128119
// Copies the CRT objects.
@@ -135,11 +126,11 @@ fn copy_third_party_objects(
135126
if target.contains("musl") {
136127
let srcdir = builder.musl_root(target).unwrap().join("lib");
137128
for &obj in &["crt1.o", "Scrt1.o", "rcrt1.o", "crti.o", "crtn.o"] {
138-
copy_and_stamp(&srcdir, obj);
129+
copy(&srcdir, obj);
139130
}
140131
} else if target.ends_with("-wasi") {
141132
let srcdir = builder.wasi_root(target).unwrap().join("lib/wasm32-wasi");
142-
copy_and_stamp(&srcdir, "crt1.o");
133+
copy(&srcdir, "crt1.o");
143134
}
144135

145136
// Copies libunwind.a compiled to be linked with x86_64-fortanix-unknown-sgx.
@@ -151,16 +142,14 @@ fn copy_third_party_objects(
151142
let src_path_env = "X86_FORTANIX_SGX_LIBS";
152143
let src =
153144
env::var(src_path_env).unwrap_or_else(|_| panic!("{} not found in env", src_path_env));
154-
copy_and_stamp(Path::new(&src), "libunwind.a");
145+
copy(Path::new(&src), "libunwind.a");
155146
}
156147

157148
if builder.config.sanitizers && compiler.stage != 0 {
158149
// The sanitizers are only copied in stage1 or above,
159150
// to avoid creating dependency on LLVM.
160-
target_deps.extend(copy_sanitizers(builder, &compiler, target));
151+
copy_sanitizers(builder, &compiler, target);
161152
}
162-
163-
target_deps
164153
}
165154

166155
/// Configure cargo to compile the standard library, adding appropriate env vars
@@ -287,14 +276,13 @@ fn copy_sanitizers(
287276
builder: &Builder<'_>,
288277
compiler: &Compiler,
289278
target: Interned<String>,
290-
) -> Vec<PathBuf> {
279+
) {
291280
let runtimes: Vec<native::SanitizerRuntime> = builder.ensure(native::Sanitizers { target });
292281

293282
if builder.config.dry_run {
294-
return Vec::new();
283+
return;
295284
}
296285

297-
let mut target_deps = Vec::new();
298286
let libdir = builder.sysroot_libdir(*compiler, target);
299287

300288
for runtime in &runtimes {
@@ -311,11 +299,7 @@ fn copy_sanitizers(
311299
.expect("failed to execute `install_name_tool`");
312300
assert!(status.success());
313301
}
314-
315-
target_deps.push(dst);
316302
}
317-
318-
target_deps
319303
}
320304

321305
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
@@ -325,7 +309,7 @@ pub struct StartupObjects {
325309
}
326310

327311
impl Step for StartupObjects {
328-
type Output = Vec<PathBuf>;
312+
type Output = ();
329313

330314
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
331315
run.path("src/rtstartup")
@@ -344,15 +328,13 @@ impl Step for StartupObjects {
344328
/// They don't require any library support as they're just plain old object
345329
/// files, so we just use the nightly snapshot compiler to always build them (as
346330
/// no other compilers are guaranteed to be available).
347-
fn run(self, builder: &Builder<'_>) -> Vec<PathBuf> {
331+
fn run(self, builder: &Builder<'_>) {
348332
let for_compiler = self.compiler;
349333
let target = self.target;
350334
if !target.contains("windows-gnu") {
351-
return vec![];
335+
return ();
352336
}
353337

354-
let mut target_deps = vec![];
355-
356338
let src_dir = &builder.src.join("src/rtstartup");
357339
let dst_dir = &builder.native_dir(target).join("rtstartup");
358340
let sysroot_dir = &builder.sysroot_libdir(for_compiler, target);
@@ -378,17 +360,13 @@ impl Step for StartupObjects {
378360

379361
let target = sysroot_dir.join((*file).to_string() + ".o");
380362
builder.copy(dst_file, &target);
381-
target_deps.push(target);
382363
}
383364

384365
for obj in ["crt2.o", "dllcrt2.o"].iter() {
385366
let src = compiler_file(builder, builder.cc(target), target, obj);
386367
let target = sysroot_dir.join(obj);
387368
builder.copy(&src, &target);
388-
target_deps.push(target);
389369
}
390-
391-
target_deps
392370
}
393371
}
394372

@@ -462,7 +440,6 @@ impl Step for Rustc {
462440
cargo,
463441
vec![],
464442
&librustc_stamp(builder, compiler, target),
465-
vec![],
466443
false,
467444
);
468445

@@ -814,7 +791,6 @@ pub fn run_cargo(
814791
cargo: Cargo,
815792
tail_args: Vec<String>,
816793
stamp: &Path,
817-
additional_target_deps: Vec<PathBuf>,
818794
is_check: bool,
819795
) -> Vec<PathBuf> {
820796
if builder.config.dry_run {
@@ -931,7 +907,6 @@ pub fn run_cargo(
931907
deps.push((path_to_add.into(), false));
932908
}
933909

934-
deps.extend(additional_target_deps.into_iter().map(|d| (d, false)));
935910
deps.sort();
936911
let mut new_contents = Vec::new();
937912
for (dep, proc_macro) in deps.iter() {

0 commit comments

Comments
 (0)