Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build For Apple Silicon (new Github runners) #2912

Open
gal064 opened this issue Dec 4, 2023 · 18 comments
Open

Build For Apple Silicon (new Github runners) #2912

gal064 opened this issue Dec 4, 2023 · 18 comments

Comments

@gal064
Copy link

gal064 commented Dec 4, 2023

Github runners for M1 are now available and I'm not familiar with QT, but it looks like you could even build an M1 version on intel silicon.

Would it be possible to have an M1 build?

@pbek
Copy link
Owner

pbek commented Dec 4, 2023

The build process for macos would need to work on Qt6 to do that I guess.
And I don't know if you could get two different architectures in one disk image with the Qt tooling.
But I also have no idea if the update script would be able to handle that.

And I'm lacking M1 hardware to be able to test the result 😁

@gal064
Copy link
Author

gal064 commented Dec 4, 2023

I'm happy to help however I can. Unfortunately know nothing about QT to actually prepare a full PR, but if you want me to run a certain GitHub action or script, or test the result happy to do so.

BTW QTOwnNotes do sometimes freeze for a few seconds on M1. I don't know if it's just a bug, or related to not being built for apple Silicon, but in the past I've seen weird behaviors like this happen on intel apps run on M1

@pbek
Copy link
Owner

pbek commented Dec 4, 2023

I'm happy to help however I can. Unfortunately know nothing about QT to actually prepare a full PR, but if you want me to run a certain GitHub action or script, or test the result happy to do so.

Thank you!
If anyone wants to pick this up, this is where the current release build process is started (uses Qt5):

build-macos:
name: '🍎 macOS Qt 5.15.2'
needs: create_release
runs-on: macos-latest
env:
QT_VERSION: 5.15.2
steps:
- name: '🧰 Checkout'
uses: actions/checkout@v4
with:
submodules: recursive
# https://download.qt.io/online/qtsdkrepository/mac_x64/desktop/
- name: '⚙️ Cache Qt'
id: cache-qt
uses: actions/cache@v3
with:
path: ../Qt
key: ${{runner.os}}-qtcachedir-${{env.QT_VERSION}}
- name: '⚙️ Install Qt'
uses: jurplel/install-qt-action@v3
with:
version: ${{env.QT_VERSION}}
modules: ${{env.QT_MODULES}}
aqtversion: '==2.0.0'
cache: ${{steps.cache-qt.outputs.cache-hit}}
- name: '⚙️ Set Env'
shell: bash
run: |
export VERSION=$(cat version.h | sed 's/[^0-9,.]//g')
echo "VERSION=${VERSION}" >> $GITHUB_ENV
- name: '⚙️ Printenv'
shell: bash
run: |
echo "VERSION=${VERSION}"
printenv
- name: '🚧 Compile application'
run: |
echo "#define RELEASE \"GitHub Actions\"" > release.h
lrelease QOwnNotes.pro
#ls ${Qt5_Dir}/bin
${{env.QMAKE}}
make -j ${{env.CORES}}
../build-systems/github/macos/create-dmg.sh
# - name: '📤 Upload artifact: macOS'
# uses: actions/upload-artifact@v3
# with:
# name: QOwnNotes.dmg
# path: src/QOwnNotes.dmg
- name: '📤 Release DMG'
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.create_release.outputs.upload_url }}
asset_path: src/QOwnNotes.dmg
asset_name: QOwnNotes.dmg
asset_content_type: application/x-apple-diskimage

Most of the actual process is abstracted to https://github.com/pbek/QOwnNotes/blob/main/build-systems/github/macos/create-dmg.sh.

In case Qt6 is needed, this is where I experimentally build the macOS build with Qt6:

build-macos:
name: '🍎 macOS Monterey'
needs: create_release
runs-on: macos-latest
env:
# Qt 6.5 doesn't support macOS 10 anymore!
QT_VERSION: 6.4.2
steps:
- name: '🧰 Checkout'
uses: actions/checkout@v4
with:
submodules: recursive
# https://download.qt.io/online/qtsdkrepository/mac_x64/desktop/
- name: '⚙️ Cache Qt'
id: cache-qt
uses: actions/cache@v3
with:
path: ../Qt
key: ${{runner.os}}-qtcachedir-${{env.QT_VERSION}}
- name: '⚙️ Install Qt'
uses: jurplel/install-qt-action@v3
with:
version: ${{env.QT_VERSION}}
modules: ${{env.QT_MODULES}}
aqtversion: '==2.0.0'
cache: ${{steps.cache-qt.outputs.cache-hit}}
- name: '⚙️ Set Env'
shell: bash
run: |
export VERSION=$(cat version.h | sed 's/[^0-9,.]//g')
echo "VERSION=${VERSION}" >> $GITHUB_ENV
- name: '⚙️ Printenv'
shell: bash
run: |
echo "VERSION=${VERSION}"
printenv
- name: '🚧 Compile application'
run: |
echo "#define RELEASE \"GitHub Actions\"" > release.h
lrelease QOwnNotes.pro
#ls ${Qt5_Dir}/bin
${{env.QMAKE}}
make -j ${{env.CORES}}
../build-systems/github/macos/create-dmg-qt6.sh
- name: '📤 Upload artifact: macOS'
uses: actions/upload-artifact@v3
with:
name: QOwnNotes.dmg
path: src/QOwnNotes.dmg

