Upcoming ARM-based Macs and importance of universal variant
ryandesign at macports.org
Mon Apr 27 08:35:24 UTC 2020
Recent news reports say Apple expects to release Macs next year that will use ARM CPUs instead of Intel. So this will be another transitional time, just like the previous i386-to-x86_64 transition and the ppc-to-i386 transition, during which we will have a userbase where not everyone is using the same CPU.
The universal variant in MacPorts allows users to build a port so that it can run on multiple architectures. Some people use MacPorts to build software that they then redistribute to others (i.e. using `port mpkg` or `port mdmg`); by using the universal variant and the right universal_archs, those redistributed versions should work on any Mac regardless what processor it uses.
My impression is that over the past few years we've allowed our support for universal builds in our port collection to bitrot a bit, due to a number of factors: universal builds are not possible with the macOS 10.14 SDK and later and probably most users and developers now use macOS 10.14 or later (or 10.13 with Xcode 10, which is also affected); many projects have switched to the new meson build system for which IIUC we have not developed a universal variant strategy ; some projects just can't be built for i386, leaving only the x86_64 arch and making testing the universal variant impossible. But please take this message as a reminder to check your ports for the ability to build universal where possible (i.e. for software that does build for i386 and if you have a system with macOS 10.13 or earlier and Xcode 9 or earlier). I have been installing all ports with the universal variant for years and I try to file bug reports when I can, but I'm probably not installing every port so I haven't tested everything.
Most ports automatically use the right compiler  and -arch flags because they use a standard build system like automake or cmake. If your port doesn't use the right compiler or if you fixed it to use the right compiler but didn't also fix it to use the right -arch flags, please fix that now; you can verify correctness on any OS version by looking at the MacPorts log of building your port and verifying that the correct compiler is invoked (i.e. "/usr/bin/clang" not "gcc") and that (almost) every invocation of the compiler also has -arch flags. The new makefile 1.0 portgroup can help do this for ports that don't have a configure phase.
Also, if your ports do something different depending on the architecture and have if statements or switch statements based on the architecture, be prepared for needing to modify that in the future to accommodate architecture values other than the current i386 ppc ppc64 x86_64 quartet.
More information about the macports-dev