From 906210db04416585c54cc93a3ea22e5729265484 Mon Sep 17 00:00:00 2001 From: Felicitas Pojtinger Date: Sun, 26 Dec 2021 15:31:51 +0100 Subject: [PATCH] build: Add Windows cross-compilation support from Linux using MSYS2 and WINE --- .github/workflows/hydrun.yaml | 6 ++++++ Hydrunfile | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/.github/workflows/hydrun.yaml b/.github/workflows/hydrun.yaml index 0abc562..2d5e5e5 100644 --- a/.github/workflows/hydrun.yaml +++ b/.github/workflows/hydrun.yaml @@ -18,6 +18,12 @@ jobs: flags: -e '--privileged' cmd: ./Hydrunfile dst: out/* + - id: stfs-windows + src: . + os: fedora:35 + flags: -e '--privileged' + cmd: ./Hydrunfile windows + dst: out/* steps: - name: Maximize build space diff --git a/Hydrunfile b/Hydrunfile index 0956c3a..ad02f12 100755 --- a/Hydrunfile +++ b/Hydrunfile @@ -2,6 +2,38 @@ set -e +# Windows +if [ "$1" = "windows" ]; then + # Install native dependencies + dnf update -y + dnf install -y curl wine + + # Install MSYS2 + curl -L -o /tmp/msys2.exe 'https://github.com/msys2/msys2-installer/releases/download/2021-11-30/msys2-base-x86_64-20211130.sfx.exe' + wine64 /tmp/msys2.exe x -y -oC:/ + + # Fix MSYS2 TLS + sed -i ~/.wine/drive_c/msys64/etc/pacman.conf -e 's/SigLevel = Required/SigLevel = Never/g' + cat /etc/pki/tls/certs/ca-bundle.crt >~/.wine/drive_c/msys64/usr/ssl/certs/ca-bundle.crt + cat /etc/pki/tls/certs/ca-bundle.trust.crt >~/.wine/drive_c/msys64/usr/ssl/certs/ca-bundle.trust.crt + + # Install GCC and Go + export WINEPATH='c:\msys64\usr\bin' + wine64 bash.exe -c 'pacman --verbose --debug --noconfirm --ignore pacman --needed -S base-devel mingw-w64-x86_64-gcc mingw-w64-x86_64-go' + + # Copy source code to directory on C drive + mkdir -p ~/.wine/drive_c/users/root/Documents/stfs + cp -rf . ~/.wine/drive_c/users/root/Documents/stfs + mkdir -p ~/.wine/drive_c/users/root/go + + wine64 bash.exe -c 'export PATH="$PATH:/mingw64/bin" && cd /c/users/root/Documents/stfs && export GOPATH="/c/users/root/go" && export GOROOT="/mingw64/lib/go" && go build -o out/stfs.windows-x86_64 ./cmd/stfs' + + mkdir -p out + cp -f ~/.wine/drive_c/users/root/Documents/stfs/out/* out + + exit 0 +fi + # Install native dependencies apt update apt install -y curl