mirror of
https://github.com/gbdev/rgbds.git
synced 2026-05-08 10:59:36 +00:00
Switch MinGW building to CMake
Automatically grabs and compiles libpng, and avoids having hacky lines in our Makefile (the compiler specification *should* be orthogonal to the build target!) Also move the MinGW package install to the `install_deps.sh` script, to move logic off of the YAML.
This commit is contained in:
@@ -2,10 +2,32 @@
|
|||||||
# This script requires `sh` instead of `bash` because the latter is not always installed on FreeBSD.
|
# This script requires `sh` instead of `bash` because the latter is not always installed on FreeBSD.
|
||||||
set -eu
|
set -eu
|
||||||
|
|
||||||
case "${1%%-*}" in
|
case $# in
|
||||||
|
1) OS="$1"; TOOLSET= ;;
|
||||||
|
2) OS="$1"; TOOLSET="$2";;
|
||||||
|
*) echo >&2 "Usage: $0 <os> [toolset]" && exit 1;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
case "${OS%%-*}" in
|
||||||
ubuntu|debian)
|
ubuntu|debian)
|
||||||
sudo apt-get -qq update
|
pkgs=bison
|
||||||
sudo apt-get install -yq bison libpng-dev pkgconf
|
case "$TOOLSET" in
|
||||||
|
mingw32)
|
||||||
|
pkgs="$pkgs libz-mingw-w64-dev g++-mingw-w64-i686-win32"
|
||||||
|
TOOLSET=
|
||||||
|
;;
|
||||||
|
mingw64)
|
||||||
|
pkgs="$pkgs libz-mingw-w64-dev g++-mingw-w64-x86-64-win32"
|
||||||
|
TOOLSET=
|
||||||
|
;;
|
||||||
|
'' | lcov)
|
||||||
|
pkgs="$pkgs libpng-dev pkgconf $TOOLSET"
|
||||||
|
TOOLSET=
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
sudo apt-get update -qq
|
||||||
|
# shellcheck disable=SC2086 # (This word splitting is intentional.)
|
||||||
|
sudo apt-get install -yq $pkgs
|
||||||
;;
|
;;
|
||||||
macos)
|
macos)
|
||||||
# macOS bundles GNU Make 3.81, which doesn't support synced output.
|
# macOS bundles GNU Make 3.81, which doesn't support synced output.
|
||||||
@@ -32,6 +54,11 @@ case "${1%%-*}" in
|
|||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
if [ -n "$TOOLSET" ]; then
|
||||||
|
printf >&2 'Unknown toolset `%s` for OS `%s`\n' "$TOOLSET" "$OS"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
# Print some system info, for easier debugging.
|
# Print some system info, for easier debugging.
|
||||||
# https://docs.github.com/en/actions/reference/workflows-and-actions/workflow-commands#grouping-log-lines
|
# https://docs.github.com/en/actions/reference/workflows-and-actions/workflow-commands#grouping-log-lines
|
||||||
|
|
||||||
|
|||||||
@@ -1,29 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
set -euo pipefail
|
|
||||||
|
|
||||||
pngver=1.6.56
|
|
||||||
arch="$1"
|
|
||||||
|
|
||||||
## Grab sources and check them
|
|
||||||
|
|
||||||
wget http://downloads.sourceforge.net/project/libpng/libpng16/$pngver/libpng-$pngver.tar.xz
|
|
||||||
echo f7d8bf1601b7804f583a254ab343a6549ca6cf27d255c302c47af2d9d36a6f18 \*libpng-$pngver.tar.xz | \
|
|
||||||
sha256sum -c -
|
|
||||||
|
|
||||||
## Extract sources and patch them
|
|
||||||
|
|
||||||
tar -xf libpng-$pngver.tar.xz
|
|
||||||
|
|
||||||
## Start building!
|
|
||||||
|
|
||||||
mkdir -p build
|
|
||||||
cd build
|
|
||||||
../libpng-$pngver/configure \
|
|
||||||
--host="$arch" --target="$arch" \
|
|
||||||
--prefix="/usr/$arch" \
|
|
||||||
--enable-shared --disable-static \
|
|
||||||
CPPFLAGS="-D_FORTIFY_SOURCE=2" \
|
|
||||||
CFLAGS="-O2 -pipe -fno-plt -fno-exceptions --param=ssp-buffer-size=4" \
|
|
||||||
LDFLAGS="-Wl,-O1,--sort-common,--as-needed -fstack-protector"
|
|
||||||
make -kj
|
|
||||||
sudo make install
|
|
||||||
@@ -11,16 +11,13 @@ env:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
coverage:
|
coverage:
|
||||||
runs-on: ubuntu-24.04
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repo
|
- name: Checkout repo
|
||||||
uses: actions/checkout@v6
|
uses: actions/checkout@v6
|
||||||
- name: Install deps
|
- name: Install deps
|
||||||
run: |
|
run: |
|
||||||
./.github/scripts/install_deps.sh ubuntu
|
.github/scripts/install_deps.sh ubuntu-latest lcov
|
||||||
- name: Install LCOV
|
|
||||||
run: |
|
|
||||||
sudo apt-get install lcov
|
|
||||||
- name: Install test dependency dependencies
|
- name: Install test dependency dependencies
|
||||||
run: |
|
run: |
|
||||||
test/fetch-test-deps.sh --get-deps ubuntu
|
test/fetch-test-deps.sh --get-deps ubuntu
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ jobs:
|
|||||||
uses: actions/checkout@v6
|
uses: actions/checkout@v6
|
||||||
- name: Install deps
|
- name: Install deps
|
||||||
run: |
|
run: |
|
||||||
./.github/scripts/install_deps.sh ${{ matrix.os }}
|
.github/scripts/install_deps.sh ${{ matrix.os }}
|
||||||
- name: Build & install using Make
|
- name: Build & install using Make
|
||||||
if: matrix.buildsys == 'make'
|
if: matrix.buildsys == 'make'
|
||||||
run: |
|
run: |
|
||||||
@@ -113,7 +113,7 @@ jobs:
|
|||||||
uses: actions/checkout@v6
|
uses: actions/checkout@v6
|
||||||
- name: Install deps
|
- name: Install deps
|
||||||
run: |
|
run: |
|
||||||
./.github/scripts/install_deps.sh macos
|
.github/scripts/install_deps.sh macos
|
||||||
- name: Cache library deps
|
- name: Cache library deps
|
||||||
uses: actions/cache@v5
|
uses: actions/cache@v5
|
||||||
with:
|
with:
|
||||||
@@ -222,45 +222,29 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
bits: [32, 64]
|
bits: [32, 64]
|
||||||
include:
|
|
||||||
- bits: 32
|
|
||||||
arch: i686
|
|
||||||
triplet: i686-w64-mingw32
|
|
||||||
- bits: 64
|
|
||||||
arch: x86-64
|
|
||||||
triplet: x86_64-w64-mingw32
|
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
runs-on: ubuntu-22.04
|
runs-on: ubuntu-latest
|
||||||
env:
|
|
||||||
DIST_DIR: win${{ matrix.bits }}
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repo
|
- name: Checkout repo
|
||||||
uses: actions/checkout@v6
|
uses: actions/checkout@v6
|
||||||
- name: Install deps
|
- name: Install deps
|
||||||
run: |
|
run: |
|
||||||
./.github/scripts/install_deps.sh ubuntu
|
.github/scripts/install_deps.sh ubuntu mingw${{ matrix.bits }}
|
||||||
- name: Install MinGW
|
|
||||||
run: | # dpkg-dev is apparently required for pkg-config for cross-building
|
|
||||||
sudo apt-get install g++-mingw-w64-${{ matrix.arch }}-win32 mingw-w64-tools libz-mingw-w64-dev dpkg-dev
|
|
||||||
- name: Install libpng dev headers for MinGW
|
|
||||||
run: |
|
|
||||||
./.github/scripts/mingw-w64-libpng-dev.sh ${{ matrix.triplet }}
|
|
||||||
- name: Cross-build Windows binaries
|
- name: Cross-build Windows binaries
|
||||||
run: |
|
run: | # MinGW does not support `--preset develop` sanitizers ASan or UBSan.
|
||||||
make mingw${{ matrix.bits }} -kj Q=
|
dll_search_dir=$(printf '%s\n' /usr/lib/gcc/*-w64-mingw32/*-win32 | tee -a /dev/stderr)
|
||||||
|
cmake -B build --preset develop -DSANITIZERS=OFF --toolchain cmake/toolchain-mingw${{ matrix.bits }}.cmake \
|
||||||
|
-DFETCHCONTENT_BASE_DIR="${{ env.DEPS_ROOT_DIR }}" -DDLL_SEARCH_DIRS="$dll_search_dir"
|
||||||
|
cmake --build build
|
||||||
- name: Package binaries
|
- name: Package binaries
|
||||||
run: | # DLL dependencies can be figured out using e.g. Dependency Walker or objdump -p
|
run: |
|
||||||
mkdir bins
|
cmake --install build --prefix . --verbose --component binaries
|
||||||
mv -v rgb{asm,link,fix,gfx}.exe bins/
|
cmake --install build --prefix . --verbose --component shared-libs
|
||||||
cp -v /usr/${{ matrix.triplet }}/lib/zlib1.dll bins
|
|
||||||
cp -v /usr/${{ matrix.triplet }}/bin/libpng16-16.dll bins
|
|
||||||
cp -v /usr/lib/gcc/${{ matrix.triplet }}/10-win32/lib{ssp-0,stdc++-6}.dll bins
|
|
||||||
[ "${{ matrix.bits }}" -ne 32 ] || cp -v /usr/lib/gcc/${{ matrix.triplet }}/10-win32/libgcc_s_dw2-1.dll bins
|
|
||||||
- name: Upload Windows binaries
|
- name: Upload Windows binaries
|
||||||
uses: actions/upload-artifact@v7
|
uses: actions/upload-artifact@v7
|
||||||
with:
|
with:
|
||||||
name: rgbds-canary-mingw-win${{ matrix.bits }}
|
name: rgbds-canary-mingw-win${{ matrix.bits }}
|
||||||
path: bins
|
path: bin
|
||||||
if-no-files-found: error
|
if-no-files-found: error
|
||||||
- name: Upload Windows test binaries
|
- name: Upload Windows test binaries
|
||||||
uses: actions/upload-artifact@v7
|
uses: actions/upload-artifact@v7
|
||||||
|
|||||||
+1
-1
@@ -14,6 +14,6 @@ CMakeCache.txt
|
|||||||
CMakeFiles/
|
CMakeFiles/
|
||||||
cmake_install.cmake
|
cmake_install.cmake
|
||||||
CMakeUserPresets.json
|
CMakeUserPresets.json
|
||||||
build/
|
build*/
|
||||||
*.dSYM/
|
*.dSYM/
|
||||||
callgrind.out.*
|
callgrind.out.*
|
||||||
|
|||||||
@@ -202,4 +202,5 @@ set(CPACK_STRIP_FILES ON) # Only applies to binary packages, not sources.
|
|||||||
set(CPACK_VERBATIM_VARIABLES ON)
|
set(CPACK_VERBATIM_VARIABLES ON)
|
||||||
set(CPACK_THREADS 0) # Use all available CPU cores.
|
set(CPACK_THREADS 0) # Use all available CPU cores.
|
||||||
set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY OFF)
|
set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY OFF)
|
||||||
|
|
||||||
include(CPack)
|
include(CPack)
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
.SUFFIXES:
|
.SUFFIXES:
|
||||||
.SUFFIXES: .cpp .y .o
|
.SUFFIXES: .cpp .y .o
|
||||||
|
|
||||||
.PHONY: all clean install checkdiff develop debug profile coverage format tidy iwyu mingw32 mingw64 wine-shim dist
|
.PHONY: all clean install checkdiff develop debug profile coverage format tidy iwyu wine-shim dist
|
||||||
|
|
||||||
# User-defined variables
|
# User-defined variables
|
||||||
|
|
||||||
@@ -256,22 +256,6 @@ iwyu:
|
|||||||
CXX="include-what-you-use" \
|
CXX="include-what-you-use" \
|
||||||
REALCXXFLAGS="-std=c++20 -I include"
|
REALCXXFLAGS="-std=c++20 -I include"
|
||||||
|
|
||||||
# Targets for the project maintainer to easily create Windows exes.
|
|
||||||
# This is not for Windows users!
|
|
||||||
# If you're building on Windows with Cygwin or MinGW, just follow the Unix
|
|
||||||
# install instructions instead.
|
|
||||||
|
|
||||||
mingw32:
|
|
||||||
$Q${MAKE} all test/gfx/randtilegen test/gfx/rgbgfx_test \
|
|
||||||
CXX=i686-w64-mingw32-g++ \
|
|
||||||
CXXFLAGS="-O3 -flto -DNDEBUG -static-libgcc -static-libstdc++" \
|
|
||||||
PKG_CONFIG="PKG_CONFIG_SYSROOT_DIR=/usr/i686-w64-mingw32 pkg-config"
|
|
||||||
|
|
||||||
mingw64:
|
|
||||||
$Q${MAKE} all test/gfx/randtilegen test/gfx/rgbgfx_test \
|
|
||||||
CXX=x86_64-w64-mingw32-g++ \
|
|
||||||
PKG_CONFIG="PKG_CONFIG_SYSROOT_DIR=/usr/x86_64-w64-mingw32 pkg-config"
|
|
||||||
|
|
||||||
wine-shim:
|
wine-shim:
|
||||||
$Qecho '#!/usr/bin/env bash' > rgbshim.sh
|
$Qecho '#!/usr/bin/env bash' > rgbshim.sh
|
||||||
$Qecho 'WINEDEBUG=-all wine $$0.exe "$${@:1}"' >> rgbshim.sh
|
$Qecho 'WINEDEBUG=-all wine $$0.exe "$${@:1}"' >> rgbshim.sh
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
# From https://www.mingw-w64.org/build-systems/cmake/
|
||||||
|
|
||||||
|
set(CMAKE_SYSTEM_NAME Windows)
|
||||||
|
set(CMAKE_SYSTEM_PROCESSOR i686)
|
||||||
|
|
||||||
|
# Specify the cross-compiler.
|
||||||
|
set(CMAKE_C_COMPILER i686-w64-mingw32-gcc)
|
||||||
|
set(CMAKE_CXX_COMPILER i686-w64-mingw32-g++)
|
||||||
|
set(CMAKE_RC_COMPILER i686-w64-mingw32-windres)
|
||||||
|
|
||||||
|
# Specify the target environment.
|
||||||
|
set(CMAKE_FIND_ROOT_PATH /usr/i686-w64-mingw32)
|
||||||
|
|
||||||
|
# Search for programs in the build host directories.
|
||||||
|
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
|
||||||
|
# Search for libraries and headers in the target directories.
|
||||||
|
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
|
||||||
|
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
|
||||||
|
|
||||||
|
# CMake determines how to examine dependencies based on the *host* system, leading to
|
||||||
|
# a "file unknown error" unless the target platform is explicitly specified.
|
||||||
|
set(CMAKE_GET_RUNTIME_DEPENDENCIES_PLATFORM "windows+pe")
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
# From https://www.mingw-w64.org/build-systems/cmake/
|
||||||
|
|
||||||
|
set(CMAKE_SYSTEM_NAME Windows)
|
||||||
|
set(CMAKE_SYSTEM_PROCESSOR x86_64)
|
||||||
|
|
||||||
|
# Specify the cross-compiler.
|
||||||
|
set(CMAKE_C_COMPILER x86_64-w64-mingw32-gcc)
|
||||||
|
set(CMAKE_CXX_COMPILER x86_64-w64-mingw32-g++)
|
||||||
|
set(CMAKE_RC_COMPILER x86_64-w64-mingw32-windres)
|
||||||
|
|
||||||
|
# Specify the target environment.
|
||||||
|
set(CMAKE_FIND_ROOT_PATH /usr/x86_64-w64-mingw32)
|
||||||
|
|
||||||
|
# Search for programs in the build host directories.
|
||||||
|
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
|
||||||
|
# Search for libraries and headers in the target directories.
|
||||||
|
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
|
||||||
|
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
|
||||||
|
|
||||||
|
# CMake determines how to examine dependencies based on the *host* system, leading to
|
||||||
|
# a "file unknown error" unless the target platform is explicitly specified.
|
||||||
|
set(CMAKE_GET_RUNTIME_DEPENDENCIES_PLATFORM "windows+pe")
|
||||||
Reference in New Issue
Block a user