Skip to content

Commit 47f22c7

Browse files
committed
Support windows-gnullvm
1 parent 1b1ed8c commit 47f22c7

14 files changed

+223
-54
lines changed

.github/.cspell/organization-dictionary.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ rustsec
2424
rustup
2525
valgrind
2626
xcompile
27-
Zdoctest
2827
Zmiri
2928

3029
// Rust target triple
@@ -152,12 +151,14 @@ endianness
152151
esac
153152
euxo
154153
gsub
154+
libc
155155
moreutils
156156
msys
157157
noninteractive
158158
noprofile
159159
norc
160160
nproc
161+
objcopy
161162
objdump
162163
pipefail
163164
powerset

.github/.cspell/project-dictionary.txt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ crtn
1717
CURDIR
1818
CXXSTDLIB
1919
debuginfo
20-
devel
2120
dilos
2221
distro
2322
earmv
@@ -45,7 +44,6 @@ ldso
4544
lgcc
4645
libada
4746
libbacktrace
48-
libc
4947
libcilkrts
5048
libexec
5149
libgcc
@@ -70,6 +68,7 @@ libstdc
7068
libunwind
7169
libvtv
7270
libx
71+
linaro
7372
lintian
7473
Loongson
7574
lstdc
@@ -106,7 +105,6 @@ nofp
106105
nosimd
107106
nostartfiles
108107
nostdinc
109-
objcopy
110108
octeon
111109
opensbi
112110
PCREL
@@ -139,8 +137,8 @@ virt
139137
wasmtime
140138
wchar
141139
WINEBOOT
142-
winehq
143140
WINEPATH
144141
WINEPREFIX
142+
wineserver
145143
Znwm
146144
zynq

.github/workflows/base.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ jobs:
6969
# illumos
7070
- target: x86_64-unknown-illumos
7171

72-
# Windows (GNU)
72+
# Windows (MinGW)
7373
# - target: i686-pc-windows-gnu # TODO
7474
- target: x86_64-pc-windows-gnu
7575
- target: x86_64-pc-windows-gnu

