From 8f2a5374c326eb75491eb2ac28add6a71b5b9b69 Mon Sep 17 00:00:00 2001 From: Steveice10 <1269164+Steveice10@users.noreply.github.com> Date: Wed, 1 Mar 2023 09:58:09 -0800 Subject: [PATCH] ci: Build macOS architectures separately and combine (#6321) * ci: Build macOS for different architectures separately. * ci: Combine macOS builds into universal binary. * ci: Disable uploading final macOS artifacts until ready to resume producing. --- .ci/macos/build.sh | 7 ++++-- .ci/macos/universal.sh | 45 ++++++++++++++++++++++++++++++++++ .github/workflows/ci.yml | 52 +++++++++++++++++++++++++++++++++++++--- 3 files changed, 99 insertions(+), 5 deletions(-) create mode 100755 .ci/macos/universal.sh diff --git a/.ci/macos/build.sh b/.ci/macos/build.sh index 5ce79183d..b6a2bb54a 100755 --- a/.ci/macos/build.sh +++ b/.ci/macos/build.sh @@ -17,7 +17,7 @@ ccache -s mkdir build && cd build # TODO: LibreSSL ASM disabled due to platform detection issues in build. cmake .. -DCMAKE_BUILD_TYPE=Release \ - -DCMAKE_OSX_ARCHITECTURES="x86_64;arm64" \ + -DCMAKE_OSX_ARCHITECTURES="$TARGET_ARCH" \ -DENABLE_QT_TRANSLATION=ON \ -DCITRA_ENABLE_COMPATIBILITY_REPORTING=${ENABLE_COMPATIBILITY_REPORTING:-"OFF"} \ -DENABLE_COMPATIBILITY_LIST_DOWNLOAD=ON \ @@ -30,4 +30,7 @@ ninja ccache -s -ctest -VV -C Release +CURRENT_ARCH=`arch` +if [ "$TARGET_ARCH" = "$CURRENT_ARCH" ]; then + ctest -VV -C Release +fi diff --git a/.ci/macos/universal.sh b/.ci/macos/universal.sh new file mode 100755 index 000000000..062de9541 --- /dev/null +++ b/.ci/macos/universal.sh @@ -0,0 +1,45 @@ +#!/bin/bash -ex + +. .ci/common/pre-upload.sh + +REV_NAME="citra-osx-${GITDATE}-${GITREV}" +ARCHIVE_NAME="${REV_NAME}.tar.gz" +COMPRESSION_FLAGS="-czvf" + +ARTIFACTS_LIST=($ARTIFACTS) + +# Set up the base artifact to combine into. +BASE_ARTIFACT=${ARTIFACTS_LIST[0]} +BASE_ARTIFACT_ARCH="${BASE_ARTIFACT##*-}" +tar xf $BASE_ARTIFACT/$REV_NAME.tar.gz -C $BASE_ARTIFACT +mv $BASE_ARTIFACT/$REV_NAME $REV_NAME + +# Executable binary paths that need to be combined. +BIN_PATHS=(citra citra-room citra-qt.app/Contents/MacOS/citra-qt) + +# Dylib paths that need to be combined. +IFS=$'\n' +DYLIB_PATHS=($(cd $REV_NAME && find . -name '*.dylib')) +unset IFS + +# Combine all of the executable binaries and dylibs. +for OTHER_ARTIFACT in "${ARTIFACTS_LIST[@]:1}"; do + OTHER_ARTIFACT_ARCH="${OTHER_ARTIFACT##*-}" + + tar xf $OTHER_ARTIFACT/$REV_NAME.tar.gz -C $OTHER_ARTIFACT + + for BIN_PATH in "${BIN_PATHS[@]}"; do + lipo -create -output $REV_NAME/$BIN_PATH $REV_NAME/$BIN_PATH $OTHER_ARTIFACT/$REV_NAME/$BIN_PATH + done + + for DYLIB_PATH in "${DYLIB_PATHS[@]}"; do + # Only merge if the libraries do not have conflicting arches, otherwise it will fail. + DYLIB_INFO=`file $REV_NAME/$DYLIB_PATH` + OTHER_DYLIB_INFO=`file $OTHER_ARTIFACT/$REV_NAME/$DYLIB_PATH` + if ! [[ "$DYLIB_INFO" =~ "$OTHER_ARTIFACT_ARCH" ]] && ! [[ "$OTHER_DYLIB_INFO" =~ "$BASE_ARTIFACT_ARCH" ]]; then + lipo -create -output $REV_NAME/$DYLIB_PATH $REV_NAME/$DYLIB_PATH $OTHER_ARTIFACT/$REV_NAME/$DYLIB_PATH + fi + done +done + +. .ci/common/post-upload.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1c29f508c..96f999f8d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -74,6 +74,9 @@ jobs: path: artifacts/ macos: runs-on: macos-latest + strategy: + matrix: + arch: ["x86_64", "arm64"] steps: - uses: actions/checkout@v3 with: @@ -82,9 +85,9 @@ jobs: uses: actions/cache@v3 with: path: ~/Library/Caches/ccache - key: ${{ runner.os }}-macos-${{ github.sha }} + key: ${{ runner.os }}-macos-${{ matrix.arch }}-${{ github.sha }} restore-keys: | - ${{ runner.os }}-macos- + ${{ runner.os }}-macos-${{ matrix.arch }}- - name: Query tag name uses: little-core-labs/get-git-tag@v3.0.2 id: tagName @@ -95,6 +98,49 @@ jobs: env: MACOSX_DEPLOYMENT_TARGET: "10.13" ENABLE_COMPATIBILITY_REPORTING: "ON" + TARGET_ARCH: ${{ matrix.arch }} + - name: Pack + run: ./.ci/macos/upload.sh + - name: Upload + uses: actions/upload-artifact@v3 + with: + name: macos-${{ matrix.arch }} + path: artifacts/ + macos-universal: + runs-on: macos-latest + needs: macos + steps: + - uses: actions/checkout@v3 + with: + submodules: recursive + - name: Query tag name + uses: little-core-labs/get-git-tag@v3.0.2 + id: tagName + - name: Download x86 build + uses: actions/download-artifact@master + with: + name: macos-x86_64 + path: macos-x86_64/ + - name: Download ARM64 build + uses: actions/download-artifact@master + with: + name: macos-arm64 + path: macos-arm64/ + - name: Create universal app + run: ./.ci/macos/universal.sh + env: + ARTIFACTS: macos-x86_64 macos-arm64 +# - name: Upload +# uses: actions/upload-artifact@v3 +# with: +# name: macos +# path: artifacts/ + - name: Delete intermediate artifacts + uses: geekyeggo/delete-artifact@v2 + with: + name: | + macos-x86_64 + macos-arm64 windows: runs-on: windows-latest steps: @@ -178,7 +224,7 @@ jobs: TRANSIFEX_API_TOKEN: ${{ secrets.TRANSIFEX_API_TOKEN }} release: runs-on: ubuntu-latest - needs: [build, android, macos, source, windows] + needs: [build, android, macos-universal, source, windows] if: ${{ startsWith(github.ref, 'refs/tags/') }} steps: - uses: actions/download-artifact@v3