QGIS-Mac-Packager icon indicating copy to clipboard operation
QGIS-Mac-Packager copied to clipboard

Build for Apple Silicon (Arm64, aarch64)

Open RemiDesgrange opened this issue 3 years ago • 22 comments

Hi :wave:

It seems that there is no QGIS build for apple silicon hardware so far. I started to look at, it's much more tricky that it seems !! I listed some checks that needed to be performed in order for QGIS to work on Apple Silicon hardware (arm64 ou aarch64)

  • [ ] Install Qt6 in /opt/Qt/6.X.Y : Qt 5 is not supported on apple silicon hardware https://www.qt.io/blog/qt-on-apple-silicon
    • [ ] sudo mv /opt/Qt/6.X.Y/{macos,clang_64}
  • [ ] update https://github.com/qgis/QGIS-Mac-Packager/blob/master/qgis_deps/distribute.sh#L41 to $(arch) (or something like that) make a rg x86 to see what’s need to be changed. Mostly recipe.sh for python stuff.
    • [ ] update distribute.sh to change the path of homebrewed installed package (cmake, ninja etc...)
    • [ ] fix compilation error in gmp.
    • [ ] remove qtwebkit from recipes to build.
  • [ ] modify the config/{nightly,ltr}.conf and config/default.conf to remove any Qt5 variant. Also add a -DWITH_QT6=ON in the config.
    • [ ] Bump Qt version to 6.2.3
    • [ ] Bump python to 3.10
    • [ ] remove hana, oracle, etc... support, I didn't search if there are some build for apple silicon.
    • [ ] Problems with homebrew path. On mac intel, it installs in /usr/local and on Apple Silicon to /opt/homebrew.

