Skip to content

Commit

Permalink
Merge pull request #671 from twvd/universal
Browse files Browse the repository at this point in the history
Add MacOS ARM64 and Universal builds to GitHub Actions
  • Loading branch information
wheremyfoodat authored Dec 8, 2024
2 parents da90749 + 1c9af52 commit 4af4780
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 24 deletions.
52 changes: 44 additions & 8 deletions .github/workflows/MacOS_Build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ env:

jobs:
build:
# The CMake configure and build commands are platform agnostic and should work equally
# well on Windows or Mac. You can convert this to a matrix build if you need
# cross-platform coverage.
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
strategy:
matrix:
arch: [x86_64, arm64]

name: MacOS-${{ matrix.arch }}
runs-on: macos-13

steps:
Expand All @@ -33,7 +34,7 @@ jobs:
- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DENABLE_USER_BUILD=ON
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DENABLE_USER_BUILD=ON -DCMAKE_OSX_ARCHITECTURES=${{ matrix.arch }}

- name: Build
# Build your program with the given configuration
Expand All @@ -49,10 +50,45 @@ jobs:
run: codesign --force -s - -vvvv Alber.app

- name: Zip it up
run: zip -r Alber Alber.app
run: zip -r Alber-${{ matrix.arch }} Alber.app

- name: Upload MacOS App
uses: actions/upload-artifact@v4
with:
name: MacOS Alber App Bundle
path: 'Alber.zip'
name: MacOS Alber App Bundle (${{ matrix.arch }})
path: Alber-${{ matrix.arch }}.zip

MacOS-Universal:
name: MacOS-Universal
needs: [build]
runs-on: macos-13

steps:
- name: Download x86_64
uses: actions/download-artifact@v4
with:
name: MacOS Alber App Bundle (x86_64)
path: x86_64
- name: Download ARM64
uses: actions/download-artifact@v4
with:
name: MacOS Alber App Bundle (arm64)
path: arm64
- name: Combine app bundles
shell: bash
run: |
set -x
unzip x86_64/*.zip -d x86_64
unzip arm64/*.zip -d arm64
lipo {x86_64,arm64}/Alber.app/Contents/MacOS/Alber -create -output Alber
cp -v -a arm64/Alber.app Alber.app
cp -v Alber Alber.app/Contents/MacOS/Alber
# Mix in x86_64 files that do not appear in the ARM64 build (e.g. libvulkan)
cp -v -R -n x86_64/Alber.app/* Alber.app/ || true
codesign --force -s - -vvvv Alber.app
zip -r -y Alber-universal.zip Alber.app
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: MacOS Alber App Bundle (universal)
path: Alber-universal.zip
58 changes: 52 additions & 6 deletions .github/workflows/Qt_Build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ jobs:
path: upload

MacOS:
strategy:
matrix:
arch: [x86_64, arm64]

name: MacOS-${{ matrix.arch }}
runs-on: macos-13

steps:
Expand All @@ -69,11 +74,17 @@ jobs:
run: |
brew install dylibbundler imagemagick
- name: Install qt
run: brew install qt && which macdeployqt
- name: Install Qt
uses: jurplel/install-qt-action@v3
with:
aqtversion: '==3.1.*'
version: '6.8.1'
host: 'mac'
target: 'desktop'
arch: 'clang_64'

- name: Configure CMake
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DENABLE_USER_BUILD=ON -DENABLE_QT_GUI=ON
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DENABLE_USER_BUILD=ON -DENABLE_QT_GUI=ON -DCMAKE_OSX_ARCHITECTURES=${{ matrix.arch }}

- name: Build
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
Expand All @@ -87,13 +98,48 @@ jobs:
run: codesign --force -s - -vvvv Alber.app

- name: Zip it up
run: zip -r Alber Alber.app
run: zip -r Alber-${{ matrix.arch }} Alber.app

- name: Upload MacOS App
uses: actions/upload-artifact@v4
with:
name: MacOS Alber App Bundle
path: 'Alber.zip'
name: MacOS Alber App Bundle (${{ matrix.arch }})
path: Alber-${{ matrix.arch }}.zip

MacOS-Universal:
name: MacOS-Universal
needs: [MacOS]
runs-on: macos-13

steps:
- name: Download x86_64
uses: actions/download-artifact@v4
with:
name: MacOS Alber App Bundle (x86_64)
path: x86_64
- name: Download ARM64
uses: actions/download-artifact@v4
with:
name: MacOS Alber App Bundle (arm64)
path: arm64
- name: Combine app bundles
shell: bash
run: |
set -x
unzip x86_64/*.zip -d x86_64
unzip arm64/*.zip -d arm64
lipo {x86_64,arm64}/Alber.app/Contents/MacOS/Alber -create -output Alber
cp -v -a arm64/Alber.app Alber.app
cp -v Alber Alber.app/Contents/MacOS/Alber
# Mix in x86_64 files that do not appear in the ARM64 build (e.g. libvulkan)
cp -v -R -n x86_64/Alber.app/* Alber.app/ || true
codesign --force -s - -vvvv Alber.app
zip -r -y Alber-universal.zip Alber.app
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: MacOS Alber App Bundle (universal)
path: Alber-universal.zip

Linux:
runs-on: ubuntu-24.04
Expand Down
43 changes: 34 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -217,26 +217,51 @@ if(ENABLE_LUAJIT)
target_link_libraries(AlberCore PRIVATE libluajit)
endif()

# Check for x64
if (CMAKE_SYSTEM_PROCESSOR STREQUAL "AMD64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "x86-64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
# Detect target architecture
if (NOT APPLE OR "${CMAKE_OSX_ARCHITECTURES}" STREQUAL "")
# Normal target detection
if (CMAKE_SYSTEM_PROCESSOR STREQUAL "AMD64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "x86-64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
set(HOST_X64 TRUE)
else()
set(HOST_X64 FALSE)
endif()

if (CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64")
set(HOST_ARM64 TRUE)
else()
set(HOST_ARM64 FALSE)
endif()
else()
# Apple target detection
if("x86_64" IN_LIST CMAKE_OSX_ARCHITECTURES)
set(HOST_X64 TRUE)
else()
set(HOST_X64 FALSE)
endif()

if("arm64" IN_LIST CMAKE_OSX_ARCHITECTURES)
set(HOST_ARM64 TRUE)
else()
set(HOST_ARM64 FALSE)
endif()

if (HOST_ARM64 AND HOST_X64)
message(FATAL_ERROR "Universal builds not supported like this! Please compile separately and stitch together")
endif()
endif()

if (HOST_X64)
add_subdirectory(third_party/xbyak) # Add xbyak submodule for x86 JITs
include_directories(third_party/xbyak)
add_compile_definitions(PANDA3DS_DYNAPICA_SUPPORTED)
add_compile_definitions(PANDA3DS_X64_HOST)
else()
set(HOST_X64 FALSE)
endif()

# Check for arm64
if (CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64")
set(HOST_ARM64 TRUE)
if (HOST_ARM64)
add_subdirectory(third_party/oaknut) # Add Oaknut submodule for arm64 JITs
include_directories(third_party/oaknut/include)
add_compile_definitions(PANDA3DS_DYNAPICA_SUPPORTED)
add_compile_definitions(PANDA3DS_ARM64_HOST)
else()
set(HOST_ARM64 FALSE)
endif()

# Enable SSE4.1 if it's not explicitly disabled
Expand Down
2 changes: 1 addition & 1 deletion third_party/LuaJIT
Submodule LuaJIT updated 2 files
+3 −0 README.md
+3 −0 src/CMakeLists.txt

0 comments on commit 4af4780

Please sign in to comment.