Skip to content

Add cross-platform GitHub Actions CI #2

Add cross-platform GitHub Actions CI

Add cross-platform GitHub Actions CI #2

Workflow file for this run

name: CMake CI
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
build:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
include:
- os: ubuntu-latest
vulkan-install: |
# Download and install Vulkan SDK using the tar.gz method
VULKAN_VERSION=$(curl -s https://vulkan.lunarg.com/sdk/latest/linux.txt)
curl -O https://sdk.lunarg.com/sdk/download/$VULKAN_VERSION/linux/vulkansdk-linux-x86_64-$VULKAN_VERSION.tar.gz
tar xf vulkansdk-linux-x86_64-$VULKAN_VERSION.tar.gz
cd $VULKAN_VERSION
./vulkansdk
# Set up environment variables
echo "VULKAN_SDK=$PWD/$VULKAN_VERSION/x86_64" >> $GITHUB_ENV
echo "PATH=$PWD/$VULKAN_VERSION/x86_64/bin:$PATH" >> $GITHUB_ENV
echo "LD_LIBRARY_PATH=$PWD/$VULKAN_VERSION/x86_64/lib:$LD_LIBRARY_PATH" >> $GITHUB_ENV
echo "VK_LAYER_PATH=$PWD/$VULKAN_VERSION/x86_64/etc/vulkan/explicit_layer.d" >> $GITHUB_ENV
deps-install: |
sudo apt-get update
sudo apt-get install -y \
libglfw3-dev \
libglm-dev \
libtinyobjloader-dev \
libstb-dev \
libyaml-cpp0.7
test-cmd: |
# Check if some of the expected executables were built
if [ -f "00_base_code/00_base_code" ]; then
echo "00_base_code built successfully"
else
echo "00_base_code build failed"
exit 1
fi
if [ -f "15_hello_triangle/15_hello_triangle" ]; then
echo "15_hello_triangle built successfully"
else
echo "15_hello_triangle build failed"
exit 1
fi
if [ -f "31_compute_shader/31_compute_shader" ]; then
echo "31_compute_shader built successfully"
else
echo "31_compute_shader build failed"
exit 1
fi
- os: windows-latest
vulkan-install: |
Invoke-WebRequest -Uri "https://sdk.lunarg.com/sdk/download/latest/windows/vulkan-sdk.exe" -OutFile "$env:TEMP\vulkan-sdk.exe"
Start-Process -FilePath "$env:TEMP\vulkan-sdk.exe" -ArgumentList "--accept-licenses --default-answer --confirm-command install" -Wait
# Add these environment variables
echo "VULKAN_SDK=C:\VulkanSDK\latest" >> $env:GITHUB_ENV
echo "VULKAN_INCLUDE_DIR=C:\VulkanSDK\latest\Include" >> $env:GITHUB_ENV
echo "VULKAN_LIBRARY=C:\VulkanSDK\latest\Lib\vulkan-1.lib" >> $env:GITHUB_ENV
deps-install: |
vcpkg install glfw3:x64-windows glm:x64-windows tinyobjloader:x64-windows stb:x64-windows
echo "CMAKE_TOOLCHAIN_FILE=$env:VCPKG_INSTALLATION_ROOT/scripts/buildsystems/vcpkg.cmake" >> $env:GITHUB_ENV
test-cmd: |
# Check if some of the expected executables were built
if (Test-Path "00_base_code/Release/00_base_code.exe") {
echo "00_base_code built successfully"
} else {
echo "00_base_code build failed"
exit 1
}
if (Test-Path "15_hello_triangle/Release/15_hello_triangle.exe") {
echo "15_hello_triangle built successfully"
} else {
echo "15_hello_triangle build failed"
exit 1
}
if (Test-Path "31_compute_shader/Release/31_compute_shader.exe") {
echo "31_compute_shader built successfully"
} else {
echo "31_compute_shader build failed"
exit 1
}
- os: macos-latest
vulkan-install: |
brew install molten-vk
curl -L -o vulkansdk.dmg "https://sdk.lunarg.com/sdk/download/latest/mac/vulkan-sdk.dmg"
hdiutil attach vulkansdk.dmg
sudo /Volumes/vulkansdk/InstallVulkan.app/Contents/MacOS/InstallVulkan --accept-licenses --default-answer --confirm-command install
hdiutil detach /Volumes/vulkansdk
deps-install: |
brew install glfw glm stb
# Install tinyobjloader from source since it's not available in brew
git clone https://github.com/tinyobjloader/tinyobjloader.git
cd tinyobjloader
cmake -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build --config Release
sudo cmake --install build
test-cmd: |
# Check if some of the expected executables were built
if [ -f "00_base_code/00_base_code" ]; then
echo "00_base_code built successfully"
else
echo "00_base_code build failed"
exit 1
fi
if [ -f "15_hello_triangle/15_hello_triangle" ]; then
echo "15_hello_triangle built successfully"
else
echo "15_hello_triangle build failed"
exit 1
fi
if [ -f "31_compute_shader/31_compute_shader" ]; then
echo "31_compute_shader built successfully"
else
echo "31_compute_shader build failed"
exit 1
fi
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- name: Cache dependencies
uses: actions/cache@v3
with:
path: |
~/.cache/pip
~/.vcpkg
~/Library/Caches/Homebrew
${{ env.VCPKG_INSTALLATION_ROOT }}
key: ${{ runner.os }}-deps-${{ hashFiles('**/CMakeLists.txt') }}
restore-keys: |
${{ runner.os }}-deps-
- name: Install dependencies
run: ${{ matrix.deps-install }}
- name: Install Vulkan SDK
run: ${{ matrix.vulkan-install }}
- name: Configure CMake
working-directory: ${{github.workspace}}/attachments
run: cmake -B build -DCMAKE_BUILD_TYPE=Release
- name: Build
working-directory: ${{github.workspace}}/attachments
run: cmake --build build --config Release
- name: Test Build Output
working-directory: ${{github.workspace}}/attachments/build
run: ${{ matrix.test-cmd }}