Core Haskell rules
Bazel

Core Haskell rules


haskell_binary

haskell_binary(name, deps, data, srcs, compiler_flags, extra_srcs, generate_so, linkstatic, main_file, main_function, prebuilt_dependencies, repl_ghci_args, src_strip_prefix, version)

Build an executable from Haskell source.

Every haskell_binary target also defines an optional REPL target that is not built by default, but can be built on request. The name of the REPL target is the same as the name of binary with "@repl" added at the end. For example, the target above also defines [email protected].

You can call the REPL like this (requires Bazel 0.15 or later):

$ bazel run //:[email protected]

Attributes

name

Name; Required

A unique name for this rule.

deps

List of labels; Optional; Default is []

List of other Haskell libraries to be linked to this target.

data

List of labels; Optional; Default is []

See Bazel documentation.

srcs

List of labels; Optional; Default is []

Haskell source files.

compiler_flags

List of strings; Optional; Default is []

Flags to pass to Haskell compiler.

extra_srcs

List of labels; Optional; Default is []

Extra (non-Haskell) source files that will be needed at compile time (e.g. by Template Haskell).

generate_so

Boolean; Optional; Default is False

Whether to generate also a .so version of executable.

linkstatic

Boolean; Optional; Default is False

If enabled, this option tells GHC to link statically whenever possible. While this captures all Haskell code built, some system libraries may still be linked dynamically, as are libraries for which there is no static library. So the resulting executable will still be dynamically linked, hence only mostly static.

main_file

Label; Optional

File containing Main module (deprecated).

main_function

String; Optional; Default is 'Main.main'

A function with type IO _, either the qualified name of a function from any module or the bare name of a function from a Main module. It is also possible to give the qualified name of any module exposing a main function.

prebuilt_dependencies

List of strings; Optional; Default is []

Non-Bazel supplied Cabal dependencies (deprecated).

repl_ghci_args

List of strings; Optional; Default is []

Arbitrary extra arguments to pass to GHCi. This extends compiler_flags and repl_ghci_args from the toolchain

src_strip_prefix

String; Optional; Default is ''

Directory in which module hierarchy starts.

version

String; Optional; Default is ''

Executable version. If this is specified, CPP version macros will be generated for this build.

Examples

haskell_binary(
    name = "hello",
    srcs = ["Main.hs", "Other.hs"],
    deps = ["//lib:some_lib"]
)

haskell_import

haskell_import(name, package)

Import packages that are prebuilt outside of Bazel.

Use this rule to make dependencies that are prebuilt (supplied as part of the compiler toolchain or elsewhere in the environment) available as targets.

Often, targets of this type will be generated automatically by frameworks such as Hazel.

Attributes

name

Name; Required

A unique name for this rule.

package

String; Optional; Default is ''

A non-Bazel-supplied GHC package name. Defaults to the name of the rule.

Examples

haskell_import(
    name = "base_pkg",
    package = "base",
)

haskell_library(
    name = "hello-lib",
    srcs = ["Lib.hs"],
    deps = [
        ":base_pkg",
        "//hello-sublib:lib",
    ],
)

haskell_library

haskell_library(name, deps, data, srcs, compiler_flags, exports, extra_srcs, hidden_modules, prebuilt_dependencies, repl_ghci_args, src_strip_prefix, version)

Build a library from Haskell source.

Every haskell_library target also defines an optional REPL target that is not built by default, but can be built on request. It works the same way as for haskell_binary.

Attributes

name

Name; Required

A unique name for this rule.

deps

List of labels; Optional; Default is []

List of other Haskell libraries to be linked to this target.

data

List of labels; Optional; Default is []

See Bazel documentation.

srcs

List of labels; Optional; Default is []

Haskell source files.

compiler_flags

List of strings; Optional; Default is []

Flags to pass to Haskell compiler.

exports

Dictionary mapping labels to strings; Optional; Default is {}

A dictionary mapping dependencies to module reexports that should be available for import by dependencies.

extra_srcs

List of labels; Optional; Default is []

Extra (non-Haskell) source files that will be needed at compile time (e.g. by Template Haskell).

hidden_modules

List of strings; Optional; Default is []

Modules that should be unavailable for import by dependencies.

prebuilt_dependencies

List of strings; Optional; Default is []

Non-Bazel supplied Cabal dependencies (deprecated).

repl_ghci_args

List of strings; Optional; Default is []

Arbitrary extra arguments to pass to GHCi. This extends compiler_flags and repl_ghci_args from the toolchain

src_strip_prefix

String; Optional; Default is ''

Directory in which module hierarchy starts.

version

String; Optional; Default is ''

Library version. Not normally necessary unless to build a library originally defined as a Cabal package. If this is specified, CPP version macro will be generated.

Examples

haskell_library(
    name = "hello-lib",
    srcs = glob(["src/**/*.hs"]),
    src_strip_prefix = "src",
    deps = [
        "//hello-sublib:lib",
    ],
    exports = {
        "//hello-sublib:lib": "Lib1 as HelloLib1, Lib2",
    },
)

haskell_test

haskell_test(name, deps, data, srcs, compiler_flags, extra_srcs, generate_so, linkstatic, main_file, main_function, prebuilt_dependencies, repl_ghci_args, src_strip_prefix, version)

Build a test suite.

Additionally, it accepts all common bazel test rule fields. This allows you to influence things like timeout and resource allocation for the test.

Attributes

name

Name; Required

A unique name for this rule.

deps

List of labels; Optional; Default is []

List of other Haskell libraries to be linked to this target.

data

List of labels; Optional; Default is []

See Bazel documentation.

srcs

List of labels; Optional; Default is []

Haskell source files.

compiler_flags

List of strings; Optional; Default is []

Flags to pass to Haskell compiler.

extra_srcs

List of labels; Optional; Default is []

Extra (non-Haskell) source files that will be needed at compile time (e.g. by Template Haskell).

generate_so

Boolean; Optional; Default is False

Whether to generate also a .so version of executable.

linkstatic

Boolean; Optional; Default is False

If enabled, this option tells GHC to link statically whenever possible. While this captures all Haskell code built, some system libraries may still be linked dynamically, as are libraries for which there is no static library. So the resulting executable will still be dynamically linked, hence only mostly static.

main_file

Label; Optional

File containing Main module (deprecated).

main_function

String; Optional; Default is 'Main.main'

A function with type IO _, either the qualified name of a function from any module or the bare name of a function from a Main module. It is also possible to give the qualified name of any module exposing a main function.

prebuilt_dependencies

List of strings; Optional; Default is []

Non-Bazel supplied Cabal dependencies (deprecated).

repl_ghci_args

List of strings; Optional; Default is []

Arbitrary extra arguments to pass to GHCi. This extends compiler_flags and repl_ghci_args from the toolchain

src_strip_prefix

String; Optional; Default is ''

Directory in which module hierarchy starts.

version

String; Optional; Default is ''

Executable version. If this is specified, CPP version macros will be generated for this build.