From 2a30a9895603b42caf84f14657dc29af7e747327 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Miku=C5=82a?= Date: Wed, 11 Sep 2024 00:53:53 +0200 Subject: [PATCH] rust: migrate CLANG{32,64} envs to gnullvm targets --- ...2-use-system-libs-for-crossed-builds.patch | 14 ++ mingw-w64-rust/0007-clang-subsystem.patch | 167 ------------------ mingw-w64-rust/PKGBUILD | 19 +- 3 files changed, 22 insertions(+), 178 deletions(-) create mode 100644 mingw-w64-rust/0002-use-system-libs-for-crossed-builds.patch delete mode 100644 mingw-w64-rust/0007-clang-subsystem.patch diff --git a/mingw-w64-rust/0002-use-system-libs-for-crossed-builds.patch b/mingw-w64-rust/0002-use-system-libs-for-crossed-builds.patch new file mode 100644 index 0000000000000..bbb3ec3b85949 --- /dev/null +++ b/mingw-w64-rust/0002-use-system-libs-for-crossed-builds.patch @@ -0,0 +1,14 @@ +diff -urN rustc-1.81.0-src.orig/compiler/rustc_llvm/build.rs rustc-1.81.0-src/compiler/rustc_llvm/build.rs +--- rustc-1.81.0-src.orig/compiler/rustc_llvm/build.rs 2024-09-10 19:43:19.681781500 +0200 ++++ rustc-1.81.0-src/compiler/rustc_llvm/build.rs 2024-09-10 20:39:11.965208700 +0200 +@@ -220,9 +220,7 @@ + let mut cmd = Command::new(&llvm_config); + cmd.arg(llvm_link_arg).arg("--libs"); + +- if !is_crossed { +- cmd.arg("--system-libs"); +- } ++ cmd.arg("--system-libs"); + + // We need libkstat for getHostCPUName on SPARC builds. + // See also: https://github.com/llvm/llvm-project/issues/64186 diff --git a/mingw-w64-rust/0007-clang-subsystem.patch b/mingw-w64-rust/0007-clang-subsystem.patch deleted file mode 100644 index f52112a0b4dea..0000000000000 --- a/mingw-w64-rust/0007-clang-subsystem.patch +++ /dev/null @@ -1,167 +0,0 @@ -diff -urN rustc-1.65.0-src.orig/compiler/rustc_target/src/spec/crt_objects.rs rustc-1.65.0-src/compiler/rustc_target/src/spec/crt_objects.rs ---- rustc-1.65.0-src.orig/compiler/rustc_target/src/spec/crt_objects.rs 2022-11-02 15:36:24.000000000 +0100 -+++ rustc-1.65.0-src/compiler/rustc_target/src/spec/crt_objects.rs 2022-11-09 22:12:19.171603900 +0100 -@@ -52,17 +52,6 @@ - obj_table.iter().map(|(z, k)| (*z, k.iter().map(|b| (*b).into()).collect())).collect() - } - --pub(super) fn all(obj: &'static str) -> CrtObjects { -- new(&[ -- (LinkOutputKind::DynamicNoPicExe, &[obj]), -- (LinkOutputKind::DynamicPicExe, &[obj]), -- (LinkOutputKind::StaticNoPicExe, &[obj]), -- (LinkOutputKind::StaticPicExe, &[obj]), -- (LinkOutputKind::DynamicDylib, &[obj]), -- (LinkOutputKind::StaticDylib, &[obj]), -- ]) --} -- - pub(super) fn pre_musl_self_contained() -> CrtObjects { - new(&[ - (LinkOutputKind::DynamicNoPicExe, &["crt1.o", "crti.o", "crtbegin.o"]), -@@ -87,25 +76,25 @@ - - pub(super) fn pre_mingw_self_contained() -> CrtObjects { - new(&[ -- (LinkOutputKind::DynamicNoPicExe, &["crt2.o", "rsbegin.o"]), -- (LinkOutputKind::DynamicPicExe, &["crt2.o", "rsbegin.o"]), -- (LinkOutputKind::StaticNoPicExe, &["crt2.o", "rsbegin.o"]), -- (LinkOutputKind::StaticPicExe, &["crt2.o", "rsbegin.o"]), -- (LinkOutputKind::DynamicDylib, &["dllcrt2.o", "rsbegin.o"]), -- (LinkOutputKind::StaticDylib, &["dllcrt2.o", "rsbegin.o"]), -+ (LinkOutputKind::DynamicNoPicExe, &["crt2.o"]), -+ (LinkOutputKind::DynamicPicExe, &["crt2.o"]), -+ (LinkOutputKind::StaticNoPicExe, &["crt2.o"]), -+ (LinkOutputKind::StaticPicExe, &["crt2.o"]), -+ (LinkOutputKind::DynamicDylib, &["dllcrt2.o"]), -+ (LinkOutputKind::StaticDylib, &["dllcrt2.o"]), - ]) - } - - pub(super) fn post_mingw_self_contained() -> CrtObjects { -- all("rsend.o") -+ CrtObjects::new() - } - - pub(super) fn pre_mingw() -> CrtObjects { -- all("rsbegin.o") -+ CrtObjects::new() - } - - pub(super) fn post_mingw() -> CrtObjects { -- all("rsend.o") -+ CrtObjects::new() - } - - pub(super) fn pre_wasi_self_contained() -> CrtObjects { -diff -urN rustc-1.65.0-src.orig/compiler/rustc_target/src/spec/i686_pc_windows_gnu.rs rustc-1.65.0-src/compiler/rustc_target/src/spec/i686_pc_windows_gnu.rs ---- rustc-1.65.0-src.orig/compiler/rustc_target/src/spec/targets/i686_pc_windows_gnu.rs 2022-11-09 21:53:40.404728900 +0100 -+++ rustc-1.65.0-src/compiler/rustc_target/src/spec/targets/i686_pc_windows_gnu.rs 2022-11-09 22:07:46.188364200 +0100 -@@ -5,7 +5,7 @@ - base.cpu = "pentium4".into(); - base.max_atomic_width = Some(64); - base.frame_pointer = FramePointer::Always; // Required for backtraces -- base.linker = Some("i686-w64-mingw32-gcc".into()); -+ base.linker = Some("i686-w64-mingw32-clang".into()); - - // Mark all dynamic libraries and executables as compatible with the larger 4GiB address - // space available to x86 Windows binaries on x86_64. -$ diff -urN rustc-1.75.0-src/compiler/rustc_target/src/spec/base/windows_gnu.rs.orig rustc-1.75.0-src/compiler/rustc_target/src/spec/base/windows_gnu.rs ---- rustc-1.75.0-src/compiler/rustc_target/src/spec/base/windows_gnu.rs.orig 2023-12-21 17:55:28.000000000 +0100 -+++ rustc-1.75.0-src/compiler/rustc_target/src/spec/base/windows_gnu.rs 2023-12-22 17:29:48.415890500 +0100 -@@ -27,25 +27,7 @@ - - // Order of `late_link_args*` was found through trial and error to work with various - // mingw-w64 versions (not tested on the CI). It's expected to change from time to time. -- let mingw_libs = &[ -- "-lmsvcrt", -- "-lmingwex", -- "-lmingw32", -- "-lgcc", // alas, mingw* libraries above depend on libgcc -- // mingw's msvcrt is a weird hybrid import library and static library. -- // And it seems that the linker fails to use import symbols from msvcrt -- // that are required from functions in msvcrt in certain cases. For example -- // `_fmode` that is used by an implementation of `__p__fmode` in x86_64. -- // The library is purposely listed twice to fix that. -- // -- // See https://github.com/rust-lang/rust/pull/47483 for some more details. -- "-lmsvcrt", -- // Math functions missing in MSVCRT (they are present in UCRT) require -- // this dependency cycle: `libmingwex.a` -> `libmsvcrt.a` -> `libmingwex.a`. -- "-lmingwex", -- "-luser32", -- "-lkernel32", -- ]; -+ let mingw_libs = &[]; - let mut late_link_args = - TargetOptions::link_args(LinkerFlavor::Gnu(Cc::No, Lld::No), mingw_libs); - add_link_args(&mut late_link_args, LinkerFlavor::Gnu(Cc::Yes, Lld::No), mingw_libs); -@@ -56,7 +38,7 @@ - // If any of our crates are dynamically linked then we need to use - // the shared libgcc_s-dw2-1.dll. This is required to support - // unwinding across DLL boundaries. -- let dynamic_unwind_libs = &["-lgcc_s"]; -+ let dynamic_unwind_libs = &["-l:libunwind.dll.a"]; - let mut late_link_args_dynamic = - TargetOptions::link_args(LinkerFlavor::Gnu(Cc::No, Lld::No), dynamic_unwind_libs); - add_link_args( -@@ -69,7 +51,7 @@ - // binaries to be redistributed without the libgcc_s-dw2-1.dll - // dependency, but unfortunately break unwinding across DLL - // boundaries when unwinding across FFI boundaries. -- let static_unwind_libs = &["-lgcc_eh", "-l:libpthread.a"]; -+ let static_unwind_libs = &["-l:libunwind.a"]; - let mut late_link_args_static = - TargetOptions::link_args(LinkerFlavor::Gnu(Cc::No, Lld::No), static_unwind_libs); - add_link_args( -@@ -83,7 +65,8 @@ - env: "gnu".into(), - vendor: "pc".into(), - // FIXME(#13846) this should be enabled for windows -- function_sections: false, -+ function_sections: true, -+ no_default_libraries: false, - linker: Some("gcc".into()), - dynamic_linking: true, - dll_tls_export: false, -diff -urN rustc-1.78.0-src/compiler/rustc_target/src/spec/targets/x86_64_pc_windows_gnu.rs.orig rustc-1.78.0-src/compiler/rustc_target/src/spec/targets/x86_64_pc_windows_gnu.rs ---- rustc-1.78.0-src/compiler/rustc_target/src/spec/targets/x86_64_pc_windows_gnu.rs.orig 2024-05-03 21:03:07.983614400 +0200 -+++ rustc-1.78.0-src/compiler/rustc_target/src/spec/targets/x86_64_pc_windows_gnu.rs 2024-05-03 21:37:12.067938000 +0200 -@@ -12,7 +12,7 @@ - ); - base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m64", "-Wl,--high-entropy-va"]); - base.max_atomic_width = Some(128); -- base.linker = Some("x86_64-w64-mingw32-gcc".into()); -+ base.linker = Some("x86_64-w64-mingw32-clang".into()); - - Target { - llvm_target: "x86_64-pc-windows-gnu".into(), -diff -urN rustc-1.76.0-src/src/bootstrap/bootstrap.py.orig rustc-1.76.0-src/src/bootstrap/bootstrap.py ---- rustc-1.76.0-src/src/bootstrap/bootstrap.py.orig 2024-02-05 22:14:29.622617100 +0100 -+++ rustc-1.76.0-src/src/bootstrap/bootstrap.py 2024-02-05 22:21:11.207527500 +0100 -@@ -616,6 +616,13 @@ - with output(self.rustc_stamp()) as rust_stamp: - rust_stamp.write(key) - -+ gcc_libs_hack = os.environ.get('GCC_LIBS_HACK') -+ gcc_libs_hack_dest = '{}/lib/rustlib/{}/lib'.format(bin_root, self.build) -+ shutil.copy(gcc_libs_hack + '/libgcc.a', gcc_libs_hack_dest) -+ shutil.copy(gcc_libs_hack + '/libgcc_eh.a', gcc_libs_hack_dest) -+ shutil.copy(gcc_libs_hack + '/libgcc_s.a', gcc_libs_hack_dest) -+ -+ - def should_fix_bins_and_dylibs(self): - """Whether or not `fix_bin_or_dylib` needs to be run; can only be True - on NixOS or if config.toml has `build.patch-binaries-for-nix` set. -diff -urN rustc-1.69.0-src/compiler/rustc_codegen_llvm/src/common.rs.orig rustc-1.69.0-src/compiler/rustc_codegen_llvm/src/common.rs ---- rustc-1.69.0-src/compiler/rustc_codegen_llvm/src/common.rs.orig 2023-06-03 18:04:48.695354700 +0200 -+++ rustc-1.69.0-src/compiler/rustc_codegen_llvm/src/common.rs 2023-06-03 18:04:55.208081500 +0200 -@@ -379,7 +379,7 @@ - } - - pub(crate) fn is_mingw_gnu_toolchain(target: &Target) -> bool { -- target.vendor == "pc" && target.os == "windows" && target.env == "gnu" && target.abi.is_empty() -+ false && target.vendor == "pc" && target.os == "windows" && target.env == "gnu" && target.abi.is_empty() - } - - pub(crate) fn i686_decorated_name( diff --git a/mingw-w64-rust/PKGBUILD b/mingw-w64-rust/PKGBUILD index dacd5b45b5e9a..8f71a78d9356d 100644 --- a/mingw-w64-rust/PKGBUILD +++ b/mingw-w64-rust/PKGBUILD @@ -4,7 +4,7 @@ # Contributor: Philippe Renon _bootstrapping=yes -if [[ $MINGW_PACKAGE_PREFIX == *-clang-aarch64 ]]; then +if [[ $MINGW_PACKAGE_PREFIX == *-clang-* ]]; then _bootstrapping=no fi @@ -20,7 +20,7 @@ pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}" $([[ ${CARCH} == i686 ]] || echo "${MINGW_PACKAGE_PREFIX}-rust-wasm") "${MINGW_PACKAGE_PREFIX}-rust-src") pkgver=1.81.0 -pkgrel=2 +pkgrel=3 pkgdesc="Systems programming language focused on safety, speed and concurrency (mingw-w64)" arch=('any') mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64' 'clang32') @@ -48,9 +48,10 @@ source=("${rust_dist_server}/${_realname}c-${pkgver}-src.tar.gz"{,.asc} "${embed_manifest_url}" "config.toml" "0001-rustc-llvm-fix-libs.patch" + # remove the next time rust is rebuilt + "0002-use-system-libs-for-crossed-builds.patch" "0004-compiler-Use-wasm-ld-for-wasm-targets.patch" "0005-win32-config.patch" - "0007-clang-subsystem.patch" "0008-disable-self-contained-for-gnu-targets.patch" "0011-disable-uac-for-installer.patch" "0012-vendor-embed-manifest.patch" @@ -62,9 +63,9 @@ sha256sums=('872448febdff32e50c3c90a7e15f9bb2db131d13c588fe9071b0ed88837ccfa7' '24ef6d949c0b5b1940c1d6a7aad78d86012152fb8845a1644bc939350d7b75e2' '3254e26a03cbbe23ab77add05a3de8717b9711428330280dc3ee7a2c924d8c3c' '7cb1773c288ffb1c1e751edc49b1890c84bf9c362742bc5225d19d474edb73a0' + '4ba4e63e7dfc78a215a0a5b1878d3e60988e9644c14e5581a09f3356dcb4ae6e' '56882f1a0f1404c10c7726d6cc37444f2b343e72b969badfcb43760f80db0f32' '7d1c4e49524b835a8eadc961b39f5594b12a522a1e24368999be2c7e85399e4e' - '87955818066f02e4a39c36a789caf45c524cf4a41f04ee1b0cc685bd5205e63e' '98bc3f2bd7371a5b8d14fd7b03bf05574e206d1d9e52bcfbe66d71398504da3c' '761d73328d9695a7a2bd2a10be8225f4a56801fee54cbb51c0841b7f16e2bde6' '23fc45f4e718770375be1c5196f035075de16d25e8f895100a3d1d2492995f86' @@ -113,8 +114,9 @@ prepare() { if [[ $MINGW_PACKAGE_PREFIX == *-clang-i686 || $MINGW_PACKAGE_PREFIX == *-clang-x86_64 ]]; then apply_patch_with_msg \ - 0007-clang-subsystem.patch + 0002-use-system-libs-for-crossed-builds.patch fi + if [[ $MINGW_PACKAGE_PREFIX == *-clang-* ]]; then apply_patch_with_msg \ 0011-disable-uac-for-installer.patch @@ -154,7 +156,7 @@ build() { "build/cache/${_stage0date}/" fi - if [[ $MINGW_PACKAGE_PREFIX == *-clang-aarch64 ]]; then + if [[ $MINGW_PACKAGE_PREFIX == *-clang-* ]]; then # We have to do the following because rust doesn't count x86_64-w64-mingw32 as a target triple OSTYPE="$CARCH-pc-windows-gnullvm" @@ -213,11 +215,6 @@ build() { sed -i '/target = \[/a\ "wasm32-unknown-unknown", "wasm32-wasip1", "wasm32-wasip1-threads", "wasm32-wasip2",' "${srcdir}/${_realname}c-${pkgver}-src/config.toml" fi - # Add target *-gnullvm - if [[ $MINGW_PACKAGE_PREFIX == *-clang-i686 || $MINGW_PACKAGE_PREFIX == *-clang-x86_64 ]]; then - sed -i '/target = \[/a\ "${CARCH}-pc-windows-gnullvm",' "${srcdir}/${_realname}c-${pkgver}-src/config.toml" - fi - # Building out of tree is not officially supported so we have to workaround some things like vendored deps cp -r ../${_realname}c-${pkgver}-src/.cargo . sed -i "s|directory = \"vendor\"|directory = \"../${_realname}c-${pkgver}-src/vendor\"|" .cargo/config.toml