Support for protocol buffers
Bazel

Support for protocol buffers


haskell_proto_toolchain

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

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).

Attributes

name

Name; Required

A unique name for this rule.

plugin

Unknown; Required

deps

List of strings; Optional

prebuilt_deps

List of strings; Optional

protoc

Unknown; Optional

Examples

In a BUILD file:

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

The prebuilt_deps and deps arguments allow to specify Haskell libraries to use to compile 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",
)

haskell_proto_library

haskell_proto_library(name, deps)

Generate Haskell library allowing to use protobuf definitions with help of proto-lens.

haskell_proto_library targets require haskell_proto_toolchain to be registered.

Attributes

name

Name; Required

A unique name for this rule.

deps

List of labels; Required

List of proto_library targets to use for generation.

Examples

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

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