From 1ee8cd50498d6ffefb90982dda365e4559670a44 Mon Sep 17 00:00:00 2001 From: Alex Huszagh Date: Fri, 17 Jun 2022 17:09:53 -0500 Subject: [PATCH] Add incomplete support for llvm-mingw targets. These targets have multiple issues:: - Rust expects the standard libraries `-lstdc++`, `-lgcc_eh` and `-lgcc` (LLVM uses `-lc++`). - No rustup support for any targets other than `i686` and `x86_64`, which we already support. - No WINE support for anything other than `i686` and `x86_64`. See cross-rs/cross#790 for discussion on this. --- ...ckerfile.aarch64-pc-windows-gnu-llvm-cross | 22 ++++++++++ ...Dockerfile.armv7-pc-windows-gnu-llvm-cross | 22 ++++++++++ .../Dockerfile.i686-pc-windows-gnu-llvm-cross | 40 +++++++++++++++++++ ...ockerfile.x86_64-pc-windows-gnu-llvm-cross | 40 +++++++++++++++++++ docker/llvm-mingw.sh | 34 ++++++++++++++++ docker/llvm-windows-entry.sh | 16 ++++++++ 6 files changed, 174 insertions(+) create mode 100644 docker/Dockerfile.aarch64-pc-windows-gnu-llvm-cross create mode 100644 docker/Dockerfile.armv7-pc-windows-gnu-llvm-cross create mode 100644 docker/Dockerfile.i686-pc-windows-gnu-llvm-cross create mode 100644 docker/Dockerfile.x86_64-pc-windows-gnu-llvm-cross create mode 100755 docker/llvm-mingw.sh create mode 100755 docker/llvm-windows-entry.sh diff --git a/docker/Dockerfile.aarch64-pc-windows-gnu-llvm-cross b/docker/Dockerfile.aarch64-pc-windows-gnu-llvm-cross new file mode 100644 index 0000000..0a4fc05 --- /dev/null +++ b/docker/Dockerfile.aarch64-pc-windows-gnu-llvm-cross @@ -0,0 +1,22 @@ +FROM ubuntu:20.04 +ARG DEBIAN_FRONTEND=noninteractive + +COPY common.sh lib.sh / +RUN /common.sh + +COPY cmake.sh / +RUN /cmake.sh + +COPY xargo.sh / +RUN /xargo.sh + +COPY cross-toolchains/docker/llvm-mingw.sh / +RUN /llvm-mingw.sh + +ENV PATH /usr/llvm-mingw/bin:$PATH + +ENV CARGO_TARGET_AARCH64_PC_WINDOWS_GNU_LINKER=aarch64-w64-mingw32-gcc \ + CARGO_TARGET_AARCH64_PC_WINDOWS_GNU_RUNNER=wine \ + CC_aarch64_pc_windows_gnu=aarch64-w64-mingw32-gcc \ + CXX_aarch64_pc_windows_gnu=aarch64-w64-mingw32-g++ \ + BINDGEN_EXTRA_CLANG_ARGS_aarch64_pc_windows_gnu="--sysroot=/usr/llvm-mingw/aarch64-w64-mingw32" diff --git a/docker/Dockerfile.armv7-pc-windows-gnu-llvm-cross b/docker/Dockerfile.armv7-pc-windows-gnu-llvm-cross new file mode 100644 index 0000000..33610be --- /dev/null +++ b/docker/Dockerfile.armv7-pc-windows-gnu-llvm-cross @@ -0,0 +1,22 @@ +FROM ubuntu:20.04 +ARG DEBIAN_FRONTEND=noninteractive + +COPY common.sh lib.sh / +RUN /common.sh + +COPY cmake.sh / +RUN /cmake.sh + +COPY xargo.sh / +RUN /xargo.sh + +COPY cross-toolchains/docker/llvm-mingw.sh / +RUN /llvm-mingw.sh + +ENV PATH /usr/llvm-mingw/bin:$PATH + +ENV CARGO_TARGET_ARMV7_PC_WINDOWS_GNU_LINKER=armv7-w64-mingw32-gcc \ + CARGO_TARGET_ARMV7_PC_WINDOWS_GNU_RUNNER=wine \ + CC_armv7_pc_windows_gnu=armv7-w64-mingw32-gcc \ + CXX_armv7_pc_windows_gnu=armv7-w64-mingw32-g++ \ + BINDGEN_EXTRA_CLANG_ARGS_armv7_pc_windows_gnu="--sysroot=/usr/llvm-mingw/armv7-w64-mingw32" diff --git a/docker/Dockerfile.i686-pc-windows-gnu-llvm-cross b/docker/Dockerfile.i686-pc-windows-gnu-llvm-cross new file mode 100644 index 0000000..46eb573 --- /dev/null +++ b/docker/Dockerfile.i686-pc-windows-gnu-llvm-cross @@ -0,0 +1,40 @@ +FROM ubuntu:20.04 +ARG DEBIAN_FRONTEND=noninteractive + +COPY common.sh lib.sh / +RUN /common.sh + +COPY cmake.sh / +RUN /cmake.sh + +COPY xargo.sh / +RUN /xargo.sh + +COPY wine.sh / +RUN /wine.sh + +COPY cross-toolchains/docker/llvm-mingw.sh / +RUN /llvm-mingw.sh + +# run-detectors are responsible for calling the correct interpreter for exe +# files. For some reason it does not work inside a docker container (it works +# fine in the host). So we replace the usual paths of run-detectors to run wine +# directly. This only affects the guest, we are not messing up with the host. +# +# See /usr/share/doc/binfmt-support/detectors +RUN mkdir -p /usr/lib/binfmt-support/ && \ + rm -f /usr/lib/binfmt-support/run-detectors /usr/bin/run-detectors && \ + ln -s /usr/bin/wine /usr/lib/binfmt-support/run-detectors && \ + ln -s /usr/bin/wine /usr/bin/run-detectors + +COPY cross-toolchains/docker/llvm-windows-entry.sh / +ENV CROSS_WINE_ARCH i686-w64-mingw32 +ENTRYPOINT ["/llvm-windows-entry.sh"] + +ENV PATH /usr/llvm-mingw/bin:$PATH + +ENV CARGO_TARGET_I686_PC_WINDOWS_GNU_LINKER=i686-w64-mingw32-gcc \ + CARGO_TARGET_I686_PC_WINDOWS_GNU_RUNNER=wine \ + CC_i686_pc_windows_gnu=i686-w64-mingw32-gcc \ + CXX_i686_pc_windows_gnu=i686-w64-mingw32-g++ \ + BINDGEN_EXTRA_CLANG_ARGS_i686_pc_windows_gnu="--sysroot=/usr/llvm-mingw/i686-w64-mingw32" diff --git a/docker/Dockerfile.x86_64-pc-windows-gnu-llvm-cross b/docker/Dockerfile.x86_64-pc-windows-gnu-llvm-cross new file mode 100644 index 0000000..1cfaf35 --- /dev/null +++ b/docker/Dockerfile.x86_64-pc-windows-gnu-llvm-cross @@ -0,0 +1,40 @@ +FROM ubuntu:20.04 +ARG DEBIAN_FRONTEND=noninteractive + +COPY common.sh lib.sh / +RUN /common.sh + +COPY cmake.sh / +RUN /cmake.sh + +COPY xargo.sh / +RUN /xargo.sh + +COPY wine.sh / +RUN /wine.sh + +COPY cross-toolchains/docker/llvm-mingw.sh / +RUN /llvm-mingw.sh + +# run-detectors are responsible for calling the correct interpreter for exe +# files. For some reason it does not work inside a docker container (it works +# fine in the host). So we replace the usual paths of run-detectors to run wine +# directly. This only affects the guest, we are not messing up with the host. +# +# See /usr/share/doc/binfmt-support/detectors +RUN mkdir -p /usr/lib/binfmt-support/ && \ + rm -f /usr/lib/binfmt-support/run-detectors /usr/bin/run-detectors && \ + ln -s /usr/bin/wine /usr/lib/binfmt-support/run-detectors && \ + ln -s /usr/bin/wine /usr/bin/run-detectors + +COPY cross-toolchains/docker/llvm-windows-entry.sh / +ENV CROSS_WINE_ARCH x86_64-w64-mingw32 +ENTRYPOINT ["/llvm-windows-entry.sh"] + +ENV PATH /usr/llvm-mingw/bin:$PATH + +ENV CARGO_TARGET_X86_64_PC_WINDOWS_GNU_LINKER=x86_64-w64-mingw32-gcc \ + CARGO_TARGET_X86_64_PC_WINDOWS_GNU_RUNNER=wine \ + CC_x86_64_pc_windows_gnu=x86_64-w64-mingw32-gcc \ + CXX_x86_64_pc_windows_gnu=x86_64-w64-mingw32-g++ \ + BINDGEN_EXTRA_CLANG_ARGS_x86_64_pc_windows_gnu="--sysroot=/usr/llvm-mingw/x86_64-w64-mingw32" diff --git a/docker/llvm-mingw.sh b/docker/llvm-mingw.sh new file mode 100755 index 0000000..a0302da --- /dev/null +++ b/docker/llvm-mingw.sh @@ -0,0 +1,34 @@ +#!/usr/bin/env bash + +set -x +set -euo pipefail + +# shellcheck disable=SC1091 +. lib.sh + +main() { + local version=20220323 + local host_os="ubuntu-18.04" + local host_arch=x86_64 + local filename="llvm-mingw-${version}-msvcrt-${host_os}-${host_arch}.tar.xz" + local url="https://github.com/mstorsjo/llvm-mingw/releases/download/$%7Bversion%7D/$%7Bfilename%7D" + + install_packages xz-utils + + local td + td="$(mktemp -d)" + + pushd "${td}" + + local root="/usr/llvm-mingw" + mkdir -p "${root}" + curl --retry 3 -sSfL "${url}" -O + tar --strip-components=1 -xJf "${filename}" --directory "${root}" + + popd + + rm -rf "${td}" + rm "${0}" +} + +main "${@}" diff --git a/docker/llvm-windows-entry.sh b/docker/llvm-windows-entry.sh new file mode 100755 index 0000000..a7c6609 --- /dev/null +++ b/docker/llvm-windows-entry.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash + +set -e + +export HOME=/tmp/home +mkdir -p "${HOME}" + +# Initialize the wine prefix (virtual windows installation) +export WINEPREFIX=/tmp/wine +mkdir -p "${WINEPREFIX}" +# FIXME: Make the wine prefix initialization faster +wineboot &> /dev/null + +export WINEPATH="/usr/bin/llvm-mingw/${CROSS_WINE_ARCH}/bin" + +exec "$@"