Encode all the protos in one go (per library), as it's vastly faster.

This commit is contained in:
David Given
2024-08-12 12:36:39 +02:00
parent 7a3a31a929
commit cac4d1ce86
7 changed files with 46 additions and 43 deletions

View File

@@ -1,11 +1,11 @@
from build.ab import Rule, normalrule, Targets
from build.ab import Rule, normalrule, Targets, TargetsMap
from build.c import cxxprogram, HostToolchain
encoders = {}
@Rule
def protoencode(self, name, srcs: Targets, proto, symbol):
def protoencode_single(self, name, srcs: Targets, proto, symbol):
if proto not in encoders:
r = cxxprogram(
name="protoencode_" + proto,
@@ -34,6 +34,27 @@ def protoencode(self, name, srcs: Targets, proto, symbol):
)
@Rule
def protoencode(self, name, proto, srcs: TargetsMap, symbol):
encoded = [
protoencode_single(
name=f"{k}_cc",
srcs=[v],
proto=proto,
symbol=f"{symbol}_{k}_pb",
)
for k, v in srcs.items()
]
normalrule(
replaces=self,
ins=encoded,
outs=[name + ".cc"],
commands=["cat {ins} > {outs}"],
label="CONCAT",
)
cxxprogram(
name="mkdoc",
srcs=["./mkdoc.cc"],

View File

@@ -121,11 +121,12 @@ int main(int argc, const char* argv[])
}
auto data = message.SerializeAsString();
auto name = argv[3];
output << "#include \"lib/globals.h\"\n"
<< "#include \"lib/proto.h\"\n"
<< "#include <string_view>\n"
<< "static const uint8_t rawData[] = {";
<< "static const uint8_t " << name << "_rawData[] = {";
int count = 0;
for (char c : data)
@@ -140,12 +141,12 @@ int main(int argc, const char* argv[])
}
output << "\n};\n";
output << "extern const std::string_view " << argv[3] << "_data;\n";
output << "const std::string_view " << argv[3]
<< "_data = std::string_view((const char*)rawData, " << data.size()
output << "extern const std::string_view " << name << "_data;\n";
output << "const std::string_view " << name
<< "_data = std::string_view((const char*)" << name << "_rawData, " << data.size()
<< ");\n";
output << "extern const ConfigProto " << argv[3] << ";\n";
output << "const ConfigProto " << argv[3] << " = parseConfigBytes("
output << "extern const ConfigProto " << name << ";\n";
output << "const ConfigProto " << name << " = parseConfigBytes("
<< argv[3] << "_data);\n";
return 0;