parent
7b8ae7ec4e
commit
4bd34da105
6 changed files with 132 additions and 33 deletions
@ -0,0 +1,44 @@ |
||||
|
||||
def tmpl_cc_binary(name, srcs, replacements = [], **kwargs): |
||||
if len(srcs) != 1: |
||||
fail("Currently srcs must have exactly 1 element") |
||||
src = srcs[0] |
||||
if not src.endswith(".tmpl"): |
||||
fail("srcs of tmpl_cc_binary must end with .tmpl") |
||||
outs = [name + "_" + src[:-5]] |
||||
sed_cmds = ["s,{},{},g".format(k, v) for k, v in replacements.items()] |
||||
cmd = "sed -e '{}' $< > $@".format("; ".join(sed_cmds)) |
||||
|
||||
native.genrule( |
||||
name = name + "_gen_srcs", |
||||
srcs = [src], |
||||
outs = outs, |
||||
cmd = cmd, |
||||
) |
||||
|
||||
native.cc_binary( |
||||
name = name, |
||||
srcs = outs, |
||||
**kwargs, |
||||
) |
||||
|
||||
def cc_lite_proto_library(name, srcs, outs): |
||||
if len(srcs) != 1: |
||||
fail("Currently srcs must have exactly 1 element") |
||||
|
||||
native.genrule( |
||||
name = name + "_gen_proto", |
||||
srcs = srcs, |
||||
outs = outs, |
||||
cmd = "cp $< $@ && chmod a+w $@ && echo 'option optimize_for = LITE_RUNTIME;' >> $@", |
||||
) |
||||
|
||||
native.proto_library( |
||||
name = name + "_proto", |
||||
srcs = outs, |
||||
) |
||||
|
||||
native.cc_proto_library( |
||||
name = name, |
||||
deps = [":" + name + "_proto"], |
||||
) |
@ -0,0 +1,6 @@ |
||||
|
||||
syntax = "proto3"; |
||||
|
||||
package upb_benchmark; |
||||
|
||||
message Empty {} |
@ -1,10 +1,10 @@ |
||||
|
||||
#include "google/protobuf/empty.pb.h" |
||||
#include "INCLUDE" |
||||
|
||||
char buf[1]; |
||||
|
||||
int main() { |
||||
google::protobuf::Empty proto; |
||||
PROTO proto; |
||||
proto.ParseFromArray(buf, 1); |
||||
proto.SerializeToArray(buf, 1); |
||||
} |
@ -1,12 +0,0 @@ |
||||
|
||||
#include "google/protobuf/empty.upb.h" |
||||
|
||||
char buf[1]; |
||||
|
||||
int main() { |
||||
upb_arena *arena = upb_arena_new(); |
||||
size_t size; |
||||
google_protobuf_Empty *proto = google_protobuf_Empty_parse(buf, 1, arena); |
||||
google_protobuf_Empty_serialize(proto, arena, &size); |
||||
return 0; |
||||
} |
@ -0,0 +1,12 @@ |
||||
|
||||
#include "INCLUDE" |
||||
|
||||
char buf[1]; |
||||
|
||||
int main() { |
||||
upb_arena *arena = upb_arena_new(); |
||||
size_t size; |
||||
PROTO *proto = PROTO_parse(buf, 1, arena); |
||||
PROTO_serialize(proto, arena, &size); |
||||
return 0; |
||||
} |
Loading…
Reference in new issue