Skip to content

Commit

Permalink
Support windows-gnullvm
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed Aug 2, 2023
1 parent 0b61d8d commit bac1a2d
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 79 deletions.
1 change: 1 addition & 0 deletions .github/.cspell/organization-dictionary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ endianness
esac
euxo
gsub
libc
moreutils
msys
noninteractive
Expand Down
2 changes: 1 addition & 1 deletion .github/.cspell/project-dictionary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ CXXSTDLIB
devel
endgroup
haswell
libc
libclang
libstdc
Loongson
Expand All @@ -19,5 +18,6 @@ WINEBOOT
winehq
WINEPATH
WINEPREFIX
wineserver
Zbuild
Zdoctest
9 changes: 5 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ env:
CARGO_NET_GIT_FETCH_WITH_CLI: true
CARGO_NET_RETRY: 10
CARGO_TERM_COLOR: always
QEMU_STRACE: 1
RUST_BACKTRACE: 1
RUSTDOCFLAGS: -D warnings
RUSTFLAGS: -D warnings
Expand Down Expand Up @@ -184,7 +183,7 @@ jobs:
# - { target: thumbv7a-pc-windows-msvc, os: windows-latest } # tier3
- { target: x86_64-pc-windows-msvc, os: windows-latest }

# Windows (GNU)
# Windows (MinGW)
# rustup target list | grep -e '-pc-windows-gnu'
# rustc --print target-list | grep -e '-pc-windows-gnu'
# Windows host:
Expand All @@ -194,13 +193,13 @@ jobs:
os: windows-latest
# Linux host:
# - target: i686-pc-windows-gnu
# os: ubuntu-22.04
- target: x86_64-pc-windows-gnu
os: ubuntu-22.04
- target: x86_64-pc-windows-gnu
runner: [email protected]
- target: x86_64-pc-windows-gnu
runner: [email protected]
- target: x86_64-pc-windows-gnullvm
- target: aarch64-pc-windows-gnullvm
# prettier-ignore
exclude:
# Segmentation fault on ubuntu 20.04: https://github.com/taiki-e/setup-cross-toolchain-action/issues/1
Expand All @@ -220,6 +219,8 @@ jobs:
persist-credentials: false
- name: Install Rust
run: rustup toolchain add nightly --no-self-update && rustup default nightly
- run: echo "QEMU_STRACE=1" >>"${GITHUB_ENV}"
if: matrix.target != 'aarch64-pc-windows-gnullvm'
- uses: ./
with:
target: ${{ matrix.target }}
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ Note: In this file, do not use the hard wrap in the middle of a sentence for com

## [Unreleased]

- Support windows-gnullvm targets on Linux host.

- aarch64-pc-windows-gnullvm
- x86_64-pc-windows-gnullvm

Running tests is supported on both targets.

## [1.14.0] - 2023-07-28

- Support Windows targets on Windows host.
Expand Down
36 changes: 24 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ GitHub Action for setup toolchains for cross compilation and cross testing for R
- [FreeBSD](#freebsd)
- [NetBSD](#netbsd)
- [WASI](#wasi)
- [Windows (GNU)](#windows-gnu)
- [Windows (MinGW)](#windows-mingw)
- [Windows (LLVM MinGW)](#windows-llvm-mingw)
- [Windows (MSVC)](#windows-msvc)
- [macOS](#macos)
- [Related Projects](#related-projects)
Expand Down Expand Up @@ -367,23 +368,21 @@ Only specifying a major version is supported.

### WASI

| C++ | test |
| --- | ---- |
| ? (libc++) | ✓ |
| libc | Clang | C++ | test |
| ---- | ----- | --- | ---- |
| wasi-sdk 20 (wasi-libc 1dfe5c3) | 16.0.0 | ? (libc++) | ✓ |

<!--
clang version and wasi-libc hash can be found here: https://github.com/taiki-e/rust-cross-toolchain#wasi
-->

**Supported targets**:

| target | host | runner | note |
| ------ | ---- | ------ | ---- |
| `wasm32-wasi` | x86_64 Linux [1] | wasmtime | |

<!--
clang version and wasi-libc hash can be found here: https://github.com/WebAssembly/wasi-sdk/tree/wasi-sdk-16/src
-->
| `wasm32-wasi` | x86_64 Linux | wasmtime | |

[1] clang 14, wasi-sdk 16 (wasi-libc 30094b6)<br>

### Windows (GNU)
### Windows (MinGW)

| C++ | test |
| --- | ---- |
Expand Down Expand Up @@ -413,6 +412,19 @@ You can select/pin the version by using `@` syntax in `runner` input option. For
runner: [email protected]
```

### Windows (LLVM MinGW)

| libc | Clang | C++ | test |
| ---- | ----- | --- | ---- |
| Mingw-w64 b190082 | 16.0.6 | ✓ (libc++) | ✓ |

**Supported targets**:

| target | host | runner | note |
| ------ | ---- | ------ | ---- |
| `aarch64-pc-windows-gnullvm` | Ubuntu (22.04) | wine | |
| `x86_64-pc-windows-gnullvm` | Ubuntu (22.04) | wine | |

### Windows (MSVC)

| C++ | test |
Expand Down
159 changes: 98 additions & 61 deletions main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ install_rust_cross_toolchain() {
retry docker create --name rust-cross-toolchain "ghcr.io/taiki-e/rust-cross-toolchain:${target}${sys_version:-}-dev-amd64"
mkdir -p .setup-cross-toolchain-action-tmp
docker cp "rust-cross-toolchain:/${target}" .setup-cross-toolchain-action-tmp/toolchain
case "${target}" in
aarch64-pc-windows-gnullvm)
docker cp "rust-cross-toolchain:/opt/wine-arm64" .setup-cross-toolchain-action-tmp/wine-arm64
sudo cp -r .setup-cross-toolchain-action-tmp/wine-arm64 /opt/wine-arm64
;;
esac
docker rm -f rust-cross-toolchain >/dev/null
sudo cp -r .setup-cross-toolchain-action-tmp/toolchain/. "${toolchain_dir}"/
rm -rf ./.setup-cross-toolchain-action-tmp
Expand Down Expand Up @@ -235,8 +241,9 @@ register_binfmt() {
local magic='MZ'
local mask=''
;;
*) bail "internal error: unrecognized register_binfmt arg" ;;
*) bail "internal error: unrecognized register_binfmt argument '$1'" ;;
esac
echo "Setting ${runner_path} as binfmt interpreter for ${target}"
echo ":${target}:M::${magic}:${mask}:${runner_path}:F" \
| sudo tee /proc/sys/fs/binfmt_misc/register >/dev/null
echo "::endgroup::"
Expand Down Expand Up @@ -381,82 +388,112 @@ EOF
runner_path="${toolchain_dir}/bin/${target}-runner"
register_binfmt wasmtime
;;
x86_64-pc-windows-gnu)
x86_64-pc-windows-gnu | x86_64-pc-windows-gnullvm | aarch64-pc-windows-gnullvm)
arch="${target%%-*}"
apt_target="${arch}-w64-mingw32"
apt_packages+=("g++-mingw-w64-${arch/_/-}")
sysroot_dir="/usr/${apt_target}"
case "${target}" in
*-gnullvm*) install_rust_cross_toolchain ;;
*)
apt_target="${arch}-w64-mingw32"
apt_packages+=("g++-mingw-w64-${arch/_/-}")
sysroot_dir="/usr/${apt_target}"
cat >>"${GITHUB_ENV}" <<EOF
CARGO_TARGET_${target_upper}_RUNNER=${target}-runner
CARGO_TARGET_${target_upper}_LINKER=${apt_target}-gcc-posix
CC_${target_lower}=${apt_target}-gcc-posix
CXX_${target_lower}=${apt_target}-g++-posix
AR_${target_lower}=${apt_target}-ar
RANLIB_${target_lower}=${apt_target}-ranlib
STRIP=${apt_target}-strip
OBJDUMP=${apt_target}-objdump
EOF
;;
esac

# https://wiki.winehq.org/Ubuntu
# https://wiki.winehq.org/Wine_User%27s_Guide#Wine_from_WineHQ
sudo dpkg --add-architecture i386
codename="$(grep '^VERSION_CODENAME=' /etc/os-release | sed 's/^VERSION_CODENAME=//')"
sudo mkdir -pm755 /etc/apt/keyrings
retry sudo wget -O /etc/apt/keyrings/winehq-archive.key https://dl.winehq.org/wine-builds/winehq.key
retry sudo wget -NP /etc/apt/sources.list.d/ "https://dl.winehq.org/wine-builds/ubuntu/dists/${codename}/winehq-${codename}.sources"
case "${runner}" in
'')
# Use winehq-devel 7.13 as default because mio/wepoll needs wine 7.13+.
# https://github.com/tokio-rs/mio/issues/1444
wine_version=7.13
wine_branch=devel
case "${target}" in
aarch64*)
wine_root=/opt/wine-arm64
wine_exe="${wine_root}"/bin/wine
qemu_arch=aarch64
case "${runner}" in
'' | wine) ;;
wine@*) bail "specifying wine version for aarch64 windows is not yet supported" ;;
*) bail "unrecognized runner '${runner}'" ;;
esac
sudo cp "${wine_root}"/lib/ld-linux-aarch64.so.1 /lib/
x "qemu-${qemu_arch}" --version
x "${wine_exe}" --version
wineboot="${wine_root}/bin/wineserver"
;;
wine@*)
wine_version="${runner#*@}"
if [[ "${wine_version}" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
wine_branch=stable
elif [[ "${wine_version}" =~ ^[0-9]+\.[0-9]+$ ]]; then
wine_branch=devel
else
bail "unrecognized runner '${runner}'"
fi
x86_64*)
wine_exe=wine
# https://wiki.winehq.org/Ubuntu
# https://wiki.winehq.org/Wine_User%27s_Guide#Wine_from_WineHQ
sudo dpkg --add-architecture i386
codename="$(grep '^VERSION_CODENAME=' /etc/os-release | sed 's/^VERSION_CODENAME=//')"
sudo mkdir -pm755 /etc/apt/keyrings
retry sudo wget -O /etc/apt/keyrings/winehq-archive.key https://dl.winehq.org/wine-builds/winehq.key
retry sudo wget -NP /etc/apt/sources.list.d/ "https://dl.winehq.org/wine-builds/ubuntu/dists/${codename}/winehq-${codename}.sources"
case "${runner}" in
'' | wine)
# Use winehq-devel 7.13 as default because mio/wepoll needs wine 7.13+.
# https://github.com/tokio-rs/mio/issues/1444
wine_version=7.13
wine_branch=devel
;;
wine@*)
wine_version="${runner#*@}"
if [[ "${wine_version}" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
wine_branch=stable
elif [[ "${wine_version}" =~ ^[0-9]+\.[0-9]+$ ]]; then
wine_branch=devel
else
bail "unrecognized runner '${runner}'"
fi
;;
*) bail "unrecognized runner '${runner}'" ;;
esac
# The suffix is 1 in most cases, rarely 2.
# https://dl.winehq.org/wine-builds/ubuntu/dists/jammy/main/binary-amd64
# https://dl.winehq.org/wine-builds/ubuntu/dists/focal/main/binary-amd64
wine_build_suffix=1
apt_packages+=(
"winehq-${wine_branch}=${wine_version}~${codename}-${wine_build_suffix}"
"wine-${wine_branch}=${wine_version}~${codename}-${wine_build_suffix}"
"wine-${wine_branch}-amd64=${wine_version}~${codename}-${wine_build_suffix}"
"wine-${wine_branch}-i386=${wine_version}~${codename}-${wine_build_suffix}"
"wine-${wine_branch}-dev=${wine_version}~${codename}-${wine_build_suffix}"
)
install_apt_packages
x wine --version
wineboot=wineboot
;;
*) bail "internal error: unrecognized target '${target}'" ;;
esac
case "${target}" in
*-gnullvm*) winepath="${toolchain_dir}/${target}/bin" ;;
*)
gcc_lib="$(basename "$(ls -d "/usr/lib/gcc/${apt_target}"/*posix)")"
winepath="/usr/lib/gcc/${apt_target}/${gcc_lib};/usr/${apt_target}/lib"
;;
*) bail "unrecognized runner '${runner}'" ;;
esac
# The suffix is 1 in most cases, rarely 2.
# https://dl.winehq.org/wine-builds/ubuntu/dists/jammy/main/binary-amd64
# https://dl.winehq.org/wine-builds/ubuntu/dists/focal/main/binary-amd64
wine_build_suffix=1
apt_packages+=(
"winehq-${wine_branch}=${wine_version}~${codename}-${wine_build_suffix}"
"wine-${wine_branch}=${wine_version}~${codename}-${wine_build_suffix}"
"wine-${wine_branch}-amd64=${wine_version}~${codename}-${wine_build_suffix}"
"wine-${wine_branch}-i386=${wine_version}~${codename}-${wine_build_suffix}"
"wine-${wine_branch}-dev=${wine_version}~${codename}-${wine_build_suffix}"
)
install_apt_packages
x wine --version

gcc_lib="$(basename "$(ls -d "/usr/lib/gcc/${apt_target}"/*posix)")"
# Adapted from https://github.com/cross-rs/cross/blob/16a64e7028d90a3fdf285cfd642cdde9443c0645/docker/windows-entry.sh
runner_path="/usr/local/bin/${target}-runner"
cat >"${runner_path}" <<EOF
cat >".${target}-runner.tmp" <<EOF
#!/bin/sh
set -eu
export HOME=/tmp/home
mkdir -p "\${HOME}"
mkdir -p "\${HOME}"/.wine
export WINEPREFIX=/tmp/wine
mkdir -p "\${WINEPREFIX}"
if [ ! -e /tmp/WINEBOOT ]; then
wineboot &>/dev/null
${wineboot} &>/dev/null
touch /tmp/WINEBOOT
fi
export WINEPATH="/usr/lib/gcc/${apt_target}/${gcc_lib};/usr/${apt_target}/lib;\${WINEPATH:-}"
exec wine "\$@"
export WINEPATH="${winepath};\${WINEPATH:-}"
exec ${wine_exe} "\$@"
EOF
chmod +x "${runner_path}"
chmod +x ".${target}-runner.tmp"
sudo mv ".${target}-runner.tmp" "${runner_path}"
register_binfmt wine

cat >>"${GITHUB_ENV}" <<EOF
CARGO_TARGET_${target_upper}_RUNNER=${target}-runner
CARGO_TARGET_${target_upper}_LINKER=${apt_target}-gcc-posix
CC_${target_lower}=${apt_target}-gcc-posix
CXX_${target_lower}=${apt_target}-g++-posix
AR_${target_lower}=${apt_target}-ar
RANLIB_${target_lower}=${apt_target}-ranlib
STRIP=${apt_target}-strip
OBJDUMP=${apt_target}-objdump
EOF
;;
*) bail "target '${target}' is not supported yet on Linux host" ;;
esac
Expand Down
2 changes: 1 addition & 1 deletion tools/ci/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ esac
skip_run() {
case "${target}" in
# x86_64h-apple-darwin is also x86_64 but build-only due to the CPU of GitHub-provided macOS runners is older than haswell.
*-freebsd* | *-netbsd* | x86_64h-apple-darwin | aarch64*-darwin* | aarch64*-windows*) return 0 ;;
*-freebsd* | *-netbsd* | x86_64h-apple-darwin | aarch64*-darwin* | aarch64*-windows-msvc) return 0 ;;
*) return 1 ;;
esac
}
Expand Down

0 comments on commit bac1a2d

Please sign in to comment.