Cabal packages
Bazel

Cabal packages


stack_snapshot

stack_snapshot(stack, **kwargs)

Use Stack to download and extract Cabal source distributions.

This rule will use Stack to compute the transitive closure of the subset of the given snapshot listed in the packages attribute, and generate a dependency graph. If a package in the closure depends on system libraries or other external libraries, use the deps attribute to list them. This attribute works like the --extra-{include,lib}-dirs flags for Stack and cabal-install do.

Packages that are in the snapshot need not have their versions specified. But any additional packages or version overrides will have to be specified with a package identifier of the form <package>-<version> in the packages attribute.

In the external repository defined by the rule, all given packages are available as top-level targets named after each package.

Attributes

stack

Unknown; Optional

The stack binary to use to enumerate package dependencies.

**kwargs

Unknown; Optional

Examples

stack_snapshot(
    name = "stackage",
    packages = ["conduit", "lens", "zlib-0.6.2"],
    tools = ["@happy//:happy", "@c2hs//:c2hs"],
    snapshot = "lts-13.15",
    deps = ["@zlib.dev//:zlib"],
)

defines @stackage//:conduit, @stackage//:lens, @stackage//:zlib library targets.

Alternatively

stack_snapshot(
    name = "stackage",
    packages = ["conduit", "lens", "zlib"],
    tools = ["@happy//:happy", "@c2hs//:c2hs"],
    local_Snapshot = "//:snapshot.yaml",
    deps = ["@zlib.dev//:zlib"],

Does the same as the previous example, provided there is a snapshot.yaml, at the root of the repository with content

resolver: lts-13.15

packages:
  - zlib-0.6.2

haskell_cabal_binary

haskell_cabal_binary(name, deps, srcs, tools)

Use Cabal to build a binary.

This rule assumes that the .cabal file defines a single executable with the same name as the package.

This rule does not use cabal-install. It calls the package's Setup.hs script directly if one exists, or the default one if not. All sources files that would have been part of a Cabal sdist need to be listed in srcs (crucially, including the .cabal file).

Attributes

name

Name; Required

A unique name for this rule.

deps

List of labels; Optional; Default is []

srcs

List of labels; Optional; Default is []

tools

List of labels; Optional; Default is []

Tool dependencies. They are built using the host configuration, since the tools are executed as part of the build.

Examples

haskell_cabal_binary(
    name = "happy",
    srcs = glob(["**"]),
)

haskell_cabal_library

haskell_cabal_library(name, deps, srcs, package_name, tools, version)

Use Cabal to build a library.

This rule does not use cabal-install. It calls the package's Setup.hs script directly if one exists, or the default one if not. All sources files that would have been part of a Cabal sdist need to be listed in srcs (crucially, including the .cabal file). A haskell_cabal_library can be substituted for any haskell_library. The two are interchangeable in most contexts. However, using a plain haskell_library sometimes leads to better build times, and does not require drafting a .cabal file.

Attributes

name

Name; Required

A unique name for this rule.

deps

List of labels; Optional; Default is []

srcs

List of labels; Optional; Default is []

package_name

String; Optional; Default is ''

Cabal package name. Defaults to name attribute.

tools

List of labels; Optional; Default is []

Tool dependencies. They are built using the host configuration, since the tools are executed as part of the build.

version

String; Required

Version of the Cabal package.

Examples

haskell_cabal_library(
    name = "lib-0.1.0.0",
    srcs = ["lib.cabal", "Lib.hs", "Setup.hs"],
)

haskell_toolchain_library(name = "base")

haskell_binary(
    name = "bin",
    deps = [":base", ":lib-0.1.0.0"],
    srcs = ["Main.hs"],
)