upb code generation

37 views
Skip to first unread message

Ranen Ghosh

unread,
Sep 15, 2025, 9:37:23 AM (10 days ago) Sep 15
to Protocol Buffers
Hi, this isn't a question but I just wanted to leave this here in case it saves someone time in the future:

At first I couldn't figure out how to get complete upb code generation output.  I followed some "AI Overview" instructions which said to use protoc's upb_out flag (which wasn't documented explicitly in the command line help for protoc), but this resulted in a header "<protoname>.upb.h" which contained an include for "<protoname>.upb_minitable.h", and the second file was not generated.

However this header file had some essential information in the comments about how plugins work
https://github.com/protocolbuffers/protobuf/blob/main/src/google/protobuf/compiler/command_line_interface.h#L141

  // The compiler determines the executable name to search for by concatenating
  // exe_name_prefix with the unrecognized flag name, removing "_out".  So, for
  // example, if exe_name_prefix is "protoc-" and you pass the flag --foo_out,
  // the compiler will try to run the program "protoc-gen-foo"

The upb executables (on Windows) are protoc-gen-upb.exe, protoc-gen-upb_minitable.exe, and protoc-gen-upbdefs.exe, so I got working output with the command (with a subdirectory "upb_out" to receive the output)

./protoc.exe --upb_out=upb_out --upb_minitable_out=upb_out --upbdefs_out=upb_out myschema.proto


Em Rauch

unread,
Sep 15, 2025, 9:56:20 AM (10 days ago) Sep 15
to Ranen Ghosh, Protocol Buffers
This looks correct, but I'll mention that upb's C code generation is not a supported API surface today like our other language's generators are; it exists only as an implementation detail for other languages, as well as some other legacy needs.

Use at your own risk, and there may be some unannounced breaking changes on that gencode API in new releases of the plugin outside of our slow/rare/announced breaking change cadence.

--
You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to protobuf+u...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/protobuf/66b6f841-8297-485e-8078-e6f333aae200n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages