Cabal packages
Bazel

Cabal packages


stack_snapshot

stack_snapshot(stack, extra_deps, vendored_packages, **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 extra_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. Additionally, the dependency graph is made available within packages.bzl as the dict packages mapping unversioned package names to structs holding the fields

  • name: The unversioned package name.
  • version: The package version.
  • deps: The list of package dependencies according to stack.
  • flags: The list of Cabal flags.

Attributes

stack

Unknown; Optional

The stack binary to use to enumerate package dependencies.

extra_deps

Unknown; Optional

Extra dependencies of packages, e.g. system libraries or C/C++ libraries.

vendored_packages

Unknown; Optional

Add or override a package to the snapshot with a custom unpacked source distribution. Each package must contain a Cabal file named &lt;package-name&gt;.cabal in the package root.

**kwargs

Unknown; Optional

Examples

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

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

Alternatively

stack_snapshot(
    name = "stackage",
    packages = ["conduit", "lens", "zlib"],
    flags = {"zlib": ["-non-blocking-ffi"]},
    tools = ["@happy//:happy", "@c2hs//:c2hs"],
    local_Snapshot = "//:snapshot.yaml",
    extra_deps = {"zlib": ["@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, flags, 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 []

flags

List of strings; Optional; Default is []

List of Cabal flags, will be passed to Setup.hs configure --flags=....

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, flags, 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 []

flags

List of strings; Optional; Default is []

List of Cabal flags, will be passed to Setup.hs configure --flags=....

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"],
)