-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
[Feature] macOS native arm64 builds #1109
Comments
Hey I'd love to add ARM builds in the future however I don't have a Mac to try any of this and GitHub doesn't have any M1 build servers. Therefor we're stuck with what we have right now. |
Xcode can build universal apps even on x86_64 and since Xcode 12 it's a default behaviour |
ImHex is built using GCC on macOS, we don't really use Apple's compiler or XCode at all because it's so outdated. Of course we could still cross compile but figuring out how to do it without having access to any Mac is basically impossible. |
Xcode uses clang and it's quite fresh. Older Xcode versions use older clang, obviously. I personally prefer clang over gcc |
BTW, cmake can generate Xcode project. |
The problem is that Apple uses their own clang version that is not the same as regular clang. And it's always multiple version behind regular clang. If I had a Mac, I'd probably put in more effort into supporting their toolchain but since I have absolutely no way of debugging using their tools, it's really just frustrating to use. |
Nevertheless, could you please keep this feature request open. I guess somebody will find a solution faster if it'd be open. |
I created a new pinned issue now with this request amongst other things that I really need help with. #1111 |
About clang/debug issue, could you explain it further? In way it's described it's very unclear, what is the problem and how to overcome it if somebody would want to look into. |
I don't know how to better explain it to be honest. |
Hey, we've decided to use this issue as the "official" one for discussion about this problem. Please comment here if you have ideas to share ! |
Note: I'm not a developer by any means. And i hardly know what I'm doing. But I got this working on my ARM mac. Compiled following the guide here: https://github.com/WerWolv/ImHex/blob/master/dist/compiling/macos.md
The only issues is that signing is much stricter on arm mac, than x86. So the generated .app won't work. Worked around this by just copying the .app folder directly into
Hopefully this information might be a little bit useful. I haven't actually used it much except checking if it starts |
Hey ! The problem isn't so much to compile it, it is that neither of us has a M1 Mac to actually compile it. |
Thanks for the help @slinderud! As none of us has any Mac, it's really difficult to setup these cross-build processes without tons of trial and error using the GitHub runners. And even if we get it to compile, we have no way of verifying if the produced binary actually runs |
I can help with testing |
I can help since I was a contributor in hyperion-project/hyperion.ng#1468 |
hey ! What we need is a way to build these binaries ourselves, possibly automatically. Do you think you can help with that ? |
The only way that would be possible from me i is to set up docker image that will be fetching code and trigger build jobs in cron like schedule and then push all results somewhere. However that would be limited to linux image. |
Hi, I don't know if you can use it for this project, but I made docker images for cross-compiling on Linux for Windows and MacOS (x86, x64, arm64) here: https://hub.docker.com/r/nemirtingas/osxcross_vcpkg |
@Nemirtingas Hey, thanks a lot for the suggestion! I tried it out but I can't seem to get vcpkg to build any libraries. The example command from your Docker hub page which installs zlib and libfmt fails with cmake throwing |
I don't know, I did the following thing and it worked:
And it worked 🤔 |
Thanks that indeed worked! I just used |
To build for arm64 macos, I use the following triplet:
|
Building for macOS 14#!/usr/bin/env bash
CC=$(brew --prefix gcc@12)/bin/gcc-12 \
CXX=$(brew --prefix gcc@12)/bin/g++-12 \
OBJC=$(brew --prefix llvm)/bin/clang \
OBJCXX=$(brew --prefix llvm)/bin/clang++ \
PKG_CONFIG_PATH="$(brew --prefix openssl)/lib/pkgconfig":"$(brew --prefix)/lib/pkgconfig" \
MACOSX_DEPLOYMENT_TARGET="14" \
cmake \
-DCMAKE_BUILD_TYPE=Release \
-DCREATE_BUNDLE=ON \
-DCREATE_PACKAGE=ON \
-DCMAKE_C_COMPILER_LAUNCHER=ccache \
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
-DCMAKE_OBJC_COMPILER_LAUNCHER=ccache \
-DCMAKE_OBJCXX_COMPILER_LAUNCHER=ccache \
-DCMAKE_OSX_ARCHITECTURES='arm64' \
--fresh \
..
gmake -j4 package; I have also used a different linker, see https://github.com/keith/ld64.lld
Universal BinaryYou can build a universal binary using both.
Example WorkflowThis is a rough example of a github action workflow using both macOS x86 and arm64:
release:
name: ${{ matrix.job.target }} (${{ matrix.job.os }})
runs-on: ${{ matrix.job.os }}
# needs: prepare # this can be a job that creates a changelog, tags the commit and does other pre-release tasks
env:
TAG: ${{ github.ref_name }}
strategy:
matrix:
job:
# The OS is used for the runner
# The platform is a generic platform name
- os: ubuntu-20.04
platform: linux
target: x86_64-unknown-linux-gnu
arch: amd64
svm_target_platform: linux-amd64
- os: ubuntu-20.04
platform: linux
target: aarch64-unknown-linux-gnu
arch: arm64
svm_target_platform: linux-aarch64
- os: macos-11
platform: darwin
target: x86_64-apple-darwin
arch: amd64
svm_target_platform: macosx-amd64
- os: macos-13
platform: darwin
target: aarch64-apple-darwin
arch: arm64
svm_target_platform: macosx-aarch64
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Apple Silicon setup
if: ${{ matrix.job.target == 'aarch64-apple-darwin' }}
run: |
echo "SDKROOT=$(xcrun -sdk macosx --show-sdk-path)" >> $GITHUB_ENV
echo "MACOSX_DEPLOYMENT_TARGET=$(xcrun -sdk macosx --show-sdk-platform-version)" >> $GITHUB_ENV
# execute cmake build for both x86 and arm64 macOS
# This can be a script that invokes cmake and make
- name: Build macOS x86 and arm64
id: macos-build
run: bash all_macos.sh
shell: bash
# Currently cmake does not create a subdirectory within build with the three-word target name
- name: Darwin link as Universal
id: macos-link
run: lipo -create -output ImHex-macos build/aarch64-apple-darwin/imhex-1.30.1-Darwin.dmg build/x86_64-apple-darwin/imhex-1.30.1-Darwin.dmg
shell: bash
# The Rest of this is optional and only needed if you want to notarize the binary
- name: Create keychain
run: |
printf ${{ secrets.APPLE_P12_BASE64 }} | base64 -d > dev.p12
security create-keychain -p "${{ secrets.APPLE_TEMPKEYCHAIN_PASSWORD }}" "${{ secrets.APPLE_TEMPKEYCHAIN_NAME }}"
security list-keychains -d user -s "${{ secrets.APPLE_TEMPKEYCHAIN_NAME }}" $(security list-keychains -d user | tr -d '"')
security set-keychain-settings "${{ secrets.APPLE_TEMPKEYCHAIN_NAME }}"
security import dev.p12 -k "${{ secrets.APPLE_TEMPKEYCHAIN_NAME }}" -P "${{ secrets.APPLE_P12_PASSWORD }}" -T "/usr/bin/codesign"
security set-key-partition-list -S apple-tool:,apple: -s -k "${{ secrets.APPLE_TEMPKEYCHAIN_PASSWORD }}" -D "${{ secrets.APPLE_CODESIGN_IDENTITY }}" -t private ${{ secrets.APPLE_TEMPKEYCHAIN_NAME }}
security default-keychain -d user -s ${{ secrets.APPLE_TEMPKEYCHAIN_NAME }}
security unlock-keychain -p ${{ secrets.APPLE_TEMPKEYCHAIN_PASSWORD }} ${{ secrets.APPLE_TEMPKEYCHAIN_NAME }}
- name: Sign the binary
run: |
codesign -o runtime --timestamp -s "${{ secrets.APPLE_CODESIGN_IDENTITY }}" -v ImHex-macos
ditto -c -k ImHex-macos ImHex-macos.zip
- name: Notarize
run: |
xcrun notarytool store-credentials --apple-id [email protected] --password "${{ secrets.APPLE_CRED }}" --team-id "${{ secrets.APPLE_TEAMID }}" altool
xcrun notarytool submit ImHex-macos.zip --keychain-profile altool --wait
- name: Rename ImHex binary
if: startsWith(github.event.ref, 'refs/tags/v') # only on new tag creation
run: mv ImHex-macos ImHex-macos-$TAG
- name: Upload artifact to action
uses: actions/upload-artifact@v3
if: startsWith(github.event.ref, 'refs/tags/v') # only on new tag creation
with:
name: ImHex-macos-${{ env.TAG }}
path: ImHex-macos-${{ env.TAG }}
|
I don't understand, what does this mean ? |
Okay, I made some progress, available here: https://github.com/iTrooz/macos-crosscompile Its not nearly finished tho, and I'm probably going to take a break from it because there are sooo much "small" problems to fix @Nemirtingas You might be interested in looking at what I did ^^ |
Well, I compiled quite some complex stuff with my toolchain and using clang/llvm for MacOS so I'm not interested in GCC |
Would you have dealt with errors like this, by any chance ? https://cdn.discordapp.com/attachments/789840633414025246/1136801105666396261/image.png |
No but I though you were trying to build for ARM while this instruction is an x86 FPU instruction. |
Well, I wanted to make a Dockerfile that worked for both x86 and Arm64, but now that you are saying it, its true that this assembler bug probably only happens in a x86 build, and the main goal is building ARM64 Oops, gotta try that |
I had to add the following to
The resulting app needed signing, but included an extraneous copy of the
|
I said I'll do it in #1414 Warning: the output zip does not pass SIP (System Integrity Protection), and I have no plan to do it for now. So if someone here has a Mac, feel free to to try to fix the problem (which is probably our build system) Link #1109 --------- Co-authored-by: Nik <[email protected]>
@WerWolv Intel builds require a minimum 12.7 macOS version but Apple Silicon ones require macOS 14.0. This means that M1 users that aren't in latest macOS version can use the Intel build but not the Apple Silicon one. |
@lucasaf04 Thanks! This might be a remnant from us figuring out how to build the ARM build. I'll see if I can lower the requirement to 12.1 as well |
@lucasaf04 The latest nightly builds only require 12.1 now. I'll be closing this issue now since I decided to just bite the bullet and get a MacBook to properly be able to add support for Apple Silicon. If there's any more issues with these builds, please open a new issue. |
Signing and notarizing would be nice. Currently when I download the app, move it to /Applications and run it I get "“ImHex” cannot be opened because the developer cannot be verified." error: and have to got to System Settings > Privacy & Security > Security > Open Anyway Also, please add the M1 build to the website. |
@verhovsky I have no plans of ever doing that because it's expensive for no reason. |
Which macOS version? |
Same as you. 14.2.1 but on a M2 MacBook Air |
Pardon me if I'm intruding here, but if there is a need for M1 or M2 runners for GitHub Actions, may I suggest giving FlyCI a try? We offer MacOS M1 and M2 runners (ARM64). For public repos, we offer 500 mins/month of free M1 usage (4 vCPUs, 7 GB RAM, 28 GB storage). The setup is super easy:
jobs:
ci:
- runs-on: macos-latest
+ runs-on: flyci-macos-large-latest-m1
steps:
- name: 👀 Checkout repo
uses: actions/checkout@v4 We're still in the public Beta phase and we currently don't have billing so you can use all of our runners for free. Once we enable billing, then contact me if you need more minutes and we might be able to work out something. Do you think this might be a good option for ImHex? Best Regards, Web: flyci.net | Twitter: flyciapp | LinkedIn: FlyCI | Discord: FlyCI |
Hey ! For now, we have a cross-compiling system that somewhat works, and we feel we are able to fix the last few issues ourselves, so we probably won't need it for ImHex That said, this is a really awesome project, and I am really glad that you advertised it to us ! I might use it in other projects in the future, of even ImHex if we can't get the current build process to work properly Thanks a lot ! |
Thanks, hopefully, you'll find a good application for our runners in the very near future! :) |
Could y'all please try this build here? At least on my M2 it works fine. |
On the latest nightly build it should really all be working now. Both the x86 and ARM version runs for me and only requires at macOS 12.1. Let's hope it stays at that. For anybody who got here because they had issues, download the nightly from https://imhex.download/#nightly or from https://imhex.werwolv.net and the issue should be gone. Also 1.33.0 or higher will have the issue fixed. |
What feature would you like to see?
Could you please add macOS M1/M2 native builds?
How will this feature be useful to you and others?
No need to install Rosetta 2 or every time build manually
Request Type
Additional context?
No response
The text was updated successfully, but these errors were encountered: