xref: /aosp_15_r20/external/grpc-grpc/third_party/README.md (revision cc02d7e222339f7a4f6ba5f422e6413f4bd931f2)
1*cc02d7e2SAndroid Build Coastguard Worker# Third-party libraries
2*cc02d7e2SAndroid Build Coastguard Worker
3*cc02d7e2SAndroid Build Coastguard WorkergRPC depends on several third-party libraries, their source code is available
4*cc02d7e2SAndroid Build Coastguard Worker(usually as a git submodule) in this directory.
5*cc02d7e2SAndroid Build Coastguard Worker
6*cc02d7e2SAndroid Build Coastguard Worker## Guidelines on updating submodules
7*cc02d7e2SAndroid Build Coastguard Worker
8*cc02d7e2SAndroid Build Coastguard Worker- IMPORTANT: whenever possible, try to only update to a stable release of a library (= not to master / random commit). Depending on unreleased revisions
9*cc02d7e2SAndroid Build Coastguard Worker  makes gRPC installation harder for users, as it forces them to always build the dependency from source and prevents them from using more
10*cc02d7e2SAndroid Build Coastguard Worker  convenient installation channels (linux packages, package managers etc.)
11*cc02d7e2SAndroid Build Coastguard Worker
12*cc02d7e2SAndroid Build Coastguard Worker- bazel BUILD uses a different dependency model - whenever updating a submodule, also update the revision in `grpc_deps.bzl` so that bazel and
13*cc02d7e2SAndroid Build Coastguard Worker  non-bazel builds stay in sync (this is actually enforced by a sanity check in some cases)
14*cc02d7e2SAndroid Build Coastguard Worker
15*cc02d7e2SAndroid Build Coastguard Worker## Considerations when adding a new third-party dependency
16*cc02d7e2SAndroid Build Coastguard Worker
17*cc02d7e2SAndroid Build Coastguard Worker- gRPC C++ needs to stay buildable/installable even if the submodules are not present (e.g. the tar.gz archive with gRPC doesn't contain the submodules),
18*cc02d7e2SAndroid Build Coastguard Worker  assuming that the dependencies are already installed. This is a requirement for being able to provide a reasonable install process (e.g. using cmake)
19*cc02d7e2SAndroid Build Coastguard Worker  and to support package managers for gRPC C++.
20*cc02d7e2SAndroid Build Coastguard Worker    - CAVEAT: upb is an exception here because of its lack of cmake support. Therefore, third_party/upb should be present to build gRPC until upb supports it.
21*cc02d7e2SAndroid Build Coastguard Worker
22*cc02d7e2SAndroid Build Coastguard Worker- Adding a new dependency is a lot of work (both for us and for the users).
23*cc02d7e2SAndroid Build Coastguard Worker  We currently support multiple build systems (BAZEL, cmake, make, ...) so adding a new dependency usually requires updates in multiple build systems
24*cc02d7e2SAndroid Build Coastguard Worker  (often not trivial). The installation process also needs to continue to work (we do have distrib tests to test many of the possible installation scenarios,
25*cc02d7e2SAndroid Build Coastguard Worker  but they are not perfect). Adding a new dependency also usually affects the installation instructions that need to be updated.
26*cc02d7e2SAndroid Build Coastguard Worker  Also keep in mind that adding a new dependency can be quite disruptive
27*cc02d7e2SAndroid Build Coastguard Worker  for the users and community - it means that all users will need to update their projects accordingly (for C++ projects often non-trivial) and
28*cc02d7e2SAndroid Build Coastguard Worker  the community-provided C++ packages (e.g. vcpkg) will need to be updated as well.
29*cc02d7e2SAndroid Build Coastguard Worker
30*cc02d7e2SAndroid Build Coastguard Worker## Checklist for adding a new third-party dependency
31*cc02d7e2SAndroid Build Coastguard Worker
32*cc02d7e2SAndroid Build Coastguard Worker**READ THIS BEFORE YOU ADD A NEW DEPENDENCY**
33*cc02d7e2SAndroid Build Coastguard Worker
34*cc02d7e2SAndroid Build Coastguard Worker- [ ] Make sure you understand the hidden costs of adding a dependency (see section above) and that you understand the     complexities of updating the build files. Maintenance of the build files isn't for free, so expect to be involved in maintenance tasks, cleanup and support (e.g resolving user bugs) of the build files in the future.
35*cc02d7e2SAndroid Build Coastguard Worker
36*cc02d7e2SAndroid Build Coastguard Worker- [ ] Once your change is ready, start an [adhoc run of artifact - packages - distribtests flow](https://fusion.corp.google.com/projectanalysis/summary/KOKORO/prod%3Agrpc%2Fcore%2Fexperimental%2Fgrpc_build_artifacts_multiplatform) and make sure everything passes (for technical reasons, not all the distribtests can run on each PR automatically).
37*cc02d7e2SAndroid Build Coastguard Worker
38*cc02d7e2SAndroid Build Coastguard Worker- [ ] Check the impact of the new dependency on the size of our distribution packages (compare BEFORE and AFTER) and post the comparison on your PR (it should not be approved without checking the impact sizes of packages first). The package sizes AFTER can be obtained from the adhoc package build from bullet point above.
39*cc02d7e2SAndroid Build Coastguard Worker
40*cc02d7e2SAndroid Build Coastguard Worker## Instructions for updating dependencies
41*cc02d7e2SAndroid Build Coastguard Worker
42*cc02d7e2SAndroid Build Coastguard WorkerUsually the process is
43*cc02d7e2SAndroid Build Coastguard Worker
44*cc02d7e2SAndroid Build Coastguard Worker1. update the submodule to selected commit (see guidance above)
45*cc02d7e2SAndroid Build Coastguard Worker2. update the dependency in `grpc_deps.bzl` to the same commit
46*cc02d7e2SAndroid Build Coastguard Worker3. update `tools/run_tests/sanity/check_submodules.sh` to make the sanity test pass
47*cc02d7e2SAndroid Build Coastguard Worker4. (when needed) run `tools/buildgen/generate_projects.sh` to regenerate the generated files
48*cc02d7e2SAndroid Build Coastguard Worker5. populate the bazel download mirror by running `bazel/update_mirror.sh`
49*cc02d7e2SAndroid Build Coastguard Worker
50*cc02d7e2SAndroid Build Coastguard WorkerUpdating some dependencies requires extra care.
51*cc02d7e2SAndroid Build Coastguard Worker
52*cc02d7e2SAndroid Build Coastguard Worker### Updating third_party/abseil-cpp
53*cc02d7e2SAndroid Build Coastguard Worker
54*cc02d7e2SAndroid Build Coastguard Worker- Two additional steps should be done before running `generate_projects.sh` above.
55*cc02d7e2SAndroid Build Coastguard Worker  - Running `src/abseil-cpp/preprocessed_builds.yaml.gen.py`.
56*cc02d7e2SAndroid Build Coastguard Worker  - Updating `abseil_version =` scripts in `templates/gRPC-C++.podspec.template` and
57*cc02d7e2SAndroid Build Coastguard Worker    `templates/gRPC-Core.podspec.template`.
58*cc02d7e2SAndroid Build Coastguard Worker- You can see an example of previous [upgrade](https://github.com/grpc/grpc/pull/24270).
59*cc02d7e2SAndroid Build Coastguard Worker
60*cc02d7e2SAndroid Build Coastguard Worker### Updating third_party/boringssl-with-bazel
61*cc02d7e2SAndroid Build Coastguard Worker
62*cc02d7e2SAndroid Build Coastguard WorkerNOTE: updating the boringssl dependency is now part of the internal grpc release tooling (see [go/grpc-release](http://go/grpc-release)).
63*cc02d7e2SAndroid Build Coastguard WorkerPrefer using the release tooling when possible. The instructions below are provided as a reference and aren't guaranteed to be up-to-date.
64*cc02d7e2SAndroid Build Coastguard Worker
65*cc02d7e2SAndroid Build Coastguard Worker- Update the `third_party/boringssl-with-bazel` submodule to the latest [`master-with-bazel`](https://github.com/google/boringssl/tree/master-with-bazel) branch
66*cc02d7e2SAndroid Build Coastguard Worker```
67*cc02d7e2SAndroid Build Coastguard Workergit submodule update --init      # just to start in a clean state
68*cc02d7e2SAndroid Build Coastguard Workercd third_party/boringssl-with-bazel
69*cc02d7e2SAndroid Build Coastguard Workergit fetch origin   # fetch what's new in the boringssl repository
70*cc02d7e2SAndroid Build Coastguard Workergit checkout origin/master-with-bazel  # checkout the current state of master-with-bazel branch in the boringssl repo
71*cc02d7e2SAndroid Build Coastguard Worker# Note the latest commit SHA on master-with-bazel branch
72*cc02d7e2SAndroid Build Coastguard Workercd ../..   # go back to grpc repo root
73*cc02d7e2SAndroid Build Coastguard Workergit status   #  will show that there are new commits in third_party/boringssl-with-bazel
74*cc02d7e2SAndroid Build Coastguard Workergit add  third_party/boringssl-with-bazel     # we actually want to update the changes to the submodule
75*cc02d7e2SAndroid Build Coastguard Workergit commit -m "update submodule boringssl-with-bazel with origin/master-with-bazel"   # commit
76*cc02d7e2SAndroid Build Coastguard Worker```
77*cc02d7e2SAndroid Build Coastguard Worker
78*cc02d7e2SAndroid Build Coastguard Worker- Update boringssl dependency in `bazel/grpc_deps.bzl` to the same commit SHA as master-with-bazel branch
79*cc02d7e2SAndroid Build Coastguard Worker    - Update `http_archive(name = "boringssl",` section by updating the sha in `strip_prefix` and `urls` fields.
80*cc02d7e2SAndroid Build Coastguard Worker    - Also, set `sha256` field to "" as the existing value is not valid. This will be added later once we know what that value is.
81*cc02d7e2SAndroid Build Coastguard Worker
82*cc02d7e2SAndroid Build Coastguard Worker- Update `tools/run_tests/sanity/check_submodules.sh` with the same commit
83*cc02d7e2SAndroid Build Coastguard Worker
84*cc02d7e2SAndroid Build Coastguard Worker- Commit these changes `git commit -m "update boringssl dependency to master-with-bazel commit SHA"`
85*cc02d7e2SAndroid Build Coastguard Worker
86*cc02d7e2SAndroid Build Coastguard Worker- Run `tools/buildgen/generate_projects.sh` to regenerate the generated files
87*cc02d7e2SAndroid Build Coastguard Worker    - Because `sha256` in `bazel/grpc_deps.bzl` was left empty, you will get a DEBUG msg like this one:
88*cc02d7e2SAndroid Build Coastguard Worker      ```
89*cc02d7e2SAndroid Build Coastguard Worker      Rule 'boringssl' indicated that a canonical reproducible form can be obtained by modifying arguments sha256 = "SHA value"
90*cc02d7e2SAndroid Build Coastguard Worker      ```
91*cc02d7e2SAndroid Build Coastguard Worker    - Commit the regenrated files `git commit -m "regenerate files"`
92*cc02d7e2SAndroid Build Coastguard Worker    - Update `bazel/grpc_deps.bzl` with the SHA value shown in the above debug msg. Commit again `git commit -m "Updated sha256"`
93*cc02d7e2SAndroid Build Coastguard Worker
94*cc02d7e2SAndroid Build Coastguard Worker- Run `tools/distrib/generate_boringssl_prefix_header.sh`
95*cc02d7e2SAndroid Build Coastguard Worker    - Commit again `git commit -m "generate boringssl prefix headers"`
96*cc02d7e2SAndroid Build Coastguard Worker
97*cc02d7e2SAndroid Build Coastguard Worker- Increment the boringssl podspec version number in
98*cc02d7e2SAndroid Build Coastguard Worker  `templates/src/objective-c/BoringSSL-GRPC.podspec.template` and `templates/gRPC-Core.podspec.template`.
99*cc02d7e2SAndroid Build Coastguard Worker  [example](https://github.com/grpc/grpc/pull/21527/commits/9d4411842f02f167209887f1f3d2b9ab5d14931a)
100*cc02d7e2SAndroid Build Coastguard Worker    - Commit again `git commit -m "Increment podspec version"`
101*cc02d7e2SAndroid Build Coastguard Worker
102*cc02d7e2SAndroid Build Coastguard Worker- Run `tools/buildgen/generate_projects.sh` (yes, again)
103*cc02d7e2SAndroid Build Coastguard Worker    - Commit again `git commit -m "Second regeneration"`
104*cc02d7e2SAndroid Build Coastguard Worker
105*cc02d7e2SAndroid Build Coastguard Worker- Create a PR with all the above commits.
106*cc02d7e2SAndroid Build Coastguard Worker
107*cc02d7e2SAndroid Build Coastguard Worker- Run `bazel/update_mirror.sh` to update GCS mirror.
108*cc02d7e2SAndroid Build Coastguard Worker
109*cc02d7e2SAndroid Build Coastguard Worker### Updating third_party/protobuf
110*cc02d7e2SAndroid Build Coastguard Worker
111*cc02d7e2SAndroid Build Coastguard WorkerUpdating the protobuf dependency is now part of the internal release process (see [go/grpc-release](http://go/grpc-release)).
112*cc02d7e2SAndroid Build Coastguard Worker
113*cc02d7e2SAndroid Build Coastguard Worker### Updating third_party/envoy-api
114*cc02d7e2SAndroid Build Coastguard Worker
115*cc02d7e2SAndroid Build Coastguard WorkerApart from the above steps, please run `tools/codegen/core/gen_upb_api.sh` to regenerate upb files.
116*cc02d7e2SAndroid Build Coastguard Worker
117*cc02d7e2SAndroid Build Coastguard Worker### Updating third_party/upb
118*cc02d7e2SAndroid Build Coastguard Worker
119*cc02d7e2SAndroid Build Coastguard WorkerSince upb is vendored in the gRPC repo, you cannot use submodule to update it. Please follow the steps below;
120*cc02d7e2SAndroid Build Coastguard Worker1. Update third_party/upb directory by running
121*cc02d7e2SAndroid Build Coastguard Worker   - `export GRPC_ROOT=~/git/grpc`
122*cc02d7e2SAndroid Build Coastguard Worker   - `wget https://github.com/protocolbuffers/protobuf/releases/download/v25.1/protobuf-25.1.zip`
123*cc02d7e2SAndroid Build Coastguard Worker   - `rm -rf $GRPC_ROOT/third_party/upb`
124*cc02d7e2SAndroid Build Coastguard Worker   - `unzip protobuf-25.1.zip -d /tmp/protobuf`
125*cc02d7e2SAndroid Build Coastguard Worker   - `cp -r /tmp/protobuf/protobuf-25.1/upb $GRPC_ROOT/third_party/upb`
126*cc02d7e2SAndroid Build Coastguard Worker2. Update the dependency in `grpc_deps.bzl` to the same commit
127*cc02d7e2SAndroid Build Coastguard Worker3. Populate the bazel download mirror by running `bazel/update_mirror.sh`
128*cc02d7e2SAndroid Build Coastguard Worker4. Run `tools/buildgen/generate_projects.sh` to regenerate the generated files
129*cc02d7e2SAndroid Build Coastguard Worker5. Run `tools/codegen/core/gen_upb_api.sh` to regenerate upb files.
130*cc02d7e2SAndroid Build Coastguard Worker
131*cc02d7e2SAndroid Build Coastguard Worker### Updating third_party/utf8_range
132*cc02d7e2SAndroid Build Coastguard Worker
133*cc02d7e2SAndroid Build Coastguard Worker```
134*cc02d7e2SAndroid Build Coastguard Worker# set to wherever your grpc repo lives
135*cc02d7e2SAndroid Build Coastguard Workerexport GRPC_ROOT=~/git/grpc
136*cc02d7e2SAndroid Build Coastguard Workerwget https://github.com/protocolbuffers/utf8_range/archive/refs/heads/main.zip
137*cc02d7e2SAndroid Build Coastguard Workerrm -rf $GRPC_ROOT/third_party/utf8_range
138*cc02d7e2SAndroid Build Coastguard Workerunzip main.zip -d $GRPC_ROOT/third_party
139*cc02d7e2SAndroid Build Coastguard Workermv $GRPC_ROOT/third_party/utf8_range-main $GRPC_ROOT/third_party/utf8_range
140*cc02d7e2SAndroid Build Coastguard Worker```
141*cc02d7e2SAndroid Build Coastguard Worker
142*cc02d7e2SAndroid Build Coastguard Worker### Updating third_party/xxhash
143*cc02d7e2SAndroid Build Coastguard Worker
144*cc02d7e2SAndroid Build Coastguard WorkerTODO(https://github.com/Cyan4973/xxHash/issues/548): revisit LICENSE
145*cc02d7e2SAndroid Build Coastguard Workerinstructions if upstream splits library and CLI.
146*cc02d7e2SAndroid Build Coastguard Worker
147*cc02d7e2SAndroid Build Coastguard WorkerThe upstream xxhash repository contains a bunch of files that we don't want, so
148*cc02d7e2SAndroid Build Coastguard Workerwe employ a rather manual update flow to pick up just the bits we care about:
149*cc02d7e2SAndroid Build Coastguard Worker
150*cc02d7e2SAndroid Build Coastguard Worker```
151*cc02d7e2SAndroid Build Coastguard Workergit remote add xxhash https://github.com/Cyan4973/xxHash.git
152*cc02d7e2SAndroid Build Coastguard Workergit fetch xxhash
153*cc02d7e2SAndroid Build Coastguard Workergit show xxhash/dev:xxhash.h > third_party/xxhash/xxhash.h
154*cc02d7e2SAndroid Build Coastguard Workergit show xxhash/dev:LICENSE | sed -nE '/^-+$/q;p' > third_party/xxhash/LICENSE
155*cc02d7e2SAndroid Build Coastguard Worker```
156