summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoshua Haberman <jhaberman@gmail.com>2019-06-02 22:02:04 -0700
committerJoshua Haberman <jhaberman@gmail.com>2019-06-02 22:02:04 -0700
commite1f84aeb10e526aab986351fa5eb4c944d0f6e7b (patch)
tree69ee5f5c4a382cea625e31993bfad7a3c111abff
parent7485261370ad0bb691c801a4128712d962cdd7d3 (diff)
parent00e739648d816fae3972c9d51fef24940cf50539 (diff)
Merge branch 'master' into rmreflective
-rw-r--r--BUILD35
-rw-r--r--CMakeLists.txt9
-rw-r--r--WORKSPACE14
-rw-r--r--bazel/upb_proto_library.bzl12
-rw-r--r--tests/benchmark.cc36
5 files changed, 97 insertions, 9 deletions
diff --git a/BUILD b/BUILD
index 11156c8..1d27b79 100644
--- a/BUILD
+++ b/BUILD
@@ -50,7 +50,11 @@ cc_library(
srcs = [
"upb/decode.c",
"upb/encode.c",
+ "upb/generated_util.h",
"upb/msg.c",
+ "upb/msg.h",
+ "upb/port_def.inc",
+ "upb/port_undef.inc",
"upb/table.c",
"upb/table.int.h",
"upb/upb.c",
@@ -58,16 +62,30 @@ cc_library(
hdrs = [
"upb/decode.h",
"upb/encode.h",
- "upb/generated_util.h",
- "upb/msg.h",
"upb/upb.h",
],
copts = COPTS,
- # Internal-only, but we have to make them public for generated code.
+ visibility = ["//visibility:public"],
+)
+
+# Common support routines used by generated code. This library has no
+# implementation, but depends on :upb and exposes a few more hdrs.
+#
+# This is public only because we have no way of visibility-limiting it to
+# upb_proto_library() only. This interface is not stable and by using it you
+# give up any backward compatibility guarantees.
+cc_library(
+ name = "generated_code_support__only_for_generated_code_do_not_use__i_give_permission_to_break_me",
textual_hdrs = [
"upb/port_def.inc",
"upb/port_undef.inc",
],
+ hdrs = [
+ "upb/generated_util.h",
+ "upb/msg.h",
+ ],
+ deps = [":upb"],
+ copts = COPTS,
visibility = ["//visibility:public"],
)
@@ -231,6 +249,17 @@ cc_binary(
# C/C++ tests ##################################################################
+cc_binary(
+ name = "benchmark",
+ testonly = 1,
+ srcs = ["tests/benchmark.cc"],
+ deps = [
+ ":descriptor_upbproto",
+ ":descriptor_upbreflection",
+ "@com_github_google_benchmark//:benchmark_main",
+ ],
+)
+
cc_library(
name = "upb_test",
testonly = 1,
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 2573173..c1c45df 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -63,15 +63,20 @@ enable_testing()
add_library(upb
upb/decode.c
upb/encode.c
+ upb/generated_util.h
upb/msg.c
+ upb/msg.h
+ upb/port_def.inc
+ upb/port_undef.inc
upb/table.c
upb/table.int.h
upb/upb.c
upb/decode.h
upb/encode.h
- upb/generated_util.h
- upb/msg.h
upb/upb.h)
+add_library(generated_code_support__only_for_generated_code_do_not_use__i_give_permission_to_break_me INTERFACE)
+target_link_libraries(generated_code_support__only_for_generated_code_do_not_use__i_give_permission_to_break_me INTERFACE
+ upb)
add_library(reflection
upb/def.c
upb/msgfactory.c
diff --git a/WORKSPACE b/WORKSPACE
index 91d2150..c1c8c3b 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -23,3 +23,17 @@ http_archive(
strip_prefix = "ragel-6.10",
urls = ["http://www.colm.net/files/ragel/ragel-6.10.tar.gz"],
)
+
+http_archive(
+ name = "com_google_googletest",
+ urls = ["https://github.com/google/googletest/archive/b6cd405286ed8635ece71c72f118e659f4ade3fb.zip"], # 2019-01-07
+ strip_prefix = "googletest-b6cd405286ed8635ece71c72f118e659f4ade3fb",
+ sha256 = "ff7a82736e158c077e76188232eac77913a15dac0b22508c390ab3f88e6d6d86",
+)
+
+http_archive(
+ name = "com_github_google_benchmark",
+ urls = ["https://github.com/google/benchmark/archive/16703ff83c1ae6d53e5155df3bb3ab0bc96083be.zip"],
+ strip_prefix = "benchmark-16703ff83c1ae6d53e5155df3bb3ab0bc96083be",
+ sha256 = "59f918c8ccd4d74b6ac43484467b500f1d64b40cc1010daa055375b322a43ba3",
+)
diff --git a/bazel/upb_proto_library.bzl b/bazel/upb_proto_library.bzl
index 09d557c..147e088 100644
--- a/bazel/upb_proto_library.bzl
+++ b/bazel/upb_proto_library.bzl
@@ -42,7 +42,7 @@ def _generate_output_file(ctx, src, extension):
else:
real_short_path = paths.relativize(src.short_path, ctx.label.package)
output_filename = paths.replace_extension(real_short_path, extension)
- ret = ctx.new_file(ctx.genfiles_dir, output_filename)
+ ret = ctx.actions.declare_file(output_filename)
return ret
def _filter_none(elems):
@@ -149,12 +149,13 @@ _WrappedGeneratedSrcs = provider(fields = ["srcs"])
def _compile_upb_protos(ctx, proto_info, proto_sources, ext):
srcs = [_generate_output_file(ctx, name, ext + ".c") for name in proto_sources]
hdrs = [_generate_output_file(ctx, name, ext + ".h") for name in proto_sources]
- transitive_sets = list(proto_info.transitive_descriptor_sets)
+ transitive_sets = proto_info.transitive_descriptor_sets.to_list()
ctx.actions.run(
inputs = depset(
- direct = [ctx.executable._upbc, proto_info.direct_descriptor_set],
+ direct = [proto_info.direct_descriptor_set],
transitive = [proto_info.transitive_descriptor_sets],
),
+ tools = [ctx.executable._upbc],
outputs = srcs + hdrs,
executable = ctx.executable._protoc,
arguments = [
@@ -229,7 +230,10 @@ _upb_proto_library_aspect = aspect(
"_cc_toolchain": attr.label(
default = "@bazel_tools//tools/cpp:current_cc_toolchain",
),
- "_upb": attr.label_list(default = ["//:upb"]),
+ "_upb": attr.label_list(default = [
+ "//:generated_code_support__only_for_generated_code_do_not_use__i_give_permission_to_break_me",
+ "//:upb"
+ ]),
"_ext": attr.string(default = ".upb"),
}),
implementation = _upb_proto_aspect_impl,
diff --git a/tests/benchmark.cc b/tests/benchmark.cc
new file mode 100644
index 0000000..bcb4ec7
--- /dev/null
+++ b/tests/benchmark.cc
@@ -0,0 +1,36 @@
+
+#include <string.h>
+#include <benchmark/benchmark.h>
+#include "google/protobuf/descriptor.upb.h"
+#include "google/protobuf/descriptor.upbdefs.h"
+
+upb_strview descriptor = google_protobuf_descriptor_proto_upbdefinit.descriptor;
+
+/* A buffer big enough to parse descriptor.proto without going to heap. */
+char buf[65535];
+
+static void BM_CreateArena(benchmark::State& state) {
+ for (auto _ : state) {
+ upb_arena* arena = upb_arena_init(buf, sizeof(buf), NULL);
+ upb_arena_free(arena);
+ }
+}
+BENCHMARK(BM_CreateArena);
+
+static void BM_ParseDescriptor(benchmark::State& state) {
+ size_t bytes = 0;
+ for (auto _ : state) {
+ upb_arena* arena = upb_arena_init(buf, sizeof(buf), NULL);
+ google_protobuf_FileDescriptorProto* set =
+ google_protobuf_FileDescriptorProto_parse(descriptor.data,
+ descriptor.size, arena);
+ if (!set) {
+ printf("Failed to parse.\n");
+ exit(1);
+ }
+ bytes += descriptor.size;
+ upb_arena_free(arena);
+ }
+ state.SetBytesProcessed(state.iterations() * descriptor.size);
+}
+BENCHMARK(BM_ParseDescriptor);
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback