Haskell 项目可以使用 cmake 吗?
我正在计划一个用 Haskell 编写的项目,也许也有一些部分是用 C 编写的。对于构建系统,我决定不选择 Haskell 程序 cabal 的常见选择,主要是因为我想了解其他语言的构建程序是如何工作的。
我听说过 CMake,我认为这是一个非常酷的产品。虽然我不知道如何使用它,但我想在该项目中使用 CMake,只是为了了解它是如何工作的。谷歌搜索没有透露任何有关如何将 cmake 与 haskell 结合使用的事实,而且我读到的所有教程都相当令人困惑。是否可能,如果可以,如何可能使用 CMake 编译用 Haskell 编写的项目?
I am planning a project written in Haskell, maybe there are some parts in C as well. For the buildsystem I decided against the common choice for Haskell programs cabal, mainly because I want to learn how building programs in other languages works.
I heard about CMake and I think it is a pretty cool product. Although I have no knowledge in how to use it, I want to use CMake for that project, just to find out how it works. Googleing did not reveal any facts about how to use cmake with haskell, and all tutorials I read were rather confusing. Is it possible, and if yes, how is it possible, to compile a project written in Haskell using CMake?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您当然可以使用 CMake 来构建 Haskell 应用程序和库。为此,您需要复制 Cabal 所做的大部分工作,这很有启发性,但也很耗时。
我建议使用 cabal build -v 来查看 Cabal 发出的命令,然后将它们转录为 CMake 形式。
或者,使用 CMake 在 Haskell 代码上调用 cabal ——这可能不会那么烦人。
You can certainly use CMake to build Haskell applications and libraries. To do so, you will need to duplicate much of what Cabal does, which will be instructive, but also time consuming.
I'd recommend using
cabal build -v
to see the commands emitted by Cabal, and then transcribing them into CMake form.Or, use CMake to call cabal on the Haskell code -- that's likely to be less annoying.
我已经为 cabal 包编写了简单的 cmake 包装器并将其放在这里:
http://bitbucket.org/arrowd /cmake-findcabal(使用“获取源”按钮下载)。
目前它可以在 Windows 和 FreeBSD 上运行,但我仍然计划稍后改进它。我已将其放入此处的答案,以便人们可以像我一样在谷歌中找到它。
I've written simple cmake wrapper for cabal packages and put it here:
http://bitbucket.org/arrowd/cmake-findcabal (use "get source" button to download it).
For now it's working for me on Windows and FreeBSD, but i still plan to improve it later. I've put this into answer here so people can find it in google, as did i.
虽然您当然可以使用通用构建工具直接构建 Haskell 代码,但结果是更难以维护,更难以与社区共享,并且更难在其上构建。建立在 Cabal 之上。
我理解这句话背后的意图,因为你想看到构建过程的所有单独步骤,但从另一种角度来看,通过避免阴谋,你不会看到 Haskell 中的程序是如何构建的,你会看到它是多么痛苦就是重建社区提供的工具。
我建议按照唐的建议去做。查看
cabal -v
的输出,以便在特定编译器(可能是 ghc)下进行构建并在 CMake 中复制这些步骤。但是,一旦你理解了这些步骤,我就会认真考虑利用这些知识并回到 Cabal。如果只是让它处理支持多个编译器、平台、包管理等问题。从而减少构建系统的脆弱性,并使其更容易打包和共享您的工作。
也就是说,除了 ghc 本身之外,我想不出有哪个非 Cabal 构建的软件包或二进制文件被社区积极使用。
不过,我确实祝您在构建过程的核心之旅中一切顺利!
While you certainly can build Haskell code directly by using a general purpose build tool, the result is much more difficult to maintain, much more difficult to share with the community and harder to build on top of than when you build on top of Cabal.
I understand the intention behind this statement in that you want to see all of the individual steps of the build process, but read another way, by avoiding cabal, you aren't seeing how programs in Haskell are built, you are seeing how painful it is to rebuild the tools provided by the community.
I would recommend doing what Don proposed. Look at the output of
cabal -v
for building under your particular compiler (probably ghc) and replicating those steps in CMake.But then, once you understand the steps, I'd seriously consider taking that knowledge and moving back to Cabal. If only to let it deal with the issues of supporting multiple compilers, platforms, package management, etc. Thereby reducing the fragility of your build system, and making it easier to package up and share your work.
To wit, I can't think of a single non-Cabal-built package or binary in active use by the community other than ghc itself.
I do, however, wish you luck on your journey into the bowels of the build process!
我重写了 @arrowdodger 的初始工作,在此过程中修复了一些存在的错误:
cmake/
目录中使用。存储库可以在以下位置找到:
https://github.com/kvanberendonck/cmake-haskell
对我来说工作得很好,而且构建速度我能够摆脱
ninja
是非常令人印象深刻的。I've rewritten @arrowdodger's initial work, in the process fixing a couple bugs that were present:
cmake/
directory because of hardcoded pathsThe repository can be found at:
https://github.com/kvanberendonck/cmake-haskell
Working beautifully for me, and the build speed I can get out of
ninja
is extremely impressive.