From 11cd541f7cd715e7d269cc89391ba411fb15bdaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Miku=C5=82a?= Date: Wed, 28 Sep 2022 21:30:25 +0200 Subject: [PATCH 1/7] wip --- mingw-w64-rust/0009-gnullvm-target.patch | 60 ++++++++++++++++++ mingw-w64-rust/PKGBUILD | 77 ++++++++++++++++-------- 2 files changed, 113 insertions(+), 24 deletions(-) create mode 100644 mingw-w64-rust/0009-gnullvm-target.patch diff --git a/mingw-w64-rust/0009-gnullvm-target.patch b/mingw-w64-rust/0009-gnullvm-target.patch new file mode 100644 index 0000000000000..2a7b2c51f0d7e --- /dev/null +++ b/mingw-w64-rust/0009-gnullvm-target.patch @@ -0,0 +1,60 @@ +diff -urN rustc-1.64.0-src.orig/compiler/rustc_llvm/build.rs rustc-1.64.0-src/compiler/rustc_llvm/build.rs +--- rustc-1.64.0-src.orig/compiler/rustc_llvm/build.rs 2022-09-24 00:14:19.728138800 +0200 ++++ rustc-1.64.0-src/compiler/rustc_llvm/build.rs 2022-09-24 17:42:37.065263700 +0200 +@@ -235,9 +235,8 @@ + let mut cmd = Command::new(&llvm_config); + cmd.arg(llvm_link_arg).arg("--libs"); + +- if !is_crossed { +- cmd.arg("--system-libs"); +- } else if target.contains("windows-gnu") { ++ cmd.arg("--system-libs"); ++ if target.contains("windows-gnu") { + println!("cargo:rustc-link-lib=shell32"); + println!("cargo:rustc-link-lib=uuid"); + } else if target.contains("netbsd") || target.contains("haiku") || target.contains("darwin") { +diff -urN rustc-1.64.0-src.orig/library/unwind/src/libunwind.rs rustc-1.64.0-src/library/unwind/src/libunwind.rs +--- rustc-1.64.0-src.orig/library/unwind/src/libunwind.rs 2022-09-19 16:07:21.000000000 +0200 ++++ rustc-1.64.0-src/library/unwind/src/libunwind.rs 2022-09-24 16:33:03.606975800 +0200 +@@ -90,7 +90,7 @@ + // rustc_codegen_ssa::src::back::symbol_export, rustc_middle::middle::exported_symbols + // and RFC 2841 + #[cfg_attr( +- all(feature = "llvm-libunwind", any(target_os = "fuchsia", target_os = "linux")), ++ any(all(feature = "llvm-libunwind", any(target_os = "fuchsia", target_os = "linux")), all(target_os = "windows", target_env = "gnu", target_abi = "llvm")), + link(name = "unwind", kind = "static", modifiers = "-bundle") + )] + extern "C-unwind" { +diff -urN rustc-1.64.0-src.orig/src/bootstrap/compile.rs rustc-1.64.0-src/src/bootstrap/compile.rs +--- rustc-1.64.0-src.orig/src/bootstrap/compile.rs 2022-09-19 16:07:21.000000000 +0200 ++++ rustc-1.64.0-src/src/bootstrap/compile.rs 2022-09-24 16:19:22.998368200 +0200 +@@ -206,7 +206,6 @@ + } + + if target == "x86_64-fortanix-unknown-sgx" +- || target.contains("pc-windows-gnullvm") + || builder.config.llvm_libunwind(target) == LlvmLibunwind::InTree + && (target.contains("linux") || target.contains("fuchsia")) + { +diff -urN rustc-1.64.0-src.orig/src/bootstrap/dist.rs rustc-1.64.0-src/src/bootstrap/dist.rs +--- rustc-1.64.0-src.orig/src/bootstrap/dist.rs 2022-09-24 00:14:19.929176800 +0200 ++++ rustc-1.64.0-src/src/bootstrap/dist.rs 2022-09-24 20:04:09.511879200 +0200 +@@ -364,18 +364,6 @@ + + builder.install(&builder.rustdoc(compiler), &image.join("bin"), 0o755); + +- let ra_proc_macro_srv = builder +- .ensure(tool::RustAnalyzerProcMacroSrv { +- compiler: builder.compiler_for( +- compiler.stage, +- builder.config.build, +- compiler.host, +- ), +- target: compiler.host, +- }) +- .expect("rust-analyzer-proc-macro-server always builds"); +- builder.install(&ra_proc_macro_srv, &image.join("libexec"), 0o755); +- + let libdir_relative = builder.libdir_relative(compiler); + + // Copy runtime DLLs needed by the compiler diff --git a/mingw-w64-rust/PKGBUILD b/mingw-w64-rust/PKGBUILD index c0d08c0460da7..2f66cae898dca 100644 --- a/mingw-w64-rust/PKGBUILD +++ b/mingw-w64-rust/PKGBUILD @@ -12,7 +12,7 @@ pkgver=1.64.0 pkgrel=1 pkgdesc="Systems programming language focused on safety, speed and concurrency (mingw-w64)" arch=('any') -mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64') +mingw_arch=('clangarm64') url="https://www.rust-lang.org/" license=('MIT' 'Apache') makedepends=("${MINGW_PACKAGE_PREFIX}-cmake" @@ -27,6 +27,7 @@ makedepends=("${MINGW_PACKAGE_PREFIX}-cmake" "${MINGW_PACKAGE_PREFIX}-autotools" $([[ "$_bootstrapping" == "no" ]] && echo "${MINGW_PACKAGE_PREFIX}-rust") "${MINGW_PACKAGE_PREFIX}-zlib" + "mingw-w64-clang-x86_64-toolchain" "git") options=('staticlibs' 'strip') #install=rust.install @@ -36,14 +37,16 @@ source=("https://static.rust-lang.org/dist/${_realname}c-${pkgver}-src.tar.gz"{, "0004-unbundle-gcc.patch" "0005-win32-config.patch" "0007-clang-subsystem.patch" - "0008-disable-self-contained.patch") + "0008-disable-self-contained.patch" + "0009-gnullvm-target.patch") sha256sums=('b3cd9f481e1a2901bf6f3808d30c69cc4ea80d93c4cc4e2ed52258b180381205' 'SKIP' '7cb1773c288ffb1c1e751edc49b1890c84bf9c362742bc5225d19d474edb73a0' '36c531c73a2c12b3e66aa22526a404c3f770f1ab7e0e76c55af6fcc1a17e46fe' 'c4e5ffeef84296d39c3e3e8f807fc8b33ce786b1e4edb21eef26b053586aca27' 'c38450682a48bb1d5a0ddaa37ae5b324d39a9e0626daa2fc695caec1a53d6c35' - '29f84cb8e05ce304e102e28912a3b4464add406a8ec37a6c6d717b9b7d81b67b') + '29f84cb8e05ce304e102e28912a3b4464add406a8ec37a6c6d717b9b7d81b67b' + '03073682837e628eb4d5bfb74c03f6c9d4ad25022ac214f9253a53f132f3084f') validpgpkeys=('108F66205EAEB0AAA8DD5E1C85AB96E6FA1BE5FE' # Rust Language (Tag and Release Signing Key) '474E22316ABF4785A88C6E8EA2C794A986419D8A' # Tom Stellard 'B6C8F98282B944E3B0D5C2530FC3042E345AD05D') # Hans Wennborg @@ -70,18 +73,23 @@ prepare() { 0005-win32-config.patch \ 0008-disable-self-contained.patch - if [[ $MINGW_PACKAGE_PREFIX == *-clang-* ]]; then + if [[ $MINGW_PACKAGE_PREFIX == *-clang-x86_64 ]]; then apply_patch_with_msg \ 0007-clang-subsystem.patch fi + + if [[ $MINGW_PACKAGE_PREFIX == *-clang-* ]]; then + apply_patch_with_msg \ + 0009-gnullvm-target.patch + fi } build() { [[ -d "${srcdir}/${MSYSTEM}" ]] && rm -rf "${srcdir}/${MSYSTEM}" mkdir -p "${srcdir}/${MSYSTEM}" && cd "${srcdir}/${MSYSTEM}" - # The ultimate hack to let the bootstrap compiler use libgcc* libs - if [[ $MINGW_PACKAGE_PREFIX == *-clang-* ]]; then + The ultimate hack to let the bootstrap compiler use libgcc* libs + if [[ $MINGW_PACKAGE_PREFIX == *-clang-x86_64 ]]; then export GCC_LIBS_HACK="$(cygpath -am build/missing-libs-hack)" mkdir -p "${GCC_LIBS_HACK}" cp "$(cygpath -u $(clang -print-libgcc-file-name))" "${GCC_LIBS_HACK}/libgcc.a" @@ -90,50 +98,68 @@ build() { export RUSTFLAGS_BOOTSTRAP="-C link-arg=-L$(cygpath -am build/missing-libs-hack)" fi - # We have to do the following because rust doesn't count x86_64-w64-mingw32 as a target triple - OSTYPE="$CARCH-pc-windows-gnu" - - # Otherwise it uses gcc during bootstrap, even when we build for clang - export CARGO_TARGET_${CARCH^^}_PC_WINDOWS_GNU_LINKER="${CC}" - local -a _rust_conf=() if [ "${_bootstrapping}" = "no" ]; then _rust_conf+=("--local-rust-root=$(cygpath -m ${MINGW_PREFIX})") fi + # We have to do the following because rust doesn't count x86_64-w64-mingw32 as a target triple + BUILD="$CARCH-pc-windows-gnu" + + # Cross compile to gnullvm host + if [[ $MINGW_PACKAGE_PREFIX == *-clang-aarch64 ]]; then + HOST="$CARCH-pc-windows-gnullvm" + export PATH="/clang64/bin:${PATH}" + _rust_conf+=("--set target.${BUILD}.cc=/clang64/bin/gcc.exe" + "--set target.${BUILD}.cxx=/clang64/bin/g++.exe" + "--set target.${BUILD}.linker=/clang64/bin/gcc.exe" + "--set target.${BUILD}.llvm-config=/clang64/bin/llvm-config.exe" + "--set target.${HOST}.cc=${MINGW_PREFIX}/bin/clang.exe" + "--set target.${HOST}.cxx=${MINGW_PREFIX}/bin/clang++.exe" + "--set target.${HOST}.linker=${MINGW_PREFIX}/bin/clang.exe" + "--set target.${HOST}.llvm-config=${MINGW_PREFIX}/bin/llvm-config.exe" + "--tools=cargo,clippy,rustfmt,src" + ) + else + HOST="$BUILD" + fi + # For a faster build: # - add --disable-docs and --disable-compiler-docs # - compile only rustc by removing --enable-extended # - run makepkg-mingw with --nocheck + # - remove --stage 2 (or set it to 1) MSYS2_ARG_CONV_EXCL="--prefix;--sysconfdir;--localstatedir" \ ../${_realname}c-${pkgver}-src/configure \ --prefix=${MINGW_PREFIX} \ --sysconfdir=${MINGW_PREFIX}/etc \ --localstatedir=${MINGW_PREFIX}/var/lib \ - --build=$OSTYPE \ - --host=$OSTYPE \ - --target=$OSTYPE \ + --build=$BUILD \ + --host=$HOST \ + --target=$HOST \ --release-channel=stable \ --release-description="Rev${pkgrel}, Built by MSYS2 project" \ --enable-ninja \ --enable-extended \ --disable-llvm-static-stdcpp \ --disable-codegen-tests \ + --enable-vendor \ --llvm-root=${MINGW_PREFIX} \ --python=${MINGW_PREFIX}/bin/python \ - ${_rust_conf} + --set target.${BUILD}.linker="${CC}" \ + ${_rust_conf[@]} DEP_NGHTTP_ROOT=${MINGW_PREFIX} \ DEP_OPENSSL_ROOT=${MINGW_PREFIX} \ DEP_Z_ROOT=${MINGW_PREFIX} \ - ${MINGW_PREFIX}/bin/python ../${_realname}c-${pkgver}-src/x.py build --verbose --stage 2 + ${MINGW_PREFIX}/bin/python ../${_realname}c-${pkgver}-src/x.py build # create the install at a temporary directory DEP_NGHTTP_ROOT=${MINGW_PREFIX} \ DEP_OPENSSL_ROOT=${MINGW_PREFIX} \ DEP_Z_ROOT=${MINGW_PREFIX} \ - DESTDIR="$PWD"/dest-rust ${MINGW_PREFIX}/bin/python ../${_realname}c-${pkgver}-src/x.py install --stage 2 --verbose + DESTDIR="$PWD"/dest-rust ${MINGW_PREFIX}/bin/python ../${_realname}c-${pkgver}-src/x.py install # move docs out of the way for splitting mv dest-rust/${MINGW_PREFIX}/share/doc dest-doc @@ -141,15 +167,18 @@ build() { rm -f dest-rust/${MINGW_PREFIX}/bin/libgcc*.dll rm -f dest-rust/${MINGW_PREFIX}/bin/libstd*.dll rm -f dest-rust/${MINGW_PREFIX}/bin/libwinpthread*.dll - rm -f dest-rust/${MINGW_PREFIX}/lib/rustlib/$OSTYPE/lib/self-contained/* + rm -f dest-rust/${MINGW_PREFIX}/lib/rustlib/$HOST/lib/self-contained/* } check() { - cd "${srcdir}/${MSYSTEM}" - DEP_NGHTTP_ROOT=${MINGW_PREFIX} \ - DEP_OPENSSL_ROOT=${MINGW_PREFIX} \ - DEP_Z_ROOT=${MINGW_PREFIX} \ - ${MINGW_PREFIX}/bin/python ../${_realname}c-${pkgver}-src/x.py test --stage 2 --exclude src/test/debuginfo + # The tests won't succeed in cross-compilation + if [[ $MINGW_PACKAGE_PREFIX != *-clang-aarch64 ]]; then + cd "${srcdir}/${MSYSTEM}" + DEP_NGHTTP_ROOT=${MINGW_PREFIX} \ + DEP_OPENSSL_ROOT=${MINGW_PREFIX} \ + DEP_Z_ROOT=${MINGW_PREFIX} \ + ${MINGW_PREFIX}/bin/python ../${_realname}c-${pkgver}-src/x.py test --stage 2 --exclude src/test/debuginfo + fi } From 1f1ab909332bea9df5a483fed7e720bc05c0c689 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Miku=C5=82a?= Date: Thu, 29 Sep 2022 17:55:04 +0200 Subject: [PATCH 2/7] Do not use group in dependencies --- mingw-w64-rust/PKGBUILD | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mingw-w64-rust/PKGBUILD b/mingw-w64-rust/PKGBUILD index 2f66cae898dca..08f35f4922d60 100644 --- a/mingw-w64-rust/PKGBUILD +++ b/mingw-w64-rust/PKGBUILD @@ -27,7 +27,8 @@ makedepends=("${MINGW_PACKAGE_PREFIX}-cmake" "${MINGW_PACKAGE_PREFIX}-autotools" $([[ "$_bootstrapping" == "no" ]] && echo "${MINGW_PACKAGE_PREFIX}-rust") "${MINGW_PACKAGE_PREFIX}-zlib" - "mingw-w64-clang-x86_64-toolchain" + "mingw-w64-clang-x86_64-clang" + "mingw-w64-clang-x86_64-libc++" "git") options=('staticlibs' 'strip') #install=rust.install From 2f9c2bc845ff402e850ed6c0ed3f062150976e0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Miku=C5=82a?= Date: Thu, 29 Sep 2022 21:59:09 +0200 Subject: [PATCH 3/7] Fix comment --- mingw-w64-rust/PKGBUILD | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mingw-w64-rust/PKGBUILD b/mingw-w64-rust/PKGBUILD index 08f35f4922d60..6aae418412960 100644 --- a/mingw-w64-rust/PKGBUILD +++ b/mingw-w64-rust/PKGBUILD @@ -89,7 +89,7 @@ build() { [[ -d "${srcdir}/${MSYSTEM}" ]] && rm -rf "${srcdir}/${MSYSTEM}" mkdir -p "${srcdir}/${MSYSTEM}" && cd "${srcdir}/${MSYSTEM}" - The ultimate hack to let the bootstrap compiler use libgcc* libs + # The ultimate hack to let the bootstrap compiler use libgcc* libs if [[ $MINGW_PACKAGE_PREFIX == *-clang-x86_64 ]]; then export GCC_LIBS_HACK="$(cygpath -am build/missing-libs-hack)" mkdir -p "${GCC_LIBS_HACK}" From c5d7cbda67ee9817315852dfb7ae8da1e51938de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Miku=C5=82a?= Date: Fri, 30 Sep 2022 02:06:30 +0200 Subject: [PATCH 4/7] Fix build triple --- mingw-w64-rust/PKGBUILD | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/mingw-w64-rust/PKGBUILD b/mingw-w64-rust/PKGBUILD index 6aae418412960..784025b6c27c6 100644 --- a/mingw-w64-rust/PKGBUILD +++ b/mingw-w64-rust/PKGBUILD @@ -79,7 +79,7 @@ prepare() { 0007-clang-subsystem.patch fi - if [[ $MINGW_PACKAGE_PREFIX == *-clang-* ]]; then + if [[ $MINGW_PACKAGE_PREFIX == *-clang-aarch64 ]]; then apply_patch_with_msg \ 0009-gnullvm-target.patch fi @@ -104,11 +104,9 @@ build() { _rust_conf+=("--local-rust-root=$(cygpath -m ${MINGW_PREFIX})") fi - # We have to do the following because rust doesn't count x86_64-w64-mingw32 as a target triple - BUILD="$CARCH-pc-windows-gnu" - # Cross compile to gnullvm host if [[ $MINGW_PACKAGE_PREFIX == *-clang-aarch64 ]]; then + BUILD="x86_64-pc-windows-gnu" HOST="$CARCH-pc-windows-gnullvm" export PATH="/clang64/bin:${PATH}" _rust_conf+=("--set target.${BUILD}.cc=/clang64/bin/gcc.exe" @@ -122,6 +120,7 @@ build() { "--tools=cargo,clippy,rustfmt,src" ) else + BUILD="$CARCH-pc-windows-gnu" HOST="$BUILD" fi From f42a352f3834504b950e5ca94e846ced43306444 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Miku=C5=82a?= Date: Fri, 30 Sep 2022 16:56:38 +0200 Subject: [PATCH 5/7] Do not vendor --- mingw-w64-rust/PKGBUILD | 1 - 1 file changed, 1 deletion(-) diff --git a/mingw-w64-rust/PKGBUILD b/mingw-w64-rust/PKGBUILD index 784025b6c27c6..28e0d6da46614 100644 --- a/mingw-w64-rust/PKGBUILD +++ b/mingw-w64-rust/PKGBUILD @@ -144,7 +144,6 @@ build() { --enable-extended \ --disable-llvm-static-stdcpp \ --disable-codegen-tests \ - --enable-vendor \ --llvm-root=${MINGW_PREFIX} \ --python=${MINGW_PREFIX}/bin/python \ --set target.${BUILD}.linker="${CC}" \ From 13ed436e173ae9686118789edc50cb0698853aac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Miku=C5=82a?= Date: Fri, 30 Sep 2022 21:31:19 +0200 Subject: [PATCH 6/7] Use clang and add gcc-compat --- mingw-w64-rust/PKGBUILD | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/mingw-w64-rust/PKGBUILD b/mingw-w64-rust/PKGBUILD index 28e0d6da46614..ff994618c95c8 100644 --- a/mingw-w64-rust/PKGBUILD +++ b/mingw-w64-rust/PKGBUILD @@ -29,6 +29,7 @@ makedepends=("${MINGW_PACKAGE_PREFIX}-cmake" "${MINGW_PACKAGE_PREFIX}-zlib" "mingw-w64-clang-x86_64-clang" "mingw-w64-clang-x86_64-libc++" + "mingw-w64-clang-x86_64-gcc-compat" "git") options=('staticlibs' 'strip') #install=rust.install @@ -109,9 +110,9 @@ build() { BUILD="x86_64-pc-windows-gnu" HOST="$CARCH-pc-windows-gnullvm" export PATH="/clang64/bin:${PATH}" - _rust_conf+=("--set target.${BUILD}.cc=/clang64/bin/gcc.exe" - "--set target.${BUILD}.cxx=/clang64/bin/g++.exe" - "--set target.${BUILD}.linker=/clang64/bin/gcc.exe" + _rust_conf+=("--set target.${BUILD}.cc=/clang64/bin/clang.exe" + "--set target.${BUILD}.cxx=/clang64/bin/clang++.exe" + "--set target.${BUILD}.linker=/clang64/bin/clang.exe" "--set target.${BUILD}.llvm-config=/clang64/bin/llvm-config.exe" "--set target.${HOST}.cc=${MINGW_PREFIX}/bin/clang.exe" "--set target.${HOST}.cxx=${MINGW_PREFIX}/bin/clang++.exe" From cc7396385017b0f29ee478df431911afb946a1f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Miku=C5=82a?= Date: Sat, 1 Oct 2022 00:06:09 +0200 Subject: [PATCH 7/7] Try with gcc --- mingw-w64-rust/PKGBUILD | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/mingw-w64-rust/PKGBUILD b/mingw-w64-rust/PKGBUILD index ff994618c95c8..bb43f8b5f88ee 100644 --- a/mingw-w64-rust/PKGBUILD +++ b/mingw-w64-rust/PKGBUILD @@ -27,9 +27,8 @@ makedepends=("${MINGW_PACKAGE_PREFIX}-cmake" "${MINGW_PACKAGE_PREFIX}-autotools" $([[ "$_bootstrapping" == "no" ]] && echo "${MINGW_PACKAGE_PREFIX}-rust") "${MINGW_PACKAGE_PREFIX}-zlib" - "mingw-w64-clang-x86_64-clang" - "mingw-w64-clang-x86_64-libc++" - "mingw-w64-clang-x86_64-gcc-compat" + "mingw-w64-x86_64-gcc" + "mingw-w64-x86_64-llvm" "git") options=('staticlibs' 'strip') #install=rust.install @@ -109,11 +108,11 @@ build() { if [[ $MINGW_PACKAGE_PREFIX == *-clang-aarch64 ]]; then BUILD="x86_64-pc-windows-gnu" HOST="$CARCH-pc-windows-gnullvm" - export PATH="/clang64/bin:${PATH}" - _rust_conf+=("--set target.${BUILD}.cc=/clang64/bin/clang.exe" - "--set target.${BUILD}.cxx=/clang64/bin/clang++.exe" - "--set target.${BUILD}.linker=/clang64/bin/clang.exe" - "--set target.${BUILD}.llvm-config=/clang64/bin/llvm-config.exe" + export PATH="/mingw64/bin:${PATH}" + _rust_conf+=("--set target.${BUILD}.cc=/mingw64/bin/gcc.exe" + "--set target.${BUILD}.cxx=/mingw64/bin/g++.exe" + "--set target.${BUILD}.linker=/mingw64/bin/gcc.exe" + "--set target.${BUILD}.llvm-config=/mingw64/bin/llvm-config.exe" "--set target.${HOST}.cc=${MINGW_PREFIX}/bin/clang.exe" "--set target.${HOST}.cxx=${MINGW_PREFIX}/bin/clang++.exe" "--set target.${HOST}.linker=${MINGW_PREFIX}/bin/clang.exe"