Deploying Haskell for Mac projects on OS X and Linux

A nice property of the Haskell ecosystem is that most code is quite easily portable between OS X and Linux (and often even Windows) — assuming you write a command line or server application. This raises the question of how to build a Haskell for Mac project, such that you can deploy it to machines that do not have a Haskell installation. Due to the Stack tool
integration of Haskell for Mac, that is quite simple.

Let’s suppose, your Haskell for Mac project is my-project.hsproj
and you want to build an executable that has all Haskell libraries statically linked, so that it is independent of any Haskell installation. We achieve this in two steps:

  1. Download a stack binary
    for your architecture. Unpack it and copy it, for example, to /usr/local/bin
  2. Now, execute the following shell commands:
$ cd my-project.hsproj
$ stack setup
$ stack build

Stack will print the location of the final executable at the end of the build process. (Alternatively, you can pass the --local-bin-path DIR
option to the last command if you want to specify an alternative location.)

This build procedure is independent of any pre-existing Haskell toolchain on the build machine and the deployment host. However, on Linux, be aware that only Haskell libraries will be statically linked. The resulting executable will still have dependencies on system libraries; hence, to minimize hassle, make sure that the build machine and deployment host use the same Linux system.

If you like to try this for yourself, just grab our command line sample project, SHA1.hsproj
, and take it for a spin.

Before you can deploy your command line or server application, you will have to test it. Aprevious article describes how to do that.

稿源:Haskell for Mac (源链) | 关于 | 阅读提示

本站遵循[CC BY-NC-SA 4.0]。如您有版权、意见投诉等问题,请通过eMail联系我们处理。
酷辣虫 » 综合编程 » Deploying Haskell for Mac projects on OS X and Linux

喜欢 (0)or分享给?

专业 x 专注 x 聚合 x 分享 CC BY-NC-SA 4.0

使用声明 | 英豪名录