README.md

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ See also [setup-cross-toolchain-action](https://github.com/taiki-e/setup-cross-t
1818
- [Redox](#redox)
1919
- [WASI](#wasi)
2020
- [Emscripten](#emscripten)
21-
- [Windows (GNU)](#windows-gnu)
21+
- [Windows (MinGW)](#windows-mingw)
22+
- [Windows (LLVM MinGW)](#windows-llvm-mingw)
2223
- [No-std](#no-std)
2324

2425
## Platform Support
@@ -300,7 +301,7 @@ clang version and wasi-libc hash can be found here: https://github.com/WebAssemb
300301
- `asmjs-unknown-emscripten`
301302
- `wasm32-unknown-emscripten`
302303

303-
### Windows (GNU)
304+
### Windows (MinGW)
304305

305306
| libc | GCC | clang | C++ | test | host |
306307
| ---- | --- | ----- | --- | ---- | ---- |
@@ -322,6 +323,24 @@ GCC version: https://packages.ubuntu.com/en/focal/gcc-mingw-w64-base
322323
| `x86_64-pc-windows-gnu` | x86_64/aarch64 linux (glibc 2.31+) |
323324
| `i686-pc-windows-gnu` | x86_64 linux (glibc 2.31+) |
324325

326+
### Windows (LLVM MinGW)
327+
328+
| libc | GCC | clang | C++ | test | host |
329+
| ---- | --- | ----- | --- | ---- | ---- |
330+
| Mingw-w64 b190082 | N/A | 16.0.6 | ✓ (libc++) | ✓ (wine) | x86_64/aarch64 linux (glibc 2.31+) |
331+
332+
<!--
333+
Mingw-w64 version: https://github.com/mstorsjo/llvm-mingw/blob/20230614/build-mingw-w64.sh#L21
334+
Clang version: https://github.com/mstorsjo/llvm-mingw/releases/tag/20230614
335+
-->
336+
337+
([Dockerfile](docker/windows-gnu.Dockerfile))
338+
339+
**Supported targets**:
340+
341+
- `aarch64-pc-windows-gnullvm`
342+
- `x86_64-pc-windows-gnullvm`
343+
325344
### No-std
326345

327346
| libc | GCC | clang | C++ | run | host |

docker/android.Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ rm -rf "${arch}"
110110
EOF
111111
ENV ANDROID_DNS_MODE=local
112112
ENV ANDROID_ROOT=/system
113-
ENV TMPDIR=/tmp/
113+
ENV TMPDIR=/tmp
114114
COPY /test-base /test-base
115115
RUN /test-base/target.sh
116116
COPY /test /test

docker/test/entrypoint.sh

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -582,13 +582,36 @@ EOF
582582
;;
583583
*-windows-gnu*)
584584
runner="${RUST_TARGET}-runner"
585-
gcc_lib="$(basename "$(ls -d "${toolchain_dir}/lib/gcc/${RUST_TARGET}"/*posix)")"
585+
case "${RUST_TARGET}" in
586+
*-gnullvm*) winepath="\${toolchain_dir}/${RUST_TARGET}/bin" ;;
587+
*)
588+
gcc_lib="$(basename "$(ls -d "${toolchain_dir}/lib/gcc/${RUST_TARGET}"/*posix)")"
589+
winepath="\${toolchain_dir}/lib/gcc/${RUST_TARGET}/${gcc_lib};\${toolchain_dir}/${RUST_TARGET}/lib"
590+
;;
591+
esac
592+
case "${RUST_TARGET}" in
593+
aarch64*)
594+
# Refs: https://gitlab.com/Linaro/windowsonarm/woa-linux/-/blob/master/containers/unified.Dockerfile
595+
wine_root=/opt/wine-arm64
596+
wine_exe="${wine_root}"/bin/wine
597+
qemu_arch=aarch64
598+
for bin in wine wineserver wine-preloader; do
599+
sed -i "s/qemu-${qemu_arch}-static/qemu-${qemu_arch}/g" "${wine_root}/bin/${bin}"
600+
done
601+
cp "${wine_root}"/lib/ld-linux-aarch64.so.1 /lib/
602+
wineprefix="export WINEPREFIX=\${WINEPREFIX:-${wine_root}/wine-prefix}"
603+
[[ -f "${toolchain_dir}/bin/qemu-${qemu_arch}" ]] || cp "$(type -P "qemu-${qemu_arch}")" "${toolchain_dir}/bin"
604+
"qemu-${qemu_arch}" --version
605+
;;
606+
*) wine_exe=wine ;;
607+
esac
586608
cat >"${toolchain_dir}/bin/${runner}" <<EOF
587609
#!/bin/sh
588610
set -eu
589611
toolchain_dir="\$(cd "\$(dirname "\$0")"/.. && pwd)"
590-
export WINEPATH="\${toolchain_dir}/lib/gcc/${RUST_TARGET}/${gcc_lib};\${toolchain_dir}/${RUST_TARGET}/lib;\${WINEPATH:-}"
591-
exec wine "\$@"
612+
export WINEPATH="${winepath};\${WINEPATH:-}"
613+
${wineprefix:-}
614+
exec ${wine_exe} "\$@"
592615
EOF
593616
chmod +x "${toolchain_dir}/bin/${runner}"
594617
cat "${toolchain_dir}/bin/${runner}"

docker/test/test.sh

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -307,16 +307,29 @@ if [[ -z "${no_std}" ]]; then
307307
amd64)
308308
case "${RUST_TARGET}" in
309309
*-windows-gnu*)
310-
# Adapted from https://github.com/cross-rs/cross/blob/16a64e7028d90a3fdf285cfd642cdde9443c0645/docker/windows-entry.sh
311-
export HOME=/tmp/home
312-
mkdir -p "${HOME}"
313-
# Initialize the wine prefix (virtual windows installation)
314-
export WINEPREFIX=/tmp/wine
315-
mkdir -p "${WINEPREFIX}"
316-
if [[ ! -e /WINEBOOT ]]; then
317-
x wineboot &>/dev/null
318-
touch /WINEBOOT
319-
fi
310+
case "${RUST_TARGET}" in
311+
aarch64*)
312+
wine_root=/opt/wine-arm64
313+
export HOME=/tmp/home
314+
mkdir -p "${HOME}/.wine"
315+
if [[ ! -e /WINEBOOT ]]; then
316+
x "${wine_root}/bin/wineserver" &>/dev/null
317+
touch /WINEBOOT
318+
fi
319+
;;
320+
*)
321+
# Adapted from https://github.com/cross-rs/cross/blob/16a64e7028d90a3fdf285cfd642cdde9443c0645/docker/windows-entry.sh
322+
export HOME=/tmp/home
323+
mkdir -p "${HOME}"
324+
# Initialize the wine prefix (virtual windows installation)
325+
export WINEPREFIX=/tmp/wine
326+
mkdir -p "${WINEPREFIX}"
327+
if [[ ! -e /WINEBOOT ]]; then
328+
x wineboot &>/dev/null
329+
touch /WINEBOOT
330+
fi
331+
;;
332+
esac
320333
;;
321334
esac
322335
;;
@@ -1081,13 +1094,15 @@ case "${RUST_TARGET}" in
10811094
for bin in "${out_dir}"/*; do
10821095
if [[ -x "${bin}" ]]; then
10831096
case "${RUST_TARGET}" in
1097+
aarch64-*) assert_file_info 'PE32\+ executable \(console\) Aarch64, for MS Windows' "${bin}" ;;
10841098
i686-*) assert_file_info 'PE32 executable \(console\) Intel 80386' "${bin}" ;;
10851099
x86_64*) assert_file_info 'PE32\+ executable \(console\) x86-64' "${bin}" ;;
10861100
*) bail "unrecognized target '${RUST_TARGET}'" ;;
10871101
esac
10881102
assert_file_info 'for MS Windows' "${bin}"
10891103
else
10901104
case "${RUST_TARGET}" in
1105+
aarch64-*) assert_file_info 'data' "${bin}" ;; # TODO: ?
10911106
i686-*) assert_file_info 'Intel 80386 COFF object file' "${bin}" ;;
10921107
x86_64*) assert_file_info 'Intel amd64 COFF object file' "${bin}" ;;
10931108
*) bail "unrecognized target '${RUST_TARGET}'" ;;

docker/windows-gnu.Dockerfile

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ FROM ghcr.io/taiki-e/rust-cross-toolchain:"${RUST_TARGET}-base${TOOLCHAIN_TAG:+"
1010
FROM ghcr.io/taiki-e/build-base:ubuntu-"${UBUNTU_VERSION}" as builder
1111
SHELL ["/bin/bash", "-euxo", "pipefail", "-c"]
1212
ARG DEBIAN_FRONTEND=noninteractive
13-
ARG UBUNTU_VERSION
1413
ARG RUST_TARGET
1514
ARG TOOLCHAIN_DIR="/${RUST_TARGET}"
1615
ARG SYSROOT_DIR="${TOOLCHAIN_DIR}/${RUST_TARGET}"
@@ -48,27 +47,20 @@ RUN <<EOF
4847
dpkg_arch="$(dpkg --print-architecture)"
4948
case "${dpkg_arch##*-}" in
5049
amd64) dpkg --add-architecture i386 ;;
51-
arm64) dpkg --add-architecture armhf ;;
50+
arm64)
51+
dpkg --add-architecture armhf
52+
# TODO: do not skip if actual host is arm64
53+
exit 0
54+
;;
5255
*) echo >&2 "unsupported architecture '${dpkg_arch}'" && exit 1 ;;
5356
esac
54-
EOF
55-
RUN apt-get -o Acquire::Retries=10 update -qq && apt-get -o Acquire::Retries=10 -o Dpkg::Use-Pty=0 install -y --no-install-recommends \
57+
# See https://wiki.winehq.org/Ubuntu when install the latest wine.
58+
apt-get -o Acquire::Retries=10 update -qq && apt-get -o Acquire::Retries=10 -o Dpkg::Use-Pty=0 install -y --no-install-recommends \
5659
wine-stable \
5760
wine32 \
5861
wine64
59-
# To install the latest wine: https://wiki.winehq.org/Ubuntu
60-
# RUN <<EOF
61-
# curl --proto '=https' --tlsv1.2 -fsSL --retry 10 --retry-connrefused https://dl.winehq.org/wine-builds/winehq.key | apt-key add -
62-
# codename="$(grep '^VERSION_CODENAME=' /etc/os-release | sed 's/^VERSION_CODENAME=//')"
63-
# echo "deb https://dl.winehq.org/wine-builds/ubuntu/ ${codename} main" >/etc/apt/sources.list.d/winehq.list
64-
# EOF
65-
# # Use winehq-devel instead of winehq-stable (6.0.2), because mio needs wine 6.11+.
66-
# # https://dl.winehq.org/wine-builds/ubuntu/dists/focal/main/binary-amd64
67-
# # https://wiki.winehq.org/Wine_User%27s_Guide#Wine_from_WineHQ
68-
# # https://github.com/tokio-rs/mio/issues/1444
69-
# RUN apt-get -o Acquire::Retries=10 update -qq && apt-get -o Acquire::Retries=10 -o Dpkg::Use-Pty=0 install -y --no-install-recommends \
70-
# winehq-devel
71-
RUN wine --version
62+
wine --version
63+
EOF
7264
ARG RUST_TARGET
7365
COPY /test-base /test-base
7466
RUN /test-base/target.sh

docker/windows-gnullvm.Dockerfile

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
# syntax=docker/dockerfile:1
2+
3+
# Refs:
4+
# - https://github.com/mstorsjo/llvm-mingw
5+
# - https://github.com/rust-lang/rust/blob/1.70.0/src/doc/rustc/src/platform-support/pc-windows-gnullvm.md
6+
7+
ARG RUST_TARGET
8+
ARG UBUNTU_VERSION=20.04
9+
ARG TOOLCHAIN_TAG=dev
10+
11+
ARG TOOLCHAIN_VERSION=20230614
12+
13+
FROM ghcr.io/taiki-e/downloader as toolchain
14+
SHELL ["/bin/bash", "-euxo", "pipefail", "-c"]
15+
RUN mkdir -p /toolchain
16+
ARG TOOLCHAIN_VERSION
17+
# https://github.com/mstorsjo/llvm-mingw/releases
18+
RUN <<EOF
19+
dpkg_arch="$(dpkg --print-architecture)"
20+
case "${dpkg_arch##*-}" in
21+
amd64) arch=x86_64 ;;
22+
arm64) arch=aarch64 ;;
23+
*) echo >&2 "unsupported architecture '${dpkg_arch}'" && exit 1 ;;
24+
esac
25+
curl --proto '=https' --tlsv1.2 -fsSL --retry 10 --retry-connrefused "https://github.com/mstorsjo/llvm-mingw/releases/download/${TOOLCHAIN_VERSION}/llvm-mingw-${TOOLCHAIN_VERSION}-ucrt-ubuntu-20.04-${arch}.tar.xz" \
26+
| tar xJf - --strip-components 1 -C /toolchain
27+
EOF
28+
29+
FROM ghcr.io/taiki-e/build-base:ubuntu-"${UBUNTU_VERSION}" as builder
30+
SHELL ["/bin/bash", "-euxo", "pipefail", "-c"]
31+
ARG DEBIAN_FRONTEND=noninteractive
32+
ARG RUST_TARGET
33+
ARG TOOLCHAIN_DIR="/${RUST_TARGET}"
34+
ARG SYSROOT_DIR="${TOOLCHAIN_DIR}/${RUST_TARGET}"
35+
COPY --from=toolchain /toolchain "${TOOLCHAIN_DIR}"
36+
37+
RUN <<EOF
38+
cc_target="${RUST_TARGET%%-*}-w64-mingw32"
39+
echo "${cc_target}" >/CC_TARGET
40+
[[ "${RUST_TARGET}" == "aarch64"* ]] || rm -rf "${TOOLCHAIN_DIR}"/aarch64-w64-mingw32
41+
[[ "${RUST_TARGET}" == "x86_64"* ]] || rm -rf "${TOOLCHAIN_DIR}"/x86_64-w64-mingw32
42+
[[ "${RUST_TARGET}" == "i686"* ]] || rm -rf "${TOOLCHAIN_DIR}"/i686-w64-mingw32
43+
{ [[ "${RUST_TARGET}" == "thumb"* ]] || [[ "${RUST_TARGET}" == "arm"* ]]; } || rm -rf "${TOOLCHAIN_DIR}"/armv7-w64-mingw32
44+
EOF
45+
46+
RUN --mount=type=bind,target=/docker \
47+
/docker/base/common.sh
48+
49+
FROM ghcr.io/taiki-e/build-base:ubuntu-"${UBUNTU_VERSION}" as test-base
50+
SHELL ["/bin/bash", "-euxo", "pipefail", "-c"]
51+
ARG DEBIAN_FRONTEND=noninteractive
52+
ENV HOME=/tmp/home
53+
COPY /test-base.sh /
54+
RUN /test-base.sh
55+
ARG RUST_TARGET
56+
RUN <<EOF
57+
dpkg_arch="$(dpkg --print-architecture)"
58+
case "${dpkg_arch##*-}" in
59+
amd64) dpkg --add-architecture i386 ;;
60+
arm64)
61+
dpkg --add-architecture armhf
62+
# TODO: do not skip if actual host is arm64
63+
exit 0
64+
;;
65+
*) echo >&2 "unsupported architecture '${dpkg_arch}'" && exit 1 ;;
66+
esac
67+
case "${RUST_TARGET}" in
68+
aarch64*) ;;
69+
*)
70+
# See https://wiki.winehq.org/Ubuntu when install the latest wine.
71+
apt-get -o Acquire::Retries=10 update -qq && apt-get -o Acquire::Retries=10 -o Dpkg::Use-Pty=0 install -y --no-install-recommends \
72+
wine-stable \
73+
wine32 \
74+
wine64
75+
wine --version
76+
;;
77+
esac
78+
EOF
79+
COPY --from=ghcr.io/taiki-e/qemu-user /usr/bin/qemu-aarch64 /usr/bin/
80+
COPY --from=linaro/wine-arm64 /opt/wine-arm64 /opt/wine-arm64
81+
RUN <<EOF
82+
case "${RUST_TARGET}" in
83+
aarch64*) ;;
84+
*)
85+
rm -rf /opt/wine-arm64
86+
mkdir -p /opt/wine-arm64
87+
;;
88+
esac
89+
EOF
90+
COPY /test-base /test-base
91+
RUN /test-base/target.sh
92+
COPY /test /test
93+
94+
FROM test-base as test-relocated
95+
SHELL ["/bin/bash", "-euxo", "pipefail", "-c"]
96+
ARG DEBIAN_FRONTEND=noninteractive
97+
ARG RUST_TARGET
98+
COPY --from=builder /"${RUST_TARGET}"/. /usr/local/
99+
RUN /test/test.sh clang
100+
RUN touch /DONE
101+
102+
FROM test-base as test
103+
SHELL ["/bin/bash", "-euxo", "pipefail", "-c"]
104+
ARG DEBIAN_FRONTEND=noninteractive
105+
ARG RUST_TARGET
106+
COPY --from=builder /"${RUST_TARGET}" /"${RUST_TARGET}"
107+
ENV PATH="/${RUST_TARGET}/bin:$PATH"
108+
RUN /test/check.sh
109+
RUN /test/test.sh clang
110+
# COPY --from=test-relocated /DONE /
111+
112+
FROM ubuntu:"${UBUNTU_VERSION}" as final
113+
SHELL ["/bin/bash", "-euxo", "pipefail", "-c"]
114+
ARG DEBIAN_FRONTEND=noninteractive
115+
ARG RUST_TARGET
116+
COPY --from=test /"${RUST_TARGET}" /"${RUST_TARGET}"
117+
COPY --from=test /opt/wine-arm64 /opt/wine-arm64
118+
ENV PATH="/${RUST_TARGET}/bin:$PATH"

0 commit comments

Comments
 (0)