ci: add GitHub actions for Linux and Windows builds

We build a "static" binary for Windows now to avoid distributing the
dependencies as DLLs.
This commit is contained in:
Matthias Schiffer 2021-12-19 23:12:25 +01:00
parent 37340926f4
commit 00b93c507d
Signed by: neocturne
GPG key ID: 16EF3F64CB201D9C
5 changed files with 151 additions and 0 deletions

View file

View file

@ -0,0 +1,22 @@
set(TARGET x86_64-w64-mingw32)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/.github/toolchains/${TARGET})
set(CMAKE_SYSTEM_NAME Windows)
set(CMAKE_SYSROOT /usr/${TARGET})
set(CMAKE_C_COMPILER ${TARGET}-gcc)
set(CMAKE_CXX_COMPILER ${TARGET}-g++)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
set(ENV{PKG_CONFIG_LIBDIR} ${CMAKE_SYSROOT}/lib/pkgconfig:${CMAKE_SYSROOT}/share/pkgconfig)
set(ENV{PKG_CONFIG_PATH} $ENV{PKG_CONFIG_LIBDIR})
set(CMAKE_BUILD_WITH_INSTALL_RPATH ON)
set(CMAKE_EXE_LINKER_FLAGS "-static")

View file

@ -0,0 +1,5 @@
# Hack: The toolchain file is evaluated too early to set the library suffixes, so we use a wrapper
# around FindPkgConfig set it right before we search for libraries.
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
include(${CMAKE_ROOT}/Modules/FindPkgConfig.cmake)

85
.github/workflows/MinedMap.yml vendored Normal file
View file

@ -0,0 +1,85 @@
name: 'MinedMap'
on: ['push', 'pull_request', 'workflow_dispatch']
jobs:
build:
name: 'Build MinedMap (${{ matrix.host }})'
runs-on: 'ubuntu-20.04'
strategy:
fail-fast: false
matrix:
host:
- 'x86_64-linux-gnu'
- 'x86_64-w64-mingw32'
include:
- host: 'x86_64-linux-gnu'
label: 'x86_64-linux-gnu'
packages: ['g++', 'libpng-dev']
prefix: '/usr'
build_libpng: false
- host: 'x86_64-w64-mingw32'
label: 'Win64'
packages: ['g++-mingw-w64-x86-64', 'libz-mingw-w64-dev']
prefix: '/usr/x86_64-w64-mingw32'
build_libpng: true
env:
CMAKE_TOOLCHAIN_FILE: '${{ github.workspace }}/.github/toolchains/${{ matrix.host }}.cmake'
steps:
- name: 'Checkout'
uses: 'actions/checkout@v2'
- name: 'Get version'
id: 'tag'
run: |
set -o pipefail
git fetch --prune --unshallow
git describe --abbrev=7 --match='v*' | sed 's/^v/::set-output name=tag::/'
- name: 'Dependencies (apt)'
run: |
sudo apt-get -y update
sudo apt-get -y install ninja-build ${{ join(matrix.packages, ' ') }}
sudo apt-get -y clean
- name: 'Dependencies (libpng)'
if: '${{ matrix.build_libpng }}'
run: |
pkgver=1.6.37
pkghash=505e70834d35383537b6491e7ae8641f1a4bed1876dbfe361201fc80868d88ca
mkdir -p build/libpng
cd build/libpng
wget http://downloads.sourceforge.net/sourceforge/libpng/libpng-$pkgver.tar.xz
echo "$pkghash libpng-$pkgver.tar.xz" | sha256sum -c -
tar xf libpng-$pkgver.tar.xz
cd libpng-$pkgver
./configure \
--prefix=${{ matrix.prefix }} \
--host=${{ matrix.host }} \
--disable-shared
make -j$(nproc)
sudo make install
sudo rm ${{ matrix.prefix }}/lib/libpng*.la
- name: 'Build'
uses: lukka/run-cmake@v10
with:
configurePreset: 'ninja'
buildPreset: 'ninja-release'
- name: 'Install'
run: |
export DESTDIR="$(pwd)/build/install"
ninja -C builds/ninja -f build-RelWithDebInfo.ninja install/strip
pkgdir='build/pkg/MinedMap-${{ steps.tag.outputs.tag }}-${{ matrix.label }}'
mkdir -p "$pkgdir"
cp "$DESTDIR/usr/local/bin"/* "$pkgdir"/
- name: 'Archive'
uses: 'actions/upload-artifact@v2'
with:
name: 'MinedMap-${{ steps.tag.outputs.tag }}-${{ matrix.label }}'
path: 'build/pkg'

39
CMakePresets.json Normal file
View file

@ -0,0 +1,39 @@
{
"version": 3,
"cmakeMinimumRequired": {
"major": 3,
"minor": 7,
"patch": 0
},
"configurePresets": [
{
"name": "ninja",
"displayName": "Ninja",
"description": "Generate Ninja project files",
"binaryDir": "${sourceDir}/builds/${presetName}",
"generator": "Ninja Multi-Config",
"cacheVariables": {
"CMAKE_TOOLCHAIN_FILE": {
"type": "FILEPATH",
"value": "$env{CMAKE_TOOLCHAIN_FILE}"
}
}
}
],
"buildPresets": [
{
"name": "ninja-debug",
"configurePreset": "ninja",
"displayName": "Build ninja-debug",
"description": "Build ninja Debug configuration",
"configuration": "Debug"
},
{
"name": "ninja-release",
"configurePreset": "ninja",
"displayName": "Build ninja-release",
"description": "Build ninja Release configuration",
"configuration": "RelWithDebInfo"
}
]
}