Haskell Stack Ports on Apple Silicon

Steven Smith steve.t.smith at gmail.com
Sat Aug 14 17:46:44 UTC 2021

> MacPorts base already knows this and allows the port to be installed on Apple Silicon even when it says supported_archs x86_64.

Then I believe there is a bug in the MacPorts download logic per the original post. When I try to install, e.g., pandoc, on an arm64 box, I hit this architecture mismatch error:

> Cannot install pandoc for the arch 'arm64' because
> It’s dependency stack is only installed for the arch 'x86_64'
> and does not have a universal variant.
> Unable to execute port: architecture mismatch

I confirm this issue is fixed if I remove the supported_archs line in the stack Portfile. When I remove this line, stack is able to build itself and run on Apple silicon (it builds and runs an x86_64 binary).

I’m at a loss whether to submit a PR for stack with the supported_archs line removed, or a bug report that this line prevents downloading and/or building stack-based binaries.

Please advise and I’ll follow up.

A separate, but related issue: it appears to me that stack/ghc builds using Rosetta on Apple silicon are not multi-threaded, and therefore take a looooong time. It would be desirable on Apple silicon to simply download the build-bot x86_64 binaries (if available), and avoid building on the M1. That this doesn’t happen by default on the M1 appears to be a related issue.

> On Aug 14, 2021, at 00:48, Ryan Schmidt <ryandesign at macports.org> wrote:
> On Aug 13, 2021, at 10:58, Steven Smith wrote:
>> If the Macports-compiled stack runs on arm64, then the prebuilt download will too.
>> The issue as far as I can tell from the internet is that stack will generate x86_64 binaries, even if running on an M1. https://www.haskell.org/ghc/blog/20200515-ghc-on-arm.html
>> These x86_64 binaries should run on an M1.
>> If so, is the best approach to remove the supported_archs line from the stack Portfile, or add arm64?
> The supported_archs line must accurately convey the set of architectures for which this port can be installed (i.e. the actual architectures of the files that get installed by the port), so that MacPorts can accurately record the architecture for which the port was installed in the registry. If the port installs only an x86_64 binary, then it must set supported_archs x86_64. (That was the case when this port was created and why the port did this at the time.) The fact that x86_64 binaries can run on Apple Silicon via Rosetta 2 is not relevant; MacPorts base already knows this and allows the port to be installed on Apple Silicon even when it says supported_archs x86_64.

More information about the macports-dev mailing list