Add cross-platform GitHub Actions CI #5
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | |
| echo "Using Vulkan SDK version: $VULKAN_VERSION" | |
| # Create a temporary directory for the SDK | |
| mkdir -p vulkan-sdk | |
| cd vulkan-sdk | |
| # Download the SDK - try .tar.xz format instead of .tar.gz | |
| curl -O "https://sdk.lunarg.com/sdk/download/$VULKAN_VERSION/linux/vulkansdk-linux-x86_64-$VULKAN_VERSION.tar.xz" | |
| # Extract the SDK - use tar with J flag for xz compression | |
| tar -xJf vulkansdk-linux-x86_64-$VULKAN_VERSION.tar.xz | |
| # 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 | |
| # Return to the original directory | |
| cd .. | |
| deps-install: | | |
| sudo apt-get update | |
| sudo apt-get install -y \ | |
| libglfw3-dev \ | |
| libglm-dev \ | |
| libtinyobjloader-dev \ | |
| libstb-dev \ | |
| cmake | |
| # Build and install yaml-cpp from source | |
| git clone https://github.com/jbeder/yaml-cpp.git | |
| cd yaml-cpp | |
| cmake -B build -DCMAKE_BUILD_TYPE=Release -DYAML_BUILD_SHARED_LIBS=ON | |
| cmake --build build --config Release -j4 | |
| 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 | |
| - os: windows-latest | |
| vulkan-install: | | |
| # Download the Vulkan SDK installer | |
| Invoke-WebRequest -Uri "https://sdk.lunarg.com/sdk/download/latest/windows/vulkan-sdk.exe" -OutFile "$env:TEMP\vulkan-sdk.exe" | |
| # Run the installer with silent options | |
| Start-Process -FilePath "$env:TEMP\vulkan-sdk.exe" -ArgumentList "--accept-licenses --default-answer --confirm-command install" -Wait -NoNewWindow | |
| # Find the actual installed SDK version | |
| $vulkanPath = Get-ChildItem "C:\VulkanSDK" | Sort-Object -Property Name -Descending | Select-Object -First 1 -ExpandProperty FullName | |
| if (-not $vulkanPath) { | |
| $vulkanPath = "C:\VulkanSDK\latest" | |
| } | |
| # Set environment variables with correct Windows-style paths | |
| echo "VULKAN_SDK=$vulkanPath" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append | |
| # Add Vulkan SDK to system PATH | |
| echo "$vulkanPath\Bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append | |
| # Set explicit CMake variables | |
| echo "CMAKE_PREFIX_PATH=$vulkanPath" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append | |
| echo "Vulkan_INCLUDE_DIR=$vulkanPath\Include" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append | |
| echo "Vulkan_LIBRARY=$vulkanPath\Lib\vulkan-1.lib" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append | |
| # Display debug information | |
| Write-Host "Vulkan SDK path: $vulkanPath" | |
| if (Test-Path "$vulkanPath\Lib") { | |
| Write-Host "Lib directory exists" | |
| } else { | |
| Write-Host "Lib directory does not exist" | |
| } | |
| if (Test-Path "$vulkanPath\Include") { | |
| Write-Host "Include directory exists" | |
| } else { | |
| Write-Host "Include directory does not exist" | |
| } | |
| 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: | | |
| # Install MoltenVK (Vulkan implementation for macOS) | |
| brew install molten-vk | |
| # Get the latest SDK version | |
| VULKAN_VERSION=$(curl -s https://vulkan.lunarg.com/sdk/latest/mac.txt) | |
| echo "Using Vulkan SDK version: $VULKAN_VERSION" | |
| # Create a temporary directory for the SDK | |
| mkdir -p vulkan-sdk | |
| cd vulkan-sdk | |
| # Download the SDK | |
| # Use the direct URL format with explicit version | |
| curl -L -o vulkansdk.tar.xz "https://sdk.lunarg.com/sdk/download/$VULKAN_VERSION/mac/vulkansdk-macos-$VULKAN_VERSION.tar.xz" | |
| # Extract the SDK - use tar with J flag for xz compression | |
| tar -xJf vulkansdk.tar.xz | |
| # Set environment variables | |
| echo "VULKAN_SDK=$PWD/vulkansdk-macos-$VULKAN_VERSION/macOS" >> $GITHUB_ENV | |
| echo "PATH=$PWD/vulkansdk-macos-$VULKAN_VERSION/macOS/bin:$PATH" >> $GITHUB_ENV | |
| echo "DYLD_LIBRARY_PATH=$PWD/vulkansdk-macos-$VULKAN_VERSION/macOS/lib:$DYLD_LIBRARY_PATH" >> $GITHUB_ENV | |
| echo "VK_LAYER_PATH=$PWD/vulkansdk-macos-$VULKAN_VERSION/macOS/share/vulkan/explicit_layer.d" >> $GITHUB_ENV | |
| echo "VK_ICD_FILENAMES=$PWD/vulkansdk-macos-$VULKAN_VERSION/macOS/share/vulkan/icd.d/MoltenVK_icd.json" >> $GITHUB_ENV | |
| # Return to the original directory | |
| cd .. | |
| deps-install: | | |
| # Install available packages through brew | |
| brew install glfw glm | |
| # Install tinyobjloader from source | |
| 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 | |
| cd .. | |
| # Install stb headers | |
| git clone https://github.com/nothings/stb.git | |
| sudo mkdir -p /usr/local/include/stb | |
| sudo cp stb/*.h /usr/local/include/stb/ | |
| 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: Verify Vulkan Installation (Windows) | |
| if: runner.os == 'Windows' | |
| run: | | |
| if (Test-Path $env:VULKAN_SDK) { | |
| echo "Vulkan SDK found at: $env:VULKAN_SDK" | |
| echo "Contents of Lib directory:" | |
| Get-ChildItem "$env:VULKAN_SDK\Lib" | |
| echo "Contents of Include directory:" | |
| Get-ChildItem "$env:VULKAN_SDK\Include" | |
| } else { | |
| echo "Vulkan SDK not found!" | |
| exit 1 | |
| } | |
| - name: Configure CMake (Windows) | |
| working-directory: ${{github.workspace}}/attachments | |
| if: runner.os == 'Windows' | |
| run: | | |
| cmake -B build -DCMAKE_BUILD_TYPE=Release ` | |
| -DVulkan_INCLUDE_DIR="$env:Vulkan_INCLUDE_DIR" ` | |
| -DVulkan_LIBRARY="$env:Vulkan_LIBRARY" ` | |
| -DCMAKE_PREFIX_PATH="$env:VULKAN_SDK" ` | |
| -DCMAKE_TOOLCHAIN_FILE="$env:CMAKE_TOOLCHAIN_FILE" | |
| # Display CMake cache to debug Vulkan detection | |
| if (Test-Path "build/CMakeCache.txt") { | |
| Write-Host "CMake cache contents:" | |
| Get-Content "build/CMakeCache.txt" | Select-String -Pattern "Vulkan" | |
| } | |
| - name: Configure CMake (Unix) | |
| working-directory: ${{github.workspace}}/attachments | |
| if: runner.os != 'Windows' | |
| 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 }} |