Maybe the qgis mac deps need to be completely revamp with 1 build for x86 and 1 build for arm (ex: `qgis-deps-x86_64-0.10.0.tar.gz).

I'll fork the repo and make some tried, but I already identify some hardcoded path that need to be added to the config files. Feel free to add more checks in order to have a complete build of QGIS on Apple Silicon hardware !

RemiDesgrange avatar Feb 08 '22 20:02 RemiDesgrange

@RemiDesgrange be aware that you can't build qgis on qt6 completely yet -- see https://github.com/qgis/QGIS-Enhancement-Proposals/issues/243 for a summary of the current situation

nyalldawson avatar Feb 08 '22 21:02 nyalldawson

Hi Remi, Thanks for raising this!

  • Regarding Qt, I think it is still possible to have Qt 5.15 on arm (https://github-wiki-see.page/m/bobwolff68/fritzing-app/wiki/Building-Qt-5.15-for-Mac-M1). I did not try. It might indeed be better to wait for https://github.com/qgis/QGIS-Enhancement-Proposals/issues/243 to be implemented.
  • For homebrew, I don't think this is an issue since we don't bundle anything coming from brew (not 100% sure though)

Side note, I am working a bit on trying to bring the deps to a CI (see https://github.com/qgis/QGIS-Mac-Packager/tree/ci-v2).

3nids avatar Feb 08 '22 21:02 3nids

I can confirm that you have an adherence to where ninja is located, we'll have to use $(brew --prefix) instead of hardocding /usr/local path, but no big change.

I'll try to build with Qt5. But I'll first have to build the deps :smile:

RemiDesgrange avatar Feb 09 '22 07:02 RemiDesgrange

On the other hand, it is possible to ship Apple Silicon and x86_64 binary in the same DMG: "universal binary" (https://developer.apple.com/documentation/apple-silicon/building-a-universal-macos-binary). I have little knowledge of how Qt build works, so no idea if it's possible or not to ship Apple Silicon and x86_64 binary of QGIS in the same DMG.

RemiDesgrange avatar Feb 09 '22 07:02 RemiDesgrange

On the other hand, it is possible to ship Apple Silicon and x86_64 binary in the same DMG: "universal binary"

that's the road vcpkg is apparently following https://github.com/microsoft/vcpkg/pull/22908

3nids avatar Feb 09 '22 07:02 3nids

we do not bundle anything from homebre

PeterPetrik avatar Feb 09 '22 07:02 PeterPetrik

@nyalldawson I identified that steps have been made to build QGIS with Qt6, What I can't see though is where we are regarding the QEP you wrote. Is it started yet? Is there a branch where we could test it (in the qgis/QGIS repo)? Thx.

RemiDesgrange avatar Feb 09 '22 07:02 RemiDesgrange

This QEP will go through the grant proposal (funding) process, so it is not started yet. All the base work for Qt6 has been merged to master, and we have a CI running with Qt6 builds for core and analysis libraries going, see https://github.com/qgis/QGIS/blob/master/.github/workflows/run-tests.yml#L62

3nids avatar Feb 09 '22 08:02 3nids

Since qt5 seems to be available for Apple Silicon right now (at least in homebrew) is there a reconsideration about this? I would be interested in working on it, but I am no CMAKE expert and could use some help.

liberostelios avatar Oct 05 '22 11:10 liberostelios

If Qt5 is available on m1, there should have nothing but some hard-coded /usr/local/opt path to change. I will see if I can find an old m1 machine to test stuff on. Every package will need to be recompile (usually, pre-compile version of lib are used). This should take some time, even on an Apple Silicon machine.

RemiDesgrange avatar Oct 06 '22 14:10 RemiDesgrange

Actually, in Apple Silicon the default path for homebrew is /opt/homebrew, instead of /usr/local. Not sure why that is, but just mentioning it. Does it matter, though? Isn't Qt5 supposed to be installed on it's own /opt/QT folder outside of homebrew?

I tried to build the dependencies, but certain things aren't working out of the box. I suppose the build configuration of certain dependencies might need to be changed to fit for the platform.

liberostelios avatar Oct 06 '22 15:10 liberostelios

Is there any news on this side?

Qt5 can be compiled on m1, several attempts have been made to have a native Apple Silicon build (see https://github.com/qgis/QGIS/issues/46299), conda have one, macports allow you to compile QGIS on a m1. Is there anything we can do to help on this topic ? Thx.

RemiDesgrange avatar Mar 06 '23 08:03 RemiDesgrange

It is possible to build up-to-date QGIS completely on Apple Silicon, running Ventura, with Xcode 14.2 – despite still using Qt5. It's all set up on MacPorts, currently for 3.28.4. There are a couple of traps, however:

  • https://github.com/qgis/QGIS/issues/52052 will cause a few files to fail compilation with Xcode 14.2 – either use a source branch (3.30+) containing this fix, or backport the commit that fixed the issue
  • The GDAL setup in MacPorts uses an integrated obsolete JPEG library. Either it has to be configured out, or you have to temporary deactivate the modern jpeg library libjpeg-turbo (port deactivate libjpeg-turbo) while building GDAL, then activate it again afterwards.

Is there anyone around who knows how to fix the QGIS-Mac-Packager? I tried, but gave up in despair rather early in the process; MacPorts was a more effective way of getting a functioning QGIS without investing several days deciphering this packager.

justinbb avatar Mar 14 '23 15:03 justinbb

The conda-forge community have successfully built QGIS 3.28 and 3.30 for Arm64 and aarach64. I wasn't able to test it much as I don't have a mac arm64 myself, but seems functional to others. But it's definitely possible:

https://github.com/conda-forge/qgis-feedstock

SrNetoChan avatar Mar 15 '23 11:03 SrNetoChan

Correct me if I'm wrong @SrNetoChan, but I can't take the DMG from conda, copy/paste it to a computer without conda, and having QGIS to work properly? That's the problem with macports/conda setup. @justinbb I already try to make this repo working with AppleSilicon but it was a lot a work, and a lot of breaking changes.

RemiDesgrange avatar Mar 15 '23 14:03 RemiDesgrange

@RemiDesgrange You can't with conda (though perhaps there is a way, never checked). You can with macports. I haven't managed to install it with macports however. Perhaps on a clean vm it might work, but I don't have experience with ports, just know there is a command to build an independent binary.

joaoponceleao avatar Mar 15 '23 17:03 joaoponceleao

Correct me if I'm wrong @SrNetoChan, but I can't take the DMG from conda, copy/paste it to a computer without conda, and having QGIS to work properly? That's the problem with macports/conda setup. @justinbb I already try to make this repo working with AppleSilicon but it was a lot a work, and a lot of breaking changes.

Probably there is, but I don't know how to do it. I know there's something called conda constructor to create installers.

https://github.com/conda/constructor

SrNetoChan avatar Mar 15 '23 18:03 SrNetoChan

conda is at the moment the easiest, quickest way to get an up-to-date QGIS running on a Mac. @SrNetoChan Nicely done!

The problem with the conda version is that it is not a Mac app bundle (though there is a vestigial bundle created by QGIS's own cmake configuration); you run it from the shell by starting "qgis" in conda's bin directory, as if it were a command-line tool, and it dynamically links with many libraries in conda's lib directory. @RemiDesgrange To move it to a new computer, it's much easier to install Miniconda3 anew, then conda install qgis, than to try to make an archive of the conda directory hierarchy and copy it elsewhere.

Compared with MacPorts, conda installs QGIS very quickly, uses more up-to-date versions of many libraries, and has a better-configured GDAL library. However, since there are various optional bits and pieces that not everyone uses, it's possible there might be gaps here and there. MacPorts does a better job of making an app bundle – not according to the rules, but it is usable.

The proofs of concept clearly exist for building on Mac (Intel or Apple Silicon) the latest QGIS with recent versions of the libraries it depends on. The problems making official, standalone app bundles should eventually get dealt with (see https://github.com/qgis/QGIS-Mac-Packager/issues/160#issuecomment-1483897570 in QGIS-Mac-Packager).

justinbb avatar Mar 25 '23 19:03 justinbb

@justinbb neither me or @gillins (who's the main maintainer of qgis-feedstock) have much experience with Mac OS, so any pointers are welcome.

SrNetoChan avatar Mar 25 '23 20:03 SrNetoChan

@SrNetoChan There is one more thing I had to do to avoid startup errors from SIP and Python. That vestigial bundle is not completely unused…

cd QGIS.app/Contents/MacOS
ln -s ../../../lib .
ln -s ../../../share .

For the more general question of making app bundles from conda: see the interesting discussion by Daniël Schreij and set of scripts. I'll try out his suggestion one of these days. However, it's still not a way of making a conformant bundle, which requires strict separation of code and data directories to allow effective code signing.

justinbb avatar Mar 26 '23 02:03 justinbb

Some time back, I wrote an article in Italian on how to install QGIS with MacPorts. It might be useful although I should update it.

https://ivano-giuliano.medium.com/installazione-di-qgis-3-beta-su-piattaforme-macos-tramite-macports-28940731ed2b

Il giorno dom 26 mar 2023 alle 04:40 justinbb @.***> ha scritto:

@SrNetoChan https://github.com/SrNetoChan There is one more thing I had to do to avoid startup errors from SIP and Python. That vestigial bundle is not completely unused…

cd QGIS.app/Contents/MacOS ln -s ../../../lib . ln -s ../../../share .

For the more general question of making app bundles from conda: see the interesting discussion by Daniël Schreij https://dschreij.github.io/how-to/package-anaconda-environments-as-apps and set of scripts https://github.com/dschreij/anaconda-env-to-osx-app. I'll try out his suggestion one of these days. However, it's still not a way of making a conformant bundle, which requires strict separation of code and data directories to allow effective code signing.

— Reply to this email directly, view it on GitHub https://github.com/qgis/QGIS-Mac-Packager/issues/147#issuecomment-1483977525, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACMJDNGPYTFXBREZW33IPSTW56UC7ANCNFSM5N3SZQRQ . You are receiving this because you are subscribed to this thread.Message ID: @.***>

ivn951 avatar Mar 26 '23 18:03 ivn951

Hi

I found this thread and it's nice to read good news regarding Mac environment, especially Apple Silicon Arch.

A small tip for those who want to test conda native build without polluting the system environment, or even try multiple QGIS vesions at once :

  • Create a conda env and install QGIS there : conda create --name qgis then conda install qgis=3.28
  • Create and Automator shortcut to have an app icon working to open QGIS and link .qgs/.qgz files to this app :
  1. Open "Automator" on your Mac (you can find it in the Applications folder).
  2. In the Automator app, select "Application" as the document type for your new workflow.
  3. In the search bar, type "Run Shell Script" and drag the "Run Shell Script" action to the workflow area on the right.
  4. In the "Run Shell Script" action, change the "Pass input" option to "as arguments".

Script:

eval "$(/Users/YOUR_USERNAME/miniforge3/bin/conda shell.zsh hook)"
conda activate qgis
qgis "$@"

digi-studio 2023-08-01 at 08 58 12

vlebert avatar Aug 01 '23 06:08 vlebert