summaryrefslogtreecommitdiff
path: root/build_defs.bzl
diff options
context:
space:
mode:
Diffstat (limited to 'build_defs.bzl')
-rw-r--r--build_defs.bzl89
1 files changed, 73 insertions, 16 deletions
diff --git a/build_defs.bzl b/build_defs.bzl
index 7445fce..fe52d9b 100644
--- a/build_defs.bzl
+++ b/build_defs.bzl
@@ -1,4 +1,3 @@
-
_shell_find_runfiles = """
# --- begin runfiles.bash initialization ---
# Copy-pasted from Bazel's Bash runfiles library (tools/bash/runfiles/runfiles.bash).
@@ -100,7 +99,7 @@ BASE=$(dirname $(rlocation upb/upb_c.so))
export LUA_CPATH="$BASE/?.so"
export LUA_PATH="$BASE/?.lua"
$(rlocation lua/lua) $(rlocation upb/tools/upbc.lua) "$@"
-"""
+""",
)
rule(
@@ -109,10 +108,10 @@ $(rlocation lua/lua) $(rlocation upb/tools/upbc.lua) "$@"
data = ["@lua//:lua", "@bazel_tools//tools/bash/runfiles", luamain] + luadeps,
)
-def lua_binary(name, luamain, luadeps=[]):
+def lua_binary(name, luamain, luadeps = []):
_lua_binary_or_test(name, luamain, luadeps, native.sh_binary)
-def lua_test(name, luamain, luadeps=[]):
+def lua_test(name, luamain, luadeps = []):
_lua_binary_or_test(name, luamain, luadeps, native.sh_test)
def generated_file_staleness_test(name, outs, generated_pattern):
@@ -163,9 +162,9 @@ def generated_file_staleness_test(name, outs, generated_pattern):
SrcList = provider(
fields = {
- 'srcs' : 'list of srcs',
- 'hdrs' : 'list of hdrs',
- }
+ "srcs": "list of srcs",
+ "hdrs": "list of hdrs",
+ },
)
def _file_list_aspect_impl(target, ctx):
@@ -205,9 +204,25 @@ upb_amalgamation = rule(
),
"libs": attr.label_list(aspects = [_file_list_aspect]),
"outs": attr.output_list(),
- }
+ },
)
+is_bazel = not hasattr(native, "genmpm")
+
+google3_dep_map = {
+ "@absl//absl/base:core_headers": "//third_party/absl/base:core_headers",
+ "@absl//absl/strings": "//third_party/absl/strings",
+ "@com_google_protobuf//:protoc": "//third_party/protobuf:protoc",
+ "@com_google_protobuf//:protobuf": "//third_party/protobuf:protobuf",
+ "@com_google_protobuf//:protoc_lib": "//third_party/protobuf:libprotoc",
+}
+
+def map_dep(dep):
+ if is_bazel:
+ return dep
+ else:
+ return google3_dep_map[dep]
+
# upb_proto_library() rule
def _remove_up(string):
@@ -218,18 +233,20 @@ 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 = {}
for dep in ctx.attr.deps:
- if hasattr(dep, 'proto'):
+ 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()]
@@ -244,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 = {
@@ -254,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):
@@ -273,3 +296,37 @@ def upb_proto_library(name, deps, upbc):
deps = [":upb"],
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