Build CXO2 Client #32
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 CXO2 Client" | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| build_type: | |
| description: 'Build Type' | |
| required: true | |
| default: 'Release' | |
| type: choice | |
| options: | |
| - Debug | |
| - Release | |
| - MinSizeRel | |
| - RelWithDebInfo | |
| windows: | |
| description: Build win32 | |
| required: true | |
| type: boolean | |
| default: true | |
| osx_arm64: | |
| description: Build osx-arm64 | |
| required: true | |
| type: boolean | |
| default: true | |
| osx_x64_86: | |
| description: Build osx-x64_86 | |
| required: true | |
| type: boolean | |
| default: true | |
| linux: | |
| description: Build linux | |
| required: true | |
| type: boolean | |
| default: true | |
| jobs: | |
| compile: | |
| runs-on: ${{ matrix.os }} | |
| if: ${{ inputs.windows || inputs.osx_arm64 || inputs.osx_x64_86 || inputs.linux }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| os: [windows-latest, macos-14, macos-15-intel, ubuntu-latest] | |
| build_type: [ '${{ inputs.build_type }}' ] | |
| include: | |
| - os: windows-latest | |
| enabled: ${{ inputs.windows }} | |
| dist_name: win32 | |
| c_compiler: cl | |
| cpp_compiler: cl | |
| msvc_arch: x86 | |
| cmake_flags: '-G Ninja' | |
| output_dir: /bin/windows/ | |
| - os: macos-14 | |
| enabled: ${{ inputs.osx_arm64 }} | |
| dist_name: osx-arm64 | |
| c_compiler: clang | |
| cpp_compiler: clang++ | |
| cmake_flags: '-DCMAKE_OSX_ARCHITECTURES=arm64 -G Xcode' | |
| output_dir: /bin/osx/arm64/ | |
| - os: macos-15-intel | |
| enabled: ${{ inputs.osx_x64_86 }} | |
| dist_name: osx-x86_64 | |
| c_compiler: clang | |
| cpp_compiler: clang++ | |
| cmake_flags: '-DCMAKE_OSX_ARCHITECTURES=x86_64 -G Xcode' | |
| output_dir: /bin/osx/x86_64/ | |
| - os: ubuntu-latest | |
| enabled: ${{ inputs.linux }} | |
| dist_name: linux-x86_64 | |
| c_compiler: gcc | |
| cpp_compiler: g++ | |
| cmake_flags: '-G Ninja -DICONV_LIB=c' | |
| output_dir: /bin/linux/ | |
| steps: | |
| - name: Checkout repository | |
| if: ${{ matrix.enabled }} | |
| uses: actions/checkout@v7 | |
| with: | |
| submodules: 'true' | |
| - name: Initialize environment | |
| if: ${{ matrix.enabled }} | |
| id: strings | |
| shell: bash | |
| env: | |
| P12_BUILD_CERTIFICATE_BASE64: ${{ secrets.P12_BUILD_CERTIFICATE_BASE64 }} | |
| P12_PASSWORD: ${{ secrets.P12_PASSWORD }} | |
| KEYCHAIN_PASSWORD: ${{ secrets.KEYCHAIN_PASSWORD }} | |
| run: | | |
| if [ "$RUNNER_OS" == "macOS" ] && [ "${{ matrix.build_type }}" == "Release" ]; then | |
| if [ -z "$P12_BUILD_CERTIFICATE_BASE64" ]; then | |
| echo "::error::macOS Release build requires signing credentials (P12_BUILD_CERTIFICATE_BASE64, P12_PASSWORD, KEYCHAIN_PASSWORD)." | |
| exit 1 | |
| fi | |
| # Setup credentials paths | |
| CERTIFICATE_PATH=$RUNNER_TEMP/build_certificate.p12 | |
| KEYCHAIN_PATH=$RUNNER_TEMP/app-signing.keychain-db | |
| # Import certificate from secrets | |
| echo -n "$P12_BUILD_CERTIFICATE_BASE64" | base64 --decode -o $CERTIFICATE_PATH | |
| # Create temporary keychain | |
| security create-keychain -p "$KEYCHAIN_PASSWORD" $KEYCHAIN_PATH | |
| security set-keychain-settings -lut 21600 $KEYCHAIN_PATH | |
| security unlock-keychain -p "$KEYCHAIN_PASSWORD" $KEYCHAIN_PATH | |
| # Import certificate to keychain | |
| security import $CERTIFICATE_PATH -P "$P12_PASSWORD" -A -t cert -f pkcs12 -k $KEYCHAIN_PATH | |
| security set-key-partition-list -S apple-tool:,apple: -k "$KEYCHAIN_PASSWORD" $KEYCHAIN_PATH | |
| security list-keychain -d user -s $KEYCHAIN_PATH | |
| echo "codesign-flags=-DCMAKE_XCODE_ATTRIBUTE_DEVELOPMENT_TEAM=${{ vars.APPLE_TEAM_ID }} -DCMAKE_XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY=${{ vars.APPLE_CODESIGN_IDENTITY }}" >> "$GITHUB_OUTPUT" | |
| elif [ "$RUNNER_OS" == "macOS" ]; then | |
| echo "Non-Release macOS build; skipping code signing (unsigned build)." | |
| echo "codesign-flags=-DCMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED=NO -DCMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED=NO" >> "$GITHUB_OUTPUT" | |
| fi | |
| if [ "$RUNNER_OS" == "Linux" ]; then | |
| sudo apt-get update | |
| sudo apt-get install -y \ | |
| ninja-build \ | |
| libx11-dev \ | |
| libxrandr-dev \ | |
| libxcursor-dev \ | |
| libxi-dev \ | |
| libudev-dev \ | |
| libgl1-mesa-dev \ | |
| libfreetype-dev \ | |
| libharfbuzz-dev \ | |
| libfontconfig1-dev \ | |
| libogg-dev \ | |
| libvorbis-dev \ | |
| libflac-dev \ | |
| libmbedtls-dev \ | |
| libssh2-1-dev | |
| fi | |
| if [ "$RUNNER_OS" == "Windows" ]; then | |
| # Configure msvc arch | |
| VSWHERE="/c/Program Files (x86)/Microsoft Visual Studio/Installer/vswhere.exe" | |
| VS_PATH=$("$VSWHERE" -latest -property installationPath | tr -d '\r') | |
| VCVARS_BAT="$(cygpath -u "$RUNNER_TEMP")/vcvars_dump.bat" | |
| { | |
| echo '@echo off' | |
| echo "call \"$VS_PATH\\VC\\Auxiliary\\Build\\vcvarsall.bat\" ${{ matrix.msvc_arch }} >nul" | |
| echo 'set' | |
| } > "$VCVARS_BAT" | |
| # Diff the environment before/after vcvarsall and export only what it changed. | |
| comm -13 \ | |
| <(cmd.exe //C set | tr -d '\r' | sort) \ | |
| <(cmd.exe //C "$(cygpath -w "$VCVARS_BAT")" | tr -d '\r' | sort) \ | |
| | while IFS='=' read -r name value; do | |
| case "$name" in | |
| ''|*' '*) ;; | |
| Path|PATH) printf '%s\n' "$value" | tr ';' '\n' >> "$GITHUB_PATH" ;; | |
| *) printf '%s=%s\n' "$name" "$value" >> "$GITHUB_ENV" ;; | |
| esac | |
| done | |
| fi | |
| # Strings variables | |
| echo "build-type=${{ matrix.build_type }}" >> "$GITHUB_OUTPUT" | |
| echo "build-type-flag=$(echo '${{ matrix.build_type }}' | tr '[:lower:]' '[:upper:]')" >> "$GITHUB_OUTPUT" | |
| echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT" | |
| echo "binary-output-dir=${{ github.workspace }}${{ matrix.output_dir }}${{ matrix.build_type }}" >> "$GITHUB_OUTPUT" | |
| - name: Cache dependencies | |
| if: ${{ matrix.enabled }} | |
| uses: actions/cache@v6 | |
| with: | |
| path: build/_deps | |
| key: deps-${{ matrix.os }}-${{ matrix.build_type }}-${{ hashFiles('CMakeLists.txt', 'modules/Genode/CMakeLists.txt') }} | |
| restore-keys: | | |
| deps-${{ matrix.os }}-${{ matrix.build_type }}- | |
| deps-${{ matrix.os }}- | |
| - name: Configure project | |
| if: ${{ matrix.enabled }} | |
| run: > | |
| cmake -B ${{ steps.strings.outputs.build-output-dir }} | |
| -DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }} | |
| -DCMAKE_C_COMPILER=${{ matrix.c_compiler }} | |
| -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} | |
| -DCMAKE_ARCHIVE_OUTPUT_DIRECTORY_${{ steps.strings.outputs.build-type-flag }}=${{ steps.strings.outputs.binary-output-dir }} | |
| -S ${{ github.workspace }} | |
| ${{ matrix.cmake_flags }} | |
| ${{ steps.strings.outputs.codesign-flags }} | |
| - name: Build resource compiler | |
| if: ${{ matrix.enabled }} | |
| run: > | |
| cmake --build ${{ steps.strings.outputs.build-output-dir }} | |
| --config ${{ matrix.build_type }} | |
| --target ResourceCompiler | |
| - name: Generate embedded resources | |
| if: ${{ matrix.enabled }} | |
| shell: bash | |
| working-directory: ${{ github.workspace }} | |
| run: ./bin/compiler/${{ matrix.build_type }}/ResourceCompiler | |
| - name: Build project | |
| if: ${{ matrix.enabled }} | |
| run: > | |
| cmake --build ${{ steps.strings.outputs.build-output-dir }} | |
| --config ${{ matrix.build_type }} | |
| --target CXO2 | |
| - name: Build assets | |
| if: ${{ matrix.enabled }} | |
| shell: bash | |
| run: | | |
| dist="${{ steps.strings.outputs.binary-output-dir }}" | |
| bundled=0 | |
| if [ -d assets/Avatar ]; then | |
| mkdir -p "$dist/Image" && cp -r assets/Avatar "$dist/Image/" && bundled=1 | |
| fi | |
| if [ -d assets/Interface ]; then | |
| mkdir -p "$dist/Image" && cp -r assets/Interface "$dist/Image/" && bundled=1 | |
| fi | |
| if [ -d assets/Music ]; then | |
| cp -r assets/Music "$dist/" && bundled=1 | |
| fi | |
| if [ "$bundled" -eq 0 ]; then | |
| echo "No assets found; packaging executable only." | |
| fi | |
| - name: Upload artifact | |
| if: ${{ matrix.enabled }} | |
| uses: actions/upload-artifact@v7 | |
| with: | |
| # Note that actions/upload-artifact will not preserve executable or any other permissions. | |
| # See https://github.com/actions/upload-artifact?tab=readme-ov-file#permission-loss | |
| name: CXO2-${{ matrix.dist_name }} | |
| path: | | |
| ${{ steps.strings.outputs.binary-output-dir }} | |
| !${{ steps.strings.outputs.binary-output-dir }}/**/*.lib | |
| !${{ steps.strings.outputs.binary-output-dir }}/**/*.a |