171 lines
6.0 KiB
YAML
171 lines
6.0 KiB
YAML
name: Reusable Build Workflow
|
|
|
|
on:
|
|
workflow_call:
|
|
inputs:
|
|
platform:
|
|
description: "Which platform to build for: 'linux' or 'windows'"
|
|
required: true
|
|
run-tests:
|
|
description: "If true, run the test suite"
|
|
type: boolean
|
|
default: false
|
|
package-dist:
|
|
description: "If true, create a distributable package (and upload artifact)"
|
|
type: boolean
|
|
default: false
|
|
|
|
jobs:
|
|
build:
|
|
runs-on: ubuntu-latest # We'll do both Linux or Windows cross from Ubuntu
|
|
steps:
|
|
- name: Check Out Code
|
|
uses: actions/checkout@v3
|
|
|
|
# ---------------------
|
|
# 1) Install Dependencies
|
|
# ---------------------
|
|
- name: Install Dependencies (Linux)
|
|
if: ${{ inputs.platform == 'linux' }}
|
|
run: |
|
|
sudo apt-get update
|
|
sudo apt-get install -y \
|
|
libasound2-dev libpulse-dev libudev-dev \
|
|
libwayland-dev wayland-protocols libxkbcommon-dev \
|
|
libx11-dev libxext-dev libxrandr-dev libxcursor-dev \
|
|
libxi-dev libxinerama-dev libxss-dev \
|
|
libegl1-mesa-dev libgl1-mesa-dev \
|
|
cmake ninja-build git build-essential binutils mold meson pkg-config \
|
|
ccache
|
|
|
|
- name: Install Dependencies (Windows cross)
|
|
if: ${{ inputs.platform == 'windows' }}
|
|
run: |
|
|
sudo apt-get update
|
|
sudo apt-get install -y \
|
|
mingw-w64 cmake ninja-build git build-essential \
|
|
binutils pkg-config meson ccache
|
|
|
|
- name: Configure ccache
|
|
run: |
|
|
echo "CMAKE_C_COMPILER_LAUNCHER=ccache" >> $GITHUB_ENV
|
|
echo "CMAKE_CXX_COMPILER_LAUNCHER=ccache" >> $GITHUB_ENV
|
|
|
|
- name: Cache ccache
|
|
uses: actions/cache@v3
|
|
with:
|
|
path: ~/.ccache
|
|
key: ${{ runner.os }}-ccache-${{ inputs.platform }}-${{ hashFiles('**/*.c', '**/*.cpp', '**/*.h', '**/CMakeLists.txt', '**/*.meson', '**/*.build') }}
|
|
restore-keys: |
|
|
${{ runner.os }}-ccache-${{ inputs.platform }}-
|
|
|
|
# ---------------------
|
|
# 2) Build SDL3
|
|
# ---------------------
|
|
- name: Cache SDL3
|
|
id: cache-sdl
|
|
uses: actions/cache@v3
|
|
with:
|
|
path: |
|
|
sdl3-${{ inputs.platform }}
|
|
sdl3-build-${{ inputs.platform }}
|
|
key: sdl3-${{ inputs.platform }}-${{ hashFiles('sdl3-*/*.CMakeLists.txt') }}
|
|
|
|
- name: Build SDL3
|
|
run: |
|
|
# Use different folder names for Linux vs Windows
|
|
if [ "${{ inputs.platform }}" = "linux" ]; then
|
|
SRC="sdl3-linux"
|
|
BUILD="sdl3-build-linux"
|
|
GIT_URL="https://github.com/libsdl-org/SDL.git"
|
|
# Possibly different branches or flags for Linux, etc.
|
|
# ...
|
|
if [ ! -d "$SRC/.git" ]; then
|
|
git clone --depth 1 --branch main "$GIT_URL" "$SRC"
|
|
fi
|
|
mkdir -p "$BUILD"
|
|
cd "$BUILD"
|
|
cmake ../"$SRC" -GNinja \
|
|
-DCMAKE_BUILD_TYPE=Release \
|
|
-DCMAKE_INSTALL_PREFIX="${PWD}/installed_sdl3" \
|
|
-DSDL_SHARED=ON -DSDL_STATIC=OFF
|
|
ninja
|
|
ninja install
|
|
|
|
elif [ "${{ inputs.platform }}" = "windows" ]; then
|
|
SRC="sdl3-win"
|
|
BUILD="sdl3-build-win"
|
|
GIT_URL="https://github.com/libsdl-org/SDL.git"
|
|
# ...
|
|
if [ ! -d "$SRC/.git" ]; then
|
|
git clone --depth 1 --branch main "$GIT_URL" "$SRC"
|
|
fi
|
|
mkdir -p "$BUILD"
|
|
cd "$BUILD"
|
|
cmake ../"$SRC" -GNinja \
|
|
-DCMAKE_SYSTEM_NAME=Windows \
|
|
-DCMAKE_C_COMPILER=x86_64-w64-mingw32-gcc \
|
|
-DCMAKE_CXX_COMPILER=x86_64-w64-mingw32-g++ \
|
|
-DCMAKE_RC_COMPILER=x86_64-w64-mingw32-windres \
|
|
-DCMAKE_BUILD_TYPE=Release \
|
|
-DCMAKE_INSTALL_PREFIX="${PWD}/installed_sdl3_win" \
|
|
-DSDL_SHARED=ON -DSDL_STATIC=OFF
|
|
ninja
|
|
ninja install
|
|
fi
|
|
|
|
# ---------------------
|
|
# 3) Build Prosperon
|
|
# ---------------------
|
|
- name: Configure PKG_CONFIG_PATH
|
|
if: ${{ inputs.platform == 'windows' }}
|
|
run: |
|
|
echo "PKG_CONFIG_PATH=${GITHUB_WORKSPACE}/sdl3-build-win/installed_sdl3_win/lib/pkgconfig:$PKG_CONFIG_PATH" >> $GITHUB_ENV
|
|
|
|
- name: Build Prosperon
|
|
run: |
|
|
if [ "${{ inputs.platform }}" = "linux" ]; then
|
|
export PKG_CONFIG_PATH="${PWD}/sdl3-build-linux/installed_sdl3/lib/pkgconfig:$PKG_CONFIG_PATH"
|
|
meson setup build_dbg -Dbuildtype=release -Db_lto=true -Db_ndebug=true
|
|
meson compile -C build_dbg
|
|
|
|
elif [ "${{ inputs.platform }}" = "windows" ]; then
|
|
meson setup --cross-file mingw32.cross build_win -Dbuildtype=release -Db_lto=true -Db_ndebug=true
|
|
meson compile -C build_win
|
|
fi
|
|
|
|
# ---------------------
|
|
# 4) (Optional) Run Tests
|
|
# ---------------------
|
|
- name: Run Test Suite
|
|
if: ${{ inputs.run-tests == true }}
|
|
run: |
|
|
# Example: just show how you'd do it
|
|
echo "Running tests..."
|
|
# e.g. meson test -C build_dbg
|
|
# or some custom test commands
|
|
echo "Tests completed!"
|
|
|
|
# ---------------------
|
|
# 5) (Optional) Package Dist
|
|
# ---------------------
|
|
- name: Package Distribution
|
|
if: ${{ inputs.package-dist == true }}
|
|
run: |
|
|
echo "Creating final _pack folder..."
|
|
mkdir _pack
|
|
if [ "${{ inputs.platform }}" = "linux" ]; then
|
|
cp build_dbg/prosperon _pack/
|
|
cp sdl3-build-linux/installed_sdl3/lib/libSDL3.so _pack/
|
|
else
|
|
cp build_win/prosperon.exe _pack/
|
|
cp sdl3-build-win/installed_sdl3_win/bin/SDL3.dll _pack/
|
|
fi
|
|
|
|
- name: Upload Artifact
|
|
if: ${{ inputs.package-dist == true }}
|
|
uses: actions/upload-artifact@v3
|
|
with:
|
|
name: prosperon-${{ inputs.platform }}
|
|
path: _pack
|