From c950f2265ef898ff760219d16298bd96fecb7155 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sat, 14 Jan 2023 17:02:21 +0000 Subject: [PATCH] Build rtstartup for MinGW from scratch Rather than copying it from an existing sysroot --- .github/workflows/main.yml | 1 - build_system/build_sysroot.rs | 34 ++++++++++++++++------------------ 2 files changed, 16 insertions(+), 19 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index f1badb792cd..1181c935b83 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -77,7 +77,6 @@ jobs: run: | sudo apt-get update sudo apt-get install -y gcc-mingw-w64-x86-64 wine-stable - rustup target add x86_64-pc-windows-gnu - name: Install AArch64 toolchain and qemu if: matrix.os == 'ubuntu-latest' && matrix.env.TARGET_TRIPLE == 'aarch64-unknown-linux-gnu' diff --git a/build_system/build_sysroot.rs b/build_system/build_sysroot.rs index 9eebcf95505..413aa3444a5 100644 --- a/build_system/build_sysroot.rs +++ b/build_system/build_sysroot.rs @@ -64,24 +64,21 @@ pub(crate) fn build_sysroot( fs::create_dir_all(&host_rustlib_lib).unwrap(); fs::create_dir_all(&target_rustlib_lib).unwrap(); - if target_triple == "x86_64-pc-windows-gnu" { - if !default_sysroot.join("lib").join("rustlib").join(&target_triple).join("lib").exists() { - eprintln!( - "The x86_64-pc-windows-gnu target needs to be installed first before it is possible \ - to compile a sysroot for it.", - ); - process::exit(1); - } - for file in fs::read_dir( - default_sysroot.join("lib").join("rustlib").join(&target_triple).join("lib"), - ) - .unwrap() - { - let file = file.unwrap().path(); - if file.extension().map_or(true, |ext| ext.to_str().unwrap() != "o") { - continue; // only copy object files - } - try_hard_link(&file, target_rustlib_lib.join(file.file_name().unwrap())); + if target_triple.ends_with("windows-gnu") { + eprintln!("[BUILD] rtstartup for {target_triple}"); + + let rtstartup_src = SYSROOT_SRC.to_path(dirs).join("library").join("rtstartup"); + + for file in ["rsbegin", "rsend"] { + let mut build_rtstartup_cmd = Command::new(&bootstrap_host_compiler.rustc); + build_rtstartup_cmd + .arg("--target") + .arg(&target_triple) + .arg("--emit=obj") + .arg("-o") + .arg(target_rustlib_lib.join(format!("{file}.o"))) + .arg(rtstartup_src.join(format!("{file}.rs"))); + spawn_and_wait(build_rtstartup_cmd); } } @@ -209,6 +206,7 @@ fn build_clif_sysroot_for_triple( // Build sysroot let mut rustflags = " -Zforce-unstable-if-unmarked -Cpanic=abort".to_string(); rustflags.push_str(&format!(" -Zcodegen-backend={}", cg_clif_dylib_path.to_str().unwrap())); + // Necessary for MinGW to find rsbegin.o and rsend.o rustflags.push_str(&format!(" --sysroot={}", DIST_DIR.to_path(dirs).to_str().unwrap())); if channel == "release" { rustflags.push_str(" -Zmir-opt-level=3");