blob: 478ab58fc471fa3faa780efd40cef92d792663bf [file] [log] [blame]
# Apache License, Version 2.0, January 2004, http://www.apache.org/licenses/
# Adapted from: https://github.com/rules-proto-grpc/rules_proto_grpc/
load("@rules_proto_grpc//internal:filter_files.bzl", "filter_files")
load("@rules_cc//cc:defs.bzl", "cc_library")
load(
"@rules_proto_grpc//:defs.bzl",
"ProtoPluginInfo",
"proto_compile_attrs",
"proto_compile_impl",
)
# Create compile rule
cc_nanopb_proto_compile = rule(
implementation = proto_compile_impl,
attrs = dict(
proto_compile_attrs,
_plugins = attr.label_list(
providers = [ProtoPluginInfo],
default = [
Label("@com_github_nanopb_nanopb//:nanopb_plugin"),
],
doc = "List of protoc plugins to apply",
),
),
toolchains = [str(Label("@rules_proto_grpc//protobuf:toolchain_type"))],
)
def cc_nanopb_proto_library(name, **kwargs): # buildifier: disable=function-docstring
# Compile protos
name_pb = name + "_pb"
cc_nanopb_proto_compile(
name = name_pb,
**{
k: v
for (k, v) in kwargs.items()
if k in proto_compile_attrs.keys()
} # Forward args
)
# Filter files to sources and headers
filter_files(
name = name_pb + "_srcs",
target = name_pb,
extensions = ["c"],
)
filter_files(
name = name_pb + "_hdrs",
target = name_pb,
extensions = ["h"],
)
# Create c library
cc_library(
name = name,
srcs = [name_pb + "_srcs"],
deps = PROTO_DEPS + kwargs.get("deps", []),
hdrs = [name_pb + "_hdrs"],
includes = [name_pb],
alwayslink = kwargs.get("alwayslink"),
copts = kwargs.get("copts"),
defines = kwargs.get("defines"),
include_prefix = kwargs.get("include_prefix"),
linkopts = kwargs.get("linkopts"),
linkstatic = kwargs.get("linkstatic"),
local_defines = kwargs.get("local_defines"),
nocopts = kwargs.get("nocopts"),
strip_include_prefix = kwargs.get("strip_include_prefix"),
visibility = kwargs.get("visibility"),
tags = kwargs.get("tags"),
)
PROTO_DEPS = [
"@com_github_nanopb_nanopb//:nanopb",
]