tweag/rules_haskell

Name: rules_haskell

Owner: Tweag I/O

Description: Haskell rules for Bazel.

Created: 2017-11-06 08:50:01.0

Updated: 2018-05-24 15:41:31.0

Pushed: 2018-05-24 15:41:33.0

Homepage: null

Size: 604

Language: Python

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Haskell rules for Bazel

CircleCI

Bazel automates building and testing software. It scales to very large multi-language projects. This project extends Bazel with build rules for Haskell. Get started building your own project using these rules wih the setup script below.

Rule summary

The full reference documentation for rules is at https://haskell.build.

WORKSPACE rules:

| Rule | Description | | —: | :— | | haskell_repositories | Declare external repositories needed for rules_haskell | | ghc_bindist | Setup a binary distribution of GHC |

BUILD rules:

| Rule | Description | | —: | :— | | haskell_library | Build a library from Haskell source. | | haskell_binary | Build an executable from Haskell source. | | haskell_test | Run a test suite. | | haskell_doc | Create API documentation. | | haskell_toolchain | Declare a compiler toolchain. | | haskell_cc_import | Import a prebuilt shared library. | | cc_haskell_import | Expose all transitive shared object libraries for haskell dependency. |

Setup

You'll need Bazel >= 0.8.1 installed.

The easy way

In a fresh directory, run:

rl https://haskell.build/start | sh

This will generate initial WORKSPACE and BUILD files for you. See the examples and the API reference below to adapt these for you project. Then,

zel build //...    # Build all targets
zel test //...     # Run all tests

You can learn more about Bazel's command line syntax here. Common commands are build, test, run and coverage.

Doing it manually

Add the following to your WORKSPACE file, and select a $VERSION (or even an arbitrary commit hash) accordingly.

_archive(
me = "io_tweag_rules_haskell",
rip_prefix = "rules_haskell-$VERSION",
ls = ["https://github.com/tweag/rules_haskell/archive/v$VERSION.tar.gz"],


("@io_tweag_rules_haskell//haskell:repositories.bzl", "haskell_repositories")
ell_repositories()

ster_toolchains("//:ghc")

Then, add this to your root BUILD file:

("@io_tweag_rules_haskell//haskell:haskell.bzl",
askell_toolchain",


ell_toolchain(
me = "ghc",
rsion = "8.2.2",
ols = "@my_ghc//:bin",

The haskell_toolchain rule instantiation brings a GHC compiler in scope. It assumes that an external repository called @my_ghc was defined, pointing to an installation of GHC. The recommended option is to provision GHC using Nix, but you can also point to an existing local installation somewhere in your filesystem. Using Nix, this is done by adding the following to your WORKSPACE file:

kgs_package(
me = "my_ghc",
tribute_path = "haskell.compiler.ghc822"

Alternatively, you can point to an existing global installation:

local_repository(
me = "my_ghc",
th = "/usr/local", # Change path accordingly.
ild_file_content = """
age(default_visibility = ["//visibility:public"])
group (name = "bin", srcs = glob(["bin/ghc*"]))
"

Examples

See rules_haskell_examples for examples of using these rules.

For rules_haskell developers

To run the test suite for these rules, you'll need Nix installed. To build and run tests locally, execute:

zel test //...
Rules

See https://haskell.build for the reference documentation on provided rules. Using ./serve-docs.sh, you can also view this documentation locally.

Language interop

We may be supporting interop with other languages in one way or another. Please see languages listed below about how.

C/C++

C/C++ libraries can be specified as dependencies. Importing prebuilt libraries and exporting Haskell libraries as C/C++ dependencies currently requires the haskell_cc_import and cc_haskell_import rules. These are temporary workarounds to Bazel limitations.

Java

You can supply java_* rule targets in deps of haskell_binary and haskell_library. This will make jars produced by those dependencies available during Haskell source compilation phase (i.e. not during linking &c. but it's subject to change) and set the CLASSPATH for that phase as well.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.