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:
- Download a stack binary for your architecture. Unpack it and copy it, for example, to
- Now, execute the following shell commands:
$ cd my-project.hsproj $ stack setup --no-system-ghc $ 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. A previous article describes how to do that.