xref: /aosp_15_r20/external/cronet/third_party/protobuf/README.chromium (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1*6777b538SAndroid Build Coastguard WorkerName: Protocol Buffers
2*6777b538SAndroid Build Coastguard WorkerShort Name: protobuf
3*6777b538SAndroid Build Coastguard WorkerURL: https://github.com/google/protobuf
4*6777b538SAndroid Build Coastguard WorkerLicense: BSD
5*6777b538SAndroid Build Coastguard WorkerLicense File: LICENSE
6*6777b538SAndroid Build Coastguard WorkerVersion: 21.12
7*6777b538SAndroid Build Coastguard WorkerCPEPrefix: cpe:/a:google:protobuf:21.12
8*6777b538SAndroid Build Coastguard WorkerRevision: f0dc78d7e6e331b8c6bb2d5283e06aa26883ca7c
9*6777b538SAndroid Build Coastguard WorkerSecurity Critical: yes
10*6777b538SAndroid Build Coastguard WorkerShipped: yes
11*6777b538SAndroid Build Coastguard Worker
12*6777b538SAndroid Build Coastguard WorkerSteps used to create the current version (or roll a newer one):
13*6777b538SAndroid Build Coastguard Worker0. Nuke third_party/protobuf from orbit (rm -rf `third_party/protobuf`). Note
14*6777b538SAndroid Build Coastguard Worker   that this removes this README.chromium so you may want it open in code search
15*6777b538SAndroid Build Coastguard Worker   or remember the steps up until 2. where you get it back.
16*6777b538SAndroid Build Coastguard Worker
17*6777b538SAndroid Build Coastguard Worker1. Pull the release from https://github.com/google/protobuf/releases (Source
18*6777b538SAndroid Build Coastguard Worker   code .tar.gz). Extract to `third_party/protobuf` (without version suffix),
19*6777b538SAndroid Build Coastguard Worker   i.e. you may `$ mv protobuf-21.12 third_party/protobuf` or similar.
20*6777b538SAndroid Build Coastguard Worker
21*6777b538SAndroid Build Coastguard Worker2. Add back chromium's non-upstream files (from this directory):
22*6777b538SAndroid Build Coastguard Worker
23*6777b538SAndroid Build Coastguard Worker   $ git checkout main BUILD.gn DEPS DIR_METADATA OWNERS README.chromium \
24*6777b538SAndroid Build Coastguard Worker     gen_chromium_file_lists.py gen_extra_chromium_files.py proto_library.gni \
25*6777b538SAndroid Build Coastguard Worker     patches/
26*6777b538SAndroid Build Coastguard Worker
27*6777b538SAndroid Build Coastguard Worker   Note: Ideally we wouldn't do this but instead have a
28*6777b538SAndroid Build Coastguard Worker   `third_party/protobuf/src/` subdirectory where upstream code goes directly
29*6777b538SAndroid Build Coastguard Worker   into. That will require updating things outside this repository (at least
30*6777b538SAndroid Build Coastguard Worker   `third_party/webrtc`) to agree on where the source code lives. I wouldn't be
31*6777b538SAndroid Build Coastguard Worker   surprised if that also required Google-internal uses of protobuf from webrtc
32*6777b538SAndroid Build Coastguard Worker   to also agree on `third_party/protobuf/src` so maybe this'll never happen?
33*6777b538SAndroid Build Coastguard Worker   Here be dragons. Probably.
34*6777b538SAndroid Build Coastguard Worker
35*6777b538SAndroid Build Coastguard Worker   Probably worth making a local `git commit` here before applying patches (next
36*6777b538SAndroid Build Coastguard Worker   step).
37*6777b538SAndroid Build Coastguard Worker
38*6777b538SAndroid Build Coastguard Worker3. Apply patches in patches/ (see the description below):
39*6777b538SAndroid Build Coastguard Worker
40*6777b538SAndroid Build Coastguard Worker   $ for patch in patches/*; do patch -s -p1 < $patch; done
41*6777b538SAndroid Build Coastguard Worker
42*6777b538SAndroid Build Coastguard Worker   When a patch fails, it's probably best to check out previous state (from 3)
43*6777b538SAndroid Build Coastguard Worker   for any changes not inside the patches/ folder, fix the patch and then try to
44*6777b538SAndroid Build Coastguard Worker   reapply everything. It's not a good idea to fix the error, forget to generate
45*6777b538SAndroid Build Coastguard Worker   a patch and leave patches/ in a bad state.
46*6777b538SAndroid Build Coastguard Worker
47*6777b538SAndroid Build Coastguard Worker   If a patch no longer applies it may not be needed, if so remove it and its
48*6777b538SAndroid Build Coastguard Worker   description in this README.chromium file. Similarly try to eventually
49*6777b538SAndroid Build Coastguard Worker   upstream any patches out of band from unblocking the roll so we can
50*6777b538SAndroid Build Coastguard Worker   eventually remove it here as well.
51*6777b538SAndroid Build Coastguard Worker
52*6777b538SAndroid Build Coastguard Worker   Probably worth committing locally here too.
53*6777b538SAndroid Build Coastguard Worker
54*6777b538SAndroid Build Coastguard Worker4. Generate `proto_sources.gni` using the script `./gen_chromium_file_lists.py`.
55*6777b538SAndroid Build Coastguard Worker
56*6777b538SAndroid Build Coastguard Worker   Add and commit `proto_sources.gni`,
57*6777b538SAndroid Build Coastguard Worker
58*6777b538SAndroid Build Coastguard Worker5. Generate descriptor_pb2.py using the script "gen_extra_chromium_files.py" in
59*6777b538SAndroid Build Coastguard Worker   the same directory as this file.
60*6777b538SAndroid Build Coastguard Worker
61*6777b538SAndroid Build Coastguard Worker   $ ./gen_extra_chromium_files.py -C ../../out/Default
62*6777b538SAndroid Build Coastguard Worker
63*6777b538SAndroid Build Coastguard Worker   Add and commit `python/google/protobuf/descriptor_pb2.py` and
64*6777b538SAndroid Build Coastguard Worker   `python/google/protobuf/compiler/plugin_pb2.py` as well.
65*6777b538SAndroid Build Coastguard Worker
66*6777b538SAndroid Build Coastguard Worker6. Update Version, CPEPrefix and Revision in this file.
67*6777b538SAndroid Build Coastguard Worker
68*6777b538SAndroid Build Coastguard WorkerNotes (hints) for the next roll(er):
69*6777b538SAndroid Build Coastguard Worker
70*6777b538SAndroid Build Coastguard Worker* This is probably harder to roll than most things you've rolled in the past.
71*6777b538SAndroid Build Coastguard Worker  Good luck! Also please reach out for help proactively. The current roll as of
72*6777b538SAndroid Build Coastguard Worker  writing this required help from multiple very-senior people to even figure out
73*6777b538SAndroid Build Coastguard Worker  what was broken in the first place. `protobuf` rolling is not in a good place.
74*6777b538SAndroid Build Coastguard Worker* Update README.chromium as you go so you don't forget (after step 2. above, so
75*6777b538SAndroid Build Coastguard Worker  you don't nuke those changes).
76*6777b538SAndroid Build Coastguard Worker* Rolling one version of protobuf likely introduces a large amount of changes.
77*6777b538SAndroid Build Coastguard Worker  We should possibly figure out if it's reasonable to stay close to tip of tree
78*6777b538SAndroid Build Coastguard Worker  and roll frequently rather than use released versions. Sharp corners here
79*6777b538SAndroid Build Coastguard Worker  likely include that the version is encoded in protobuf output and I (pbos@)
80*6777b538SAndroid Build Coastguard Worker  don't know if that version tag changes immediately on format incompatibilities
81*6777b538SAndroid Build Coastguard Worker  or get bumped every time something format incompatible is introduced.
82*6777b538SAndroid Build Coastguard Worker* After v3.20 protobuf-javascript/ split out from upstream protobuf/. You may
83*6777b538SAndroid Build Coastguard Worker  need to be aware of both repositories. Also upstream protobuf/ seems to move
84*6777b538SAndroid Build Coastguard Worker  faster / out of sync with protobuf-javascript/. Hopefully that doesn't cause
85*6777b538SAndroid Build Coastguard Worker  format incompatibilities in the future (protobuf/ supports something we need
86*6777b538SAndroid Build Coastguard Worker  that protobuf-javascript/ doesn't).
87*6777b538SAndroid Build Coastguard Worker* Any argument changes to `protoc_wrapper` in `third_party/protobuf/BUILD.gn`
88*6777b538SAndroid Build Coastguard Worker  may require updating `build/config/siso/protoc_wrapper.star` as well.
89*6777b538SAndroid Build Coastguard Worker* We've seen instances where instead of rolling protobuf a local copy of a new
90*6777b538SAndroid Build Coastguard Worker  built-in type has been checked in. When that happens you may see ODR
91*6777b538SAndroid Build Coastguard Worker  violations as your built-in type is defined in multiple files. If that happens
92*6777b538SAndroid Build Coastguard Worker  you may want to move the copy that should never have been checked in into its
93*6777b538SAndroid Build Coastguard Worker  own namespace, complete the roll and then cleanup the local copy.
94*6777b538SAndroid Build Coastguard Worker* third_party/mediapipe checks in a weird modified copy of
95*6777b538SAndroid Build Coastguard Worker  `third_party/protobuf/src/google/protobuf/any.pb.cc` called `any_lite.pb.cc`.
96*6777b538SAndroid Build Coastguard Worker  This precompiled protobuf will get invalidated on any protobuf version bumps
97*6777b538SAndroid Build Coastguard Worker  and you'll need to either painstakingly generated a new one (do a diff of the
98*6777b538SAndroid Build Coastguard Worker  checked-in `any_lite.pb.{cc,h}` and current `any.pb.{cc,h}` to aid you in the
99*6777b538SAndroid Build Coastguard Worker  process.
100*6777b538SAndroid Build Coastguard Worker  WARNING: This item is a lot larger than it looks. We should really
101*6777b538SAndroid Build Coastguard Worker  either fix mediapipe upstream to build with `MEDIAPIPE_PROTO_LITE` and
102*6777b538SAndroid Build Coastguard Worker  `MEDIAPIPE_PROTO_THIRD_PARTY` both set, but it looks like that configuration
103*6777b538SAndroid Build Coastguard Worker  has bit rotted.
104*6777b538SAndroid Build Coastguard Worker
105*6777b538SAndroid Build Coastguard WorkerNote about vpython:
106*6777b538SAndroid Build Coastguard Worker
107*6777b538SAndroid Build Coastguard WorkerSome Python scripts end up mixing protoc output from this copy of protobuf with
108*6777b538SAndroid Build Coastguard Workerthe google.protobuf module from vpython's protobuf. If Python scripts break due
109*6777b538SAndroid Build Coastguard Workerto the vpython copy of protobuf, you may need to update the version in
110*6777b538SAndroid Build Coastguard Worker//.vpython3. See https://crbug.com/1320047.
111*6777b538SAndroid Build Coastguard Worker
112*6777b538SAndroid Build Coastguard WorkerDescription of the patches:
113*6777b538SAndroid Build Coastguard Worker
114*6777b538SAndroid Build Coastguard Worker- 0004-fix-shared-library-exports.patch
115*6777b538SAndroid Build Coastguard Worker
116*6777b538SAndroid Build Coastguard Worker  This patch allows exporting protobuf symbols in Linux .so libraries, so
117*6777b538SAndroid Build Coastguard Worker  that protobuf can be built as a component (see http://crrev.com/179806).
118*6777b538SAndroid Build Coastguard Worker
119*6777b538SAndroid Build Coastguard Worker- 0008-uninline_get_empty_string.patch
120*6777b538SAndroid Build Coastguard Worker- 0010-uninline-generated-code.patch
121*6777b538SAndroid Build Coastguard Worker
122*6777b538SAndroid Build Coastguard Worker  These patches uninline some functions, resulting in a significant reduction
123*6777b538SAndroid Build Coastguard Worker  (somewhere between 500 KB and 1 MB) of binary size.
124*6777b538SAndroid Build Coastguard Worker
125*6777b538SAndroid Build Coastguard Worker- 0021-Fix-protobuf-s-library-.gitinore-file.patch
126*6777b538SAndroid Build Coastguard Worker
127*6777b538SAndroid Build Coastguard Worker  Un-ignores python/google/protobuf/descriptor_pb2.py and
128*6777b538SAndroid Build Coastguard Worker  python/google/protobuf/compiler/plugin_pb2.py
129*6777b538SAndroid Build Coastguard Worker
130*6777b538SAndroid Build Coastguard Worker- 0022-Allow-deprecated-fields.patch
131*6777b538SAndroid Build Coastguard Worker
132*6777b538SAndroid Build Coastguard Worker  Allows deprecated fields to be used without extra C++ compiler warnings.
133*6777b538SAndroid Build Coastguard Worker
134*6777b538SAndroid Build Coastguard Worker- 0026-remove-sprintf.patch
135*6777b538SAndroid Build Coastguard Worker
136*6777b538SAndroid Build Coastguard Worker  Imports
137*6777b538SAndroid Build Coastguard Worker  https://github.com/protocolbuffers/protobuf/commit/c0fc2e881bc36aafb0bf539bf41889611370f60c
138*6777b538SAndroid Build Coastguard Worker  to remove use of sprintf.
139*6777b538SAndroid Build Coastguard Worker
140*6777b538SAndroid Build Coastguard Worker- 0027-no-noreturn.patch
141*6777b538SAndroid Build Coastguard Worker
142*6777b538SAndroid Build Coastguard Worker  Removes an instance of [[noreturn]]. The attribute is correct, but the way
143*6777b538SAndroid Build Coastguard Worker  protobuf's GOOGLE_LOG(FATAL) is defined, the compiler can't see this and it
144*6777b538SAndroid Build Coastguard Worker  trips -Winvalid-noreturn. See https://github.com/protocolbuffers/protobuf/issues/9817
145*6777b538SAndroid Build Coastguard Worker
146*6777b538SAndroid Build Coastguard Worker- 0029-make-initializers-optimizable.patch
147*6777b538SAndroid Build Coastguard Worker
148*6777b538SAndroid Build Coastguard Worker  Makes the InitProtobufDefaults() static initializer optimizable by Clang when
149*6777b538SAndroid Build Coastguard Worker  built with libc++. It patches out the OnShutdownDestroyString call, which we
150*6777b538SAndroid Build Coastguard Worker  do not need, and removes the thread-safe initialization. Thread safety is only
151*6777b538SAndroid Build Coastguard Worker  needed if a static initializer spawns a thread which then calls
152*6777b538SAndroid Build Coastguard Worker  InitProtobufDefaults() without synchronizing with the start of main().
153*6777b538SAndroid Build Coastguard Worker  (Anything which happens after main() starts can rely on the initializer
154*6777b538SAndroid Build Coastguard Worker  running.)
155*6777b538SAndroid Build Coastguard Worker
156*6777b538SAndroid Build Coastguard Worker- 0030-workaround-window-constinit.patch
157*6777b538SAndroid Build Coastguard Worker
158*6777b538SAndroid Build Coastguard Worker  Disables PROTOBUF_CONSTINIT in generated code in Windows shared library
159*6777b538SAndroid Build Coastguard Worker  builds. Protobuf's default instances take pointers to a dllimport variable,
160*6777b538SAndroid Build Coastguard Worker  fixed_address_empty_string. This is not constinit on Windows. This is a bug in
161*6777b538SAndroid Build Coastguard Worker  protobuf as the default instance was intended to be constant-initialized. But
162*6777b538SAndroid Build Coastguard Worker  the components build in Chromium is a developer configuration, so we tolerate
163*6777b538SAndroid Build Coastguard Worker  an initializer as long as the build works, until protobuf has a proper fix.
164*6777b538SAndroid Build Coastguard Worker
165*6777b538SAndroid Build Coastguard Worker  See https://github.com/protocolbuffers/protobuf/issues/10159.
166*6777b538SAndroid Build Coastguard Worker
167*6777b538SAndroid Build Coastguard Worker- 0031-workaround-cfi-unrelated-cast.patch
168*6777b538SAndroid Build Coastguard Worker
169*6777b538SAndroid Build Coastguard Worker  A workaround for Clang's Control Flow Integrity check for casting pointers to
170*6777b538SAndroid Build Coastguard Worker  memory that his not yet initialized to be of that type for empty arrays, does
171*6777b538SAndroid Build Coastguard Worker  not work, and still fails. This patch removes the workaround and instead
172*6777b538SAndroid Build Coastguard Worker  disables cfi-unrelated-cast for the affected methods and simplifies them.
173*6777b538SAndroid Build Coastguard Worker
174*6777b538SAndroid Build Coastguard Worker  See https://github.com/protocolbuffers/protobuf/issues/10186.
175*6777b538SAndroid Build Coastguard Worker  See https://bugs.chromium.org/p/chromium/issues/detail?id=1294200#c26.
176*6777b538SAndroid Build Coastguard Worker
177*6777b538SAndroid Build Coastguard Worker- 0032-cxx20.patch
178*6777b538SAndroid Build Coastguard Worker
179*6777b538SAndroid Build Coastguard Worker  Fixes necessary to build in --std=c++20 mode.
180*6777b538SAndroid Build Coastguard Worker
181*6777b538SAndroid Build Coastguard Worker  Imports https://critique.corp.google.com/cl/451177197 (a portion of
182*6777b538SAndroid Build Coastguard Worker  https://github.com/protocolbuffers/protobuf/commit/6dd8af4ecfa7987bddb309862932886b84f1e4ef
183*6777b538SAndroid Build Coastguard Worker  ).
184*6777b538SAndroid Build Coastguard Worker
185*6777b538SAndroid Build Coastguard Worker- 0033-no-enum-conversion-warn.patch
186*6777b538SAndroid Build Coastguard Worker
187*6777b538SAndroid Build Coastguard Worker  Avoid hitting the clang error -Wenum-constexpr-conversion by specifying width
188*6777b538SAndroid Build Coastguard Worker  of the enum.
189*6777b538SAndroid Build Coastguard Worker
190*6777b538SAndroid Build Coastguard Worker  Imports https://critique.corp.google.com/cl/466986872.
191*6777b538SAndroid Build Coastguard Worker
192*6777b538SAndroid Build Coastguard Worker- 0034-change-macro-to-avoid-pedantic-warning.patch
193*6777b538SAndroid Build Coastguard Worker
194*6777b538SAndroid Build Coastguard Worker  Avoid hitting -Wextra-semi.
195*6777b538SAndroid Build Coastguard Worker
196*6777b538SAndroid Build Coastguard Worker  Imports (rebased):
197*6777b538SAndroid Build Coastguard Worker  https://github.com/protocolbuffers/protobuf/commit/def602dd07b7eae1cac6823705975317b5607fc3
198*6777b538SAndroid Build Coastguard Worker
199*6777b538SAndroid Build Coastguard Worker- 0035-fix-shared-library-constants
200*6777b538SAndroid Build Coastguard Worker
201*6777b538SAndroid Build Coastguard Worker  Fixes for component build when building with MediaPipe. AnyMetadata::PackFrom
202*6777b538SAndroid Build Coastguard Worker  is called which require string constants to be exported.
203*6777b538SAndroid Build Coastguard Worker
204*6777b538SAndroid Build Coastguard Worker- 0036-fix-undefined-memcpy-call.patch
205*6777b538SAndroid Build Coastguard Worker
206*6777b538SAndroid Build Coastguard Worker  Fixes an undefined call to memcpy which may be passed NULL, 0. NULL, 0 is
207*6777b538SAndroid Build Coastguard Worker  forbidden in C, due to a mistake in the C language specification. This
208*6777b538SAndroid Build Coastguard Worker  partially integrates
209*6777b538SAndroid Build Coastguard Worker  https://github.com/protocolbuffers/protobuf/commit/b2e1d7d8a1b1959c782595cd815c22fb690ac8e2
210*6777b538SAndroid Build Coastguard Worker  from upstream and may be removed when protobuf is updated past that commit.
211*6777b538SAndroid Build Coastguard Worker
212*6777b538SAndroid Build Coastguard Worker- 0037-fix-wextra-semi.patch
213*6777b538SAndroid Build Coastguard Worker
214*6777b538SAndroid Build Coastguard Worker  Removes an extra semicolon, fixed in upstream
215*6777b538SAndroid Build Coastguard Worker  https://github.com/protocolbuffers/protobuf/commit/3e6f8ee152db71ae49cc95649feab50d2faacdfa
216*6777b538SAndroid Build Coastguard Worker
217*6777b538SAndroid Build Coastguard Worker- 0038-silence-implicit-precision-loss.patch
218*6777b538SAndroid Build Coastguard Worker
219*6777b538SAndroid Build Coastguard Worker  Silences -Wshorten-64-to-32 for now. Fixed in upstream
220*6777b538SAndroid Build Coastguard Worker  https://github.com/protocolbuffers/protobuf/commit/d85c9944c55fb38f4eae149979a0f680ea125ecb
221*6777b538SAndroid Build Coastguard Worker
222*6777b538SAndroid Build Coastguard Worker- 0039-generate-mediapipe-anylite.patch
223*6777b538SAndroid Build Coastguard Worker
224*6777b538SAndroid Build Coastguard Worker  Workaround to allow generating protobuf code compatible with
225*6777b538SAndroid Build Coastguard Worker  third_party/mediapipe. This replaces checked-in precompiled .pb.cc files. See
226*6777b538SAndroid Build Coastguard Worker  https://crbug.com/332939935, which when/if resolved should make this patch
227*6777b538SAndroid Build Coastguard Worker  obsolete.
228*6777b538SAndroid Build Coastguard Worker
229*6777b538SAndroid Build Coastguard Worker- 0040-fix-ndk-major.patch
230*6777b538SAndroid Build Coastguard Worker
231*6777b538SAndroid Build Coastguard Worker  Fix Android compile error that affects webrtc. Fixed in upstream
232*6777b538SAndroid Build Coastguard Worker  https://github.com/protocolbuffers/protobuf/commit/9471a882256eaf01027524e8b6c15cbb5e42bef6
233