Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 0ac4456

Browse files
committed
Move rtstartup build to build_clif_sysroot_for_triple
Also pass build/rtstartup as sysroot when building the standard library
1 parent 6f1e177 commit 0ac4456

File tree

1 file changed

+32
-25
lines changed

1 file changed

+32
-25
lines changed

build_system/build_sysroot.rs

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -56,28 +56,6 @@ pub(crate) fn build_sysroot(
5656
spawn_and_wait(build_cargo_wrapper_cmd);
5757
}
5858

59-
if target_triple.ends_with("windows-gnu") {
60-
eprintln!("[BUILD] rtstartup for {target_triple}");
61-
62-
let rtstartup_src = SYSROOT_SRC.to_path(dirs).join("library").join("rtstartup");
63-
let mut target_libs = SysrootTarget { triple: target_triple.clone(), libs: vec![] };
64-
65-
for file in ["rsbegin", "rsend"] {
66-
let obj = RelPath::BUILD.to_path(dirs).join(format!("{file}.o"));
67-
let mut build_rtstartup_cmd = Command::new(&bootstrap_host_compiler.rustc);
68-
build_rtstartup_cmd
69-
.arg("--target")
70-
.arg(&target_triple)
71-
.arg("--emit=obj")
72-
.arg("-o")
73-
.arg(&obj)
74-
.arg(rtstartup_src.join(format!("{file}.rs")));
75-
spawn_and_wait(build_rtstartup_cmd);
76-
target_libs.libs.push(obj);
77-
}
78-
79-
target_libs.install_into_sysroot(&DIST_DIR.to_path(dirs))
80-
}
8159
match sysroot_kind {
8260
SysrootKind::None => {} // Nothing to do
8361
SysrootKind::Llvm => {
@@ -190,6 +168,7 @@ pub(crate) static SYSROOT_RUSTC_VERSION: RelPath = BUILD_SYSROOT.join("rustc_ver
190168
pub(crate) static SYSROOT_SRC: RelPath = BUILD_SYSROOT.join("sysroot_src");
191169
pub(crate) static STANDARD_LIBRARY: CargoProject =
192170
CargoProject::new(&BUILD_SYSROOT, "build_sysroot");
171+
pub(crate) static RTSTARTUP_SYSROOT: RelPath = RelPath::BUILD.join("rtstartup");
193172

194173
#[must_use]
195174
fn build_clif_sysroot_for_triple(
@@ -216,6 +195,35 @@ fn build_clif_sysroot_for_triple(
216195
}
217196
}
218197

198+
let mut target_libs = SysrootTarget { triple: compiler.triple.clone(), libs: vec![] };
199+
200+
if compiler.triple.ends_with("windows-gnu") {
201+
eprintln!("[BUILD] rtstartup for {}", compiler.triple);
202+
203+
RTSTARTUP_SYSROOT.ensure_fresh(dirs);
204+
205+
let rtstartup_src = SYSROOT_SRC.to_path(dirs).join("library").join("rtstartup");
206+
let mut rtstartup_target_libs =
207+
SysrootTarget { triple: compiler.triple.clone(), libs: vec![] };
208+
209+
for file in ["rsbegin", "rsend"] {
210+
let obj = RTSTARTUP_SYSROOT.to_path(dirs).join(format!("{file}.o"));
211+
let mut build_rtstartup_cmd = Command::new(&compiler.rustc);
212+
build_rtstartup_cmd
213+
.arg("--target")
214+
.arg(&compiler.triple)
215+
.arg("--emit=obj")
216+
.arg("-o")
217+
.arg(&obj)
218+
.arg(rtstartup_src.join(format!("{file}.rs")));
219+
spawn_and_wait(build_rtstartup_cmd);
220+
rtstartup_target_libs.libs.push(obj.clone());
221+
target_libs.libs.push(obj);
222+
}
223+
224+
rtstartup_target_libs.install_into_sysroot(&RTSTARTUP_SYSROOT.to_path(dirs));
225+
}
226+
219227
let build_dir = STANDARD_LIBRARY.target_dir(dirs).join(&compiler.triple).join(channel);
220228

221229
if !super::config::get_bool("keep_sysroot") {
@@ -230,7 +238,8 @@ fn build_clif_sysroot_for_triple(
230238
let mut rustflags = " -Zforce-unstable-if-unmarked -Cpanic=abort".to_string();
231239
rustflags.push_str(&format!(" -Zcodegen-backend={}", cg_clif_dylib_path.to_str().unwrap()));
232240
// Necessary for MinGW to find rsbegin.o and rsend.o
233-
rustflags.push_str(&format!(" --sysroot={}", DIST_DIR.to_path(dirs).to_str().unwrap()));
241+
rustflags
242+
.push_str(&format!(" --sysroot={}", RTSTARTUP_SYSROOT.to_path(dirs).to_str().unwrap()));
234243
if channel == "release" {
235244
rustflags.push_str(" -Zmir-opt-level=3");
236245
}
@@ -242,8 +251,6 @@ fn build_clif_sysroot_for_triple(
242251
build_cmd.env("__CARGO_DEFAULT_LIB_METADATA", "cg_clif");
243252
spawn_and_wait(build_cmd);
244253

245-
let mut target_libs = SysrootTarget { triple: compiler.triple, libs: vec![] };
246-
247254
for entry in fs::read_dir(build_dir.join("deps")).unwrap() {
248255
let entry = entry.unwrap();
249256
if let Some(ext) = entry.path().extension() {

0 commit comments

Comments
 (0)