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 · 39 comments
Open

Build For Apple Silicon (new Github runners) #2912

gal064 opened this issue Dec 4, 2023 · 39 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 😉

@sfatula
Copy link

sfatula commented Dec 7, 2024

It does not build even with nix 24.11, and nix lists it as available for aarch64 darwin, it is not. Same error as I reported elsewhere here:

   error: Package ‘xvfb-run-1+g87f6705’ in /nix/store/g7wwck770vsq4df6xli5i4gcyhgqp13q-source/pkgs/tools/misc/xvfb-run/default.nix:59 is not available on the requested hostPlatform:

@pbek
Copy link
Owner

pbek commented Dec 8, 2024

Hm, that's just to run the (graphical) application to generate the shell completion. 🤔

https://github.com/NixOS/nixpkgs/blob/d0797a04b81caeae77bcff10a9dde78bc17f5661/pkgs/applications/office/qownnotes/default.nix#L56-L61

@sfatula
Copy link

sfatula commented Dec 8, 2024

But nix errors out so stuff does not build. What's the solution? xvfd was not included on Macs anymore long ago. xquartz might make it happen I suppose.

@pbek
Copy link
Owner

pbek commented Dec 8, 2024

@pbek
Copy link
Owner

pbek commented Dec 9, 2024

How are yours built for Intel and can't they be posted for Apple Silicon too?

The whole build chain, release process and update mechanism is structured around one single macOS package...

While the build works, the main toolbar is messed up in that half the icons are missing

Hm, can you turn on the internal icon theme?

I don't care if nix works per se, what I am looking for is simply a native Mac build (on Apple Silicon not Intel) of qownnotes

If there is no other way, then the nix release could be that build. Nix can also update that package.

pbek added a commit that referenced this issue Dec 9, 2024
Signed-off-by: Patrizio Bekerle <[email protected]>
pbek added a commit that referenced this issue Dec 9, 2024
Signed-off-by: Patrizio Bekerle <[email protected]>
pbek added a commit that referenced this issue Dec 9, 2024
Signed-off-by: Patrizio Bekerle <[email protected]>
pbek added a commit that referenced this issue Dec 9, 2024
Signed-off-by: Patrizio Bekerle <[email protected]>
pbek added a commit that referenced this issue Dec 9, 2024
pbek added a commit that referenced this issue Dec 9, 2024
pbek added a commit that referenced this issue Dec 9, 2024
Signed-off-by: Patrizio Bekerle <[email protected]>
pbek added a commit that referenced this issue Dec 9, 2024
Signed-off-by: Patrizio Bekerle <[email protected]>
pbek added a commit that referenced this issue Dec 9, 2024
pbek added a commit that referenced this issue Dec 9, 2024
pbek added a commit that referenced this issue Dec 9, 2024
pbek added a commit that referenced this issue Dec 9, 2024
Signed-off-by: Patrizio Bekerle <[email protected]>
pbek added a commit that referenced this issue Dec 9, 2024
@pbek
Copy link
Owner

pbek commented Dec 9, 2024

