简体   繁体   English

如何使用 GHC/stack 在 macOS 上创建本机 ARM 可执行文件

[英]How to create native ARM executables on macOS using GHC/stack

GHC now ( since 8.10.5 ) supports producing ARM code on macOS. GHC 现在( 自 8.10.5 起)支持在 macOS 上生成 ARM 代码。

What flags or options in GHC or Stack do I need to use in order for it to produce ARM executables?我需要使用 GHC 或 Stack 中的哪些标志或选项才能生成 ARM 可执行文件?

Context: I have an Apple silicon Mac.上下文:我有一台 Apple Silicon Mac。 It can run x86_64 code via Rosetta but it can also run native ARM code.它可以通过 Rosetta 运行x86_64代码,但也可以运行本机 ARM 代码。

I will avoid discussing cross-compilation, since I don't think it is necessary.我将避免讨论交叉编译,因为我认为没有必要。

For versions below GHC 9.2, you need to pass -fllvm in ghc-options .对于 GHC 9.2 以下的版本,您需要在ghc-options中传递-fllvm This is because GHC didn't include a Native Code Generator for the M1 yet.这是因为 GHC 还没有包含 M1 的本机代码生成器。 The Stack guide has a section on using ghc-options . Stack 指南中有一节是关于使用 ghc-options 的 You can set them globally, or you can set them for a narrower scope. You can try stack repl --resolver lts-19.1 --ghc-options -fllvm in your project to see if its dependencies are compatible with GHC 9.0.2, which is what LTS 19.1 uses.你可以全局设置,也可以设置为更窄的scope。你可以在你的项目中尝试stack repl --resolver lts-19.1 --ghc-options -fllvm看看它的依赖是否兼容GHC 9.0.2,这就是 LTS 19.1 使用的。

For versions GHC 9.2+, GHC has a Native Code Generator such that it can compile for the M1 without LLVM.对于 GHC 9.2+ 版本,GHC 有一个本地代码生成器,因此它可以在没有 LLVM 的情况下为 M1 编译。 This should just work, with no need to pass any special ghc-options .这应该可以正常工作,不需要传递任何特殊ghc-options

Make sure you are using Stack v2.7.5+, because this version added support for installing GHC on macOS aarch64 (which is what the M1 is).确保您使用的是 Stack v2.7.5+,因为此版本添加了对在 macOS aarch64(M1 就是这样)上安装 GHC 的支持。 See the changelog .请参阅变更日志 You can upgrade Stack using stack upgrade .您可以使用stack upgrade升级 Stack。

Stack v2.7.5 hasn't been tested with versions above GHC 9.0 though, so you may want to use Cabal instead, if you choose to use GHC 9.2+. Stack v2.7.5 尚未在 GHC 9.0 以上的版本中进行过测试,因此如果您选择使用 GHC 9.2+,则可能需要使用 Cabal。 See this snippet:看到这个片段:

$ stack repl --compiler ghc-9.2.2
Stack has not been tested with GHC versions above 9.0, and using 9.2.2, this may fail

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 MacOS 12.0.1 上安装 protobuf 错误:C 编译器无法创建可执行文件 - install protobuf on MacOS 12.0.1 error: C compiler cannot create executables macos-如何告诉cabal / ghc在/ opt中查找库/包含文件? - macos - how to tell cabal/ghc to look in /opt for libraries/include files? 如何在 MacOS 上的 NodeJS 本机插件上创建 OpenGL 上下文? - How to create an OpenGL context on an NodeJS native addon on MacOS? 在 ARM macOS 上,当显式 raise()-ing 信号时,一些返回地址在堆栈中出现乱码 - On ARM macOS when explicitly raise()-ing a signal, some return addresses are garbled on the stack 使用 MacOS clang 汇编程序交叉汇编 Linux Arm64 - Cross assemble Linux Arm64 using MacOS clang assembler macOS如何为进程分配堆栈和堆? - How does macOS allocate stack and heap for a process? 如何在 macOS 上的堆栈跟踪中显示行号? - How to display line numbers in stack traces on macOS? 如何在 MacOS 中使用终端创建动态(可增长)DMG 文件 - How create dynamic (growable) DMG file using terminal in MacOS 如何使用 VBA for Excel for MacOS 创建文本文件 - How to create text file using VBA for Excel for MacOS 如何在 Windows 上使用 VS 创建 MacOS 控制台应用程序 - How to create a MacOS Console App using VS on Windows
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM