Anybody here using rules_haskell in Bazel as a build system?

I’ve recently had the need to build C libraries and Haskell software (and then link them). It’s possible albeit annoying to get coworkers up to speed, as they need to build a C library and install it in a global location (e.g. /usr/local/lib), and THEN build the Haskell software.

Looks like Bazel is a polyglot built system with support for Haskell via rules_haskell, and I’m wondering if it would be worth the time/effort to port to Bazel.

Has anyone here used Bazel to build Haskell programs + libraries in other languages?

I test drove it for a couple of weeks together with rules_nixpkgs, it worked fine but I abandoned the approach because I would get weird issues with bazel and it was a time sink. For your particular problem, have you considered providing the C package via nix

2 Likes

I haven’t considered nix at all because I need to develop on Windows sometimes.

I’ll keep our current workflow for now then. When I don’t have a restriction to develop on Windows, I can revisit this. Thanks!

Hi @LaurentRDC,

I am working on rules_haskell, and yes we (Tweag’s Scalable Builds group) do have experience using Bazel and Haskell + X :smiley:

To get an idea how to integrate C and Haskell with Bazel, you could have a look at the quickstart example. If you have a bazel binary in PATH, just run curl https://haskell.build/start | sh. This project builds a C library (zlib) and uses it to build the zlib Haskell package which is used as a dependency of a binary.

Whether it’s worth the time / effort to migrate to Bazel (or some other polyglot build system) depends on different factors. DM me if you want to have a chat about that or to arrange a call where we can learn more about your use case and give you some guidance.

3 Likes

I’ll have a look at the example - - looks very similar to what we’re doing.

Reading more about Bazel tells me that it’s worth checking out at least a little bit more. I’ll be sure to reach out if I have any questions

1 Like

We’re using Blaze for the Haskell training at Google making use of the internal infrastructure developed some years ago. But there’s no official Haskell project so the infrastructure is stale. Recently we tried to migrate to using rules_haskell but it didn’t fit with a bunch of the internal assumptions.

However, maybe I should try and update the training course to actually support Bazel in OSS too. That is, try and make the Makefile support Bazel too, not only Stack / Cabal

Cabal supports pkg-config, which is already a compatibility layer that lets you specify a C dependency by name, and have it get included and linked across distributions. If the pkg-config dependency is missing, you’ll get an error message that it couldn’t find the dependency, and it is straightforward to find the name of the package that provides the library and header files.

Ask yourself whether you really want to start using a niche build system by a company that is known for abandoning its projects. You’re only saving a single line of code like apt install zlib1g-dev, but you’re taking on hundreds thousands of lines by adding a new build system. This argument also partly works for Nix.

My experience testing out Bazel for Haskell is that it has really bad ergonomics and failure modes. It’s the same as Nix in that regard. Based on that experience, I haven’t explored further, despite the possible benefits.

2 Likes