name: MacOS Build Steps on: workflow_call: inputs: jobName: required: true type: string artifactPrefixName: required: true type: string os: required: false type: string default: macos-26 arch: required: false type: string default: x86-64 patchesUrl: required: false type: string default: https://github.com/PCSX2/pcsx2_patches/releases/latest/download fetchTags: required: false type: boolean default: false stableBuild: required: false type: boolean default: false sign_and_notarize: required: false type: boolean default: false jobs: build_macos: name: ${{ inputs.jobName }} runs-on: ${{ inputs.os }} # Set some sort of timeout in the event of run-away builds. We are limited on concurrent jobs so, get rid of them. timeout-minutes: 120 env: POWERSHELL_TELEMETRY_OPTOUT: 1 CCACHE_BASEDIR: ${{ github.workspace }} CCACHE_DIR: ${{ github.workspace }}/.ccache CCACHE_COMPRESS: true CCACHE_COMPRESSLEVEL: 9 CCACHE_MAXSIZE: 100M # Only way to use a secret in an if statement SIGN_KEY: ${{ secrets.APPLE_SIGN_P12_B64 }} steps: - name: Checkout Repository uses: actions/checkout@v7 # actions/checkout elides tags, fetch them primarily for releases - name: Fetch Tags if: ${{ inputs.fetchTags }} run: git fetch --tags --no-recurse-submodules - name: Add stable release identifier file if: ${{ inputs.stableBuild == true || inputs.stableBuild == 'true' }} shell: bash run: | echo "#define DEFAULT_UPDATER_CHANNEL \"stable\"" > ./pcsx2-qt/DefaultUpdaterChannel.h cat ./pcsx2-qt/DefaultUpdaterChannel.h - name: Use Xcode 26.2 run: sudo xcode-select -s /Applications/Xcode_26.2.app - name: Install Metal Toolchain run: | for i in {1..5}; do if xcrun metal -v; then break; fi xcodebuild -downloadComponent MetalToolchain done - name: Prepare Artifact Metadata id: artifact-metadata shell: bash env: PREFIX: ${{ inputs.artifactPrefixName }} EVENT_NAME: ${{ github.event_name }} PR_TITLE: ${{ github.event.pull_request.title }} PR_NUM: ${{ github.event.pull_request.number }} PR_SHA: ${{ github.event.pull_request.head.sha }} run: ./.github/workflows/scripts/common/name-artifacts.sh - name: Install Packages env: HOMEBREW_NO_INSTALL_CLEANUP: 1 HOMEBREW_NO_ANALYTICS: 1 run: | if ! brew install ccache nasm; then brew update brew install ccache nasm fi - name: Cache Dependencies id: cache-deps uses: actions/cache@v6 with: path: ~/deps key: ${{ inputs.os }} ${{ inputs.arch }} deps ${{ hashFiles('.github/workflows/scripts/macos/*', '.github/workflows/scripts/common/*.patch') }} - name: Build Dependencies if: steps.cache-deps.outputs.cache-hit != 'true' run: | .github/workflows/scripts/macos/build-dependencies${{ case(inputs.arch == 'x86-64', '', '-universal') }}.sh "$HOME/deps" - name: Download patches run: | cd bin/resources aria2c -Z "${{ inputs.patchesUrl }}/patches.zip" # -- SETUP CCACHE - https://cristianadam.eu/20200113/speeding-up-c-plus-plus-github-actions-using-ccache/ - name: Prepare ccache timestamp id: ccache_cache_timestamp run: echo "timestamp=$(date -u "+%Y-%m-%d-%H;%M;%S")" >> $GITHUB_OUTPUT - name: Cache ccache cache uses: actions/cache@v6 with: path: .ccache key: ${{ inputs.os }} ${{ inputs.arch }} ccache ${{ steps.ccache_cache_timestamp.outputs.timestamp }} restore-keys: ${{ inputs.os }} ${{ inputs.arch }} ccache - name: Generate CMake Files run: | cmake -DCMAKE_PREFIX_PATH="$HOME/deps" \ -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_OSX_ARCHITECTURES="${{ case(inputs.arch == 'x86-64', 'x86_64', inputs.arch) }}" \ -DDISABLE_ADVANCE_SIMD=ON \ -DCMAKE_INTERPROCEDURAL_OPTIMIZATION=${{ case(inputs.arch == 'x86-64', 'ON', 'OFF') }} \ -DUSE_LINKED_FFMPEG=ON \ -DCMAKE_C_COMPILER_LAUNCHER=ccache \ -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ -DCMAKE_DISABLE_PRECOMPILE_HEADERS=ON \ -B build . - name: Build PCSX2 working-directory: build run: | ccache -p ccache -s ccache -z make -j$(getconf _NPROCESSORS_ONLN) # macOS doesn't use make install ccache -s # Ensure there's no global constructors in multi-isa files for dir in */CMakeFiles/GS-{avx,avx2}.dir; do if find "$dir" -name "*.o" | xargs nm | grep _GLOBAL_; then echo "::error::Multi-isa files must not have global constructors!" exit 1 fi done - name: Build GSRunner if: inputs.arch != 'x86-64' working-directory: build run: make -j$(getconf _NPROCESSORS_ONLN) pcsx2-gsrunner - name: Run Tests working-directory: build run: make -j$(getconf _NPROCESSORS_ONLN) unittests - name: Clean Caches run: | ccache -s ccache --evict-older-than 1d ccache -s - name: Prepare Build Artifacts run: | mv build/pcsx2*/PCSX2.app PCSX2.app - name: Pull the Signing Keys and Notarization Credentials if: ${{ inputs.sign_and_notarize == true && env.SIGN_KEY }} run: | echo "${{ secrets.APPLE_SIGN_P12_B64 }}" | base64 -d > cert.p12 echo "${{ secrets.APPLE_APPSTORECONNECT_CFG }}" | base64 -d > key.json - name: Sign the Application if: ${{ inputs.sign_and_notarize == true && env.SIGN_KEY }} uses: indygreg/apple-code-sign-action@5e7a4a01fe4dffe948ef3bcf1f4538d963cb0c72 with: input_path: 'PCSX2.app' p12_file: cert.p12 p12_password: "${{ secrets.APPLE_SIGN_P12_PASS }}" sign_args: | --for-notarization --code-signature-flags=runtime --entitlements-xml-file=pcsx2/Resources/PCSX2.entitlements notarize: true # max_wait_seconds is only present on my fork located at F0bes/apple-code-sign-action@demo4 # If we are timing out we should switch to the newest upstream (if I get it upstreamed) # or use my fork. # max_wait_seconds: '2000' staple: true # Generated using rcodesign # Despite what the docs say, I found that this file is required and I had 0 luck # passing the issuer id, key, etc through arguments. app_store_connect_api_key_json_file: 'key.json' - name: Zip Build Artifacts if: inputs.arch == 'x86-64' run: | TAG="$(git tag --points-at HEAD)" if [ -z "$TAG" ]; then APPNAME="${{ steps.artifact-metadata.outputs.artifact-name }}" else APPNAME="PCSX2-$TAG" fi mv PCSX2.app "$APPNAME.app" tar --options xz:compression-level=9 -cvJf "${{ steps.artifact-metadata.outputs.artifact-name }}.tar.xz" "$APPNAME.app" mkdir ci-artifacts cp "${{ steps.artifact-metadata.outputs.artifact-name }}.tar.xz" ci-artifacts/macOS.tar.xz - name: Upload Artifact if: inputs.arch == 'x86-64' uses: actions/upload-artifact@v7 with: name: ${{ steps.artifact-metadata.outputs.artifact-name }} path: "*.tar.xz"