new sample texview #41
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: Build Sokol Libraries | |
| on: | |
| push: | |
| branches: [ main, develop ] | |
| pull_request: | |
| branches: [ main, develop ] | |
| workflow_dispatch: # Allow manual triggering | |
| # Required permissions for private repositories | |
| permissions: | |
| contents: write # Allow workflow to push commits back to repository | |
| jobs: | |
| # Check if source files that affect library builds have changed | |
| check-changes: | |
| name: Check for library source changes | |
| runs-on: ubuntu-latest | |
| outputs: | |
| should_build: ${{ steps.check_sources.outputs.changed }} | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 2 | |
| - name: Check for source changes | |
| id: check_sources | |
| run: | | |
| SHOULD_BUILD=false | |
| # Check if this is a manual workflow dispatch | |
| if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then | |
| echo "Manual workflow dispatch - building libraries" | |
| SHOULD_BUILD=true | |
| # Check if this is the first commit | |
| elif ! git rev-parse HEAD~1 >/dev/null 2>&1; then | |
| echo "First commit - building all libraries" | |
| SHOULD_BUILD=true | |
| else | |
| # Get changed files | |
| CHANGED_FILES=$(git diff --name-only HEAD~1 HEAD) | |
| echo "Files changed in this commit:" | |
| echo "$CHANGED_FILES" | |
| # Files/directories that affect library builds | |
| BUILD_AFFECTING_PATTERNS=" | |
| ^ext/ | |
| ^src/sokol/ | |
| ^bindgen/ | |
| ^scripts/build-.*\.sh$ | |
| ^scripts/build-.*\.ps1$ | |
| ^CMakeLists\.txt$ | |
| ^Directory\.Build\.props$ | |
| .*\.targets$ | |
| " | |
| # Check if any changed files match build-affecting patterns | |
| while IFS= read -r changed_file; do | |
| for pattern in $BUILD_AFFECTING_PATTERNS; do | |
| if echo "$changed_file" | grep -qE "$pattern"; then | |
| echo "Build-affecting file changed: $changed_file" | |
| SHOULD_BUILD=true | |
| break 2 | |
| fi | |
| done | |
| done <<< "$CHANGED_FILES" | |
| fi | |
| if [ "$SHOULD_BUILD" = true ]; then | |
| echo "changed=true" >> $GITHUB_OUTPUT | |
| echo "✓ Will build libraries" | |
| else | |
| echo "changed=false" >> $GITHUB_OUTPUT | |
| echo "✓ No source changes affecting libraries - skipping build" | |
| fi | |
| generate-bindings: | |
| name: Generate C# Bindings | |
| runs-on: ubuntu-latest | |
| needs: check-changes | |
| if: | | |
| needs.check-changes.outputs.should_build == 'true' && | |
| github.ref == 'refs/heads/main' && | |
| github.event_name == 'push' | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| submodules: recursive | |
| - name: Install clang | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y clang | |
| - name: Generate bindings | |
| run: | | |
| cd bindgen | |
| python3 gen.py | |
| rm -rf *.json | |
| rm -rf __pycache__ | |
| - name: Check for binding changes | |
| id: check_changes | |
| run: | | |
| if git diff --quiet src/; then | |
| echo "No binding changes detected" | |
| echo "changed=false" >> $GITHUB_OUTPUT | |
| else | |
| echo "Binding changes detected" | |
| echo "changed=true" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Commit binding changes | |
| if: steps.check_changes.outputs.changed == 'true' | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git add src/ | |
| git commit -m "Auto-update C# bindings [skip ci] | |
| Generated from commit: ${{ github.sha }} | |
| Workflow run: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} | |
| Bindings regenerated from Sokol C headers" | |
| git push origin main | |
| build-windows: | |
| name: Build Windows (${{ matrix.arch }}) | |
| runs-on: windows-latest | |
| needs: check-changes | |
| if: needs.check-changes.outputs.should_build == 'true' | |
| strategy: | |
| matrix: | |
| arch: [x64] # Can add Win32, ARM64 if needed | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| submodules: recursive | |
| - name: Setup CMake | |
| uses: lukka/get-cmake@latest | |
| - name: Configure CMake | |
| run: | | |
| mkdir build-windows | |
| cd build-windows | |
| cmake ../ext -G "Visual Studio 17 2022" -A ${{ matrix.arch }} | |
| - name: Build Debug | |
| run: | | |
| cd build-windows | |
| cmake --build . --config Debug | |
| - name: Build Release | |
| run: | | |
| cd build-windows | |
| cmake --build . --config Release | |
| - name: Create output directories | |
| shell: pwsh | |
| run: | | |
| New-Item -ItemType Directory -Force "libs/windows/${{ matrix.arch }}/debug" | Out-Null | |
| New-Item -ItemType Directory -Force "libs/windows/${{ matrix.arch }}/release" | Out-Null | |
| - name: Copy artifacts | |
| shell: pwsh | |
| run: | | |
| $debugDll = "build-windows/Debug/sokol.dll" | |
| $debugLib = "build-windows/Debug/sokol.lib" | |
| $releaseDll = "build-windows/Release/sokol.dll" | |
| $releaseLib = "build-windows/Release/sokol.lib" | |
| $debugDestDir = "libs/windows/${{ matrix.arch }}/debug" | |
| $releaseDestDir = "libs/windows/${{ matrix.arch }}/release" | |
| # Function to check if file changed | |
| function ShouldCopyFile($sourcePath, $destPath) { | |
| if (!(Test-Path $sourcePath)) { | |
| Write-Host "Source file $sourcePath does not exist" | |
| return $false | |
| } | |
| if (!(Test-Path $destPath)) { | |
| Write-Host "Destination file $destPath does not exist - copying" | |
| return $true | |
| } | |
| $sourceHash = Get-FileHash $sourcePath -Algorithm SHA256 | |
| $destHash = Get-FileHash $destPath -Algorithm SHA256 | |
| if ($sourceHash.Hash -ne $destHash.Hash) { | |
| Write-Host "File $destPath changed (SHA256 differs) - copying" | |
| return $true | |
| } else { | |
| Write-Host "File $destPath unchanged - skipping copy" | |
| return $false | |
| } | |
| } | |
| # Copy debug files if changed | |
| if (ShouldCopyFile $debugDll "$debugDestDir/sokol.dll") { | |
| Copy-Item -Force $debugDll $debugDestDir/ | |
| } | |
| if (ShouldCopyFile $debugLib "$debugDestDir/sokol.lib") { | |
| Copy-Item -Force $debugLib $debugDestDir/ | |
| } | |
| # Copy release files if changed | |
| if (ShouldCopyFile $releaseDll "$releaseDestDir/sokol.dll") { | |
| Copy-Item -Force $releaseDll $releaseDestDir/ | |
| } | |
| if (ShouldCopyFile $releaseLib "$releaseDestDir/sokol.lib") { | |
| Copy-Item -Force $releaseLib $releaseDestDir/ | |
| } | |
| - name: Upload artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: windows-${{ matrix.arch }} | |
| path: libs/windows/${{ matrix.arch }}/**/* | |
| retention-days: 30 | |
| build-macos: | |
| name: Build macOS (${{ matrix.arch }}) | |
| runs-on: macos-latest | |
| needs: check-changes | |
| if: needs.check-changes.outputs.should_build == 'true' | |
| strategy: | |
| matrix: | |
| arch: [arm64, x86_64] | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| submodules: recursive | |
| - name: Setup CMake | |
| uses: lukka/get-cmake@latest | |
| - name: Configure and Build | |
| run: | | |
| mkdir build-macos-${{ matrix.arch }} | |
| cd build-macos-${{ matrix.arch }} | |
| # Configure for specific architecture | |
| cmake ../ext -DCMAKE_OSX_ARCHITECTURES=${{ matrix.arch }} -DCMAKE_BUILD_TYPE=Debug | |
| cmake --build . --config Debug | |
| # Create output directories | |
| mkdir -p ../libs/macos/${{ matrix.arch }}/debug | |
| # Check if debug library changed before copying | |
| if [ -f "../libs/macos/${{ matrix.arch }}/debug/libsokol.dylib" ]; then | |
| OLD_DEBUG_HASH=$(sha256sum "../libs/macos/${{ matrix.arch }}/debug/libsokol.dylib" | cut -d' ' -f1) | |
| NEW_DEBUG_HASH=$(sha256sum "libsokol.dylib" | cut -d' ' -f1) | |
| if [ "$OLD_DEBUG_HASH" = "$NEW_DEBUG_HASH" ]; then | |
| echo "Debug library unchanged - skipping copy" | |
| else | |
| echo "Debug library changed - copying" | |
| cp libsokol.dylib ../libs/macos/${{ matrix.arch }}/debug/ | |
| fi | |
| else | |
| echo "Debug library doesn't exist - copying" | |
| cp libsokol.dylib ../libs/macos/${{ matrix.arch }}/debug/ | |
| fi | |
| # Build Release | |
| cmake ../ext -DCMAKE_OSX_ARCHITECTURES=${{ matrix.arch }} -DCMAKE_BUILD_TYPE=Release | |
| cmake --build . --config Release | |
| mkdir -p ../libs/macos/${{ matrix.arch }}/release | |
| # Check if release library changed before copying | |
| if [ -f "../libs/macos/${{ matrix.arch }}/release/libsokol.dylib" ]; then | |
| OLD_RELEASE_HASH=$(sha256sum "../libs/macos/${{ matrix.arch }}/release/libsokol.dylib" | cut -d' ' -f1) | |
| NEW_RELEASE_HASH=$(sha256sum "libsokol.dylib" | cut -d' ' -f1) | |
| if [ "$OLD_RELEASE_HASH" = "$NEW_RELEASE_HASH" ]; then | |
| echo "Release library unchanged - skipping copy" | |
| else | |
| echo "Release library changed - copying" | |
| cp libsokol.dylib ../libs/macos/${{ matrix.arch }}/release/ | |
| fi | |
| else | |
| echo "Release library doesn't exist - copying" | |
| cp libsokol.dylib ../libs/macos/${{ matrix.arch }}/release/ | |
| fi | |
| - name: Upload artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: macos-${{ matrix.arch }} | |
| path: libs/macos/${{ matrix.arch }}/**/* | |
| retention-days: 30 | |
| build-linux: | |
| name: Build Linux (${{ matrix.arch }}) | |
| runs-on: ubuntu-latest | |
| needs: check-changes | |
| if: needs.check-changes.outputs.should_build == 'true' | |
| strategy: | |
| matrix: | |
| include: | |
| - arch: x86_64 | |
| packages: "" | |
| # Note: ARM64 cross-compilation removed due to repository limitations | |
| # ARM64 builds should be done natively on ARM64 hardware | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| submodules: recursive | |
| - name: Install dependencies | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y \ | |
| build-essential \ | |
| cmake \ | |
| libx11-dev \ | |
| libxcursor-dev \ | |
| libxi-dev \ | |
| libasound2-dev \ | |
| libgl1-mesa-dev \ | |
| ${{ matrix.packages }} | |
| - name: Configure and Build | |
| run: | | |
| mkdir build-linux | |
| cd build-linux | |
| # Build Debug | |
| cmake ../ext -DCMAKE_BUILD_TYPE=Debug | |
| cmake --build . --config Debug | |
| mkdir -p ../libs/linux/${{ matrix.arch }}/debug | |
| # Check if debug library changed before copying | |
| if [ -f "../libs/linux/${{ matrix.arch }}/debug/libsokol.so" ]; then | |
| OLD_DEBUG_HASH=$(sha256sum "../libs/linux/${{ matrix.arch }}/debug/libsokol.so" | cut -d' ' -f1) | |
| NEW_DEBUG_HASH=$(sha256sum "libsokol.so" | cut -d' ' -f1) | |
| if [ "$OLD_DEBUG_HASH" = "$NEW_DEBUG_HASH" ]; then | |
| echo "Debug library unchanged - skipping copy" | |
| else | |
| echo "Debug library changed - copying" | |
| cp libsokol.so ../libs/linux/${{ matrix.arch }}/debug/ | |
| fi | |
| else | |
| echo "Debug library doesn't exist - copying" | |
| cp libsokol.so ../libs/linux/${{ matrix.arch }}/debug/ | |
| fi | |
| # Build Release | |
| cmake ../ext -DCMAKE_BUILD_TYPE=Release | |
| cmake --build . --config Release | |
| mkdir -p ../libs/linux/${{ matrix.arch }}/release | |
| # Check if release library changed before copying | |
| if [ -f "../libs/linux/${{ matrix.arch }}/release/libsokol.so" ]; then | |
| OLD_RELEASE_HASH=$(sha256sum "../libs/linux/${{ matrix.arch }}/release/libsokol.so" | cut -d' ' -f1) | |
| NEW_RELEASE_HASH=$(sha256sum "libsokol.so" | cut -d' ' -f1) | |
| if [ "$OLD_RELEASE_HASH" = "$NEW_RELEASE_HASH" ]; then | |
| echo "Release library unchanged - skipping copy" | |
| else | |
| echo "Release library changed - copying" | |
| cp libsokol.so ../libs/linux/${{ matrix.arch }}/release/ | |
| fi | |
| else | |
| echo "Release library doesn't exist - copying" | |
| cp libsokol.so ../libs/linux/${{ matrix.arch }}/release/ | |
| fi | |
| - name: Upload artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: linux-${{ matrix.arch }} | |
| path: libs/linux/${{ matrix.arch }}/**/* | |
| retention-days: 30 | |
| build-web: | |
| name: Build Web (Emscripten) | |
| runs-on: ubuntu-latest | |
| needs: check-changes | |
| if: needs.check-changes.outputs.should_build == 'true' | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| submodules: recursive | |
| - name: Setup Emscripten | |
| uses: mymindstorm/setup-emsdk@v14 | |
| with: | |
| version: '3.1.34' | |
| - name: Build Debug | |
| run: | | |
| mkdir build-emscripten-debug | |
| cd build-emscripten-debug | |
| emcmake cmake ../ext -DCMAKE_BUILD_TYPE=Debug | |
| cmake --build . | |
| mkdir -p ../libs/emscripten/x86/debug | |
| # Check if debug library changed before copying | |
| if [ -f "../libs/emscripten/x86/debug/sokol.a" ]; then | |
| OLD_DEBUG_HASH=$(sha256sum "../libs/emscripten/x86/debug/sokol.a" | cut -d' ' -f1) | |
| NEW_DEBUG_HASH=$(sha256sum "sokol.a" | cut -d' ' -f1) | |
| if [ "$OLD_DEBUG_HASH" = "$NEW_DEBUG_HASH" ]; then | |
| echo "Debug library unchanged - skipping copy" | |
| else | |
| echo "Debug library changed - copying" | |
| cp sokol.a ../libs/emscripten/x86/debug/ | |
| fi | |
| else | |
| echo "Debug library doesn't exist - copying" | |
| cp sokol.a ../libs/emscripten/x86/debug/ | |
| fi | |
| - name: Build Release | |
| run: | | |
| mkdir build-emscripten-release | |
| cd build-emscripten-release | |
| emcmake cmake ../ext -DCMAKE_BUILD_TYPE=Release | |
| cmake --build . | |
| mkdir -p ../libs/emscripten/x86/release | |
| # Check if release library changed before copying | |
| if [ -f "../libs/emscripten/x86/release/sokol.a" ]; then | |
| OLD_RELEASE_HASH=$(sha256sum "../libs/emscripten/x86/release/sokol.a" | cut -d' ' -f1) | |
| NEW_RELEASE_HASH=$(sha256sum "sokol.a" | cut -d' ' -f1) | |
| if [ "$OLD_RELEASE_HASH" = "$NEW_RELEASE_HASH" ]; then | |
| echo "Release library unchanged - skipping copy" | |
| else | |
| echo "Release library changed - copying" | |
| cp sokol.a ../libs/emscripten/x86/release/ | |
| fi | |
| else | |
| echo "Release library doesn't exist - copying" | |
| cp sokol.a ../libs/emscripten/x86/release/ | |
| fi | |
| - name: Upload artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: emscripten-x86 | |
| path: libs/emscripten/**/* | |
| retention-days: 30 | |
| # Combine all artifacts into a single release | |
| combine-artifacts: | |
| name: Combine All Libraries | |
| needs: [check-changes, generate-bindings, build-windows, build-macos, build-linux, build-web] | |
| runs-on: ubuntu-latest | |
| if: | | |
| always() && | |
| needs.check-changes.outputs.should_build == 'true' && | |
| (needs.build-windows.result == 'success' || needs.build-windows.result == 'skipped') && | |
| (needs.build-macos.result == 'success' || needs.build-macos.result == 'skipped') && | |
| (needs.build-linux.result == 'success' || needs.build-linux.result == 'skipped') && | |
| (needs.build-web.result == 'success' || needs.build-web.result == 'skipped') | |
| steps: | |
| - name: Download all artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| path: libs | |
| - name: Reorganize artifacts | |
| run: | | |
| # Reorganize the downloaded artifacts into proper structure | |
| mkdir -p combined-libs | |
| # Windows | |
| if [ -d "libs/windows-x64" ]; then | |
| mkdir -p combined-libs/windows/x64 | |
| cp -r libs/windows-x64/* combined-libs/windows/x64/ || true | |
| fi | |
| # macOS | |
| if [ -d "libs/macos-arm64" ]; then | |
| mkdir -p combined-libs/macos/arm64 | |
| cp -r libs/macos-arm64/* combined-libs/macos/arm64/ || true | |
| fi | |
| if [ -d "libs/macos-x86_64" ]; then | |
| mkdir -p combined-libs/macos/x86_64 | |
| cp -r libs/macos-x86_64/* combined-libs/macos/x86_64/ || true | |
| fi | |
| # Linux | |
| if [ -d "libs/linux-x86_64" ]; then | |
| mkdir -p combined-libs/linux/x86_64 | |
| cp -r libs/linux-x86_64/* combined-libs/linux/x86_64/ || true | |
| fi | |
| if [ -d "libs/linux-aarch64" ]; then | |
| mkdir -p combined-libs/linux/aarch64 | |
| cp -r libs/linux-aarch64/* combined-libs/linux/aarch64/ || true | |
| fi | |
| # Emscripten | |
| if [ -d "libs/emscripten-x86" ]; then | |
| mkdir -p combined-libs/emscripten | |
| cp -r libs/emscripten-x86/* combined-libs/emscripten/ || true | |
| fi | |
| # Show structure | |
| echo "Combined libraries structure:" | |
| find combined-libs -type f | |
| - name: Upload combined artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: sokol-libraries-all-platforms | |
| path: combined-libs/**/* | |
| retention-days: 90 | |
| - name: Create release archive | |
| if: github.ref == 'refs/heads/main' && github.event_name == 'push' | |
| run: | | |
| cd combined-libs | |
| tar -czf ../sokol-libraries.tar.gz * | |
| cd .. | |
| zip -r sokol-libraries.zip combined-libs/* | |
| - name: Upload release archives | |
| if: github.ref == 'refs/heads/main' && github.event_name == 'push' | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: sokol-libraries-archives | |
| path: | | |
| sokol-libraries.tar.gz | |
| sokol-libraries.zip | |
| retention-days: 90 | |
| - name: Commit libraries to repository | |
| if: github.ref == 'refs/heads/main' && github.event_name == 'push' | |
| run: | | |
| # Checkout the repository (artifacts download doesn't include repo files) | |
| git clone --depth 2 --branch main https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git repo | |
| cd repo | |
| # Configure git | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| # Remove old libraries (if they exist) | |
| rm -rf libs/windows libs/macos libs/linux libs/emscripten | |
| # Ensure libs directory exists | |
| mkdir -p libs | |
| # Copy new libraries | |
| cp -r ../combined-libs/* libs/ | |
| echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" | |
| echo "📦 Updating libraries..." | |
| echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" | |
| # Stage changes | |
| git add libs/ | |
| # Commit and push | |
| git commit -m "Auto-update built libraries [skip ci] | |
| Built from commit: ${{ github.sha }} | |
| Workflow run: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} | |
| Platform sizes: | |
| - Windows x64: $(du -sh libs/windows/x64 | cut -f1) | |
| - macOS arm64: $(du -sh libs/macos/arm64 | cut -f1) | |
| - macOS x86_64: $(du -sh libs/macos/x86_64 | cut -f1) | |
| - Linux x86_64: $(du -sh libs/linux/x86_64 | cut -f1) | |
| - Emscripten: $(du -sh libs/emscripten | cut -f1)" | |
| git push origin main | |
| echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" | |
| echo "✅ Libraries committed and pushed successfully" | |
| echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" |