Distributing a Haskell program on Homebrew
Asked Answered
L

2

6

I'm writing a program in Haskell on my Mac (command line executable, not an app). I'm using GitHub to host the git repository and homepage. I made the <project>.cabal and Setup.hs files since Cabal makes it easy to build, test and generate documentation. I might also upload to Hackage, I don't know.

When I tag version 1.0, I want to make a Homebrew formula to download the tarball from GitHub and build it. I want the only dependency to be GHC.

I will use runhaskell Setup configure/build/install (with the prefix as /usr/local/Cellar/…) rather than the cabal command to avoid depending on cabal-install.

This is all fine until I start using packages from Hackage, e.g. blaze-builder and aeson. How should I manage this?

I don't want to force non-Haskellers to have to download the whole Haskell platform. Ideally, people should be able to just let Homebrew install GHC before it builds my program, and then if they so choose, remove GHC after. If I make the Haskell platform a dependency and first install my Haskell dependencies through cabal-install or similar,

  1. The ~/.cabal/ folder with the packages will be left behind, even if afterwards they
    brew uninstall haskell-platform
  2. I might as well only be going through Hackage and making people cabal install it, i.e. limit the scope for the most part to Haskellers.

I see Cabal(-install) + Hackage as a useful tool for development and for Haskellers but not appropriate for this.

Should I just download the source of the packages I'm using and include it in my source tree, adding it to the build command as well? Or should I be using the --package-db option (found here)? Or could my formula download the tarball for the package on the fly and build it too?

I looked at cabal2arch a bit (Arch wiki, GitHub repo) but I'm not sure how it handles dependencies, or if it's just doing what I don't want to do.

Lutes answered 22/7, 2012 at 20:37 Comment(7)
Wouldn't it be easier to distribute a binary so non Haskeleers don't need to build it. There is a packager mentioned on Haskell wiki Haskellers can build from source using cabal.Stanleigh
The link you mentioned is for app bundles—my program is a command line tool. It would be easier, yes, but I really like homebrew as a package manager and it likes to build everything from source (see the "Why are you compiling everything?" section in github.com/mxcl/homebrew/wiki/FAQ). You can use "bottles" with homebrew but that is really for things which take hours to build (like Qt), and you can't host the binary just anywhere.Lutes
But most users don't have homebrew and surely easier for users to download a simple binary for the compiled program rather than a package manager. If you must use a manager try macports and make your code a port then macports will build it centrally and users download prebuilt binaries.Stanleigh
I don't really like macports, and if I distributed a binary I don't know where I would host it. I just wanted to provide a convenient one liner for people who use homebrew, and the only barrier to me doing that is figuring out how to handle the hackage dependencies. This isn't so much a practical question of distribution as it is, how do I do this specific thing?Lutes
Is there no way to make a homebrew formula for blaze-builder, aeson, etc. and add them as dependencies?Ebby
Well, they're libraries, so I'm not sure how I would do that… They would have to be registered with GHC via ghc-pkg, and Homebrew has no uninstall hooks AFAIK which would allow unregistering them. But maybe that would work.Lutes
You could compile GHC and cabal to a specific directory, and let cabal reside somewhere where you can manage it. Then you proceed with a cabal-dev install of your package and copy the executable to where you want it in the Homebrew bin directory. Then you remove the GHC and cabal sources/build directory. But I think that's rather circuitous. If you want people to compile from source they should have the necessary infrastructure already, so require a GHC/Cabal install. I'm not sure what the Homebrew policy is for this though.Ickes
A
1

In my opinion, if you decide to go with a package manager, you should make sure all dependencies can be built or are readily available in some other way. If you are only relying on GHC and its core set of libraries, there should be no need for the entire platform to be built alongside.

However, if you wish to build from source (which, IMO is a good idea in numerous, but not all) cases, then building all dependencies is something you have to live with. We do the same for our build system [1] we use in an HPC environment for deploying scientific software on our supercomputers. But it does come at a cost. Bootstrapping such a system can require quite some time, since you want the entire toolchain and all required libraries to be present.

In fact, as we speak, I am putting support in our build system for GHC and haskell packages, and yes, dependencies will be pulled in as well, if needed. At the very least, I'll make sure we can deploy cabal such that our users can install Haskell stuff on their accounts if they desire.

TL;DR Add support for dependencies.

[1] http://hpcugent.github.com/easybuild

Amphictyony answered 7/2, 2013 at 9:24 Comment(0)
E
0

Hledger is a Haskell program and it can be installed just using homebrew. You can take a look here in the formula file:

https://github.com/Homebrew/homebrew-core/blob/master/Formula/hledger.rb

As you can see in the file, they are some dependencies included ghc and cabal-install.

Elconin answered 5/2, 2018 at 18:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.