BTW QTOwnNotes do sometimes freeze for a few seconds on M1. I don't know if it's just a bug, or related to not being built for apple Silicon, but in the past I've seen weird behaviors like this happen on intel apps run on M1

Any debug logs?

@pbek pbek added Type: Feature adds functionality Help wanted and removed Type: Support labels Dec 4, 2023
@pbek
Copy link
Owner

pbek commented Dec 4, 2023

Building should maybe even work with Qt5 and qmake says: https://doc-snapshots.qt.io/qt5-5.15/macos.html#architectures

@gal064, so in theory you could try to fork the QOwnNotes repository and add QMAKE_APPLE_DEVICE_ARCHS="x86_64 arm64" to this line:

If you enabled GitHub actions and push your changes to the release branch, that should trigger building a release for you. Of course, that would result in an app for only the M1 (if it works).

@gal064
Copy link
Author

gal064 commented Dec 4, 2023

Tried to run it but I'm getting:
"Trying to compile Botan configured as x86_64 with non-x86_64 compiler."

Also tried to comment out the x86 config in botan.pri and received the following:
ld: symbol(s) not found for architecture arm64

I'm not sure if that error is unrelated or making changes to the pri file created that error. I was pretty much guessing

@pbek
Copy link
Owner

pbek commented Dec 4, 2023

I guess Botan is able to compile for ARM, so it must be something with the settings... 🤔

@gal064
Copy link
Author

gal064 commented Dec 4, 2023

Yep. I have no idea how to push forward here, so if you or anyone else want to pick this up would be greatly appreciated.

Anyway I'll submit a bug on the small freezes when it happens next

@pbek
Copy link
Owner

pbek commented Jan 28, 2024

I tried just adding QMAKE_APPLE_DEVICE_ARCHS = x86_64 arm64 to the project file in fdd5e05, but the build on macOS failed, without telling why. 🤔
https://github.com/pbek/QOwnNotes/actions/runs/7685776723/job/20943900082

pbek added a commit that referenced this issue Jan 28, 2024
@spoelstraethan
Copy link
Contributor

I wonder if any of the notes here on cross compilation might help/work?

https://github.com/qbittorrent/qBittorrent/wiki/Compilation:-macOS-(x86_64,-arm64,-cross-compilation)#qt

@gal064
Copy link
Author

gal064 commented Jan 29, 2024

Looking at the logs, can the failure might be due to this:

:17:
libraries/botan/botan.h:293:6: error: "Trying to compile Botan configured as x86_64 with non-x86_64 compiler."
    #error "Trying to compile Botan configured as x86_64 with non-x86_64 compiler."
     ^

@gal064
Copy link
Author

gal064 commented Jan 29, 2024

I ran into the same issue but wasn't sure how to set it up

@pbek
Copy link
Owner

pbek commented Jan 29, 2024

Ah, good find! Hm... 🤔

@KwisatzJim
Copy link

I have a MBPro M3 Pro and was able to build for Apple Silicon. I did the fallowing:
git clone https://github.com/pbek/QOwnNotes.git -b release --depth=1
cd QOwnNotes
git submodule update --init

brew install qt-creator

brew install qt
You can add Homebrew's Qt to QtCreator's "Qt Versions" in:
Preferences > Qt Versions > Link with Qt...
pressing "Choose..." and selecting as the Qt installation path:
/opt/homebrew

brew install qt@5
fallow procedure to add qt5 to QT Creator:
You can add Homebrew's Qt to QtCreator's "Qt Versions" in:
Preferences > Qt Versions > Link with Qt...
pressing "Choose..." and selecting as the Qt installation path:
/opt/homebrew/opt/qt@5

open QT Creator
open the project file src/QOwnNotes.pro

then I think there was a 'configure project' button but it's not there now and I don't recall exactly, sorry. But that did it's thing for a while. I've never used QT Creator before so going by memory.

then I built it and ran it and it worked, building an Apple Silicon version

@KwisatzJim
Copy link

hmmm... ran into a hitch, I copied the .app to my Mac Mini M2 and it crashed on start until I installed qt@5

@pbek
Copy link
Owner

pbek commented Apr 14, 2024

You could try to use the package manager nix to install QOwnNotes on the mac. 🤔

@KwisatzJim
Copy link

You could try to use the package manager nix to install QOwnNotes on the mac. 🤔

ok, not bad idea, but the nix version is 24.4.0 and current release is 24.4.2. But it is Apple Silicon which is nice.

@pbek
Copy link
Owner

pbek commented Apr 14, 2024

Will be surely in the build pipeline. QOwnNotes is at 24.4.2 in nix.

@pbek
Copy link
Owner

pbek commented Apr 14, 2024

I'd like to know if it worked in case you try 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants