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 (Arm64, aarch64) #147

Open
11 tasks
RemiDesgrange opened this issue Feb 8, 2022 · 23 comments
Open
11 tasks

Build for Apple Silicon (Arm64, aarch64) #147

RemiDesgrange opened this issue Feb 8, 2022 · 23 comments

Comments

@RemiDesgrange
Copy link

RemiDesgrange commented Feb 8, 2022

Hi 👋

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 !

@nyalldawson
Copy link

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

@3nids
Copy link
Member

3nids commented Feb 8, 2022

Hi Remi,
Thanks for raising this!

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).

@RemiDesgrange
Copy link
Author

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 😄

@RemiDesgrange
Copy link
Author

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.

@3nids
Copy link
Member

3nids commented Feb 9, 2022

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 microsoft/vcpkg#22908

@PeterPetrik
Copy link
Contributor

we do not bundle anything from homebre

@RemiDesgrange
Copy link
Author

RemiDesgrange commented Feb 9, 2022

@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.

@3nids
Copy link
Member

3nids commented Feb 9, 2022

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

@liberostelios
Copy link

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.

@RemiDesgrange
Copy link
Author

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.

@liberostelios
Copy link

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.

@RemiDesgrange
Copy link
Author

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 qgis/QGIS#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.

@justinbb
Copy link
Contributor

justinbb commented Mar 14, 2023

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:

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.

@SrNetoChan
Copy link
Member

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

@RemiDesgrange
Copy link
Author

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.

@joaoponceleao
Copy link

@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.

@SrNetoChan
Copy link
Member

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

@justinbb
Copy link
Contributor

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 #160 (comment) in QGIS-Mac-Packager).

@SrNetoChan
Copy link
Member

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

@justinbb
Copy link
Contributor

@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.

@ivn951
Copy link

ivn951 commented Mar 26, 2023 via email

@vlebert
Copy link

vlebert commented Aug 1, 2023

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

@luispuerto
Copy link

Is there any easy and simple way to make this happen? I mean have the last version of QGIS for Apple Silicon and with Qt6 built? I'm wondering why we don't use Homebrew for this… even if we just need to build locally.

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

No branches or pull requests