Skip to content

Latest commit

 

History

History
241 lines (168 loc) · 7.54 KB

File metadata and controls

241 lines (168 loc) · 7.54 KB

Protobuf

Guide

Reference

Starlark reference

Install

WORKSPACE.bazel

PROTO_VERSION = "7e4afce6fe62dbff0a4a03450143146f9f2d7488"
http_archive(
    name = "rules_proto",
    sha256 = "8e7d59a5b12b233be5652e3d29f42fba01c7cbab09f6b3a8d0a57ed6d1e9a0da",
    strip_prefix = "rules_proto-%s" % PROTO_VERSION,
    urls = ["https://github.com/bazelbuild/rules_proto/archive/%s.tar.gz" % PROTO_VERSION],
)
load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies", "rules_proto_toolchains")
rules_proto_dependencies()
rules_proto_toolchains()

PROTO_GRPC_VERSION = "2.0.0"
http_archive(
    name = "rules_proto_grpc",
    urls = ["https://github.com/rules-proto-grpc/rules_proto_grpc/archive/%s.tar.gz" % PROTO_GRPC_VERSION],
    sha256 = "d771584bbff98698e7cb3cb31c132ee206a972569f4dc8b65acbdd934d156b33",
    strip_prefix = "rules_proto_grpc-%s" % PROTO_GRPC_VERSION,
)
load("@rules_proto_grpc//:repositories.bzl", "rules_proto_grpc_toolchains", "rules_proto_grpc_repos")
rules_proto_grpc_toolchains()
rules_proto_grpc_repos()

Add google-protobuf as an external dependency.

Configure

BUILD.bazel

load("@better_rules_javascript//protobuf:rules.bzl", "js_protoc")

package(default_visibility = ["//visibility:public"])

cjs_root(
    descriptor = "proto.package.json",
    name = "proto_root",
    package_name = "@better_rules_javascript_test/proto"
)

js_protoc(
    name = "js_protoc",
    root = ":proto_root",
    runtime = "@npm//google-protobuf:lib",
)

package.json

{}

rules.bzl

load("@better_rules_javascript//protobuf:aspects.bzl", "js_proto_aspect")
load("@better_rules_javascript//protobuf:rules.bzl", "js_proto_library_rule")

js_proto = js_proto_aspect("@better_rules_javascript_test//:lib_protoc")

js_proto_library = js_proto_library_rule(js_proto)

Use

load("@rules_proto//proto:defs.bzl", "proto_library")
load("//:rules.bzl", "js_proto_library")

proto_library(
    name = "proto",
    srcs = glob(["**/*.proto"]),
)

js_proto_library(
    name = "js",
    dep = ":proto",
)

//protobuf:aspects.bzl

js_proto_aspect

js_proto_aspect(js_protoc)

Create js_proto aspect.

PARAMETERS

Name Description Default Value
js_protoc JsProtobuf label none

//protobuf:providers.bzl

JsProtoInfo

JsProtoInfo(transitive_libs)

FIELDS

Name Description
transitive_libs Transitive library structs

JsProtobuf

JsProtobuf(runtime)

FIELDS

Name Description
runtime Runtime dependencies

create_lib

create_lib(label, path, deps, js, js_deps)
Create library struct

PARAMETERS

Name Description Default Value
label Label none
path Directory path none
deps Labels of dependencies none
js List of declaration files none
js_deps

-

none

//protobuf:rules.bzl

js_proto_export

js_proto_export(name, dep, lib)

JavaScript protobuf library

ATTRIBUTES

Name Description Type Mandatory Default
name A unique name for this target. Name required
dep - Label optional None
lib - Label optional None

js_protoc

js_protoc(name, runtime)

JavaScript protobuf tools

ATTRIBUTES

Name Description Type Mandatory Default
name A unique name for this target. Name required
runtime Runtime dependencies Label optional None

js_proto_libraries_rule

js_proto_libraries_rule(js_proto)
Create js_proto_library rule.

PARAMETERS

Name Description Default Value
js_proto Aspect none