The nixos package from https://github.com/pbek/QOwnNotes/blob/main/default.nix should build now.
(See https://github.com/pbek/QOwnNotes/actions/runs/12243377462).

But I wonder which platform the regular macOS app build is current running on... It does look as if macos-latest is already on aarch64. 🤔

@sfatula, @KwisatzJim could you maybe send the first paragraph from the debug settings when running the regular build?

@sfatula
Copy link

sfatula commented Dec 10, 2024

If I get a chance before flying out I can try it. Meanwhile, I turned on the internal theme (restarted of course), same issue. So, I turned off dark mode icon theme, still no change.

Here's my debug settings from the regular intel build:

`## General Info

Current Date: Mon Dec 9 22:02:22 2024
Version: 24.9.2
Build date: Sep 5 2024
Build number: 1124
Platform: macosx (cocoa)
Operating System: macOS 14.7
Build architecture: x86_64
Current architecture: x86_64
Release: GitHub Actions
Qt Version (build): 5.15.2
Qt Version (runtime): 5.15.2
Portable mode: no
Settings path / key: /Users/sfatula/Library/Preferences/com.pbe.QOwnNotes.plist
Application database path: /Users/sfatula/Library/Application Support/PBE/QOwnNotes/QOwnNotes.sqlite
Application arguments: /Applications/QOwnNotes.app/Contents/MacOS/QOwnNotes
Qt Debug: 0
Locale (system): en_US
Locale (interface): empty
Primary screen resolution: 2560x1440
Icon theme: breeze-dark-qownnotes
Notes in current note folder: 220
Calendar items: 0
Enabled scripts: 1
Database drivers: `QSQLITE, QODBC, QODBC3, QPSQL, QPSQL7``

@pbek
Copy link
Owner

pbek commented Dec 10, 2024

x86_64, thank you.

@sfatula
Copy link

sfatula commented Dec 10, 2024

For the one I built somewhat and mostly works but has (at least) the icon issues, it looks like this on Apple Silicon:

`## General Info

Current Date: Tue Dec 10 00:26:43 2024
Version: 24.11.1
Build date: Nov 8 2024
Build number: 1138
Platform: macosx (cocoa)
Operating System: macOS Sonoma (14.7)
Build architecture: arm64
Current architecture: arm64
Release: GitHub
Qt Version (build): 6.8.0
Qt Version (runtime): 6.8.0
Portable mode: no
Settings path / key: /Users/sfatula/Library/Preferences/com.pbe.QOwnNotes.plist
Application database path: /Users/sfatula/Library/Application Support/PBE/QOwnNotes/QOwnNotes.sqlite
Application arguments: ./QOwnNotes
Qt Debug: 0
Locale (system): en_US
Locale (interface): empty
Primary screen resolution: 2560x1440
Icon theme: breeze-dark-qownnotes
Notes in current note folder: 220
Calendar items: 0
Enabled scripts: 1
Database drivers: `QSQLITE, QODBC, QPSQL``

@pbek
Copy link
Owner

pbek commented Dec 10, 2024

Thank you.
This version should also give you shell completion: https://github.com/NixOS/nixpkgs/pull/363327/files

pbek added a commit that referenced this issue Dec 10, 2024
@pbek
Copy link
Owner

pbek commented Dec 10, 2024

24.12.2

  • The nix package now builds also for macOS on x86_64 and aarch64, aka. Apple Silicon
    (for #2912)
    • There is an open pull request for it at #363327 on NixOS/nixpkgs
    • This could serve as a native package for macOS on Apple Silicon hardware

@sfatula
Copy link

sfatula commented Dec 11, 2024

So, I did use that default.nix file, it does run to completion. I do not find a .app file, I searched everything under /nix/store. And it's not in /Applications/Nix Apps either. A find command finds it nowhere. I do see the binary file again (in my case at /nix/store/d929s2zwg8lybx9yd3g504w359c4820f-qownnotes-24.11.2/bin/) but that's not a Mac app. It can be run but it should be packaged like all other Mac apps with a .app extension and a bunch of stuff underneath that. I would guess most any Mac app on nix has a packager to do so. An example might be the commonLinux program remmina which I use.

The other good news is the icons all look good. I'm leaving town for a week to visit family so won't be able to do much more, but maybe look at remmina builder on nix, it should have an example of how to package it for OSX.

I can run the new version for now, I can wrap something around it so it's an app if you think that useful to make sure all the various features work on Apple Silicon, in my case a Mac Studio which has an M1 processor.

@pbek
Copy link
Owner

pbek commented Dec 11, 2024

I do not find a .app file

If you compile something that is not part of your nix configuration, nix creates a ./result folder.

The other good news is the icons all look good.

The icons from which build?

@sfatula
Copy link

sfatula commented Dec 11, 2024

I made it part of my nix configuration as I didn't know how to compile something outside of my nix configuration, no ./result folder. I overlaid the nix default.nix with this one and did a darwin-rebuild. So, just as if someone used nix to build it, no .app (Mac app) file, just the binary that gets included amongst other things in the .app file (which is actually a folder). I only had one app being built with nix, remmina as it was the only source for Apple Silicon version. So, not much need to learn anything about it.

The icons from the new build work fine. From previous build as I had noted above a few days ago, it did not. I can turn the binary into a app "file" via automator or other simple method. I just htink it should build a proper .app "file" so others than may use it don't have to mnss around.

@pbek
Copy link
Owner

pbek commented Dec 12, 2024

The icons from the new build work fine.

The aarch64_darwin nix build or the x86 macOS release build?

I just htink it should build a proper .app "file" so others than may use it don't have to mnss around.

I've found some hints of packages dealing with an app file, but I'm not sure yet why it wasn't created in the build process.

https://github.com/search?q=repo%3ANixOS%2Fnixpkgs+%22.app%22+path%3A*.nix&type=code

In the release build, I create the app file in the build script with macOS tooling...

@sfatula
Copy link

sfatula commented Dec 12, 2024

The aarch64_darwin build, icons work perfectly (as did the original x86 build). It did not work with the first nix build made originally with your initial nix changes. I don't have a x86 machine. Mac with m# chip can run x86 binaries but it's via a code translater and you have to install it. Thus far, everything works with the arm build. Been using it for a day. How nix works is beyond me, never looked at the developer doc. But you asked them so hopefully they have an answer or maybe it just works once included in their entire system.

pbek added a commit that referenced this issue Dec 13, 2024
Signed-off-by: Patrizio Bekerle <[email protected]>
@pbek
Copy link
Owner

pbek commented Dec 13, 2024

NixOS/nixpkgs#363327 is now merged into master and will be soon in nixos-unstable. You can track the progress here: https://nixpk.gs/pr-tracker.html?pr=363327

pbek added a commit that referenced this issue Dec 13, 2024
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

5 participants