From 14b18e9e43482d113dd0754928da008e5302bc33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Miku=C5=82a?= Date: Wed, 2 Aug 2023 00:11:36 +0200 Subject: [PATCH] Provide prebuilt std for gnullvm targets --- .../host-x86_64/dist-various-1/Dockerfile | 11 +++++- .../dist-various-1/install-llvm-mingw.sh | 7 ++++ .../platform-support/pc-windows-gnullvm.md | 36 +++++++++++++------ .../rfcs/rfc-2627-raw-dylib/dlltool-failed.rs | 1 + .../rfc-2627-raw-dylib/invalid-dlltool.rs | 1 + 5 files changed, 44 insertions(+), 12 deletions(-) create mode 100755 src/ci/docker/host-x86_64/dist-various-1/install-llvm-mingw.sh diff --git a/src/ci/docker/host-x86_64/dist-various-1/Dockerfile b/src/ci/docker/host-x86_64/dist-various-1/Dockerfile index 09fbbac466c72..4cca2879481a3 100644 --- a/src/ci/docker/host-x86_64/dist-various-1/Dockerfile +++ b/src/ci/docker/host-x86_64/dist-various-1/Dockerfile @@ -55,6 +55,9 @@ RUN ./install-riscv64-none-elf.sh COPY host-x86_64/dist-various-1/install-riscv32-none-elf.sh /build RUN ./install-riscv32-none-elf.sh +COPY host-x86_64/dist-various-1/install-llvm-mingw.sh /build +RUN ./install-llvm-mingw.sh + # Suppress some warnings in the openwrt toolchains we downloaded ENV STAGING_DIR=/tmp @@ -110,6 +113,9 @@ ENV TARGETS=$TARGETS,armv7r-none-eabi ENV TARGETS=$TARGETS,armv7r-none-eabihf ENV TARGETS=$TARGETS,thumbv7neon-unknown-linux-gnueabihf ENV TARGETS=$TARGETS,armv7a-none-eabi +ENV TARGETS=$TARGETS,aarch64-pc-windows-gnullvm +ENV TARGETS=$TARGETS,i686-pc-windows-gnullvm +ENV TARGETS=$TARGETS,x86_64-pc-windows-gnullvm ENV CFLAGS_armv5te_unknown_linux_musleabi="-march=armv5te -marm -mfloat-abi=soft" \ CFLAGS_arm_unknown_linux_musleabi="-march=armv6 -marm" \ @@ -139,7 +145,10 @@ ENV CFLAGS_armv5te_unknown_linux_musleabi="-march=armv5te -marm -mfloat-abi=soft CC_riscv64imac_unknown_none_elf=riscv64-unknown-elf-gcc \ CFLAGS_riscv64imac_unknown_none_elf=-march=rv64imac -mabi=lp64 \ CC_riscv64gc_unknown_none_elf=riscv64-unknown-elf-gcc \ - CFLAGS_riscv64gc_unknown_none_elf=-march=rv64gc -mabi=lp64 + CFLAGS_riscv64gc_unknown_none_elf=-march=rv64gc -mabi=lp64 \ + CC_aarch64_pc_windows_gnullvm=aarch64-w64-mingw32-clang \ + CC_i686_pc_windows_gnullvm=i686-w64-mingw32-clang \ + CC_x86_64_pc_windows_gnullvm=x86_64-w64-mingw32-clang ENV RUST_CONFIGURE_ARGS \ --musl-root-armv5te=/musl-armv5te \ diff --git a/src/ci/docker/host-x86_64/dist-various-1/install-llvm-mingw.sh b/src/ci/docker/host-x86_64/dist-various-1/install-llvm-mingw.sh new file mode 100755 index 0000000000000..3a700a3832d78 --- /dev/null +++ b/src/ci/docker/host-x86_64/dist-various-1/install-llvm-mingw.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +set -ex + +archive=llvm-mingw-20231128-ucrt-ubuntu-20.04-x86_64.tar.xz +curl -L https://github.com/mstorsjo/llvm-mingw/releases/download/20231128/${archive} | \ +tar --extract --lzma --strip 1 --directory /usr/local diff --git a/src/doc/rustc/src/platform-support/pc-windows-gnullvm.md b/src/doc/rustc/src/platform-support/pc-windows-gnullvm.md index a6246fa3bd804..ed55bcf4f35e5 100644 --- a/src/doc/rustc/src/platform-support/pc-windows-gnullvm.md +++ b/src/doc/rustc/src/platform-support/pc-windows-gnullvm.md @@ -1,6 +1,6 @@ # \*-pc-windows-gnullvm -**Tier: 3** +**Tier: 2 (without host tools)** Windows targets similar to `*-pc-windows-gnu` but using UCRT as the runtime and various LLVM tools/libraries instead of GCC/Binutils. @@ -12,38 +12,52 @@ Target triples available so far: ## Target maintainers - [@mati865](https://github.com/mati865) +- [@thomcc](https://github.com/thomcc) ## Requirements -The easiest way to obtain these targets is cross-compilation but native build from `x86_64-pc-windows-gnu` is possible with few hacks which I don't recommend. +The easiest way to obtain these targets is cross-compilation, but native build from `x86_64-pc-windows-gnu` is possible with few hacks which I don't recommend. Std support is expected to be on pair with `*-pc-windows-gnu`. Binaries for this target should be at least on pair with `*-pc-windows-gnu` in terms of requirements and functionality. Those targets follow Windows calling convention for `extern "C"`. -Like with any other Windows target created binaries are in PE format. +Like with any other Windows target, created binaries are in PE format. ## Building the target -For cross-compilation I recommend using [llvm-mingw](https://github.com/mstorsjo/llvm-mingw) toolchain, one change that seems necessary beside configuring cross compilers is disabling experimental `m86k` target. Otherwise LLVM build fails with `multiple definition ...` errors. -Native bootstrapping builds require rather fragile hacks until host artifacts are available so I won't describe them here. +These targets can be easily cross-compiled +using [llvm-mingw](https://github.com/mstorsjo/llvm-mingw) toolchain or [MSYS2 CLANG*](https://www.msys2.org/docs/environments/) environments. +Just fill `[target.*]` sections for both build and resulting compiler and set installation prefix in `config.toml`. +Then run `./x.py install`. +In my case I had ran `./x.py install --host x86_64-pc-windows-gnullvm --target x86_64-pc-windows-gnullvm` inside MSYS2 MINGW64 shell +so `x86_64-pc-windows-gnu` was my build toolchain. + +Native bootstrapping is doable in two ways: +- cross-compile gnullvm host toolchain and use it as build toolchain for the next build, +- copy libunwind libraries and rename them to mimic libgcc like here: https://github.com/msys2/MINGW-packages/blob/68e640756df2df6df6afa60f025e3f936e7b977c/mingw-w64-rust/PKGBUILD#L108-L109, stage0 compiler will be mostly broken but good enough to build the next stage. + +The second option might stop working anytime, so it's not recommended. ## Building Rust programs -Rust does not yet ship pre-compiled artifacts for this target. To compile for -this target, you will either need to build Rust with the target enabled (see -"Building the target" above), or build your own copy of `core` by using -`build-std` or similar. +Rust does ship a pre-compiled std library for those targets. +That means one can easily cross-compile for those targets from other hosts if C proper toolchain is installed. + +Alternatively full toolchain can be built as described in the previous section. ## Testing Created binaries work fine on Windows or Wine using native hardware. Testing AArch64 on x86_64 is problematic though and requires spending some time with QEMU. -Once these targets bootstrap themselves on native hardware they should pass Rust testsuite. +Most of x86_64 testsuite does pass when cross-compiling, +with exception for `rustdoc` and `ui-fulldeps` that fail with and error regarding a missing library, +they do pass in native builds though. +The only failing test is std's `process::tests::test_proc_thread_attributes` for unknown reason. ## Cross-compilation toolchains and C code -Compatible C code can be built with Clang's `aarch64-pc-windows-gnu`, `i686-pc-windows-gnullvm` and `x86_64-pc-windows-gnu` targets as long as LLVM based C toolchains are used. +Compatible C code can be built with Clang's `aarch64-pc-windows-gnu`, `i686-pc-windows-gnullvm` and `x86_64-pc-windows-gnu` targets as long as LLVM-based C toolchains are used. Those include: - [llvm-mingw](https://github.com/mstorsjo/llvm-mingw) - [MSYS2 with CLANG* environment](https://www.msys2.org/docs/environments) diff --git a/tests/ui/rfcs/rfc-2627-raw-dylib/dlltool-failed.rs b/tests/ui/rfcs/rfc-2627-raw-dylib/dlltool-failed.rs index 5ff3cd25e67be..7d7c238049253 100644 --- a/tests/ui/rfcs/rfc-2627-raw-dylib/dlltool-failed.rs +++ b/tests/ui/rfcs/rfc-2627-raw-dylib/dlltool-failed.rs @@ -3,6 +3,7 @@ //@ only-gnu //@ only-windows //@ needs-dlltool +//@ ignore-llvm //@ compile-flags: --crate-type lib --emit link //@ normalize-stderr-test: "[^ ']*/dlltool.exe" -> "$$DLLTOOL" //@ normalize-stderr-test: "[^ ]*/foo.def" -> "$$DEF_FILE" diff --git a/tests/ui/rfcs/rfc-2627-raw-dylib/invalid-dlltool.rs b/tests/ui/rfcs/rfc-2627-raw-dylib/invalid-dlltool.rs index ac6a2998a4762..f7431d801f97f 100644 --- a/tests/ui/rfcs/rfc-2627-raw-dylib/invalid-dlltool.rs +++ b/tests/ui/rfcs/rfc-2627-raw-dylib/invalid-dlltool.rs @@ -2,6 +2,7 @@ //@ only-gnu //@ only-windows +//@ ignore-llvm //@ compile-flags: --crate-type lib --emit link -Cdlltool=does_not_exit.exe #[link(name = "foo", kind = "raw-dylib")] extern "C" {