Support for protocol buffers
Bazel

Support for protocol buffers


haskell_proto_library

haskell_proto_library(name, deps)

Generate Haskell library allowing to use protobuf definitions.

Uses proto-lens.

Examples

proto_library(
  name = "foo_proto",
  srcs = ["foo.proto"],
)

haskell_proto_library(
  name = "foo_haskell_proto",
  deps = [":foo_proto"],
)

haskell_proto_library targets require haskell_proto_toolchain to be registered.

Attributes

name Name; required

A unique name for this target.

deps List of labels; required

List of proto_library targets to use for generation.


haskell_proto_toolchain

haskell_proto_toolchain(name, plugin, deps, protoc, kwargs)

Declare a Haskell protobuf toolchain.

You need at least one of these declared somewhere in your BUILD files for the haskell_proto_library rules to work. Once declared, you then need to register the toolchain using register_toolchains in your WORKSPACE file (see example below).

Examples

In a BUILD file:

haskell_proto_toolchain(
  name = "protobuf-toolchain",
  protoc = "@com_google_protobuf//:protoc",
  plugin = "@stackage-exe//proto-lens-protoc",
  deps = [
    "base",
    "bytestring",
    "containers",
    "data-default-class",
    "lens-family",
    "proto-lens",
    "text",
  ],
)

The deps attribute is for specifying Haskell libraries to use when compiling the auto-generated source files.

In WORKSPACE you could have something like this:

http_archive(
  name = "com_google_protobuf",
  sha256 = "cef7f1b5a7c5fba672bec2a319246e8feba471f04dcebfe362d55930ee7c1c30",
  strip_prefix = "protobuf-3.5.0",
  urls = ["https://github.com/google/protobuf/archive/v3.5.0.zip"],
)

nixpkgs_package(
  name = "protoc_gen_haskell",
  repository = "@nixpkgs",
  attribute_path = "haskell.packages.ghc822.proto-lens-protoc
)

register_toolchains(
  "//tests:ghc", # assuming you called your Haskell toolchain "ghc"
  "//tests:protobuf-toolchain",
)

Attributes

name required

A unique name for this toolchain.

plugin required

Proto-lens-protoc plugin for protoc.

deps optional; default is []

List of other Haskell libraries to be linked to protobuf libraries.

protoc optional; default is Label("@com_google_protobuf//:protoc")

Protoc compiler.

kwargs optional