7
0
mirror of https://gitlab.com/raylibtemplates/rt.git synced 2026-06-05 02:00:54 -04:00
Files
RaylibTemplate-C/.github/workflows/cmake-multi-platform.yml

147 lines
4.7 KiB
YAML

name: CMake on multiple platforms
on:
push:
tags:
- "v*"
workflow_dispatch:
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: windows-latest
c_compiler: cl
cpp_compiler: cl
platform: Windows
artifact_name: windows
build_type: Release
- os: ubuntu-latest
c_compiler: gcc
cpp_compiler: g++
platform: Linux
artifact_name: linux
build_type: Release
- os: macos-latest
c_compiler: clang
cpp_compiler: clang++
platform: MacOS
artifact_name: macos
build_type: Release
- os: ubuntu-latest
c_compiler: emcc
cpp_compiler: em++
platform: Web
artifact_name: web
build_type: Release
steps:
- uses: actions/checkout@v4
- name: Set reusable strings
id: strings
shell: bash
run: |
echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT"
- name: Install Linux Dependencies
if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install -y libasound2-dev mesa-common-dev libx11-dev libxrandr-dev libxi-dev xorg-dev libgl1-mesa-dev libglu1-mesa-dev vim-common
- name: Install MacOS Dependencies
if: runner.os == 'macOS'
run: |
brew install cmake
xcode-select --install || true # Install Command Line Tools (includes xxd)
- name: Install Windows Dependencies
if: runner.os == 'Windows'
run: |
# Download xxd for Windows
curl -L -o xxd.exe https://github.com/easyaspi314/xxd-standalone/releases/download/v1.0.0/xxd.exe
# Add the current directory to PATH so xxd can be found
echo "${{ github.workspace }}" >> $GITHUB_PATH
shell: bash
- name: Cache CMake files
uses: actions/cache@v3
with:
path: |
~/.cmake
${{ github.workspace }}/build/_deps
key: ${{ runner.os }}-cmake-${{ matrix.c_compiler }}-${{ hashFiles('**/CMakeLists.txt', '**/*.cmake') }}
restore-keys: |
${{ runner.os }}-cmake-${{ matrix.c_compiler }}-
${{ runner.os }}-cmake-
- name: Cache emsdk
if: matrix.c_compiler == 'emcc'
uses: actions/cache@v3
with:
path: |
emsdk-cache
key: ${{ runner.os }}-emsdk-${{ hashFiles('.github/workflows/**') }}
restore-keys: |
${{ runner.os }}-emsdk-
- name: Setup Emscripten
if: matrix.c_compiler == 'emcc'
uses: mymindstorm/setup-emsdk@v12
with:
actions-cache-folder: emsdk-cache
version: 3.1.45
- name: Setup Web Build Environment
if: matrix.c_compiler == 'emcc'
run: |
mkdir -p ${{ steps.strings.outputs.build-output-dir }}/assets
# cp -r assets/* ${{ steps.strings.outputs.build-output-dir }}/assets/
- name: Configure CMake
run: >
cmake -B ${{ steps.strings.outputs.build-output-dir }}
-DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }}
-DCMAKE_C_COMPILER=${{ matrix.c_compiler }}
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
${{ matrix.c_compiler == 'emcc' && '-DPLATFORM=Web -DCMAKE_EXE_LINKER_FLAGS="-s USE_GLFW=3 -s ASYNCIFY -s TOTAL_MEMORY=67108864 -s FORCE_FILESYSTEM=1 --preload-file assets --shell-file ../src/shell.html"' || '' }}
-S ${{ github.workspace }}
- name: Build
run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }}
- name: Test
working-directory: ${{ steps.strings.outputs.build-output-dir }}
run: ctest --build-config ${{ matrix.build_type }}
- name: Create Release ZIP
run: |
cd ${{ steps.strings.outputs.build-output-dir }}
if [ "${{ matrix.platform }}" = "Web" ]; then
zip -r ../${{ matrix.artifact_name }}.zip *.html *.js *.data
elif [ "${{ matrix.platform }}" = "Windows" ]; then
cd ${{ matrix.build_type }}
zip -r ../../${{ matrix.artifact_name }}.zip *.exe
else
zip -r ../${{ matrix.artifact_name }}.zip * -x "*.cmake" "*.txt" "*.json" "*.a" "*.o" "*.d" "*.make" "*.internal" "*.marks" "Makefile" ".ninja*" "*.ninja" "CMakeFiles/*"
fi
shell: bash
- name: Upload Release Asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: ${{ matrix.artifact_name }}.zip
asset_name: ${{ matrix.artifact_name }}.zip
asset_content_type: application/zip