Skip to content

Commit d611b42

Browse files
authored
Rollup merge of rust-lang#39892 - petrochenkov:rt, r=alexcrichton
Fix test caching on Windows/GNU Addresses rust-lang#36385 (comment) Previously the sysroot directory was purged on every build and mingw startup objects were rebuilt unconditionally and always triggered test reruns. Now the sysroot directory is reused and mingw startup objects are rebuilt only when necessary, so test caching works.
2 parents 6f16bc3 + 0c4c6fd commit d611b42

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

src/bootstrap/compile.rs

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use std::fs::{self, File};
2121
use std::path::{Path, PathBuf};
2222
use std::process::Command;
2323

24-
use build_helper::{output, mtime};
24+
use build_helper::{output, mtime, up_to_date};
2525
use filetime::FileTime;
2626

2727
use util::{exe, libdir, is_dylib, copy};
@@ -132,21 +132,29 @@ pub fn build_startup_objects(build: &Build, for_compiler: &Compiler, target: &st
132132

133133
let compiler = Compiler::new(0, &build.config.build);
134134
let compiler_path = build.compiler_path(&compiler);
135-
let into = build.sysroot_libdir(for_compiler, target);
136-
t!(fs::create_dir_all(&into));
137-
138-
for file in t!(fs::read_dir(build.src.join("src/rtstartup"))) {
139-
let file = t!(file);
140-
let mut cmd = Command::new(&compiler_path);
141-
build.run(cmd.env("RUSTC_BOOTSTRAP", "1")
142-
.arg("--target").arg(target)
143-
.arg("--emit=obj")
144-
.arg("--out-dir").arg(&into)
145-
.arg(file.path()));
135+
let src_dir = &build.src.join("src/rtstartup");
136+
let dst_dir = &build.native_dir(target).join("rtstartup");
137+
let sysroot_dir = &build.sysroot_libdir(for_compiler, target);
138+
t!(fs::create_dir_all(dst_dir));
139+
t!(fs::create_dir_all(sysroot_dir));
140+
141+
for file in &["rsbegin", "rsend"] {
142+
let src_file = &src_dir.join(file.to_string() + ".rs");
143+
let dst_file = &dst_dir.join(file.to_string() + ".o");
144+
if !up_to_date(src_file, dst_file) {
145+
let mut cmd = Command::new(&compiler_path);
146+
build.run(cmd.env("RUSTC_BOOTSTRAP", "1")
147+
.arg("--target").arg(target)
148+
.arg("--emit=obj")
149+
.arg("--out-dir").arg(dst_dir)
150+
.arg(src_file));
151+
}
152+
153+
copy(dst_file, &sysroot_dir.join(file.to_string() + ".o"));
146154
}
147155

148156
for obj in ["crt2.o", "dllcrt2.o"].iter() {
149-
copy(&compiler_file(build.cc(target), obj), &into.join(obj));
157+
copy(&compiler_file(build.cc(target), obj), &sysroot_dir.join(obj));
150158
}
151159
}
152160

0 commit comments

Comments
 (0)