grpc/templates
Jan Tattermusch 0f1afec5a8
[protobuf] Upgrade third_party/protobuf to 22.x (#32606)
The very non-trivial upgrade of third_party/protobuf to 22.x
This PR strives to be as small as possible and many changes that were
compatible with protobuf 21.x and didn't have to be merged atomically
with the upgrade were already merged.
Due to the complexity of the upgrade, this PR wasn't created
automatically by a tool, but manually. Subsequent upgraded of
third_party/protobuf with our OSS release script should work again once
this change is merged.

This is best reviewed commit-by-commit, I tried to group changes in
logical areas.

Notable changes:
- the upgrade of third_party/protobuf submodule, the bazel protobuf
dependency itself
- upgrade of UPB dependency to 22.x (in the past, we used to always
upgrade upb to "main", but upb now has release branch as well). UPB
needs to be upgraded atomically with protobuf since there's a de-facto
circular dependency (new protobuf depends on new upb, which depends on
new protobuf for codegen).
- some protobuf and upb bazel rules are now aliases, so `
extract_metadata_from_bazel_xml.py` and `gen_upb_api_from_bazel_xml.py`
had to be modified to be able to follow aliases and reach the actual
aliased targets.
- some protobuf public headers were renamed, so especially
`src/compiler` needed to be updated to use the new headers.
- protobuf and upb now both depend on utf8_range project, so since we
bundle upb with grpc in some languages, we now have to bundle utf8_range
as well (hence changes in build for python, PHP, objC, cmake etc).
- protoc now depends on absl and utf8_range (previously protobuf had
absl dependency, but not for the codegen part), so python's
make_grpcio_tools.py required partial rewrite to be able to handle those
dependencies in the grpcio_tools build.
- many updates and fixes required for C++ distribtests (currently they
all pass, but we'll probably need to follow up, make protobuf's and
grpc's handling of dependencies more aligned and revisit the
distribtests)
- bunch of other changes mostly due to overhaul of protobuf's and upb's
internal build layout.

TODOs:
- [DONE] make sure IWYU and clang_tidy_code pass
- create a list of followups (e.g. work to reenable the few tests I had
to disable and to remove workaround I had to use)
- [DONE in cl/523706129] figure out problem(s) with internal import

---------

Co-authored-by: Craig Tiller <ctiller@google.com>
2023-04-12 18:43:58 +02:00
..
doc Update bazel_support.md (#31986) 2023-01-02 14:46:48 +01:00
examples/php/echo Update PHP docker images PHP versions (#31779) 2022-12-07 13:20:48 -08:00
include Convert c-style comments to C++-style comments (#31923) 2022-12-22 23:01:53 -08:00
src Update third_party/boringssl-with-bazel (#32721) 2023-03-27 15:11:48 -07:00
test [tests] Convert core e2e tests to gtest (#32603) 2023-04-03 22:19:57 -07:00
tools [fork] Generate GDB backtraces in fork tests on Kokoro (#32535) 2023-03-08 10:30:46 -08:00
CMakeLists.txt.template Fix cmake on macos (#32241) 2023-01-31 10:12:46 -08:00
Makefile.template Remove unnecessary gflags related comments in makefile (#28846) 2022-09-20 16:04:12 -07:00
README.md simplify build.yaml: get rid of the "secure" field (#25547) 2021-03-04 15:07:24 +01:00
_metadata.py.template Add Python xDS user agent (#26191) 2021-06-14 16:35:00 -07:00
build_config.rb.template fix remaining license notices 2017-06-08 11:22:41 +02:00
composer.json.template update required minimal php version to 7.0 2020-11-19 23:52:44 +03:00
config.m4.template [protobuf] Upgrade third_party/protobuf to 22.x (#32606) 2023-04-12 18:43:58 +02:00
config.w32.template [protobuf] Upgrade third_party/protobuf to 22.x (#32606) 2023-04-12 18:43:58 +02:00
gRPC-C++.podspec.template Update Abseil to 20230125 (#32139) 2023-01-30 16:20:24 -08:00
gRPC-Core.podspec.template [protobuf] Upgrade third_party/protobuf to 22.x (#32606) 2023-04-12 18:43:58 +02:00
gRPC-ProtoRPC.podspec.template Setting C++ lang dialect for objc cocoapod specs (#31071) 2022-09-20 13:59:17 -07:00
gRPC-RxLibrary.podspec.template Setting C++ lang dialect for objc cocoapod specs (#31071) 2022-09-20 13:59:17 -07:00
gRPC.podspec.template Setting C++ lang dialect for objc cocoapod specs (#31071) 2022-09-20 13:59:17 -07:00
grpc.def.template Cleaning up cruft to properly create a dll file. 2016-01-30 21:05:35 +01:00
grpc.gemspec.template [ruby]: add pre-compiled binaries for ruby 3.2; drop them for ruby 2.6 (#32089) 2023-01-19 15:32:26 -08:00
grpc.gyp.template Changed C99 to C11 (#29687) 2022-05-20 14:03:04 -07:00
package.xml.template Replace disrespectful words 2021-02-08 14:29:18 -08:00

README.md

Regenerating project files

Prerequisites

  • python
  • pip install mako (the template processor)
  • pip install pyyaml (to read the yaml files)
  • go (required by boringssl dependency)
# Regenerate the projects files (and other generated files) using templates
tools/buildgen/generate_projects.sh

Quick justification

We've approached the problem of the build system from a lot of different angles. The main issue was that there isn't a single build system that was going to single handedly cover all of our usage cases.

So instead we decided to work the following way:

  • A build.yaml file at the root is the source of truth for listing all the targets and files needed to build grpc and its tests, as well as a basic system for dependency description.

  • Most of the build systems supported by gRPC (e.g. Makefile, cmake, XCode) have a template defined in this directory. The templates use the information from the build.yaml file to generate the project files specific to a given build system.

This way we can maintain as many project system as we see fit, without having to manually maintain them when we add or remove new code to the repository. Only the structure of the project file is relevant to the template. The actual list of source code and targets isn't.

Structure of build.yaml

The build.yaml file has the following structure:

settings:  # global settings, such as version number
  ...
filegroups:  # groups of files that are automatically expanded
  ...
libs:  # list of libraries to build
  ...
targets:   # list of targets to build
  ...

The filegroups are helpful to re-use a subset of files in multiple targets. One filegroups entry has the following structure:

- name: "arbitrary string", # the name of the filegroup
  public_headers: # list of public headers defined in that filegroup
  - ...
  headers: # list of headers defined in that filegroup
  - ...
  src: # list of source files defined in that filegroup
  - ...

The libs collection contains the list of all the libraries we describe. Some may be helper libraries for the tests. Some may be installable libraries. Some may be helper libraries for installable binaries.

The targets array contains the list of all the binary targets we describe. Some may be installable binaries.

One libs or targets entry has the following structure (see below for details):

name: "arbitrary string", # the name of the library
build: "build type",      # in which situation we want that library to be
                          # built and potentially installed (see below).
language: "...",          # the language tag; "c" or "c++"
public_headers:           # list of public headers to install
headers:                  # list of headers used by that target
src:                      # list of files to compile
baselib: boolean,         # this is a low level library that has system
                          # dependencies
filegroups:               # list of filegroups to merge to that project
                          # note that this will be expanded automatically
deps:                     # list of libraries this target depends on
dll: "..."                # see below.

The "build" tag

Currently, the "build" tag have these meanings:

  • "all": library to build on "make all", and install on the system.
  • "protoc": a protoc plugin to build on "make all" and install on the system.
  • "private": a library to only build for tests.
  • "test": a test binary to run on "make test".
  • "tool": a binary to be built upon "make tools".

All of the targets should always be present in the generated project file, if possible and applicable. But the build tag is what should group the targets together in a single build command.

The "baselib" boolean

This means this is a library that will provide most of the features for gRPC. In particular, if we're locally building OpenSSL, protobuf or zlib, then we should merge OpenSSL, protobuf or zlib inside that library. That effect depends on the "language" tag. OpenSSL and zlib are for "c" libraries, while protobuf is for "c++" ones.

The template system

We're currently using the mako templates renderer. That choice enables us to simply render text files without dragging with us a lot of other features. Feel free to explore the current templates in that directory.

The renderer engine

As mentioned, the renderer is using mako templates, but some glue is needed to process all of that. See the buildgen folder for more details. We're mainly loading the build.json file, and massaging it, in order to get the list of properties we need, into a Python dictionary, that is then passed to the template while rending it.

The plugins

The file build.json itself isn't passed straight to the template files. It is first processed and modified by a few plugins. For example, the version expander is a plugin.

The structure of a plugin is simple. The plugin must defined the function mako_plugin that takes a Python dictionary. That dictionary represents the current state of the build.json contents. The plugin can alter it to whatever feature it needs to add.