Skip to content

Update CMakeLists.txt #10

Update CMakeLists.txt

Update CMakeLists.txt #10

Workflow file for this run

# NextSSL — Multi-platform CI/CD
#
# Triggers:
# - Push to main / master
# - Pull request against main / master
# - Manual via "Run workflow" button
#
# Jobs:
# build : compile nextssl for every platform x arch matrix entry
# build-macos-universal : lipo-merge x86_64 + arm64 into a fat dylib
#
# Artifacts (12 total):
# nextssl-win-x86_64 / x86 / arm64
# nextssl-linux-x86_64 / x86 / arm64 / armv7 / riscv64
# nextssl-macos-x86_64 / arm64 / universal
# nextssl-web-wasm32
name: Build
on:
push:
branches: [ main, master ]
pull_request:
branches: [ main, master ]
workflow_dispatch:
# Cancel in-flight runs for the same ref (saves minutes)
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
# ------------------------------------------------------------------------------
# Builds
# ------------------------------------------------------------------------------
jobs:
build:
name: Build ${{ matrix.label }}
runs-on: ${{ matrix.runner }}
strategy:
fail-fast: false
matrix:
include:
# -- Windows ---------------------------------------------------------
- label: "Windows x86_64 (MSVC)"
runner: windows-2022
os_tag: win
arch_tag: x86_64
cmake_arch: x64
toolchain: msvc
shared: ON
- label: "Windows x86 / i686 (MSVC)"
runner: windows-2022
os_tag: win
arch_tag: x86
cmake_arch: Win32
toolchain: msvc
shared: ON
- label: "Windows arm64 (MSVC cross)"
runner: windows-2022
os_tag: win
arch_tag: arm64
cmake_arch: ARM64
toolchain: msvc
shared: ON
# -- Linux glibc native ----------------------------------------------
- label: "Linux x86_64 (GCC)"
runner: ubuntu-22.04
os_tag: linux
arch_tag: x86_64
toolchain: native
apt_extra: ""
cross_args: ""
shared: ON
- label: "Linux x86 / i686 (GCC -m32)"
runner: ubuntu-22.04
os_tag: linux
arch_tag: x86
toolchain: native-m32
apt_extra: "gcc-multilib"
cross_args: "-DCMAKE_C_FLAGS=-m32 -DCMAKE_SYSTEM_PROCESSOR=i686"
shared: ON
# -- Linux glibc cross -----------------------------------------------
- label: "Linux arm64 / AArch64 (cross)"
runner: ubuntu-22.04
os_tag: linux
arch_tag: arm64
toolchain: cross
apt_extra: "gcc-aarch64-linux-gnu binutils-aarch64-linux-gnu libc6-dev-arm64-cross"
cross_args: >-
-DCMAKE_SYSTEM_NAME=Linux
-DCMAKE_SYSTEM_PROCESSOR=aarch64
-DCMAKE_C_COMPILER=aarch64-linux-gnu-gcc
-DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY
shared: ON
- label: "Linux armv7hf (cross)"
runner: ubuntu-22.04
os_tag: linux
arch_tag: armv7
toolchain: cross
apt_extra: "gcc-arm-linux-gnueabihf binutils-arm-linux-gnueabihf libc6-dev-armhf-cross"
cross_args: >-
-DCMAKE_SYSTEM_NAME=Linux
-DCMAKE_SYSTEM_PROCESSOR=armv7
-DCMAKE_C_COMPILER=arm-linux-gnueabihf-gcc
-DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY
shared: ON
- label: "Linux riscv64 (cross)"
runner: ubuntu-22.04
os_tag: linux
arch_tag: riscv64
toolchain: cross
apt_extra: "gcc-riscv64-linux-gnu binutils-riscv64-linux-gnu libc6-dev-riscv64-cross"
cross_args: >-
-DCMAKE_SYSTEM_NAME=Linux
-DCMAKE_SYSTEM_PROCESSOR=riscv64
-DCMAKE_C_COMPILER=riscv64-linux-gnu-gcc
-DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY
shared: ON
# -- macOS -----------------------------------------------------------
- label: "macOS x86_64 (Apple Clang)"
runner: macos-13
os_tag: macos
arch_tag: x86_64
toolchain: native
shared: ON
- label: "macOS arm64 / M-series (Apple Clang)"
runner: macos-14
os_tag: macos
arch_tag: arm64
toolchain: native
shared: ON
# -- WebAssembly -----------------------------------------------------
- label: "WASM (Emscripten)"
runner: ubuntu-22.04
os_tag: web
arch_tag: wasm32
toolchain: emscripten
shared: ON
steps:
- uses: actions/checkout@v4
# -- Linux: system packages ----------------------------------------------
- name: Install Linux build packages
if: runner.os == 'Linux' && matrix.toolchain != 'emscripten'
run: |
sudo apt-get update -qq
sudo apt-get install -y --no-install-recommends \
cmake ninja-build ccache ${{ matrix.apt_extra }}
# -- macOS: cmake + ninja + ccache ---------------------------------------
# brew install returns exit 1 when a package is already up-to-date in some
# versions; use `brew upgrade ... || brew install ...` for idempotency.
- name: Install macOS build packages
if: runner.os == 'macOS'
run: |
for pkg in cmake ninja ccache; do
brew upgrade "$pkg" 2>/dev/null || brew install "$pkg"
done
# -- WASM: system packages + Emscripten SDK ------------------------------
- name: Install WASM build packages
if: matrix.toolchain == 'emscripten'
run: |
sudo apt-get update -qq
sudo apt-get install -y --no-install-recommends cmake ninja-build ccache
- name: Set up Emscripten SDK
if: matrix.toolchain == 'emscripten'
uses: mymindstorm/setup-emsdk@v14
with:
version: latest
actions-cache-folder: .emsdk-cache
# -- Windows: install Ninja via Chocolatey (no third-party action needed)
- name: Install Ninja (Windows)
if: runner.os == 'Windows'
shell: pwsh
run: |
if (-not (Get-Command ninja -ErrorAction SilentlyContinue)) {
choco install ninja --yes --no-progress
}
# ========================================================================
# Compiler cache
# Cache key: runner.os + arch_tag + hash(CMakeLists + src)
# Restore-keys: fall back to same OS/arch, then OS only so all jobs on the
# same runner OS share a cache pool and seed each other.
# continue-on-error: true so a cache service hiccup never fails a build.
# ========================================================================
- name: Cache ccache (Linux / macOS)
if: runner.os != 'Windows'
uses: actions/cache@v4
continue-on-error: true
with:
path: ~/.ccache
key: ccache-${{ runner.os }}-${{ matrix.arch_tag }}-${{ hashFiles('CMakeLists.txt', 'src/**/*.c', 'src/**/*.h') }}
restore-keys: |
ccache-${{ runner.os }}-${{ matrix.arch_tag }}-
ccache-${{ runner.os }}-
- name: Configure ccache limits
if: runner.os != 'Windows'
run: |
ccache --set-config=max_size=500M
ccache --set-config=compression=true
ccache -z
- name: Cache sccache (Windows)
if: runner.os == 'Windows'
uses: actions/cache@v4
continue-on-error: true
with:
path: ${{ env.LOCALAPPDATA }}\Mozilla\sccache
key: sccache-win-${{ matrix.arch_tag }}-${{ hashFiles('CMakeLists.txt', 'src/**/*.c', 'src/**/*.h') }}
restore-keys: |
sccache-win-${{ matrix.arch_tag }}-
sccache-win-
# sccache is pre-installed on windows-2022 runners; --start-server is
# idempotent (exits 0 even if already running).
- name: Start sccache server (Windows)
if: runner.os == 'Windows'
shell: pwsh
run: |
if (Get-Command sccache -ErrorAction SilentlyContinue) {
sccache --start-server
Write-Host "sccache server started"
} else {
Write-Host "sccache not found — compiler caching disabled for this job"
}
# ========================================================================
# CMake configure
# All steps use -S . to make the source directory explicit.
# ========================================================================
- name: CMake configure (Windows MSVC)
if: matrix.toolchain == 'msvc'
shell: pwsh
run: |
$launcher = if (Get-Command sccache -ErrorAction SilentlyContinue) { "sccache" } else { "" }
$args = @(
"-S", ".",
"-B", "_build",
"-A", "${{ matrix.cmake_arch }}",
"-DCMAKE_BUILD_TYPE=Release",
"-DNEXTSSL_SHARED=${{ matrix.shared }}"
)
if ($launcher) { $args += "-DCMAKE_C_COMPILER_LAUNCHER=$launcher" }
cmake @args
- name: CMake configure (Linux native)
if: matrix.toolchain == 'native'
run: >
cmake -S . -B _build -G Ninja
-DCMAKE_BUILD_TYPE=Release
-DNEXTSSL_SHARED=${{ matrix.shared }}
-DCMAKE_C_COMPILER_LAUNCHER=ccache
- name: CMake configure (Linux -m32)
if: matrix.toolchain == 'native-m32'
run: >
cmake -S . -B _build -G Ninja
-DCMAKE_BUILD_TYPE=Release
-DNEXTSSL_SHARED=${{ matrix.shared }}
-DCMAKE_C_COMPILER_LAUNCHER=ccache
${{ matrix.cross_args }}
- name: CMake configure (Linux cross)
if: matrix.toolchain == 'cross'
run: >
cmake -S . -B _build -G Ninja
-DCMAKE_BUILD_TYPE=Release
-DNEXTSSL_SHARED=${{ matrix.shared }}
-DCMAKE_C_COMPILER_LAUNCHER=ccache
${{ matrix.cross_args }}
- name: CMake configure (macOS)
if: runner.os == 'macOS'
run: >
cmake -S . -B _build -G Ninja
-DCMAKE_BUILD_TYPE=Release
-DNEXTSSL_SHARED=${{ matrix.shared }}
-DCMAKE_C_COMPILER_LAUNCHER=ccache
- name: CMake configure (WASM)
if: matrix.toolchain == 'emscripten'
run: >
emcmake cmake -S . -B _build -G Ninja
-DCMAKE_BUILD_TYPE=Release
-DNEXTSSL_SHARED=${{ matrix.shared }}
-DCMAKE_C_COMPILER_LAUNCHER=ccache
-DCMAKE_RUNTIME_OUTPUT_DIRECTORY="${{ github.workspace }}/bin/web"
-DCMAKE_LIBRARY_OUTPUT_DIRECTORY="${{ github.workspace }}/bin/web"
# ========================================================================
# Build
# Pipe output through tee so errors appear in the runner log AND are
# saved to logs/build.log for the artifact upload below.
# ========================================================================
- name: Build (MSVC)
if: matrix.toolchain == 'msvc'
shell: pwsh
run: |
New-Item -ItemType Directory -Force logs | Out-Null
cmake --build _build --config Release --parallel 2>&1 |
Tee-Object logs\build.log
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
- name: Build (non-MSVC)
if: matrix.toolchain != 'msvc'
shell: bash
run: |
mkdir -p logs
cmake --build _build --parallel 2>&1 | tee logs/build.log
exit ${PIPESTATUS[0]}
# ========================================================================
# Post-build
# ========================================================================
- name: Show ccache stats
if: runner.os != 'Windows'
run: ccache -s
- name: Show sccache stats
if: runner.os == 'Windows'
shell: pwsh
run: |
if (Get-Command sccache -ErrorAction SilentlyContinue) { sccache --show-stats }
# Normalise output directory: CMakeLists.txt names the dir from
# CMAKE_SYSTEM_PROCESSOR which may differ from our arch_tag for cross builds.
- name: Normalise output directory
if: runner.os != 'Windows'
shell: bash
run: |
DST="bin/${{ matrix.os_tag }}/${{ matrix.arch_tag }}"
SRC=$(find bin -mindepth 2 -maxdepth 2 -type d 2>/dev/null | head -1)
if [ -n "$SRC" ] && [ "$SRC" != "$DST" ]; then
mkdir -p "$DST"
cp -r "$SRC"/. "$DST/"
fi
# ========================================================================
# Log collection — runs ALWAYS (success or failure)
# Collects: build output, CMake configure logs, compiler/tool versions.
# ========================================================================
- name: Collect build logs
if: always()
shell: bash
run: |
mkdir -p logs
# CMake configure logs (present even when build fails at configure)
for f in \
_build/CMakeFiles/CMakeError.log \
_build/CMakeFiles/CMakeOutput.log \
_build/CMakeFiles/cmake.check_cache; do
[ -f "$f" ] && cp "$f" "logs/$(basename $f)" || true
done
# Tool version info (helps reproduce failures locally)
{
echo "=== cmake ==="
cmake --version
echo "=== ninja ==="
ninja --version 2>/dev/null || echo "n/a"
echo "=== cc ==="
${CC:-cc} --version 2>/dev/null || echo "n/a"
echo "=== uname ==="
uname -a
} > logs/env.txt 2>&1 || true
- name: Collect build logs (Windows)
if: always() && runner.os == 'Windows'
shell: pwsh
run: |
New-Item -ItemType Directory -Force logs | Out-Null
foreach ($f in @(
"_build\CMakeFiles\CMakeError.log",
"_build\CMakeFiles\CMakeOutput.log"
)) {
if (Test-Path $f) { Copy-Item $f logs\ }
}
@(
"=== cmake ===", (cmake --version),
"=== cl ===", (cl 2>&1 | Select-Object -First 1),
"=== uname ===", ([System.Environment]::OSVersion)
) | Out-File logs\env.txt -Encoding utf8
# ========================================================================
# Artifact uploads — binary (only on success) + logs (always)
# ========================================================================
- name: Upload binary artifact
if: success()
uses: actions/upload-artifact@v4
with:
name: nextssl-${{ matrix.os_tag }}-${{ matrix.arch_tag }}
path: bin/${{ matrix.os_tag }}/${{ matrix.arch_tag }}/
retention-days: 30
if-no-files-found: warn
- name: Upload build logs
if: always()
uses: actions/upload-artifact@v4
with:
name: logs-${{ matrix.os_tag }}-${{ matrix.arch_tag }}
path: logs/
retention-days: 30
if-no-files-found: ignore
# ------------------------------------------------------------------------------
# macOS Universal (fat) binary -- merged from x86_64 + arm64 artifacts
# ------------------------------------------------------------------------------
build-macos-universal:
name: Build macOS universal (fat)
needs: build
runs-on: macos-14
steps:
- uses: actions/checkout@v4
- name: Download macOS x86_64 artifact
uses: actions/download-artifact@v4
with:
name: nextssl-macos-x86_64
path: _fat/x86_64
- name: Download macOS arm64 artifact
uses: actions/download-artifact@v4
with:
name: nextssl-macos-arm64
path: _fat/arm64
- name: Create universal binary with lipo
run: |
mkdir -p bin/macos/universal
lipo -create \
_fat/x86_64/libnextssl.dylib \
_fat/arm64/libnextssl.dylib \
-output bin/macos/universal/libnextssl.dylib
lipo -info bin/macos/universal/libnextssl.dylib
- name: Upload universal artifact
uses: actions/upload-artifact@v4
with:
name: nextssl-macos-universal
path: bin/macos/universal/
if-no-files-found: error
retention-days: 30