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

174 lines
5.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-gcc
artifact_name: linux-gcc
build_type: Release
- os: ubuntu-latest
c_compiler: clang
cpp_compiler: clang++
platform: Linux-clang
artifact_name: linux-clang
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
- name: Install MacOS Dependencies
if: runner.os == 'macOS'
run: |
brew install cmake
- 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 }}
# For regular pushes, upload as artifacts
- name: Upload Build Artifacts
if: github.event_name != 'release'
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.platform }}-build
path: |
${{ matrix.platform == 'Web' && format('{0}/*.{html,js,data}', steps.strings.outputs.build-output-dir) }}
${{ matrix.platform == 'Windows' && format('{0}/{1}/*.exe', steps.strings.outputs.build-output-dir, matrix.build_type) }}
${{ contains(matrix.platform, 'Linux') && format('{0}/*', steps.strings.outputs.build-output-dir) }}
${{ matrix.platform == 'MacOS' && format('{0}/*', steps.strings.outputs.build-output-dir) }}
assets/**
exclude: |
${{ contains(matrix.platform, 'Linux') || matrix.platform == 'MacOS' ? '**/*.cmake
**/*.txt
**/*.json
**/*.a
**/*.o
**/*.d
**/*.make
**/*.internal
**/*.marks
**/Makefile
**/.ninja*
**/*.ninja
**/CMakeFiles/**' : '' }}
# For releases, create ZIP files and upload to the release
- name: Create Release ZIP
if: github.event_name == 'release'
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
if: github.event_name == 'release'
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