diff --git a/benchmarks/BUILD b/benchmarks/BUILD index 720f8c681b..2ab830f7fc 100644 --- a/benchmarks/BUILD +++ b/benchmarks/BUILD @@ -6,7 +6,7 @@ load( load( ":build_defs.bzl", "tmpl_cc_binary", - "cc_lite_proto_library", + "cc_optimizefor_proto_library", "expand_suffixes", "proto_library", ) @@ -165,10 +165,11 @@ tmpl_cc_binary( ":" + k + "_cc_proto", ], ), -cc_lite_proto_library( +cc_optimizefor_proto_library( srcs = [k + ".proto"], outs = [k + "_lite.proto"], name = k + "_cc_lite_proto", + optimize_for = "LITE_RUNTIME", ), tmpl_cc_binary( name = k + "_lite_protobuf_binary", @@ -181,14 +182,33 @@ tmpl_cc_binary( deps = [ ":" + k + "_cc_lite_proto", ], -)) for k, v in SIZE_BENCHMARKS.items()] +), +cc_optimizefor_proto_library( + srcs = [k + ".proto"], + outs = [k + "_codesize.proto"], + name = k + "_cc_codesize_proto", + optimize_for = "CODE_SIZE", +), +tmpl_cc_binary( + name = k + "_codesize_protobuf_binary", + testonly = 1, + gen = ":gen_protobuf_binary_cc", + args = [ + package_name() + "/" + k + "_codesize.pb.h", + "upb_benchmark::" + v, + ], + deps = [ + ":" + k + "_cc_codesize_proto", + ], +) +) for k, v in SIZE_BENCHMARKS.items()] genrule( testonly = 1, name = "size_data", srcs = expand_suffixes( SIZE_BENCHMARKS.keys(), - suffixes = ["_upb_binary", "_protobuf_binary", "_lite_protobuf_binary"], + suffixes = ["_upb_binary", "_protobuf_binary", "_lite_protobuf_binary", "_codesize_protobuf_binary"], ), outs = ["size_data.txt"], # We want --format=GNU which counts rodata with data, not text. diff --git a/benchmarks/build_defs.bzl b/benchmarks/build_defs.bzl index 533c84454c..ff534fb926 100644 --- a/benchmarks/build_defs.bzl +++ b/benchmarks/build_defs.bzl @@ -34,7 +34,7 @@ def tmpl_cc_binary(name, gen, args, replacements = [], **kwargs): **kwargs, ) -def cc_lite_proto_library(name, srcs, outs): +def cc_optimizefor_proto_library(name, srcs, outs, optimize_for): if len(srcs) != 1: fail("Currently srcs must have exactly 1 element") @@ -42,7 +42,7 @@ def cc_lite_proto_library(name, srcs, outs): name = name + "_gen_proto", srcs = srcs, outs = outs, - cmd = "cp $< $@ && chmod a+w $@ && echo 'option optimize_for = LITE_RUNTIME;' >> $@", + cmd = "cp $< $@ && chmod a+w $@ && echo 'option optimize_for = " + optimize_for + ";' >> $@", ) proto_library(