ci: Cross-compile for Windows via Ubuntu

This commit is contained in:
Matt Borgerson 2021-05-20 17:25:51 -07:00 committed by mborgerson
parent 085d631309
commit 7c35590be0
8 changed files with 301 additions and 82 deletions

View File

@ -10,67 +10,15 @@ jobs:
run: |
export BUILD_TAG=build-$(date -u +'%Y%m%d%H%M')
echo "BUILD_TAG=$BUILD_TAG" >> $GITHUB_ENV
mkdir -p dist
echo -n $BUILD_TAG > dist/tag
echo -n $BUILD_TAG > tag
- name: Upload Artifacts
uses: actions/upload-artifact@v1
uses: actions/upload-artifact@v2
with:
name: dist
path: dist
name: tag
path: tag
Windows:
runs-on: windows-latest
needs: Init
strategy:
matrix:
configuration: ["Debug", "Release"]
include:
- configuration: Debug
build_param: --debug
artifact_name: xemu-win-debug.zip
- configuration: Release
build_param:
artifact_name: xemu-win-release.zip
steps:
- name: Clone Tree
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Install Dependencies
run: |
echo "Downloading MSYS2 environment..."
Invoke-WebRequest -Uri "https://github.com/mborgerson/xemu-msys2/releases/latest/download/msys64.7z" -OutFile "msys64.7z"
echo "Extracting MSYS2 environment..."
7z x -y msys64.7z "-oC:\tools\"
C:\tools\msys64\usr\bin\bash.exe -lc "pacman --needed --noconfirm -S mingw-w64-x86_64-ninja mingw-w64-x86_64-diffutils"
# - name: Initialize Compiler Cache
# id: cache
# uses: actions/cache@v1
# with:
# path: C:\tools\msys64\tmp\xemu-ccache
# key: cache-${{ runner.os }}-${{ matrix.configuration }}-${{ github.sha }}
# restore-keys: cache-${{ runner.os }}-${{ matrix.configuration }}-
- name: Compile
run: |
C:\tools\msys64\usr\bin\bash.exe -lc @"
set -e
cd `$GITHUB_WORKSPACE
# export CCACHE_DIR=/tmp/xemu-ccache
# export CCACHE_MAXSIZE=250M
# export PATH="/usr/lib/ccache/bin:/mingw64/bin:`$PATH"
export PATH="/mingw64/bin:`$PATH"
./build.sh ${{ matrix.build_param }}
# echo -e '\nCompiler Cache Stats:'
# ccache -s -c
"@
7z a ${{ matrix.artifact_name }} .\dist\*
- name: Upload Build Artifact
uses: actions/upload-artifact@v1
with:
name: dist
path: ${{ matrix.artifact_name }}
Ubuntu:
UbuntuWinCross:
name: Build for Windows (${{ matrix.configuration }}) on Ubuntu
runs-on: ubuntu-latest
needs: Init
strategy:
@ -79,10 +27,63 @@ jobs:
include:
- configuration: Debug
build_param: --debug
artifact_name: xemu-ubuntu-debug.tgz
artifact_name: xemu-win-debug
artifact_filename: xemu-win-debug.zip
- configuration: Release
build_param:
artifact_name: xemu-ubuntu-release.tgz
artifact_name: xemu-win-release
artifact_filename: xemu-win-release.zip
env:
DOCKER_IMAGE_NAME: mborgerson/xemu-ubuntu-win64-cross:latest
steps:
- name: Clone Tree
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Initialize Compiler Cache
id: cache
uses: actions/cache@v2
with:
path: /tmp/xemu-ccache
key: cache-wincross-${{ runner.os }}-${{ matrix.configuration }}-${{ github.sha }}
restore-keys: cache-wincross-${{ runner.os }}-${{ matrix.configuration }}-
- name: Pull Docker Image
run: docker pull $DOCKER_IMAGE_NAME
- name: Compile
run: |
mkdir -p /tmp/xemu-ccache
docker run --rm \
-v $PWD:/xemu -w /xemu \
-v /tmp/xemu-ccache:/tmp/xemu-ccache \
-e CCACHE_DIR=/tmp/xemu-ccache \
-e CCACHE_MAXSIZE=512M \
-u $(id -u):$(id -g) \
$DOCKER_IMAGE_NAME \
bash -c "./build.sh -p win64-cross ${{ matrix.build_param }} && ccache -sc"
cd dist
zip -r ../${{ matrix.artifact_filename }} *
- name: Upload Build Artifact
uses: actions/upload-artifact@v2
with:
name: ${{ matrix.artifact_name }}
path: ${{ matrix.artifact_filename }}
Ubuntu:
name: Build for Ubuntu
runs-on: ubuntu-latest
needs: Init
strategy:
matrix:
configuration: ["Debug", "Release"]
include:
- configuration: Debug
build_param: --debug
artifact_name: xemu-ubuntu-debug
artifact_filename: xemu-ubuntu-debug.tgz
- configuration: Release
build_param:
artifact_name: xemu-ubuntu-release
artifact_filename: xemu-ubuntu-release.tgz
steps:
- name: Clone Tree
uses: actions/checkout@v2
@ -111,17 +112,18 @@ jobs:
export CCACHE_DIR=/tmp/xemu-ccache
export CCACHE_MAXSIZE=512M
export PATH="/usr/lib/ccache:$PATH"
./build.sh ${{ matrix.build_param }}
./build.sh ${{ matrix.build_param }} --extra-cflags="-fuse-ld=gold"
echo -e "\nCompiler Cache Stats:"
ccache -s -c
tar -czvf ${{ matrix.artifact_name }} --transform "s#^dist#xemu#" dist
tar -czvf ${{ matrix.artifact_filename }} --transform "s#^dist#xemu#" dist
- name: Upload Build Artifact
uses: actions/upload-artifact@v1
uses: actions/upload-artifact@v2
with:
name: dist
path: ${{ matrix.artifact_name }}
name: ${{ matrix.artifact_name }}
path: ${{ matrix.artifact_filename }}
macOS:
name: Build for macOS
runs-on: macOS-latest
needs: Init
strategy:
@ -130,10 +132,12 @@ jobs:
include:
- configuration: Debug
build_param: --debug
artifact_name: xemu-macos-debug.zip
artifact_name: xemu-macos-debug
artifact_filename: xemu-macos-debug.zip
- configuration: Release
build_param:
artifact_name: xemu-macos-release.zip
artifact_name: xemu-macos-release
artifact_filename: xemu-macos-release.zip
steps:
- name: Clone Tree
uses: actions/checkout@v2
@ -181,28 +185,28 @@ jobs:
echo -e "\nCompiler Cache Stats:"
ccache -s -c
pushd dist
zip -r ../${{ matrix.artifact_name }} xemu.app
zip -r ../${{ matrix.artifact_filename }} xemu.app
popd
- name: Upload Build Artifact
uses: actions/upload-artifact@v1
uses: actions/upload-artifact@v2
with:
name: dist
path: ${{ matrix.artifact_name }}
name: ${{ matrix.artifact_name }}
path: ${{ matrix.artifact_filename }}
Release:
if: github.event_name == 'push' && (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/xemu-v'))
runs-on: ubuntu-latest
needs: [Ubuntu, Windows, macOS]
needs: [Ubuntu, macOS, UbuntuWinCross]
env:
BUILD_TAG:
steps:
- name: Download Artifacts
uses: actions/download-artifact@v1
uses: actions/download-artifact@v2
with:
name: dist
name: ${{ matrix.artifact_name }}
- name: Get Package Info
run: |
echo "BUILD_TAG=$(cat dist/tag)" >> $GITHUB_ENV
echo "BUILD_TAG=$(cat dist/tag/tag)" >> $GITHUB_ENV
- name: Create Release
id: create_release
uses: actions/create-release@v1
@ -221,7 +225,7 @@ jobs:
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_name: xemu-win-debug.zip
asset_path: dist/xemu-win-debug.zip
asset_path: dist/xemu-win-debug/xemu-win-debug.zip
asset_content_type: application/zip
- name: Upload Release Assets (Windows Release Build)
id: upload-release-asset-win-release
@ -231,7 +235,7 @@ jobs:
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_name: xemu-win-release.zip
asset_path: dist/xemu-win-release.zip
asset_path: dist/xemu-win-release/xemu-win-release.zip
asset_content_type: application/zip
- name: Upload Release Assets (macOS Release Build)
id: upload-release-asset-macos-release
@ -241,7 +245,7 @@ jobs:
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_name: xemu-macos-release.zip
asset_path: dist/xemu-macos-release.zip
asset_path: dist/xemu-macos-release/xemu-macos-release.zip
asset_content_type: application/zip
- name: Upload Release Assets (macOS Debug Build)
id: upload-release-asset-macos-debug
@ -251,7 +255,7 @@ jobs:
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_name: xemu-macos-debug.zip
asset_path: dist/xemu-macos-debug.zip
asset_path: dist/xemu-macos-debug/xemu-macos-debug.zip
asset_content_type: application/zip
# Sync archive version of source (including submodule code) to the
@ -260,7 +264,7 @@ jobs:
# package creation.
PushToPPA:
if: github.event_name == 'push' && (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/xemu-v'))
needs: [Ubuntu, Windows, macOS]
needs: [Ubuntu, macOS, UbuntuWinCross]
runs-on: ubuntu-latest
steps:
- name: Clone Tree

View File

@ -17,6 +17,17 @@ package_windows() {
strip dist/xemuw.exe
}
package_wincross() {
STRIP=${CROSSPREFIX}strip
rm -rf dist
mkdir -p dist
cp build/qemu-system-i386.exe dist/xemu.exe
cp build/qemu-system-i386w.exe dist/xemuw.exe
cp -r "${project_source_dir}/data" dist/
$STRIP dist/xemu.exe
$STRIP dist/xemuw.exe
}
package_macos() {
#
# Create bundle
@ -130,6 +141,7 @@ job_count="$(get_job_count)" 2>/dev/null
job_count="${job_count:-${default_job_count}}"
debug=""
opts=""
platform="$(uname -s)"
while [ ! -z "${1}" ]
do
@ -142,6 +154,10 @@ do
debug="y"
shift
;;
'-p'*)
platform="${2}"
shift 2
;;
*)
break
;;
@ -156,7 +172,8 @@ else
opts="--enable-lto"
fi
case "$(uname -s)" in # Adjust compilation options based on platform
case "$platform" in # Adjust compilation options based on platform
Linux)
echo 'Compiling for Linux...'
sys_cflags='-Wno-error=redundant-decls'
@ -181,8 +198,16 @@ case "$(uname -s)" in # Adjust compilation options based on platform
postbuild='package_windows' # set the above function to be called after build
target="qemu-system-i386.exe qemu-system-i386w.exe"
;;
win64-cross)
echo 'Cross-compiling for Windows...'
export AR=${AR:-$CROSSAR}
sys_cflags='-Wno-error'
opts="$opts --cross-prefix=$CROSSPREFIX --static --disable-fortify-source"
postbuild='package_wincross' # set the above function to be called after build
target="qemu-system-i386.exe qemu-system-i386w.exe"
;;
*)
echo "could not detect OS $(uname -s), aborting" >&2
echo "Unsupported platform $platform, aborting" >&2
exit -1
;;
esac

