Skip to content

Build Packages

Build Packages #4

# Build release packages for all platforms
# Based on "CMake on multiple platforms" starter workflows https://github.com/actions/starter-workflows/blob/main/ci/cmake-multi-platform.yml
name: Build Packages
# This is an expensive workflow, so only run on demand.
# Building on Windows costs x2 and MacOS costs x10!
on: workflow_dispatch
env:
build_type: Release
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
# Set fail-fast to false to ensure that feedback is delivered for all matrix combinations. Consider changing this to true when your workflow is stable.
fail-fast: false
# Set up a matrix to run the following 3 configurations:
# 1. Windows, x64, latest MSVC compiler toolchain on the default runner image, default generator
# 2. Windows, win32, latest MSVC compiler toolchain on the default runner image, default generator
# 3. Linux, x64, latest Clang compiler toolchain on the default runner image, default generator
# 4. MacOS, Intel Silicon, x64, latest Clang compiler toolchain on the default runner image, default generator
# TODO: 5. MacOS, Apple Silicon (macos-14/latest), x64, latest Clang compiler toolchain on the default runner image, default generator
matrix:
os: [windows-latest, ubuntu-latest, macos-13]
architecture: [x64, win32]
include:
# - os: windows-latest
# c_compiler: cl
# cpp_compiler: cl
# architecture: x64
# - os: windows-latest
# c_compiler: cl
# cpp_compiler: cl
# architecture: win32
# - os: ubuntu-latest
# c_compiler: clang
# cpp_compiler: clang++
# architecture: x64
- os: macos-13
c_compiler: clang
cpp_compiler: clang++
exclude:
- os: ubuntu-latest
#architecture: win32 # TEMP: Disable ubuntu while https://gitlab.freedesktop.org is down
- os: macos-13
architecture: win32
- os: windows-latest # TEMP: Disable windows while testing mac
steps:
- name: Update packages
if: runner.os == 'Linux'
run: sudo apt-get update
- name: Install packages
if: runner.os == 'Linux'
run: sudo apt-get install -y libgl1-mesa-dev #TODO: May require --fix-missing
- name: Checkout repository
uses: actions/checkout@master
- name: Checkout submodules
run: git submodule update --init --recursive
# Workaround for "ubuntu-latest runners have an incompatible combination of clang and libstdc++" https://github.com/actions/runner-images/issues/8659
# From: https://github.com/actions/runner-images/discussions/9446#discussioncomment-8668540
- name: ubuntu clang/libstdc++ workaround
uses: mjp41/workaround8649@c8550b715ccdc17f89c8d5c28d7a48eeff9c94a8
with:
os: ${{ matrix.os }}
- name: Set reusable strings
# Turn repeated input strings (such as the build output directory) into step outputs. These step outputs can be used throughout the workflow file.
id: strings
shell: bash
run: |
echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT"
echo "package-dir=${{ github.workspace }}/packages" >> "$GITHUB_OUTPUT"
# Configure CMake in a 'build' subdirectory.
# `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
# -T and -A are only required for the Visual Studio generator to use the 64-bit toolset to build either 64 or 32 bit builds
- name: Configure CMake (Windows)
if: runner.os == 'Windows'
run: >
cmake -B ${{ steps.strings.outputs.build-output-dir }}
-DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }}
-DCMAKE_C_COMPILER=${{ matrix.c_compiler }}
-S ${{ github.workspace }}
-T host=x64
-A ${{ matrix.architecture }}
- name: Configure CMake (not Windows)
if: runner.os != 'Windows'
run: >
cmake -B ${{ steps.strings.outputs.build-output-dir }}
-DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }}
-DCMAKE_C_COMPILER=${{ matrix.c_compiler }}
-DCMAKE_BUILD_TYPE=${{ env.build_type }}
-S ${{ github.workspace }}
# Set version environment variable
# https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-environment-variable
# n.b. VERSION.txt is generated by the Configure CMake step, so this must be called subsequently
# n.b. GitHub actions uses pwsh (PowerShell) as the default shell on Windows (not CMD)
- name: Set version env var (PowerShell)
if: runner.os == 'Windows'
run: |
$Env:VER = Get-Content VERSION.txt
echo "VERSION=$Env:VER" >> $env:GITHUB_ENV
- name: Set version env var (Bash)
if: runner.os != 'Windows'
run: |
VER=$(cat VERSION.txt)
echo "VERSION=$VER" >> $GITHUB_ENV
- name: Print version
run: echo VERSION=${{ env.VERSION }}
- name: Build
# Build your program with the given configuration.
# --config is needed because the default Windows generator is a multi-config generator (Visual Studio generator).
run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ env.build_type }}
# Build package into the build/out/ directory
- name: Package
run: cpack --config build/CPackConfig.cmake -C ${{ env.build_type }}
- name: Upload package
uses: actions/upload-artifact@v4
with:
name: packages-${{ env.VERSION }}-${{ runner.os }}-${{ matrix.architecture }} # name given to uploaded artifact e.g. packages-0.6.3-Windows-x64
path: |
build/out
!build/out/_CPack_Packages/
overwrite: true