From a66b49acd854938751b6a1d123ebbb38f61ed786 Mon Sep 17 00:00:00 2001 From: Silvio Tomatis Date: Mon, 9 Dec 2024 12:38:39 +0100 Subject: [PATCH] Add mac os build CI job --- .github/workflows/build.yml | 194 ++++++++++++++++++++++++++++++++++-- 1 file changed, 188 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index fa3c7c2..b304370 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -36,9 +36,191 @@ jobs: cache-key: flatpak-builder-${{ github.sha }} arch: ${{ matrix.arch }} -# The above job will build the application as a flatpack and -# publish it as an artifact. To test it locally you can download -# the zip artifact, extract it, install the flatpack and run it. -# unzip aardvark-x86_64.zip -# flatpak --user install aardvark.flatpak -# flatpak run org.p2panda.aardvark \ No newline at end of file + # The above job will build the application as a flatpack and + # publish it as an artifact. To test it locally you can download + # the zip artifact, extract it, install the flatpack and run it. + # unzip aardvark-x86_64.zip + # flatpak --user install aardvark.flatpak + # flatpak run org.p2panda.aardvark + + macos: + name: "macOS" + runs-on: macos-latest + strategy: + fail-fast: false + matrix: + include: + - target: x86_64-apple-darwin + arch: x86_64 + - target: aarch64-apple-darwin + arch: arm64 + steps: + - uses: actions/checkout@v4 + - uses: moonrepo/setup-rust@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + # Cache Homebrew packages + - uses: actions/cache@v4 + with: + path: | + ~/Library/Caches/Homebrew + /usr/local/Homebrew + /opt/homebrew + key: ${{ runner.os }}-${{ matrix.arch }}-brew-${{ hashFiles('.github/workflows/build.yml') }} + restore-keys: | + ${{ runner.os }}-${{ matrix.arch }}-brew- + + - name: Setup x86_64 Homebrew + if: matrix.arch == 'x86_64' + run: | + HOMEBREW_PREFIX="/usr/local" + sudo mkdir -p /usr/local + sudo chown -R $(whoami) /usr/local + arch -x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" + eval "$(/usr/local/bin/brew shellenv)" + echo "PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:/usr/local/opt/pango/lib/pkgconfig:/usr/local/opt/cairo/lib/pkgconfig:/usr/local/opt/gdk-pixbuf/lib/pkgconfig:/usr/local/opt/graphene/lib/pkgconfig:/usr/local/opt/libffi/lib/pkgconfig:/usr/local/opt/gtk4/lib/pkgconfig:/usr/local/opt/libadwaita/lib/pkgconfig" >> $GITHUB_ENV + + - name: Install pkg-config (x86_64) + if: matrix.arch == 'x86_64' + run: arch -x86_64 /usr/local/bin/brew install pkg-config || echo ERROR + + - name: Install GDK-Pixbuf (x86_64) + if: matrix.arch == 'x86_64' + run: arch -x86_64 /usr/local/bin/brew install gdk-pixbuf || echo ERROR + + - name: Install Cairo (x86_64) + if: matrix.arch == 'x86_64' + run: arch -x86_64 /usr/local/bin/brew install cairo || echo ERROR + + - name: Install Pango (x86_64) + if: matrix.arch == 'x86_64' + run: arch -x86_64 /usr/local/bin/brew install pango || echo ERROR + + - name: Install AT-SPI2-Core (x86_64) + if: matrix.arch == 'x86_64' + run: arch -x86_64 /usr/local/bin/brew install at-spi2-core || echo ERROR + + - name: Install Graphene (x86_64) + if: matrix.arch == 'x86_64' + run: arch -x86_64 /usr/local/bin/brew install graphene || echo ERROR + + - name: Install GTK4 (x86_64) + if: matrix.arch == 'x86_64' + run: arch -x86_64 /usr/local/bin/brew install gtk4 || echo ERROR + + - name: Install Libadwaita (x86_64) + if: matrix.arch == 'x86_64' + run: arch -x86_64 /usr/local/bin/brew install -v libadwaita + + - name: Install dylibbundler (x86_64) + if: matrix.arch == 'x86_64' + run: arch -x86_64 /usr/local/bin/brew install -v dylibbundler + + - name: Install dylibbundler ARM64 + if: matrix.arch == 'arm64' + run: brew install -v dylibbundler + + - name: Verify and link x86_64 packages + if: matrix.arch == 'x86_64' + run: | + # Verify installations + arch -x86_64 /usr/local/bin/brew list pango + arch -x86_64 /usr/local/bin/brew list cairo + arch -x86_64 /usr/local/bin/brew list gdk-pixbuf + arch -x86_64 /usr/local/bin/brew list gtk4 + arch -x86_64 /usr/local/bin/brew list libadwaita + + # Link packages individually with error handling + for package in pango cairo gdk-pixbuf gtk4 libadwaita; do + arch -x86_64 /usr/local/bin/brew link --force $package || true + done + + - name: Install ARM64 dependencies + if: matrix.arch == 'arm64' + run: | + brew install pkg-config gtk4 pango cairo gdk-pixbuf at-spi2-core graphene libadwaita || true + brew upgrade pkg-config gtk4 pango cairo gdk-pixbuf at-spi2-core graphene libadwaita || true + + - name: Finalize ARM64 setup + if: matrix.arch == 'arm64' + run: | + echo "PKG_CONFIG_PATH=/opt/homebrew/lib/pkgconfig" >> $GITHUB_ENV + echo "PKG_CONFIG_ALLOW_CROSS=1" >> $GITHUB_ENV + - name: Add target ${{ matrix.target }} + run: rustup target add ${{ matrix.target }} + - name: Build + env: + PKG_CONFIG_ALLOW_CROSS: "1" + CFLAGS: "-I/usr/local/include -I/usr/local/include/gtk-4.0 -I/usr/local/include/glib-2.0 -I/usr/local/lib/glib-2.0/include" + LDFLAGS: "-L/usr/local/lib -framework Cocoa -framework Security" + MACOSX_DEPLOYMENT_TARGET: "10.15" + PKG_CONFIG_SYSROOT_DIR: "" + PKG_CONFIG_PATH: "${{ env.PKG_CONFIG_PATH }}" + run: cargo build --release --target ${{ matrix.target }} + - name: Install glib-compile-resources + if: matrix.arch == 'x86_64' + run: arch -x86_64 /usr/local/bin/brew install glib || echo ERROR + + - name: Install glib-compile-resources ARM64 + if: matrix.arch == 'arm64' + run: brew install glib || echo ERROR + + - name: Compile GResource + run: | + mkdir -p target/${{ matrix.target }}/release/ + glib-compile-resources --sourcedir src --target target/${{ matrix.target }}/release/aardvark.gresource src/aardvark.gresource.xml + + - name: Create App Bundle + run: | + mkdir -p Aardvark.app/Contents/{MacOS,Resources}/share/aardvark + cp target/${{ matrix.target }}/release/aardvark Aardvark.app/Contents/MacOS/ + cp target/${{ matrix.target }}/release/aardvark.gresource Aardvark.app/Contents/Resources/share/aardvark/ + + # Create Info.plist + cat > Aardvark.app/Contents/Info.plist << EOF + + + + + CFBundleExecutable + aardvark + CFBundleIdentifier + org.p2panda.aardvark + CFBundleName + Aardvark + CFBundlePackageType + APPL + CFBundleShortVersionString + 0.1.0 + LSMinimumSystemVersion + 10.15 + CFBundleSupportedPlatforms + + MacOSX + + + + EOF + + # Bundle dependencies + - name: Bundle dependencies + run: | + dylibbundler -od -b -x Aardvark.app/Contents/MacOS/aardvark \ + -d Aardvark.app/Contents/Frameworks/ \ + -p @executable_path/../Frameworks/ + # Create DMG + - name: Create DMG + run: hdiutil create -volname "Aardvark" -srcfolder Aardvark.app -ov -format UDZO aardvark-${{ matrix.arch }}.dmg + - name: Upload Artifact + uses: actions/upload-artifact@v3 + with: + name: aardvark-macos-${{ matrix.arch }} + path: aardvark-${{ matrix.arch }}.dmg + - name: Smoke test the artifact + env: + RUST_BACKTRACE: "full" + RUST_LOG: "debug" + G_MESSAGES_DEBUG: "all" + run: ./Aardvark.app/Contents/MacOS/aardvark + continue-on-error: true # Not currently working because of gresources