Add clang format from samples repo #362
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: | |
| workflow_dispatch: | |
| inputs: | |
| force_android_build: | |
| description: 'Force Android build to run regardless of file changes' | |
| required: false | |
| type: boolean | |
| default: false | |
| pull_request: | |
| types: [ opened, synchronize, reopened ] | |
| push: | |
| branches: [ main ] | |
| jobs: | |
| check-android-changes: | |
| name: Check Android Changes | |
| runs-on: ubuntu-latest | |
| outputs: | |
| should_build: ${{ steps.check.outputs.should_build }} | |
| steps: | |
| - uses: actions/checkout@v3 | |
| with: | |
| fetch-depth: 0 # Fetch all history for all branches and tags | |
| - name: Check for Android changes | |
| id: check | |
| run: | | |
| # For push events, check if workflow file has changed | |
| if [ "${{ github.event_name }}" == "push" ] && [ -n "${{ github.event.before }}" ] && [ -n "${{ github.event.after }}" ]; then | |
| if git diff --name-only ${{ github.event.before }} ${{ github.event.after }} | grep -q ".github/workflows/workflow.yml"; then | |
| echo "Workflow file has changed, building Android" | |
| echo "should_build=true" >> $GITHUB_OUTPUT | |
| exit 0 | |
| fi | |
| fi | |
| # For pull requests, check the files changed in the PR | |
| if [ "${{ github.event_name }}" == "pull_request" ]; then | |
| echo "Checking files changed in pull request..." | |
| # Check if PR has android label or title contains android | |
| if [[ "${{ contains(github.event.pull_request.labels.*.name, 'android') }}" == "true" || \ | |
| "${{ contains(github.event.pull_request.title, 'android') }}" == "true" || \ | |
| "${{ contains(github.event.pull_request.title, 'Android') }}" == "true" ]]; then | |
| echo "PR has android label or title contains android" | |
| echo "should_build=true" >> $GITHUB_OUTPUT | |
| exit 0 | |
| fi | |
| # Get the list of files changed in the PR | |
| git fetch origin ${{ github.event.pull_request.base.ref }} --depth=1 | |
| PR_FILES=$(git diff --name-only origin/${{ github.event.pull_request.base.ref }} ${{ github.sha }}) | |
| else | |
| # For pushes, check the files changed in the last commit | |
| echo "Checking files changed in push..." | |
| # If this is the first commit, build Android | |
| if [ "${{ github.event.before }}" == "0000000000000000000000000000000000000000" ]; then | |
| echo "First commit, building Android" | |
| echo "should_build=true" >> $GITHUB_OUTPUT | |
| exit 0 | |
| fi | |
| # Get the list of files changed in the push | |
| PR_FILES=$(git diff --name-only ${{ github.event.before }} ${{ github.event.after }}) | |
| fi | |
| # Check if any Android-related files have changed | |
| ANDROID_PATTERN="attachments/34_android.cpp|attachments/35_gltf_ktx.cpp|attachments/android/|attachments/27_shader_depth.(frag|vert)" | |
| if echo "$PR_FILES" | grep -E "$ANDROID_PATTERN"; then | |
| echo "Android-related files have changed" | |
| echo "should_build=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "No Android-related files have changed" | |
| echo "should_build=false" >> $GITHUB_OUTPUT | |
| fi | |
| build: | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| os: [ubuntu-latest, windows-latest] | |
| include: | |
| - os: ubuntu-latest | |
| ccache: ccache | |
| vulkan-install: | | |
| VULKAN_VERSION=$(curl -s https://vulkan.lunarg.com/sdk/latest/linux.txt) | |
| echo "Using Vulkan SDK version: $VULKAN_VERSION" | |
| mkdir -p vulkan-sdk | |
| cd vulkan-sdk | |
| curl -O "https://sdk.lunarg.com/sdk/download/$VULKAN_VERSION/linux/vulkansdk-linux-x86_64-$VULKAN_VERSION.tar.xz" | |
| tar -xJf vulkansdk-linux-x86_64-$VULKAN_VERSION.tar.xz | |
| 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 | |
| cd .. | |
| deps-install: | | |
| chmod +x scripts/install_dependencies_linux.sh | |
| ./scripts/install_dependencies_linux.sh | |
| test-cmd: | | |
| 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 | |
| ccache: sccache | |
| vulkan-install: | | |
| if (Test-Path "C:\VulkanSDK") { | |
| Write-Host "Using cached Vulkan SDK" | |
| } else { | |
| Write-Host "Downloading Vulkan SDK..." | |
| choco install -y aria2 | |
| aria2c --split=16 --max-connection-per-server=16 --min-split-size=1M --dir="$env:TEMP" --out="vulkan-sdk.exe" "https://sdk.lunarg.com/sdk/download/latest/windows/vulkan-sdk.exe" | |
| Write-Host "Installing minimal Vulkan SDK components..." | |
| try { | |
| Start-Process -FilePath "$env:TEMP\vulkan-sdk.exe" -ArgumentList "--accept-licenses --default-answer --confirm-command install --components VulkanRT,VulkanSDK64,VulkanDXC,VulkanTools" -Wait -NoNewWindow | |
| if (-not (Test-Path "C:\VulkanSDK")) { | |
| Write-Host "Vulkan SDK installation failed: C:\VulkanSDK directory not found" | |
| Write-Host "Attempting to install without specifying components..." | |
| Start-Process -FilePath "$env:TEMP\vulkan-sdk.exe" -ArgumentList "--accept-licenses --default-answer --confirm-command install" -Wait -NoNewWindow | |
| } | |
| } catch { | |
| Write-Host "Error installing Vulkan SDK: $_" | |
| Write-Host "Attempting to install without specifying components..." | |
| Start-Process -FilePath "$env:TEMP\vulkan-sdk.exe" -ArgumentList "--accept-licenses --default-answer --confirm-command install" -Wait -NoNewWindow | |
| } | |
| } | |
| $vulkanPath = "" | |
| if (Test-Path "C:\VulkanSDK") { | |
| $vulkanPath = Get-ChildItem "C:\VulkanSDK" | Sort-Object -Property Name -Descending | Select-Object -First 1 -ExpandProperty FullName | |
| } | |
| if (-not $vulkanPath) { | |
| if (Test-Path "C:\VulkanSDK\latest") { | |
| $vulkanPath = "C:\VulkanSDK\latest" | |
| } else { | |
| Write-Host "Warning: Vulkan SDK not found. Creating a temporary directory structure." | |
| # Create a temporary directory structure for the build to continue | |
| New-Item -ItemType Directory -Force -Path "C:\VulkanSDK\latest\Include\vulkan" | Out-Null | |
| New-Item -ItemType Directory -Force -Path "C:\VulkanSDK\latest\Lib" | Out-Null | |
| New-Item -ItemType Directory -Force -Path "C:\VulkanSDK\latest\Bin" | Out-Null | |
| # Create an empty vulkan.h file | |
| New-Item -ItemType File -Force -Path "C:\VulkanSDK\latest\Include\vulkan\vulkan.h" | Out-Null | |
| # Create an empty vulkan-1.lib file | |
| New-Item -ItemType File -Force -Path "C:\VulkanSDK\latest\Lib\vulkan-1.lib" | Out-Null | |
| $vulkanPath = "C:\VulkanSDK\latest" | |
| } | |
| } | |
| echo "VULKAN_SDK=$vulkanPath" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append | |
| echo "$vulkanPath\Bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append | |
| 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 | |
| Write-Host "Vulkan SDK path: $vulkanPath" | |
| deps-install: | | |
| .\scripts\install_dependencies_windows.bat | |
| echo "CMAKE_TOOLCHAIN_FILE=$env:VCPKG_INSTALLATION_ROOT/scripts/buildsystems/vcpkg.cmake" >> $env:GITHUB_ENV | |
| test-cmd: | | |
| 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 | |
| } | |
| runs-on: ${{ matrix.os }} | |
| steps: | |
| - uses: actions/checkout@v3 | |
| - name: Cache vcpkg packages (Windows) | |
| if: runner.os == 'Windows' | |
| uses: actions/cache@v3 | |
| with: | |
| path: | | |
| ${{ env.VCPKG_INSTALLATION_ROOT }}/installed | |
| ${{ env.VCPKG_INSTALLATION_ROOT }}/packages | |
| ${{ env.VCPKG_INSTALLATION_ROOT }}/buildtrees | |
| ${{ env.VCPKG_INSTALLATION_ROOT }}/downloads | |
| ${{ runner.temp }}/vcpkg-cache | |
| key: ${{ runner.os }}-vcpkg-${{ hashFiles('scripts/install_dependencies_windows.bat', '**/CMakeLists.txt') }} | |
| restore-keys: | | |
| ${{ runner.os }}-vcpkg-${{ hashFiles('scripts/install_dependencies_windows.bat') }}- | |
| ${{ runner.os }}-vcpkg- | |
| - name: Cache Vulkan SDK (Windows) | |
| if: runner.os == 'Windows' | |
| uses: actions/cache@v3 | |
| with: | |
| path: C:\VulkanSDK | |
| key: ${{ runner.os }}-vulkan-sdk-${{ hashFiles('**/CMakeLists.txt', '**/*.cpp', '**/*.h') }} | |
| restore-keys: | | |
| ${{ runner.os }}-vulkan-sdk-${{ hashFiles('**/CMakeLists.txt') }}- | |
| ${{ runner.os }}-vulkan-sdk- | |
| - name: Cache apt packages (Ubuntu) | |
| if: runner.os == 'Linux' | |
| uses: actions/cache@v3 | |
| with: | |
| path: /var/cache/apt/archives | |
| key: ${{ runner.os }}-apt-${{ hashFiles('**/workflow.yml') }} | |
| restore-keys: | | |
| ${{ runner.os }}-apt- | |
| - name: Cache ccache files | |
| uses: actions/cache@v3 | |
| with: | |
| path: | | |
| ~/.ccache | |
| ~/.cache/sccache | |
| key: ${{ runner.os }}-${{ matrix.ccache }}-${{ github.sha }} | |
| restore-keys: | | |
| ${{ runner.os }}-${{ matrix.ccache }}- | |
| - name: Cache Vulkan SDK (Ubuntu) | |
| if: runner.os == 'Linux' | |
| uses: actions/cache@v3 | |
| with: | |
| path: | | |
| ${{ github.workspace }}/vulkan-sdk | |
| key: ${{ runner.os }}-vulkan-sdk-${{ hashFiles('**/CMakeLists.txt') }}-${{ hashFiles('**/*.cpp') }} | |
| restore-keys: | | |
| ${{ runner.os }}-vulkan-sdk-${{ hashFiles('**/CMakeLists.txt') }}- | |
| ${{ runner.os }}-vulkan-sdk- | |
| - name: Install ccache (Ubuntu) | |
| if: runner.os == 'Linux' | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y ccache | |
| ccache --max-size=2G | |
| ccache -z | |
| echo "CCACHE_DIR=$HOME/.ccache" >> $GITHUB_ENV | |
| echo "PATH=/usr/lib/ccache:$PATH" >> $GITHUB_ENV | |
| - name: Cache sccache binary (Windows) | |
| if: runner.os == 'Windows' | |
| id: cache-sccache | |
| uses: actions/cache@v3 | |
| with: | |
| path: ${{ runner.temp }}/sccache | |
| key: ${{ runner.os }}-sccache-0.5.4 | |
| - name: Install sccache (Windows) | |
| if: runner.os == 'Windows' | |
| run: | | |
| if (Test-Path "$env:RUNNER_TEMP\sccache\sccache.exe") { | |
| Write-Host "Using cached sccache binary" | |
| $sccachePath = "$env:RUNNER_TEMP\sccache" | |
| } else { | |
| Write-Host "Downloading and installing sccache..." | |
| New-Item -ItemType Directory -Force -Path "$env:RUNNER_TEMP\sccache" | |
| aria2c --split=8 --max-connection-per-server=8 --min-split-size=1M --dir="$env:RUNNER_TEMP" --out="sccache.tar.gz" "https://github.com/mozilla/sccache/releases/download/v0.5.4/sccache-v0.5.4-x86_64-pc-windows-msvc.tar.gz" | |
| tar -xzf "$env:RUNNER_TEMP\sccache.tar.gz" --strip-components=1 -C "$env:RUNNER_TEMP\sccache" "sccache-v0.5.4-x86_64-pc-windows-msvc/sccache.exe" | |
| $sccachePath = "$env:RUNNER_TEMP\sccache" | |
| } | |
| echo "$sccachePath" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append | |
| echo "SCCACHE_DIR=$HOME/.cache/sccache" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append | |
| echo "SCCACHE_CACHE_SIZE=4G" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append | |
| echo "SCCACHE_ERROR_LOG=$HOME/.cache/sccache/sccache.log" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append | |
| echo "SCCACHE_LOG=info" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append | |
| echo "RUST_LOG=sccache=info" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append | |
| New-Item -ItemType Directory -Force -Path "$HOME/.cache/sccache" | |
| & "$sccachePath\sccache.exe" --version | |
| - 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" | |
| $criticalPaths = @( | |
| "$env:VULKAN_SDK\Include", | |
| "$env:VULKAN_SDK\Lib", | |
| "$env:VULKAN_SDK\Bin", | |
| "$env:VULKAN_SDK\Include\vulkan\vulkan.h", | |
| "$env:VULKAN_SDK\Lib\vulkan-1.lib" | |
| ) | |
| $allPathsExist = $true | |
| foreach ($path in $criticalPaths) { | |
| if (Test-Path $path) { | |
| echo "✓ Found: $path" | |
| } else { | |
| echo "✗ Missing: $path" | |
| $allPathsExist = $false | |
| } | |
| } | |
| # Check for glslangValidator.exe, but don't fail if it's missing | |
| if (Test-Path "$env:VULKAN_SDK\Bin\glslangValidator.exe") { | |
| echo "✓ Found: $env:VULKAN_SDK\Bin\glslangValidator.exe" | |
| } else { | |
| echo "✗ Missing: $env:VULKAN_SDK\Bin\glslangValidator.exe (not critical)" | |
| } | |
| if ($allPathsExist) { | |
| echo "Vulkan SDK installation verified successfully" | |
| } else { | |
| echo "Warning: Vulkan SDK installation is incomplete, but we'll continue anyway." | |
| echo "Some features may not work correctly." | |
| } | |
| } else { | |
| echo "Warning: Vulkan SDK not found, but we'll continue anyway." | |
| echo "Some features may not work correctly." | |
| } | |
| - name: Cache build artifacts (Windows) | |
| if: runner.os == 'Windows' | |
| uses: actions/cache@v3 | |
| with: | |
| path: | | |
| ${{github.workspace}}/attachments/build | |
| key: ${{ runner.os }}-build-msvc-${{ hashFiles('**/CMakeLists.txt', 'scripts/install_dependencies_windows.bat') }}-${{ hashFiles('**/*.cpp', '**/*.h', '**/*.hpp') }} | |
| restore-keys: | | |
| ${{ runner.os }}-build-msvc-${{ hashFiles('**/CMakeLists.txt', 'scripts/install_dependencies_windows.bat') }}- | |
| ${{ runner.os }}-build-msvc-${{ hashFiles('**/CMakeLists.txt') }}- | |
| ${{ runner.os }}-build-msvc- | |
| - name: Configure CMake with MSVC (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" ` | |
| -DCMAKE_C_COMPILER_LAUNCHER=sccache ` | |
| -DCMAKE_CXX_COMPILER_LAUNCHER=sccache ` | |
| -DCMAKE_CXX_FLAGS="/MP /EHsc /Zi /W3 /O2" ` | |
| -DCMAKE_SHARED_LINKER_FLAGS="/DEBUG:FASTLINK" ` | |
| -DCMAKE_EXE_LINKER_FLAGS="/DEBUG:FASTLINK" | |
| if (Test-Path "build/CMakeCache.txt") { | |
| Write-Host "CMake cache contents:" | |
| Get-Content "build/CMakeCache.txt" | Select-String -Pattern "Vulkan" | |
| } | |
| - name: Verify Vulkan Installation (Ubuntu) | |
| if: runner.os == 'Linux' | |
| run: | | |
| if [ -d "$VULKAN_SDK" ]; then | |
| echo "Vulkan SDK found at: $VULKAN_SDK" | |
| else | |
| echo "Vulkan SDK not found!" | |
| exit 1 | |
| fi | |
| - name: Cache build artifacts (Ubuntu) | |
| if: runner.os == 'Linux' | |
| uses: actions/cache@v3 | |
| with: | |
| path: ${{github.workspace}}/attachments/build | |
| key: ${{ runner.os }}-build-${{ hashFiles('**/CMakeLists.txt') }}-${{ hashFiles('**/*.cpp') }}-${{ hashFiles('**/*.h') }} | |
| restore-keys: | | |
| ${{ runner.os }}-build-${{ hashFiles('**/CMakeLists.txt') }}- | |
| ${{ runner.os }}-build- | |
| - name: Configure CMake (Unix) | |
| working-directory: ${{github.workspace}}/attachments | |
| if: runner.os != 'Windows' | |
| run: | | |
| export CC="clang" | |
| export CXX="clang++" | |
| cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=Release \ | |
| -DCMAKE_CXX_SCAN_FOR_MODULES=ON \ | |
| -DCMAKE_CXX_FLAGS="-std=c++20" \ | |
| -DCMAKE_C_COMPILER_LAUNCHER=ccache \ | |
| -DCMAKE_CXX_COMPILER_LAUNCHER=ccache | |
| - name: Build | |
| working-directory: ${{github.workspace}}/attachments | |
| run: cmake --build build --config Release --parallel 4 | |
| - name: ccache statistics | |
| if: runner.os == 'Linux' | |
| run: ccache -s | |
| - name: sccache statistics | |
| if: runner.os == 'Windows' | |
| run: sccache -s | |
| - name: Test Build Output | |
| working-directory: ${{github.workspace}}/attachments/build | |
| run: ${{ matrix.test-cmd }} | |
| android-build: | |
| name: Android Build | |
| runs-on: ubuntu-latest | |
| # We need to run a preliminary job to check for changes | |
| needs: check-android-changes | |
| if: needs.check-android-changes.outputs.should_build == 'true' || github.event.inputs.force_android_build == 'true' | |
| steps: | |
| - uses: actions/checkout@v3 | |
| - name: Cache ccache files | |
| uses: actions/cache@v3 | |
| with: | |
| path: ~/.ccache | |
| key: android-ccache-${{ hashFiles('attachments/android/app/src/main/cpp/CMakeLists.txt', 'attachments/34_android.cpp', 'attachments/35_gltf_ktx.cpp') }} | |
| restore-keys: | | |
| android-ccache-${{ hashFiles('attachments/android/app/src/main/cpp/CMakeLists.txt') }} | |
| android-ccache- | |
| - name: Cache KTX and tinygltf | |
| uses: actions/cache@v3 | |
| with: | |
| path: | | |
| /usr/local/include/ktx | |
| /usr/local/lib/libktx* | |
| /usr/local/include/tinygltf | |
| key: android-libs-${{ hashFiles('attachments/android/app/src/main/cpp/CMakeLists.txt') }} | |
| restore-keys: | | |
| android-libs- | |
| - name: Cache Gradle packages | |
| uses: actions/cache@v3 | |
| with: | |
| path: | | |
| ~/.gradle/caches | |
| ~/.gradle/wrapper | |
| ${{github.workspace}}/attachments/android/.gradle | |
| ${{github.workspace}}/attachments/android/app/.cxx | |
| ${{github.workspace}}/attachments/android/app/build/intermediates | |
| ${{github.workspace}}/attachments/android/app/build/outputs | |
| ${{github.workspace}}/attachments/android/app/build/generated | |
| key: ${{ runner.os }}-gradle-${{ hashFiles('attachments/android/app/src/main/cpp/CMakeLists.txt', 'attachments/34_android.cpp', 'attachments/35_gltf_ktx.cpp', 'attachments/android/app/build.gradle') }} | |
| restore-keys: | | |
| ${{ runner.os }}-gradle-${{ hashFiles('attachments/android/app/src/main/cpp/CMakeLists.txt') }} | |
| ${{ runner.os }}-gradle- | |
| - name: Install and configure ccache | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y ccache | |
| ccache --max-size=4G | |
| ccache --set-config=compression=true | |
| ccache --set-config=compression_level=9 | |
| ccache --set-config=sloppiness=file_macro,time_macros,include_file_mtime,include_file_ctime | |
| ccache --set-config=hash_dir=false | |
| ccache -z | |
| echo "CCACHE_DIR=$HOME/.ccache" >> $GITHUB_ENV | |
| echo "PATH=/usr/lib/ccache:$PATH" >> $GITHUB_ENV | |
| echo "CCACHE_COMPRESS=1" >> $GITHUB_ENV | |
| echo "CCACHE_COMPRESSLEVEL=9" >> $GITHUB_ENV | |
| echo "CCACHE_MAXSIZE=4G" >> $GITHUB_ENV | |
| - name: Set up Android SDK and NDK | |
| run: | | |
| echo "ANDROID_SDK_ROOT=$ANDROID_SDK_ROOT" >> $GITHUB_ENV | |
| echo "ANDROID_NDK_HOME=$ANDROID_NDK_ROOT" >> $GITHUB_ENV | |
| echo "Android SDK location: $ANDROID_SDK_ROOT" | |
| echo "Android NDK location: $ANDROID_NDK_ROOT" | |
| yes | $ANDROID_SDK_ROOT/cmdline-tools/latest/bin/sdkmanager --install "cmake;4.0.2" | |
| - name: Install Vulkan SDK and glslangValidator | |
| run: | | |
| if command -v glslangValidator &> /dev/null; then | |
| echo "glslangValidator already installed:" | |
| glslangValidator --version | |
| else | |
| sudo apt-get update | |
| sudo apt-get install -y glslang-tools | |
| which glslangValidator | |
| glslangValidator --version | |
| fi | |
| echo "VULKAN_SDK=/usr" >> $GITHUB_ENV | |
| echo "PATH=/usr/bin:$PATH" >> $GITHUB_ENV | |
| - name: Install KTX library | |
| run: | | |
| if [ -d "/usr/local/include/ktx" ] && [ -f "/usr/local/lib/libktx.so" ]; then | |
| echo "KTX library already installed from cache" | |
| else | |
| echo "Installing KTX library..." | |
| git clone --depth 1 --branch v4.1.0 https://github.com/KhronosGroup/KTX-Software.git | |
| cd KTX-Software | |
| mkdir build && cd build | |
| cmake .. -DCMAKE_BUILD_TYPE=Release \ | |
| -DKTX_FEATURE_TOOLS=OFF \ | |
| -DKTX_FEATURE_DOC=OFF \ | |
| -DKTX_FEATURE_LOADTEST_APPS=OFF \ | |
| -DCMAKE_C_COMPILER_LAUNCHER=ccache \ | |
| -DCMAKE_CXX_COMPILER_LAUNCHER=ccache | |
| cmake --build . --config Release --parallel 4 | |
| sudo cmake --install . | |
| cd ../.. | |
| fi | |
| - name: Install tinygltf | |
| run: | | |
| if [ -d "/usr/local/include/tinygltf" ]; then | |
| echo "tinygltf library already installed from cache" | |
| else | |
| echo "Installing tinygltf..." | |
| git clone --depth 1 https://github.com/syoyo/tinygltf.git | |
| cd tinygltf | |
| mkdir build && cd build | |
| cmake .. -DCMAKE_BUILD_TYPE=Release \ | |
| -DTINYGLTF_BUILD_LOADER_EXAMPLE=OFF \ | |
| -DTINYGLTF_BUILD_GL_EXAMPLES=OFF \ | |
| -DTINYGLTF_BUILD_VALIDATOR_EXAMPLE=OFF \ | |
| -DCMAKE_C_COMPILER_LAUNCHER=ccache \ | |
| -DCMAKE_CXX_COMPILER_LAUNCHER=ccache | |
| cmake --build . --config Release --parallel 4 | |
| sudo cmake --install . | |
| cd ../.. | |
| fi | |
| - name: Build Android Chapters | |
| working-directory: ${{github.workspace}}/attachments/android | |
| run: | | |
| if [ ! -f "gradlew" ]; then | |
| echo "Generating Gradle wrapper..." | |
| gradle wrapper | |
| fi | |
| SUPPORTED_CHAPTERS=$(grep -A 20 "set(SUPPORTED_CHAPTERS" app/src/main/cpp/CMakeLists.txt | sed -n '/set(SUPPORTED_CHAPTERS/,/)/p' | grep -o '"[^"]*"' | sed 's/"//g') | |
| readarray -t CHAPTERS <<< "$SUPPORTED_CHAPTERS" | |
| echo "Detected supported Android chapters: ${CHAPTERS[@]}" | |
| echo "org.gradle.jvmargs=-Xmx4g -XX:MaxMetaspaceSize=512m -XX:+HeapDumpOnOutOfMemoryError" > gradle.properties | |
| echo "org.gradle.parallel=true" >> gradle.properties | |
| echo "org.gradle.caching=true" >> gradle.properties | |
| echo "org.gradle.configureondemand=true" >> gradle.properties | |
| echo "android.useAndroidX=true" >> gradle.properties | |
| echo "android.enableJetifier=false" >> gradle.properties | |
| echo "kotlin.incremental=true" >> gradle.properties | |
| mkdir -p build-outputs | |
| for ((i=0; i<${#CHAPTERS[@]}; i++)); do | |
| chapter="${CHAPTERS[$i]}" | |
| if [ -n "$chapter" ]; then | |
| echo "Building $chapter chapter..." | |
| ./gradlew assembleDebug --parallel --max-workers=4 --build-cache -Pchapter=$chapter -PabiFilters=x86_64 | |
| if [ -f "app/build/outputs/apk/debug/app-debug.apk" ]; then | |
| echo "$chapter built successfully" | |
| cp app/build/outputs/apk/debug/app-debug.apk build-outputs/${chapter}.apk | |
| else | |
| echo "$chapter build failed" | |
| exit 1 | |
| fi | |
| fi | |
| done | |
| ccache -s |