mirror of
				https://github.com/davidgiven/fluxengine.git
				synced 2025-10-24 11:11:02 -07:00 
			
		
		
		
	Encode all the protos in one go (per library), as it's vastly faster.
This commit is contained in:
		| @@ -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"], | ||||
|   | ||||
| @@ -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; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user