summaryrefslogtreecommitdiff
path: root/build_defs.bzl
diff options
context:
space:
mode:
Diffstat (limited to 'build_defs.bzl')
-rw-r--r--build_defs.bzl52
1 files changed, 45 insertions, 7 deletions
diff --git a/build_defs.bzl b/build_defs.bzl
index 6cf387e..fe52d9b 100644
--- a/build_defs.bzl
+++ b/build_defs.bzl
@@ -233,7 +233,7 @@ def _remove_up(string):
return _remove_suffix(string, ".proto")
-def _upb_proto_library_srcs_impl(ctx):
+def _upb_proto_srcs_impl(ctx, suffix):
sources = []
outs = []
include_dirs = {}
@@ -241,10 +241,12 @@ def _upb_proto_library_srcs_impl(ctx):
if hasattr(dep, "proto"):
for src in dep.proto.transitive_sources:
sources.append(src)
- include_dirs[_remove_suffix(src.path, _remove_up(src.short_path) + "." + src.extension)] = True
- outs.append(ctx.actions.declare_file(_remove_up(src.short_path) + ".upb.h"))
- outs.append(ctx.actions.declare_file(_remove_up(src.short_path) + ".upb.c"))
- outdir = _remove_suffix(outs[-1].path, _remove_up(src.short_path) + ".upb.c")
+ include_dir = _remove_suffix(src.path, _remove_up(src.short_path) + "." + src.extension)
+ if include_dir:
+ include_dirs[include_dir] = True
+ outs.append(ctx.actions.declare_file(_remove_up(src.short_path) + suffix + ".h"))
+ outs.append(ctx.actions.declare_file(_remove_up(src.short_path) + suffix + ".c"))
+ outdir = _remove_suffix(outs[-1].path, _remove_up(src.short_path) + suffix + ".c")
source_paths = [d.path for d in sources]
include_args = ["-I" + root for root in include_dirs.keys()]
@@ -259,6 +261,12 @@ def _upb_proto_library_srcs_impl(ctx):
return [DefaultInfo(files = depset(outs))]
+def _upb_proto_library_srcs_impl(ctx):
+ return _upb_proto_srcs_impl(ctx, ".upb")
+
+def _upb_proto_reflection_library_srcs_impl(ctx):
+ return _upb_proto_srcs_impl(ctx, ".upbdefs")
+
_upb_proto_library_srcs = rule(
implementation = _upb_proto_library_srcs_impl,
attrs = {
@@ -269,10 +277,10 @@ _upb_proto_library_srcs = rule(
"protoc": attr.label(
executable = True,
cfg = "host",
- default = "@com_google_protobuf//:protoc",
+ default = map_dep("@com_google_protobuf//:protoc"),
),
"deps": attr.label_list(),
- }
+ },
)
def upb_proto_library(name, deps, upbc):
@@ -289,6 +297,36 @@ def upb_proto_library(name, deps, upbc):
copts = ["-Ibazel-out/k8-fastbuild/bin"],
)
+_upb_proto_reflection_library_srcs = rule(
+ implementation = _upb_proto_reflection_library_srcs_impl,
+ attrs = {
+ "upbc": attr.label(
+ executable = True,
+ cfg = "host",
+ ),
+ "protoc": attr.label(
+ executable = True,
+ cfg = "host",
+ default = map_dep("@com_google_protobuf//:protoc"),
+ ),
+ "deps": attr.label_list(),
+ },
+)
+
+def upb_proto_reflection_library(name, deps, upbc):
+ srcs_rule = name + "_defsrcs.cc"
+ _upb_proto_reflection_library_srcs(
+ name = srcs_rule,
+ upbc = upbc,
+ deps = deps,
+ )
+ native.cc_library(
+ name = name,
+ srcs = [":" + srcs_rule],
+ deps = [":upb"],
+ copts = ["-Ibazel-out/k8-fastbuild/bin"],
+ )
+
def licenses(*args):
# No-op (for Google-internal usage).
pass
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback