Skip to content

Commit

Permalink
Build for Apple Silicon (#1743)
Browse files Browse the repository at this point in the history
Co-authored-by: Spitz <noella.spitz@ndw2544mac.isis.cclrc.ac.uk>
Co-authored-by: Adam Washington <adam.washington@stfc.ac.uk>
Co-authored-by: Tristan Youngs <tristan.youngs@stfc.ac.uk>
  • Loading branch information
4 people committed Jan 26, 2024
1 parent 4e67ebe commit 3add928
Show file tree
Hide file tree
Showing 12 changed files with 353 additions and 26 deletions.
12 changes: 9 additions & 3 deletions .github/workflows/build/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,15 @@ runs:
target: ${{ inputs.target }}
cacheOnly: ${{ inputs.cacheOnly }}

- name: Build (OSX)
if: runner.os == 'MacOS'
uses: "./.github/workflows/build/osx"
- name: Build (OSX) Intel
if: runner.os == 'MacOS' && env.OSX_CMAKE_TARGET == 'x86_64'
uses: "./.github/workflows/build/osx-intel"
with:
cacheOnly: ${{ inputs.cacheOnly }}

- name: Build (OSX) Silicon
if: runner.os == 'MacOS' && env.OSX_CMAKE_TARGET == 'arm64'
uses: "./.github/workflows/build/osx-silicon"
with:
cacheOnly: ${{ inputs.cacheOnly }}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ runs:
python-version: ${{ env.pythonVersion }}

- name: Install Homebrew Dependencies for Intel
if: ${{ inputs.cacheOnly == 'false' && env.OSX_CMAKE_TARGET == 'x86_64' }}
if: ${{ inputs.cacheOnly == 'false' }}
shell: bash
run: |
Expand Down Expand Up @@ -60,7 +60,7 @@ runs:
id: cache-conan
uses: actions/cache@v3
with:
key: osx-conan-${{ env.conanHash }}
key: osx-intel-conan-${{ env.conanHash }}
path: |
~/.conan
~/.conancache
Expand Down
132 changes: 132 additions & 0 deletions .github/workflows/build/osx-silicon/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
name: Build
description: Build on OSX

inputs:
threading:
default: true
antlrVersion:
default: "4.13.1"
ftglVersion:
default: "2.1.3-rc5"
extraCMakeFlags:
default: ""
cacheOnly:
type: boolean
default: false

runs:
using: "composite"
steps:

#
# Setup / Install Dependencies
#

- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: ${{ env.pythonVersion }}

- name: Install Homebrew Dependencies
if: ${{ inputs.cacheOnly }}
shell: bash
run: |
set -ex
brew update-reset
brew install ninja
PACKAGES=(libpng freetype ftgl antlr)
for PACKAGE in "${PACKAGES[@]}"
do
brew fetch --force --bottle-tag=arm64_monterey $PACKAGE
brew install $(brew --cache --bottle-tag=arm64_monterey $PACKAGE)
done
- name: Install Python Dependencies
shell: bash
run: |
pip3 install --user aqtinstall conan==1.58.0
- name: Retrieve Qt Cache
id: cache-qt
uses: actions/cache@v3
with:
key: osx-qt-${{ env.qtVersion }}
path: ${{ runner.temp }}/qt

- name: Install Qt
if: ${{ steps.cache-qt.outputs.cache-hit != 'true' }}
shell: bash
run: |
export PATH="$(python3 -m site --user-base)/bin:$PATH"
aqt install-qt --outputdir ${{ runner.temp }}/qt mac desktop ${{ env.qtVersion }}
#
# Main Build
#

- name: Install Conan Dependencies
shell: bash
run: |
set -ex
# Setup paths
export PATH="$(python3 -m site --user-base)/bin:$PATH"
mkdir build && cd build
conan config set storage.download_cache="${GITHUB_WORKSPACE}/.conancache"
conan install .. --build missing -s arch=armv8
- name: Build
if: ${{ inputs.cacheOnly == 'false' }}
shell: bash
run: |
set -ex
# Setup paths
# Must specify correct arm64 libs
export PATH="$(python3 -m site --user-base)/bin:$PATH"
Qt6_DIR=${{ runner.temp }}/qt/${{ env.qtVersion }}/macos/lib/cmake/Qt6
QT_BASE_DIR=${{ runner.temp }}/qt/${{ env.qtVersion }}/macos
ANTLR_EXE=$(brew --prefix antlr)/antlr-${{ inputs.antlrVersion }}-complete.jar
FTGL_INCLUDE_DIRS=$(brew --prefix ftgl)/include/
FTGL_LIBRARIES=$(brew --prefix ftgl)/lib/libftgl.2.dylib
CMAKE_PARAMS=(
-DGUI:bool=true
-DMULTI_THREADING:bool=${{ inputs.threading }}
-DJava_JAVA_EXECUTABLE:path=$JAVA_HOME_21_X64/bin/java
-DANTLR_EXECUTABLE:string=$ANTLR_EXE
-DFTGL_INCLUDE_DIRS:path=$FTGL_INCLUDE_DIRS
-DFTGL_LIBRARIES:path=$FTGL_LIBRARIES
-DCMAKE_OSX_ARCHITECTURES:string="arm64"
-DQT_BASE_DIR=$QT_BASE_DIR
)
echo "Detected ANTLR exe as [$ANTLR_EXE]"
echo "JAVA HOME: $JAVA_HOME_21_X64"
# Build
cd build
cmake -G Ninja "${CMAKE_PARAMS[@]}" ${{ inputs.extraCMakeFlags }} ../
cmake --build . --config Release
cd ../
# Deploy Conan dependencies for ease
mkdir deploy && cd deploy
conan install .. -g deploy -s arch=armv8
# Copy over ftgl so it can be shipped with the bundle
mkdir ftgl
cp $(brew --prefix ftgl)/lib/libftgl.2.dylib ftgl
cp $(brew --prefix ftgl)/lib/libftgl.2.1.3.dylib ftgl
- name: Upload Raw Build Artifacts
if: ${{ inputs.cacheOnly == 'false' }}
uses: actions/upload-artifact@v3
with:
name: osx-build-artifacts-silicon
path: |
${{ github.workspace }}/build
${{ github.workspace }}/deploy
retention-days: 1
6 changes: 6 additions & 0 deletions .github/workflows/continuous.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ jobs:
fail-fast: false
matrix:
include:
- os: macos-latest
osx_cmake_target: arm64
osx_conan_target: armv8
- os: macos-latest
osx_cmake_target: x86_64
osx_conan_target: x86_64
Expand Down Expand Up @@ -77,6 +80,9 @@ jobs:
fail-fast: false
matrix:
include:
- os: macos-latest
osx_cmake_target: arm64
osx_conan_target: armv8
- os: macos-latest
osx_cmake_target: x86_64
osx_conan_target: x86_64
Expand Down
10 changes: 7 additions & 3 deletions .github/workflows/package/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ runs:
using: "composite"
steps:

- name: Package (OSX)
if: runner.os == 'MacOS'
uses: "./.github/workflows/package/osx"
- name: Package (OSX) Intel
if: runner.os == 'MacOS' && env.OSX_CMAKE_TARGET == 'x86_64'
uses: "./.github/workflows/package/osx-intel"

- name: Package (OSX) Silicon
if: runner.os == 'MacOS' && env.OSX_CMAKE_TARGET == 'arm64'
uses: "./.github/workflows/package/osx-silicon"

- name: Package (Windows)
if: runner.os == 'Windows'
Expand Down
77 changes: 77 additions & 0 deletions .github/workflows/package/osx-intel/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: Package
description: Package OSX artifacts

runs:
using: "composite"
steps:

- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: ${{ env.pythonVersion }}

- name: Retrieve Qt Cache
uses: actions/cache@v3
with:
key: osx-qt-${{ env.qtVersion }}
path: ${{ runner.temp }}/qt

- name: Download Raw Build Artifacts
uses: actions/download-artifact@v3
with:
name: osx-build-artifacts
path: ${{ github.workspace }}

- name: Install Python Dependencies
shell: bash
run: |
pip3 install --user dmgbuild biplist
- name: Install Custom Dependencies
shell: bash
run: |
set -ex
wget https://raw.githubusercontent.com/disorderedmaterials/scripts/master/prep-dmg
chmod u+x ./prep-dmg
- name: Prepare DMG Dirs
shell: bash
run: |
set -ex
Qt6_ROOT=${{ runner.temp }}/qt/${{ env.qtVersion }}/macos/
export PATH="$(python3 -m site --user-base)/bin:$PATH"
# Handle ANTLR & TBB
cp ./deploy/antlr4-cppruntime/lib/libantlr4-runtime.*.dylib /usr/local/lib
cp ./deploy/antlr4-cppruntime/lib/libantlr4-runtime.dylib /usr/local/lib/libantlr4-runtime.dylib
for FILE in ./deploy/onetbb/lib/*.dylib; do
FILENAME=$(basename $FILE)
cp ./deploy/onetbb/lib/$FILENAME /usr/local/lib/$FILENAME
done
install_name_tool -add_rpath "@executable_path/../Frameworks/" build/bin/dissolve-gui.app/Contents/MacOS/dissolve-gui
install_name_tool -add_rpath "/usr/local/lib" build/bin/dissolve-gui.app/Contents/MacOS/dissolve-gui
./prep-dmg -a Dissolve-GUI -v ${{ env.dissolveVersion }} -b build/bin/dissolve-gui.app/Contents/MacOS/dissolve-gui -d ${Qt6_ROOT} -i icon/icon-1024x1024.png -p build/bin/dissolve-gui.app/Contents/Info.plist -L /usr/local/lib
- name: Create Disk Image
shell: bash
run: |
set -ex
export PATH="$(python3 -m site --user-base)/bin:$PATH"
# Fix icon link
sed -i -e "s/Dissolve.icns/Dissolve-GUI.icns/g" Dissolve-GUI-${dissolveVersion}/Dissolve-GUI.app/Contents/Info.plist
# Create DMG
dmgbuild -s ci/osx/dmgbuild-settings.py -D app=./Dissolve-GUI-${dissolveVersion}/Dissolve-GUI.app -D icon=./Dissolve-GUI-${dissolveVersion}/Dissolve-GUI.app/Contents/Resources/Dissolve-GUI.icns "Dissolve GUI" Dissolve-GUI-${dissolveVersion}.dmg
# Collect artifacts
mkdir packages
mv Dissolve-GUI-${dissolveVersion}.dmg packages/
- name: Upload Package Artifacts
uses: actions/upload-artifact@v3
with:
name: packages
path: ${{ github.workspace }}/packages
83 changes: 83 additions & 0 deletions .github/workflows/package/osx-silicon/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
name: Package
description: Package OSX artifacts

runs:
using: "composite"
steps:

- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: ${{ env.pythonVersion }}

- name: Retrieve Qt Cache
uses: actions/cache@v3
with:
key: osx-qt-${{ env.qtVersion }}
path: ${{ runner.temp }}/qt

- name: Download Raw Build Artifacts
uses: actions/download-artifact@v3
with:
name: osx-build-artifacts-silicon
path: ${{ github.workspace }}

- name: Install Python Dependencies
shell: bash
run: |
pip3 install --user dmgbuild biplist
- name: Install Custom Dependencies
shell: bash
run: |
set -ex
wget https://raw.githubusercontent.com/disorderedmaterials/scripts/master/prep-dmg
chmod u+x ./prep-dmg
- name: Prepare DMG Dirs
shell: bash
run: |
set -ex
Qt6_ROOT=${{ runner.temp }}/qt/${{ env.qtVersion }}/macos/
export PATH="$(python3 -m site --user-base)/bin:$PATH"
install_name_tool -add_rpath "@executable_path/../Frameworks/" build/bin/dissolve-gui.app/Contents/MacOS/dissolve-gui
# Add homebrew rpath
install_name_tool -add_rpath "/opt/homebrew/lib" build/bin/dissolve-gui.app/Contents/MacOS/dissolve-gui
./prep-dmg -a Dissolve-GUI -v ${{ env.dissolveVersion }} -b build/bin/dissolve-gui.app/Contents/MacOS/dissolve-gui -d ${Qt6_ROOT} -i icon/icon-1024x1024.png -p build/bin/dissolve-gui.app/Contents/Info.plist
# Copy dependencies into Frameworks folder in app bundle
cp ./deploy/antlr4-cppruntime/lib/libantlr4-runtime.4.13.1.dylib Dissolve-GUI-${dissolveVersion}/Dissolve-GUI.app/Contents/Frameworks/libantlr4-runtime.4.13.1.dylib
cp ./deploy/antlr4-cppruntime/lib/libantlr4-runtime.dylib Dissolve-GUI-${dissolveVersion}/Dissolve-GUI.app/Contents/Frameworks/libantlr4-runtime.dylib
cp ./deploy/ftgl/libftgl.2.dylib Dissolve-GUI-${dissolveVersion}/Dissolve-GUI.app/Contents/Frameworks/libftgl.2.dylib
cp ./deploy/ftgl/libftgl.2.dylib Dissolve-GUI-${dissolveVersion}/Dissolve-GUI.app/Contents/Frameworks/libftgl.2.1.3.dylib
for FILE in ./deploy/onetbb/lib/*.dylib; do
FILENAME=$(basename $FILE)
cp ./deploy/onetbb/lib/$FILENAME Dissolve-GUI-${dissolveVersion}/Dissolve-GUI.app/Contents/Frameworks/$FILENAME
done
- name: Create Disk Image
shell: bash
run: |
set -ex
export PATH="$(python3 -m site --user-base)/bin:$PATH"
# Fix icon link
sed -i -e "s/Dissolve.icns/Dissolve-GUI.icns/g" Dissolve-GUI-${dissolveVersion}/Dissolve-GUI.app/Contents/Info.plist
# Create DMG
dmgbuild -s ci/osx/dmgbuild-settings.py -D app=./Dissolve-GUI-${dissolveVersion}/Dissolve-GUI.app -D icon=./Dissolve-GUI-${dissolveVersion}/Dissolve-GUI.app/Contents/Resources/Dissolve-GUI.icns "Dissolve GUI" Dissolve-GUI-${dissolveVersion}.dmg
# Collect artifacts
mkdir packages
mv Dissolve-GUI-${dissolveVersion}.dmg packages/
- name: Upload Package Artifacts
uses: actions/upload-artifact@v3
with:
name: packages
path: ${{ github.workspace }}/packages
12 changes: 11 additions & 1 deletion .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ jobs:
fail-fast: false
matrix:
include:
- os: macos-latest
osx_cmake_target: arm64
osx_conan_target: armv8
- os: macos-latest
osx_cmake_target: x86_64
osx_conan_target: x86_64
Expand Down Expand Up @@ -74,7 +77,14 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ macos-latest, windows-latest ]
include:
- os: macos-latest
osx_cmake_target: arm64
osx_conan_target: armv8
- os: macos-latest
osx_cmake_target: x86_64
osx_conan_target: x86_64
- os: windows-latest
runs-on: ${{ matrix.os }}
env:
OSX_CMAKE_TARGET: ${{ matrix.osx_cmake_target }}
Expand Down

0 comments on commit 3add928

Please sign in to comment.