View File

@ -0,0 +1,40 @@
--- SDL2-2.0.12/CMakeLists.txt.orig 2020-04-11 16:44:16.343880000 +0300
+++ SDL2-2.0.12/CMakeLists.txt 2020-04-11 16:48:12.677114500 +0300
@@ -1916,12 +1916,12 @@
set(EXTRA_CFLAGS ${_EXTRA_CFLAGS})
# Compat helpers for the configuration files
-if(NOT CMAKE_HOST_WIN32)
+if(NOT MSVC OR CYGWIN)
# TODO: we need a Windows script, too
execute_process(COMMAND sh ${SDL2_SOURCE_DIR}/build-scripts/updaterev.sh
WORKING_DIRECTORY ${SDL2_BINARY_DIR})
endif()
-if(NOT WINDOWS OR CYGWIN)
+if(NOT MSVC)
set(prefix ${CMAKE_INSTALL_PREFIX})
set(exec_prefix "\${prefix}")
set(libdir "\${exec_prefix}/lib${LIB_SUFFIX}")
@@ -2134,7 +2134,7 @@
RUNTIME DESTINATION bin)
##### Export files #####
-if (WINDOWS)
+if (MSVC)
set(PKG_PREFIX "cmake")
else ()
set(PKG_PREFIX "lib${LIB_SUFFIX}/cmake/SDL2")
@@ -2175,11 +2175,11 @@
set(SOPOSTFIX "")
endif()
-if(NOT (WINDOWS OR CYGWIN))
+if(NOT (MSVC OR CYGWIN))
if(SDL_SHARED)
set(SOEXT ${CMAKE_SHARED_LIBRARY_SUFFIX}) # ".so", ".dylib", etc.
get_target_property(SONAME SDL2 OUTPUT_NAME)
- if(NOT ANDROID)
+ if(NOT ANDROID AND NOT MINGW)
install(CODE "
execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink
\"lib${SONAME}${SOPOSTFIX}${SOEXT}\" \"libSDL2${SOPOSTFIX}${SOEXT}\"

View File

@ -0,0 +1,11 @@
--- SDL2-2.0.12/CMakeLists.txt.orig 2020-04-13 09:22:12.737714600 +0300
+++ SDL2-2.0.12/CMakeLists.txt 2020-04-13 09:22:17.728045700 +0300
@@ -2099,7 +2099,7 @@
if(SDL_STATIC)
set (BUILD_SHARED_LIBS FALSE)
add_library(SDL2-static STATIC ${SOURCE_FILES})
- if (NOT SDL_SHARED OR NOT WIN32)
+ if (NOT SDL_SHARED OR NOT MSVC)
set_target_properties(SDL2-static PROPERTIES OUTPUT_NAME "SDL2")
# Note: Apparently, OUTPUT_NAME must really be unique; even when
# CMAKE_IMPORT_LIBRARY_SUFFIX or the like are given. Otherwise

View File

@ -0,0 +1,81 @@
#
# Environment to cross-compile xemu for Windows
#
FROM ubuntu:20.04
RUN apt-get update \
&& DEBIAN_FRONTEND=noninteractive \
apt-get -qy install \
software-properties-common \
lsb-release \
git \
autoconf \
automake \
autopoint \
bash \
bison \
bzip2 \
flex \
g++ \
g++-multilib \
gettext \
git \
gperf \
intltool \
libc6-dev-i386 \
libgdk-pixbuf2.0-dev \
libltdl-dev \
libssl-dev \
libtool-bin \
libxml-parser-perl \
lzip \
make \
openssl \
p7zip-full \
patch \
perl \
python \
ruby \
sed \
unzip \
wget \
xz-utils
RUN cd /opt \
&& git clone https://github.com/mxe/mxe.git \
&& cd mxe \
&& make \
MXE_TARGETS=x86_64-w64-mingw32.static \
MXE_PLUGIN_DIRS=plugins/gcc10 \
cc
RUN make -C /opt/mxe \
MXE_TARGETS=x86_64-w64-mingw32.static \
MXE_PLUGIN_DIRS=plugins/gcc10 \
glib \
libepoxy \
pixman \
libsamplerate \
openssl
RUN make -C /opt/mxe \
MXE_TARGETS=x86_64-w64-mingw32.static \
MXE_PLUGIN_DIRS=plugins/gcc10 \
cmake
RUN apt-get install ninja-build
COPY sdl2.mk /opt/mxe/src/sdl2.mk
COPY 001-fix-cmake-target-relocation.patch /opt/mxe/src/sdl2-1-cmake.patch
COPY 003-fix-static-library-name.patch /opt/mxe/src/sdl2-3-static.patch
COPY sdl2-2-link.patch /opt/mxe/src/sdl2-2-link.patch
RUN make -C /opt/mxe \
MXE_TARGETS=x86_64-w64-mingw32.static \
MXE_PLUGIN_DIRS=plugins/gcc10 \
sdl2
ENV CROSSPREFIX=x86_64-w64-mingw32.static-
ENV CROSSAR=${CROSSPREFIX}gcc-ar
ENV PATH="/opt/mxe/.ccache/bin:/opt/mxe/usr/x86_64-pc-linux-gnu/bin:/opt/mxe/usr/bin:${PATH}"

View File

@ -0,0 +1,9 @@
sdl2.mk is a copy of existing autotools based configuration, modified to instead
use CMake, which appears to be the preferred method when building for Windows,
msys2 project also uses the CMake system.
These patches come from msys2:
- 001-fix-cmake-target-relocation.patch
- 003-fix-static-library-name.patch
Origin: https://github.com/msys2/MINGW-packages/tree/master/mingw-w64-SDL2

View File

@ -0,0 +1,17 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index b9b9eb62..5d92e60d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1636,10 +1636,10 @@ elseif(WINDOWS)
file(GLOB VERSION_SOURCES ${SDL2_SOURCE_DIR}/src/main/windows/*.rc)
file(GLOB SDLMAIN_SOURCES ${SDL2_SOURCE_DIR}/src/main/windows/*.c)
if(MINGW OR CYGWIN)
- list(APPEND EXTRA_LIBS mingw32)
+ list(APPEND EXTRA_LIBS SDL2main mingw32)
list(APPEND EXTRA_LDFLAGS "-mwindows")
set(SDL_CFLAGS "${SDL_CFLAGS} -Dmain=SDL_main")
- list(APPEND SDL_LIBS "-lmingw32" "-lSDL2main" "-mwindows")
+ list(APPEND SDL_LIBS "-lSDL2main" "-lmingw32" "-mwindows")
endif()
elseif(APPLE)

View File

@ -0,0 +1,32 @@
# This file is part of MXE. See LICENSE.md for licensing information.
PKG := sdl2
$(PKG)_WEBSITE := https://www.libsdl.org/
$(PKG)_DESCR := SDL2
$(PKG)_IGNORE :=
$(PKG)_VERSION := 2.0.14
$(PKG)_CHECKSUM := d8215b571a581be1332d2106f8036fcb03d12a70bae01e20f424976d275432bc
$(PKG)_SUBDIR := SDL2-$($(PKG)_VERSION)
$(PKG)_FILE := SDL2-$($(PKG)_VERSION).tar.gz
$(PKG)_URL := https://www.libsdl.org/release/$($(PKG)_FILE)
$(PKG)_DEPS := cc libiconv libsamplerate
define $(PKG)_UPDATE
$(WGET) -q -O- 'https://hg.libsdl.org/SDL/tags' | \
$(SED) -n 's,.*release-\([0-9][^<]*\).*,\1,p' | \
head -1
endef
define $(PKG)_BUILD
cd '$(BUILD_DIR)' && $(TARGET)-cmake '$(SOURCE_DIR)' \
-DSDL_SHARED=$(CMAKE_SHARED_BOOL) \
-DSDL_STATIC=$(CMAKE_STATIC_BOOL) \
-DVERBOSE=1
$(MAKE) -C '$(BUILD_DIR)' -j '$(JOBS)'
$(MAKE) -C '$(BUILD_DIR)' -j 1 install
'$(TARGET)-gcc' \
-W -Wall -Werror -ansi -pedantic \
'$(TEST_FILE)' -o '$(PREFIX)/$(TARGET)/bin/test-sdl2.exe' \
`'$(TARGET)-pkg-config' sdl2 --cflags --libs`
endef