[protobuf] Add upb_full and protoc-gen-upbdefs

The upb Python C extension (google._upb._message) needs two things the
GN build does not currently provide:

  * The full upb runtime, including reflection, JSON, text, and util,
    built against regular (non-bootstrap) descriptor gencode. :upb only
    contains the subset protoc needs and is built with
    UPB_BOOTSTRAP_STAGE=0.
  * descriptor.upbdefs.{h,c}, which upstream generates with the
    protoc-gen-upbdefs plugin from upb_generator/reflection.

Without these, the only way to build the extension in-tree is to list
the upb runtime sources in the consuming BUILD.gn and hand-write a
replacement for protoc-gen-upbdefs, as fxr/1953775 currently does for
//src/performance/lib/tp_shell.

Add:

  * :upb_full, a host-only static library containing the full upb
    runtime and utf8_range, built against the checked-in CMake
    descriptor gencode in upb/reflection/cmake. Its source list is
    generated by gen.py (UPB_FULL_SOURCES). It must not be linked into
    the same binary as :upb, because the stage0 and CMake descriptor
    gencode define conflicting symbols, and it is visible only to
    //src/performance/lib/tp_shell for now.
  * :protoc-gen-upbdefs, built from upb_generator/reflection against
    :upb_full and :protobuf_full, with the same visibility as :protoc.
    It works with proto_library's generator_plugin_label.

Bug: 364925797
Test: Built the upb Python extension in //src/performance/lib/tp_shell
Test: against these targets (rebased fxr/1953775) and ran
Test: fx test --host tp_shell_test trace_importing_fxt_test
Change-Id: Ia5d19dcf03fdffc20cede3aee28f507caa2f1c58
Reviewed-on: https://fuchsia-review.googlesource.com/c/protobuf-gn/+/1953501
Reviewed-by: Alex Pankhurst <pankhurst@google.com>
Reviewed-by: Anivia Li <aniviali@google.com>
3 files changed
tree: 176a93ac12610e993e31deb72ad83c98602aa948
  1. upb_generator/
  2. AUTHORS
  3. BUILD.gn
  4. BUILD.input.gn
  5. CONTRIBUTING.md
  6. gen.py
  7. LICENSE
  8. OWNERS
  9. PATENTS
  10. proto_library.gni
  11. protoc_wrapper.py
  12. README.md
README.md

Protocol Buffers GN Build Support

This repository contains GN build system support for Protocol Buffers. It's in its own repository because it needs to be shared by Fuchsia and Cobalt.

This repo should be checked out such that:

  • It is in //build/secondary/third_party/protobuf.
  • Protobuf is in //third_party/protobuf/src.
  • //.gn contains secondary_source = "//build/secondary/"

See the GN documentation on secondary_source.

Updating Build Files

WARNING: DO NOT MODIFY THE BUILD.gn FILE DIRECTLY!

The BUILD.gn file in this directory is generated automatically. Any manual changes will be overwritten.

To make changes to the build configuration:

  1. Edit the BUILD.input.gn file to suit your needs, for example managing visibility, suppressing warnings, etc.
  2. Run the gen.py script located in this directory to regenerate the BUILD.gn file:
    ./gen.py [commit_hash]
    
    If no commit hash is specified, it defaults to HEAD of //third_party/protobuf/src.
  3. Commit both the updated BUILD.input.gn and the newly generated BUILD.gn file.

Failing to modify BUILD.input.gn will result in your changes being lost the next time the build file is regenerated.