Skip to content

Commit c950f22

Browse files
committed
Build rtstartup for MinGW from scratch
Rather than copying it from an existing sysroot
1 parent 629eab7 commit c950f22

File tree

2 files changed

+16
-19
lines changed

2 files changed

+16
-19
lines changed

.github/workflows/main.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ jobs:
7777
run: |
7878
sudo apt-get update
7979
sudo apt-get install -y gcc-mingw-w64-x86-64 wine-stable
80-
rustup target add x86_64-pc-windows-gnu
8180
8281
- name: Install AArch64 toolchain and qemu
8382
if: matrix.os == 'ubuntu-latest' && matrix.env.TARGET_TRIPLE == 'aarch64-unknown-linux-gnu'

build_system/build_sysroot.rs

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -64,24 +64,21 @@ pub(crate) fn build_sysroot(
6464
fs::create_dir_all(&host_rustlib_lib).unwrap();
6565
fs::create_dir_all(&target_rustlib_lib).unwrap();
6666

67-
if target_triple == "x86_64-pc-windows-gnu" {
68-
if !default_sysroot.join("lib").join("rustlib").join(&target_triple).join("lib").exists() {
69-
eprintln!(
70-
"The x86_64-pc-windows-gnu target needs to be installed first before it is possible \
71-
to compile a sysroot for it.",
72-
);
73-
process::exit(1);
74-
}
75-
for file in fs::read_dir(
76-
default_sysroot.join("lib").join("rustlib").join(&target_triple).join("lib"),
77-
)
78-
.unwrap()
79-
{
80-
let file = file.unwrap().path();
81-
if file.extension().map_or(true, |ext| ext.to_str().unwrap() != "o") {
82-
continue; // only copy object files
83-
}
84-
try_hard_link(&file, target_rustlib_lib.join(file.file_name().unwrap()));
67+
if target_triple.ends_with("windows-gnu") {
68+
eprintln!("[BUILD] rtstartup for {target_triple}");
69+
70+
let rtstartup_src = SYSROOT_SRC.to_path(dirs).join("library").join("rtstartup");
71+
72+
for file in ["rsbegin", "rsend"] {
73+
let mut build_rtstartup_cmd = Command::new(&bootstrap_host_compiler.rustc);
74+
build_rtstartup_cmd
75+
.arg("--target")
76+
.arg(&target_triple)
77+
.arg("--emit=obj")
78+
.arg("-o")
79+
.arg(target_rustlib_lib.join(format!("{file}.o")))
80+
.arg(rtstartup_src.join(format!("{file}.rs")));
81+
spawn_and_wait(build_rtstartup_cmd);
8582
}
8683
}
8784

@@ -209,6 +206,7 @@ fn build_clif_sysroot_for_triple(
209206
// Build sysroot
210207
let mut rustflags = " -Zforce-unstable-if-unmarked -Cpanic=abort".to_string();
211208
rustflags.push_str(&format!(" -Zcodegen-backend={}", cg_clif_dylib_path.to_str().unwrap()));
209+
// Necessary for MinGW to find rsbegin.o and rsend.o
212210
rustflags.push_str(&format!(" --sysroot={}", DIST_DIR.to_path(dirs).to_str().unwrap()));
213211
if channel == "release" {
214212
rustflags.push_str(" -Zmir-opt-level=3");

0 commit comments

Comments
 (0)