Compare commits

...

447 commits

Author SHA1 Message Date
Protobuf Team Bot
7b091ee68e Auto-generate files after cl/970967137
Some checks failed
Tests / Bazel (push) Has been skipped
Auto-generate stale checked-in files / Refresh stale files (push) Failing after 0s
Tests / Apply Safe for Tests Label (push) Failing after 0s
Tests / Validate YAML (push) Has been skipped
Scorecard supply-chain security / Scorecard analysis (push) Failing after 4s
Tests / C++ (push) Has been skipped
Tests / Java (push) Has been skipped
Tests / Python (push) Has been skipped
Tests / Ruby (push) Has been skipped
Tests / PHP (push) Has been skipped
Tests / Remove safety tag (push) Failing after 0s
Tests / PHP Extension (push) Has been skipped
Tests / C# (push) Has been skipped
Tests / Objective-C (push) Has been skipped
Tests / Rust (push) Has been skipped
Tests / μpb (push) Has been skipped
Tests / hpb (push) Has been skipped
Tests / Staleness (push) Has been cancelled
Tests / All Blocking Tests (push) Has been cancelled
2026-08-26 03:24:01 +00:00
Protobuf Team Bot
6a21212800 Hopefully final batch of return value checks before UPB_NODISCARD enforcement
PiperOrigin-RevId: 970967137
2026-08-25 20:13:17 -07:00
Protobuf Team Bot
b6ca8b9fb1 Support non-canonical extensions in Python upb unknown fields.
PiperOrigin-RevId: 970866648
2026-08-25 16:19:50 -07:00
Protobuf Team Bot
67322442bd Auto-generate files after cl/970851165 2026-08-25 23:08:01 +00:00
Protobuf Team Bot
d43953b4b9 Add upb_Message_NextWireFormatUnknown to iterate over unknown fields in wire format.
PiperOrigin-RevId: 970851165
2026-08-25 15:56:43 -07:00
Protobuf Team Bot
b8ce5dceea Auto-generate files after cl/970834999 2026-08-25 22:41:40 +00:00
Joshua Haberman
f1c23cb216 Prepare Protobuf for a future version of Bazel which will lack the proto fragment
The ultimate effect of this change will be that both the native flags and Starlark flags will continue to work with future versions of Bazel that lack the proto fragment, until such time as we deprecate or remove the flags in a Protobuf release.  This decouples Bazel releases from Protobuf behavior changes.

1. Builds on the Bazel 8-compatible abstraction layer we submitted in cl/955468205 by setting `HAS_NATIVE_PROTO_FLAGS` properly in Bazel.  We do this by adding a `rules.has_proto_fragment` setting to the `proto_bazel_features.bzl` mechanism: we know that the fragment no longer needs to be read in Bazel 9+, because we can use `flag_alias()` instead.
2. Adds `flag_alias()` declarations in MODULE.bazel for all compat layer flags.  This will work in Bazel 9, but is ignored in Bazel 8.

This leads to a slight inconsistency.  Consider the following set of flags set by a user:

```
--@protobuf//bazel/flags:protocopt=foo --protocopt=bar
```

In Bazel 9+, where the flag alias is respected, the final value of the flag will be `bar`.  In Bazel 8, where we emulate `flag_alias()` by reconciling the two different values at analysis time, we always prefer the Starlark version (and cannot tell the relative order), so the final value of the flag will be `foo`.

To avoid this, prefer setting the Starlark version of the flag whenever possible.

PiperOrigin-RevId: 970834999
2026-08-25 15:30:42 -07:00
corpagent-eng-adazhang
ea0f2968ed Internal change
PiperOrigin-RevId: 970808467
2026-08-25 14:46:43 -07:00
Protobuf Team Bot
ff9440f2ee Auto-generate files after cl/970790688 2026-08-25 21:29:46 +00:00
Joshua Haberman
734819d9dc Delete com_google_protobuf_previous_release and associated breaking tests
When trying to land https://github.com/protocolbuffers/protobuf/pull/28957, I ran into problems with the `@com_google_protobuf_previous_release` repo.  The root cause of these problems was that this repo combines a previous version of all of our `.bzl` files (like `proto_library.bzl`) with the *current* version of our `MODULE.bazel` file.

This is a combination that no user will actually encounter, and when skew between the two causes issues, it is very difficult to debug and fix.

If we want to re-introduce these breaking change tests in the future, an alternative approach that would cause fewer problems is to use the examples module at https://github.com/protocolbuffers/protobuf/tree/main/examples.  That module could include previous versions of the `.proto` files, as well as the breaking change tests to compare against the protos in `@com_google_protobuf`.

Since the examples module does not contain a copy of all our `.bzl` files, this design would avoid the `.bzl` skew that causes problems in the current setup.

PiperOrigin-RevId: 970790688
2026-08-25 14:21:28 -07:00
Protobuf Team Bot
2d75af0868 Auto-generate files after cl/970750490 2026-08-25 20:36:15 +00:00
Samuel Benzaquen
1cf5e73656 Remove version pin from the script.
Let it get the one from .bazeliskrc

This fixes the autoupdater robot.

PiperOrigin-RevId: 970750490
2026-08-25 13:25:37 -07:00
Tony Liao
6836552e25 Allow later enum aliases to overwrite in C# custom JSON enum mapping.
When constructing the custom JSON enum name map in C# JsonParser, remove the
ContainsKey check so that subsequent aliased enum values overwrite earlier ones,
aligning with the "last match wins" semantics used across C++, Java, PHP, and Python.

PiperOrigin-RevId: 970656172
2026-08-25 10:50:27 -07:00
Samuel Benzaquen
b445fe13b1 Continue cleaning up after the GLOBALS experiment.
Change registration APIs to take ClassData* instead of prototypes.

PiperOrigin-RevId: 970649058
2026-08-25 10:41:13 -07:00
Jason Lunn
3df019d491 Forward-port Rust crate swap (#29397)
Cherrypick crate fixes from 36.x to main

Closes #29397

COPYBARA_INTEGRATE_REVIEW=https://github.com/protocolbuffers/protobuf/pull/29397 from protocolbuffers:forward_port_crate_swap 2b5bb9fe65
PiperOrigin-RevId: 970589358
2026-08-25 09:08:44 -07:00
Protobuf Team Bot
d17cf67434 Use monomorphic static dispatch for Java Protobuf submessage parsing
PiperOrigin-RevId: 970550003
2026-08-25 07:51:15 -07:00
Samuel Benzaquen
d3daee4c68 Continue cleaning up after the GLOBALS experiment.
Remove branching for MessageGlobalsBase and the trait.

PiperOrigin-RevId: 970537151
2026-08-25 07:25:40 -07:00
Tony Liao
9d98477ca9 Optimize pure Python parse path for custom JSON enum names.
This implementation is similar to our Java idea in cl/949670944,
basically the idea is that we will have a local map (dictionary) that
will be populated the very first time we try to parse into an enum
field. The lifetime of this dictionary will be tied to the Parser
instance, similar to the Java implementation.

BENCHMARKS (baseline stats are recorded at cl/952170250):

Python:
```
[BENCHMARK] ParseJsonDefault:                med 10.06 us/op | p99 11.22 us/op | mean 10.10 ± 0.20 us/op
[BENCHMARK] ParseJsonCustom:                 med 20.33 us/op | p99 22.23 us/op | mean 20.40 ± 0.34 us/op
[BENCHMARK] ParseJsonUnknownIgnored:         med 24.21 us/op | p99 26.25 us/op | mean 24.31 ± 0.44 us/op
[BENCHMARK] ParseRepeatedJsonDefault:        med 1.94 us/item | p99 2.05 us/item | mean 1.95 ± 0.03 us/item
[BENCHMARK] ParseRepeatedJsonCustom:         med 2.26 us/item | p99 2.45 us/item | mean 2.27 ± 0.03 us/item
[BENCHMARK] ParseRepeatedJsonUnknownIgnored: med 5.31 us/item | p99 5.52 us/item | mean 5.32 ± 0.05 us/item
```

Cpp:
```
[BENCHMARK] ParseJsonDefault:                med 8.66 us/op | p99 9.21 us/op | mean 8.70 ± 0.13 us/op
[BENCHMARK] ParseJsonCustom:                 med 26.33 us/op | p99 29.71 us/op | mean 26.44 ± 0.69 us/op
[BENCHMARK] ParseJsonUnknownIgnored:         med 28.46 us/op | p99 31.80 us/op | mean 28.59 ± 0.67 us/op
[BENCHMARK] ParseRepeatedJsonDefault:        med 1.72 us/item | p99 2.19 us/item | mean 1.74 ± 0.06 us/item
[BENCHMARK] ParseRepeatedJsonCustom:         med 2.12 us/item | p99 2.38 us/item | mean 2.13 ± 0.04 us/item
[BENCHMARK] ParseRepeatedJsonUnknownIgnored: med 4.61 us/item | p99 4.92 us/item | mean 4.62 ± 0.07 us/item
```

UPB:
```
[BENCHMARK] ParseJsonDefault:                med 11.22 us/op | p99 12.29 us/op | mean 11.27 ± 0.21 us/op
[BENCHMARK] ParseJsonCustom:                 med 37.54 us/op | p99 39.25 us/op | mean 37.65 ± 0.46 us/op
[BENCHMARK] ParseJsonUnknownIgnored:         med 41.18 us/op | p99 48.45 us/op | mean 41.30 ± 0.89 us/op
[BENCHMARK] ParseRepeatedJsonDefault:        med 2.10 us/item | p99 2.19 us/item | mean 2.10 ± 0.02 us/item
[BENCHMARK] ParseRepeatedJsonCustom:         med 2.58 us/item | p99 2.73 us/item | mean 2.59 ± 0.03 us/item
[BENCHMARK] ParseRepeatedJsonUnknownIgnored: med 5.70 us/item | p99 5.90 us/item | mean 5.71 ± 0.04 us/item
```

Seeing these benchmarks, we can see a very noticeable improvement in
`ParseRepeatedJsonCustom` and `ParseRepeatedJsonUnknownIgnored` cases --
which correspond to the pathological cases that we are worried about.
Singular fields are taking longer to parse in our microbenchmark because
the cache that we've added is tied to each Parser instance and must be
re-instantiated across every `Parse` call.

PiperOrigin-RevId: 970528683
2026-08-25 07:09:41 -07:00
Protobuf Team Bot
7f86060aae Avoid unchecked cast warnings in TextFormat.parse
Use Class.cast instead of unchecked casts to eliminate @SuppressWarnings("unchecked") in TextFormat.parse overloads.

Shouldn't be a performance problem - this is only available in full runtime (not android) where hotspot has a class.cast intrinsic (and text proto parsing is relatively slow anyway, this won't be the bottleneck).

PiperOrigin-RevId: 970171466
2026-08-24 17:04:58 -07:00
Protobuf Team Bot
44baf91cc1 Improve type safety in ProtobufList.concatenate
Use Collection<?> for the sizing check to eliminate unchecked cast warning and narrow @SuppressWarnings("unchecked") to the specific ProtobufList fast-path assignment.

PiperOrigin-RevId: 970165037
2026-08-24 16:54:42 -07:00
Protobuf Team Bot
11117398dd Update CodedInputStream Javadoc regarding exception handling and isAtEnd behavior.
PiperOrigin-RevId: 970118591
2026-08-24 15:32:21 -07:00
Protobuf Team Bot
0258a65743 Internal change
PiperOrigin-RevId: 970105512
2026-08-24 15:09:41 -07:00
Protobuf Team Bot
205d45b629 Migrate Java(Lite|Mutable|)ProtoLibraryTest.testEmptySrcsForJavaApi to Starlark-based analysis test.
PiperOrigin-RevId: 970099350
2026-08-24 14:58:47 -07:00
Protobuf Team Bot
4d20214ca8 Internal change.
PiperOrigin-RevId: 970073736
2026-08-24 14:21:14 -07:00
Protobuf Team Bot
dee117a787 Avoid empty byte array allocations in Proto Lite toByteArray().
In AbstractMessageLite.toByteArray(), check if getSerializedSize() == 0 and return Internal.EMPTY_BYTE_ARRAY directly instead of allocating a new 0-byte array and CodedOutputStream wrappers.

PiperOrigin-RevId: 970010400
2026-08-24 12:44:01 -07:00
Protobuf Team Bot
672eda6f1f Fasttable: Fix overly strict assert.
PiperOrigin-RevId: 969873676
2026-08-24 08:43:17 -07:00
Protobuf Team Bot
f1a2ca97f8 Avoid unchecked cast warning in Internal.getDefaultInstance
Use Class.cast instead of an unchecked generic cast to avoid compiler warnings and ensure runtime type safety.

Not a big deal but a nice opportunity to remove a warning.

This is only used in the full runtime AFAIK, where hotspot has an intrinsic for Class.cast so shouldn't be a performance issue.

PiperOrigin-RevId: 969794451
2026-08-24 05:40:20 -07:00
Protobuf Team Bot
a55c302e3f Automated Code Change
PiperOrigin-RevId: 969413413
2026-08-23 09:06:54 -07:00
Protobuf Team Bot
407b27d8da Automated Code Change
PiperOrigin-RevId: 969393499
2026-08-23 07:56:27 -07:00
Ada Zhang
e712d276bc Add upb_Message_NextSerializableField and unify field presence checks.
PiperOrigin-RevId: 968809631
2026-08-21 18:42:09 -07:00
Sandy Zhang
718a3e58b4 Document context and Java runtime guidance on feature extension restriction.
PiperOrigin-RevId: 968759632
2026-08-21 16:33:49 -07:00
Protobuf Team Bot
2901ce6db3 Handle refcount issues on allocation failure in python
PiperOrigin-RevId: 968724072
2026-08-21 15:34:04 -07:00
Protobuf Team Bot
bf50167a85 Allow disabling lazy parsing in individual ExtensionRegistryLite which will signal the parsing whether should parse extension fields lazily.
PiperOrigin-RevId: 968674119
2026-08-21 13:57:24 -07:00
Samuel Benzaquen
39882988a9 Remove tc_table from MessageInfo.
This reduces the size of ExtensionInfo.

PiperOrigin-RevId: 968562757
2026-08-21 10:17:44 -07:00
Samuel Benzaquen
035554bd86 Continue cleaning up after the GLOBALS experiment.
Remove TcParser::GetTable and migrate callers to MessageTraits.

PiperOrigin-RevId: 968547835
2026-08-21 09:52:47 -07:00
Protobuf Team Bot
e29507ff0d Migrate upb_Message_NextUnknown to upb_Message_NextUnknown2 in _cel_UnknownFields_FromMessage to support non-canonical extensions.
PiperOrigin-RevId: 968134008
2026-08-20 16:51:29 -07:00
Clayton Knittel
12d69dbd9f Automated rollback of commit 6b336e7038.
PiperOrigin-RevId: 968043364
2026-08-20 14:07:43 -07:00
Protobuf Team Bot
5957f0ecdb Enable FastTable for non-opt builds.
PiperOrigin-RevId: 968007366
2026-08-20 13:10:05 -07:00
Samuel Benzaquen
50c6c24a2b Remove table prefetching experiment.
It didn't pan out and was never turned on.

PiperOrigin-RevId: 967969922
2026-08-20 12:09:14 -07:00
Clayton Knittel
60a6b5f352 Move generated methods specialized by simple bases to Helpers_.
PiperOrigin-RevId: 967928105
2026-08-20 11:02:19 -07:00
Protobuf Team Bot
03e410d5f7 Migrate JavaProtoLibraryTest.testJavaProtosExposesJavaProvider and lite / mutable counterparts JavaLiteProtoLibraryTest and JavaMutableProtoLibraryTest to Starlark-based analysis test.
PiperOrigin-RevId: 967869339
2026-08-20 09:30:04 -07:00
Protobuf Team Bot
f6cd30a44e Enable FastTable for non-opt builds.
PiperOrigin-RevId: 967807696
2026-08-20 07:25:36 -07:00
Ada Zhang
a972dac424 Support printing non-canonical extensions in the text encoder.
PiperOrigin-RevId: 967565448
2026-08-19 21:20:45 -07:00
Clayton Knittel
bca6336df1 Move internal message helper functions into the Helpers_ struct.
This change moves internal helper methods (PlacementNew_, InternalNewImpl_, and InternalGenerateClassData_) from the main message class into a nested `Helpers_` struct.

PiperOrigin-RevId: 967513868
2026-08-19 18:28:39 -07:00
Protobuf Team Bot
8917ad8c48 Fix unused return value warnings in upb call sites and tests.
Several functions in upb marked with UPB_NODISCARD had their return values ignored in test and wrapper call sites.

Check and assert the return values of upb_Message_SetString, upb_Message_SetInt32, upb_ExtensionRegistry_AddArray, _upb_Message_AddUnknown, upb_Array_New, and _upb_Array_ResizeUninitialized across upb and protobuf tests and wrappers.

PiperOrigin-RevId: 967461770
2026-08-19 16:15:36 -07:00
Protobuf Team Bot
9996b547f7 Fasttable: fix gaps in malformed tag guarding.
PiperOrigin-RevId: 967454749
2026-08-19 16:04:34 -07:00
Protobuf Team Bot
229a528948 Handle more allocation failures
PiperOrigin-RevId: 967454374
2026-08-19 15:59:03 -07:00
Protobuf Team Bot
2de70d7105 Add allocation failure tests for unknowns and defbuilder
PiperOrigin-RevId: 967386997
2026-08-19 13:46:43 -07:00
Clayton Knittel
bdf71ccdd1 Move InternalGenerateParseTable_ to .pb.cc.
This moves `InternalGenerateParseTable_` to the nested `_Internals` class, which is only defined in `.pb.cc`, and renames it to `GenerateParseTable` (now that the `Internal` would be redundant).

PiperOrigin-RevId: 967383875
2026-08-19 13:41:28 -07:00
Samuel Benzaquen
676d7209c3 Internal change
PiperOrigin-RevId: 967359668
2026-08-19 12:55:58 -07:00
Samuel Benzaquen
e12fe75fc7 Use the enum validation data for dynamic extensions too.
This removes an unnecessary branch in validation code and will allow reducing
the size of ExtensionInfo in a future change.

PiperOrigin-RevId: 967326524
2026-08-19 11:48:44 -07:00
Samuel Benzaquen
2c1ea6b8c9 Hide the synthetic MapEntry class in the pb.cc file.
This reduces the cost of including the headers.

PiperOrigin-RevId: 967299746
2026-08-19 11:00:02 -07:00
Protobuf Team Bot
d21931d398 Remove C23 requirement from FastTable.
Provide dummy argument for variadic macro to satisfy pre-C23 requirements.

Remove trailing `;` that duplicates `;` generated by macro expansion.

PiperOrigin-RevId: 967288052
2026-08-19 10:38:05 -07:00
Samuel Benzaquen
7ef3576267 Continue cleaning up after the GLOBALS experiment.
Clean up ExtensionInfo to contain a ClassData* instead.

PiperOrigin-RevId: 967283147
2026-08-19 10:27:48 -07:00
Protobuf Team Bot
c1d8a858cd Short-circuit empty packed fields in CodedInputStream.countPackedVarints
0-length packed fields occur but are fairly rare since our serializers will emit nothing instead of emitting a 0-length packed field. But, there's little reason to leave inequality case behind since we're checking against <=0 anyway.

PiperOrigin-RevId: 967271476
2026-08-19 10:08:51 -07:00
Samuel Benzaquen
c5055727eb Continue cleaning up after the GLOBALS experiment.
Remove some preprocessor branching in the runtime.

PiperOrigin-RevId: 967240247
2026-08-19 09:05:21 -07:00
Samuel Benzaquen
1a23830881 [Py/C++] Fixed data race in Python free threading by removing obsolete hack
We previously had a hack in Python/C++ Protobuf to account for the fact that LazyField did not properly remember a custom DescriptorPool or MessageFactory that was set in the ParseContext at parse time.

The code has since been fixed to properly handle the case where ParseContext contains a custom DescriptorPool/MessageFactory.  Removing the hack removes the data race under free threading.

PiperOrigin-RevId: 967236272
2026-08-19 08:59:26 -07:00
Ada Zhang
2256d8f028 Support converting non-canonical extensions in upb message conversion.
PiperOrigin-RevId: 966915077
2026-08-18 18:24:53 -07:00
Protobuf Team Bot
6165c52793 Validate tag match before treating unlinked submessages as unknown fields.
Otherwise colliding fields will incorrectly end up in unknowns.

PiperOrigin-RevId: 966858004
2026-08-18 16:10:58 -07:00
Ada Zhang
d068b54ba6 Internal
PiperOrigin-RevId: 966853376
2026-08-18 16:07:00 -07:00
Protobuf Team Bot
37f78578e7 - Updates DslList and ExtensionList to take a lazy supplier lambda () -> List<E>, retaining secondary constructors for binary backward compatibility with existing compiled proto code.
PiperOrigin-RevId: 966853174
2026-08-18 16:01:51 -07:00
Protobuf Team Bot
6e4f4ca54a Fix UPB_FASTTABLE declaration to avoid errors with recursive C macro expansion.
Place "hidden" attribute behind macro conditioned on compiler support.

Disable UPB_FASTTABLE on Windows, as MSVC doesn't support required compiler features. (Existing detection can be confounded on Windows for clang-cl, which may run in normal mode during codegen but compile final binaries in MSVC compat mode.)

PiperOrigin-RevId: 966832345
2026-08-18 15:17:19 -07:00
Tony Liao
f9f94388a3 Additional unit tests for Python handling of custom JSON enum names.
The unit tests added in the initial implementation in cl/925012500 and
cl/922729754 were fairly minimal. I took some inspiration from our C++
and Java unit tests for JSON's custom enum name parsing to come up with
these new test cases.

This change also adds a python Benchmark that we can use to verify that
our optimizations in cl/952170251 actually works.

Benchmark results across all three proto implementations (cpp, python, upb):

=== C++ Extension Protos (json_format_benchmark_cpp_protos) ===
[BENCHMARK] ParseJsonDefault:                med 8.70 us/op | p99 9.56 us/op | mean 8.74 ± 0.15 us/op
[BENCHMARK] ParseJsonCustom:                 med 17.39 us/op | p99 21.64 us/op | mean 17.43 ± 0.51 us/op
[BENCHMARK] ParseJsonUnknownIgnored:         med 26.97 us/op | p99 32.04 us/op | mean 27.06 ± 0.65 us/op
[BENCHMARK] ParseRepeatedJsonDefault:        med 1.71 us/item | p99 1.83 us/item | mean 1.71 ± 0.02 us/item
[BENCHMARK] ParseRepeatedJsonCustom:         med 9.18 us/item | p99 9.88 us/item | mean 9.20 ± 0.11 us/item
[BENCHMARK] ParseRepeatedJsonUnknownIgnored: med 18.79 us/item | p99 19.19 us/item | mean 18.81 ± 0.13 us/item

=== UPB Extension Protos (json_format_benchmark_upb_protos) ===
[BENCHMARK] ParseJsonDefault:                med 8.70 us/op | p99 9.56 us/op | mean 8.74 ± 0.15 us/op
[BENCHMARK] ParseJsonCustom:                 med 17.39 us/op | p99 21.64 us/op | mean 17.43 ± 0.51 us/op
[BENCHMARK] ParseJsonUnknownIgnored:         med 26.97 us/op | p99 32.04 us/op | mean 27.06 ± 0.65 us/op
[BENCHMARK] ParseRepeatedJsonDefault:        med 1.71 us/item | p99 1.83 us/item | mean 1.71 ± 0.02 us/item
[BENCHMARK] ParseRepeatedJsonCustom:         med 9.18 us/item | p99 9.88 us/item | mean 9.20 ± 0.11 us/item
[BENCHMARK] ParseRepeatedJsonUnknownIgnored: med 18.79 us/item | p99 19.19 us/item | mean 18.81 ± 0.13 us/item

=== Pure Python Protos (json_format_benchmark_python_protos) ===
[BENCHMARK] ParseJsonDefault:                med 10.26 us/op | p99 11.20 us/op | mean 10.30 ± 0.25 us/op
[BENCHMARK] ParseJsonCustom:                 med 16.59 us/op | p99 18.35 us/op | mean 16.70 ± 0.45 us/op
[BENCHMARK] ParseJsonUnknownIgnored:         med 25.09 us/op | p99 28.22 us/op | mean 25.27 ± 0.65 us/op
[BENCHMARK] ParseRepeatedJsonDefault:        med 1.94 us/item | p99 3.25 us/item | mean 1.97 ± 0.14 us/item
[BENCHMARK] ParseRepeatedJsonCustom:         med 7.16 us/item | p99 10.35 us/item | mean 7.24 ± 0.39 us/item
[BENCHMARK] ParseRepeatedJsonUnknownIgnored: med 15.43 us/item | p99 19.54 us/item | mean 15.54 ± 0.49 us/item

PiperOrigin-RevId: 966820541
2026-08-18 14:57:30 -07:00
Protobuf Team Bot
86c32b72d9 Fix fasttable support in Kotlin UPB.
When fasttable is enabled, generated minitable headers transitively include internal fasttable headers (such as field_parsers.h / combinations.h / types.h). Adding field_parsers to upb_cinterop's deps under fasttable_enabled_setting ensures that these declarations are provided centrally by upb_cinterop.klib and not duplicated across individual proto libraries.

PiperOrigin-RevId: 966816120
2026-08-18 14:48:59 -07:00
Protobuf Team Bot
b9c05c1d72 Internal change.
PiperOrigin-RevId: 966801750
2026-08-18 14:19:21 -07:00
Samuel Benzaquen
c8cc70ea9b Skip RepeatedVarint.Int32Overflow test on aarch64.
PiperOrigin-RevId: 966792622
2026-08-18 14:03:17 -07:00
Samuel Benzaquen
bf0c808084 Continue cleaning up after the GLOBALS experiment.
Merge ClassDataLite and ClassDataFull into ClassData.
Remove dead constructor parameters.

PiperOrigin-RevId: 966749162
2026-08-18 12:44:28 -07:00
Protobuf Team Bot
915853d5ef Automated rollback of commit 780ba8c700.
PiperOrigin-RevId: 966636867
2026-08-18 09:27:45 -07:00
Clayton Knittel
f930654518 Check consistency of ClassData types of RepeatedPtrField members in the destructor.
The repeated field destructor caches the element destructor and calls it on each element of a repeated field, rather than going through full dynamic dispatch for each element. Currently, if the elements of a repeated field are of different types, this code may segfault in non-obvious ways (e.g. mismatch size-delete, or memory corruption). The DCHECK gives a better error message when you have repeated fields of mixed element types.

This code is only active with `enable_custom_vtable`.

PiperOrigin-RevId: 966610091
2026-08-18 08:34:15 -07:00
Protobuf Team Bot
53bc98a9f4 Internal change.
PiperOrigin-RevId: 966561020
2026-08-18 06:37:04 -07:00
Protobuf Team Bot
42879bb405 Delete examples/.bazelversion
The version number is set to 7.1.0 and the contents of the example would never work on 7.x.

Our CI always sets a version which is why this not mattering, but it appears that if you hold it exactly right bazelisk will use this version if present, but fall back to latest bazel if not. Just deleting the file so we don't let it rot again.

PiperOrigin-RevId: 966558235
2026-08-18 06:34:01 -07:00
Protobuf Team Bot
cfb934ad48 Optimize Java Protobuf packed varint counting using SWAR bitwise operations.
Implements 64-bit SWAR chunking via ByteBuffer on non-Android devices, falling back to a scalar countdown loop on Android devices. Sub-8 byte inputs bypass 64-bit chunking and fall through to scalar counting.

### JMH Microbenchmark Results (VarintCountingBenchmark)

| Payload Length | Scalar Baseline | SWAR (ByteBuffer) | Speedup |
| :--- | :--- | :--- | :--- |
| 1 B | 1.78 ns/op | 1.91 ns/op | 1.0x (parity) |
| 4 B | 3.75 ns/op | 3.65 ns/op | 1.0x (parity) |
| 8 B | 6.19 ns/op | 3.44 ns/op | 1.8x faster |
| 16 B | 9.93 ns/op | 4.00 ns/op | 2.5x faster |
| 32 B | 18.58 ns/op | 5.06 ns/op | 3.7x faster |
| 64 B | 35.50 ns/op | 7.51 ns/op | 4.7x faster |
| 128 B | 74.66 ns/op | 10.92 ns/op | 6.8x faster |
| 1024 B | 641.02 ns/op | 75.63 ns/op | 8.5x faster |

PiperOrigin-RevId: 966557820
2026-08-18 06:29:53 -07:00
Protobuf Team Bot
720e5468ce Migrate Protobuf Python C extensions to rules_python toolchain targets.
Update _message to use rules_python's py_extension macro (which
automatically injects required toolchain headers and manages shared library
extensions across platforms), and update _api_implementation.so to depend
directly on `@rules_python//python/cc:current_py_cc_headers` instead of
`@system_python`.

Using `py_extension` and `current_py_cc_headers` decouples Python C
extensions from the custom system_python.bzl script while maintaining
current host-interpreter behavior during the migration.

#test-continuous

PiperOrigin-RevId: 966345187
2026-08-17 21:03:55 -07:00
Protobuf Team Bot
80d472933a Auto-generate files after cl/966337187 2026-08-18 03:47:16 +00:00
Protobuf Team Bot
857623168c Automated rollback of commit d46a6ff074.
PiperOrigin-RevId: 966337187
2026-08-17 20:39:44 -07:00
Protobuf Team Bot
d5d2b624a6 Fix TODO(b/364873432) in Bazel cc_proto_library rules.
PiperOrigin-RevId: 966282837
2026-08-17 17:58:02 -07:00
Protobuf Team Bot
9ff0d2d197 Auto-generate files after cl/966266256 2026-08-18 00:27:25 +00:00
Protobuf Team Bot
c6b856d785 Introduce overflow checking functions for add and multiply in upb to replace error-prone manual checks
PiperOrigin-RevId: 966266256
2026-08-17 17:17:05 -07:00
Protobuf Team Bot
993604ee07 Auto-generate files after cl/966258037 2026-08-18 00:08:38 +00:00
Clayton Knittel
07eec573f3 Move static generated message helpers to a new private Helpers_ class of the message.
This change eliminates redundant debug info from being generated for `Clear` / `ByteSizeLong` / `_InternalSerialize` outside the TU compiling `.pb.cc` for a message. It does so via [constructor homing](https://blog.llvm.org/posts/2021-04-05-constructor-homing-for-debug-info/) on the `Helpers_` class.

This is only in effects when `:enable_custom_vtable=true`.

PiperOrigin-RevId: 966258037
2026-08-17 16:58:56 -07:00
Protobuf Team Bot
4374cbf43b Internal change.
PiperOrigin-RevId: 966255809
2026-08-17 16:54:30 -07:00
Charlie Beattie
b43ac42ce0 Protocol buffers support being created from memoryviews.
PiperOrigin-RevId: 966179112
2026-08-17 14:23:02 -07:00
Protobuf Team Bot
45aa47c5a1 Auto-generate files after PR #29130 2026-08-17 21:00:59 +00:00
BarakSrour
1e1a0a8c76 Validate php_class_prefix and objc_class_prefix in code generators (#29130)
## Summary

Follow-up to #28667, which added character validation for `php_namespace`, `php_metadata_namespace`, `ruby_package` and `csharp_namespace` because they are emitted directly into generated source without validation.

Two options in the same family were not covered and are still unvalidated on `main`:

| option | read at | validated before this PR |
|---|---|---|
| `php_class_prefix` | `php/names.cc` (`ClassNamePrefixImpl`) | no |
| `objc_class_prefix` | `objectivec/names.cc` (`FileClassPrefix`) | no |

`php_class_prefix` is easy to miss by inspection: the guard added in #28667 and both of its call sites are in `php_generator.cc`, while `php_class_prefix` is read from `names.cc`.

## What happens today

**PHP.** The generator emits `class <php_class_prefix><Name> extends ...`, so a prefix that closes the declaration and opens its own is emitted verbatim:

```proto
option php_class_prefix = "Pfx{} class Injected { public static function pwn() { return 'INJECTED'; } } class ";
```

`protoc --php_out` exits 0 and the generated file contains:

```php
class Pfx{} class Injected { public static function pwn() { return 'INJECTED'; } } class M extends \Google\Protobuf\Internal\Message
```

That is valid PHP (`php -l`: no syntax errors), the injected class is defined and its code runs, and `Tp\M` is still generated correctly — so nothing fails to build and nothing looks wrong.

**Objective-C.** `FileClassPrefix` returns the option verbatim, so with `objc_class_prefix = "A\";void pwn(){}//"` the value lands in `@interface` / `@implementation` declarations, a `typedef struct` tag and the `.prefix = "..."` string literal. I have not built the resulting Objective-C, so I am claiming unvalidated emission here rather than a working payload.

Worth noting separately: a prefix check already exists, but it validates style rather than characters, so it warns about a legitimate short prefix and says nothing about a hostile one:

```
objc_class_prefix = "AB"                 -> warning: Invalid 'option objc_class_prefix = "AB";'
objc_class_prefix = "A\";void pwn(){}//" -> no diagnostic at all
```

## Changes

- **PHP generator** — generalised `IsValidPhpNamespace` to `IsValidPhpOption(value, option_name, error)` so the error names the offending option, and applied it to `php_class_prefix` alongside the two existing options. The message still begins `Invalid character`, so the tests added in #28667 are unaffected.
- **Objective-C generator** — new `ValidateObjCClassPrefixChars()` rejects prefixes containing anything outside `[A-Za-z0-9_]`, run from `ValidateObjCClassPrefixes()` over every file ahead of the expected-prefixes opt-outs.
- Tests for both, in the reject/accept pattern used by #28667.

## Notes for review

Three things I'd rather flag than have you find:

1. **The Objective-C check is an allowlist, not a denylist.** The prefix is pasted into C identifiers, where nothing outside `[A-Za-z0-9_]` is ever valid, so an allowlist closes the class rather than chasing characters. I checked every `objc_class_prefix` in this repo (including the deliberately-empty one) and none would be rejected. Happy to switch to the `absl::CharSet` denylist used for PHP/Ruby/C# if you'd prefer consistency over precision.

2. **Placement matters.** The character check runs in `ValidateObjCClassPrefixes()` over every file, ahead of both documented opt-outs (`expected_prefixes_path=-` and `expected_prefixes_suppressions`), since disabling the naming *policy* should not disable a correctness check. There is a regression test per opt-out.

3. **Java is gated, but to a much narrower bar** — `java/file.cc` rejects only `;`, `\r`, `\n` and space, and its comment says it checks "only a subset". Since Java accepts `/**/` as a whitespace substitute, `java_outer_classname = "Evil/**/implements/**/Cloneable"` and `"Evil/*"` are both emitted into the class declaration on current `main`. I could not get code execution out of that (`;` blocks statement injection); the demonstrated effect is generated code that will not compile. **Not changed in this PR** — mentioning it in case you want the bar aligned, and happy to do it in a follow-up.

Also, for whatever it's worth to release planning: #28667 itself is not in any released binary yet — the validation string is absent from both `protoc 35.1` and `protoc 36.0-rc2`, since it landed after the v36 branch was cut.

## Testing

`src/google/protobuf/compiler/php/generator_unittest.cc` — `InvalidPhpClassPrefixRejected`, `ValidPhpClassPrefixAccepted`.

`src/google/protobuf/compiler/objectivec/generator_unittest.cc` (new file, plus its `cc_test` target) — `InvalidObjCClassPrefixRejected`, `InvalidObjCClassPrefixRejectedWithExpectedPrefixesDisabled`, `InvalidObjCClassPrefixRejectedWhenSuppressed`, `ValidObjCClassPrefixAccepted`, `ObjCClassPrefixWithUnderscoreAccepted`.

The two opt-out tests fail with the character check in its original location inside `ValidateObjCClassPrefix()`, and pass with it moved.

Both directions are covered, so the tests fail if the validation is removed *and* if it is made too strict.

---

_Both tests were run locally against this branch (`bazel test //src/google/protobuf/compiler/php:generator_unittest //src/google/protobuf/compiler/objectivec:generator_unittest`), and re-run with the two guards reverted to confirm they fail without the fix._

Closes #29130

COPYBARA_INTEGRATE_REVIEW=https://github.com/protocolbuffers/protobuf/pull/29130 from BarakSrour:validate-class-prefix-options a2bbd8f2ea
PiperOrigin-RevId: 966161028
2026-08-17 13:51:19 -07:00
Protobuf Team Bot
4de1634dd1 Refactor dense enum cache initialization to use absl::call_once.
PiperOrigin-RevId: 966158391
2026-08-17 13:46:07 -07:00
Protobuf Team Bot
dc693bc891 Auto-generate files after cl/966151323 2026-08-17 20:42:12 +00:00
Protobuf Team Bot
d46a6ff074 Enable FastTable for non-opt builds.
PiperOrigin-RevId: 966151323
2026-08-17 13:31:56 -07:00
Protobuf Team Bot
b41fd533ea Internal change.
PiperOrigin-RevId: 966146891
2026-08-17 13:26:28 -07:00
yashanil98
ced0495598 fix(protoc): honor --fatal_warnings in encode/decode mode (#28033)
Fixes #10486.

When an input message passed to `protoc --encode` or `--decode` is missing required fields, protoc prints `warning: Input message is missing required fields: ...`. That warning was written straight to stderr in `EncodeOrDecode` and never influenced the exit code, so protoc returned 0 even with `--fatal_warnings` set, defeating its `-Werror`-like purpose.

This makes `EncodeOrDecode` return a non-zero exit when `--fatal_warnings` is set and the message is missing required fields. The check happens after the output is written, matching the compile path (which also produces its output before failing). When `--fatal_warnings` is not set, behavior is unchanged: the output and the warning are still produced and the exit code stays 0.

A maintainer confirmed this is a valid bug and invited a PR on the issue.

Test: added `EncodeDecodeTest.PartialWithFatalWarnings` asserting a non-zero exit (and that the warning is still emitted) when encoding a message with missing required fields under `--fatal_warnings`.

  ./build/tests --gtest_filter='*EncodeDecodeTest.*'

Result: 18 tests pass, including the new one.

Closes #28033

COPYBARA_INTEGRATE_REVIEW=https://github.com/protocolbuffers/protobuf/pull/28033 from yashanil98:fix/issue-10486-fatal-warnings-encode-decode d0bb423371
PiperOrigin-RevId: 965995070
2026-08-17 08:55:10 -07:00
Protobuf Team Bot
dc32c23f48 Auto-generate files after cl/965979781 2026-08-17 15:31:18 +00:00
Daniel Finnie
8fa07c6359 Clean up some includes in TextFormat.
PiperOrigin-RevId: 965979781
2026-08-17 08:19:49 -07:00
Samuel Benzaquen
becdd958d1 Continue cleaning up after the GLOBALS experiment.
Remove PROTOBUF_MESSAGE_GLOBALS branching in generated code.

PiperOrigin-RevId: 965977817
2026-08-17 08:15:07 -07:00
Protobuf Team Bot
944d9909ce Automated Code Change
PiperOrigin-RevId: 965775373
2026-08-16 23:53:48 -07:00
Protobuf Team Bot
e5c8ffa6cd Automated Code Change
PiperOrigin-RevId: 965767499
2026-08-16 23:31:01 -07:00
Protobuf Team Bot
169e0f9b47 Automated Code Change
PiperOrigin-RevId: 965744650
2026-08-16 22:18:33 -07:00
Clayton Knittel
228537eb47 Internal change.
PiperOrigin-RevId: 965698725
2026-08-16 19:34:45 -07:00
Clayton Knittel
8da17f0e28 Internal change.
PiperOrigin-RevId: 965416239
2026-08-15 23:31:25 -07:00
Protobuf Team Bot
e7e6ef07ba Optimize NameOfDenseEnum by performing an early bounds check.
PiperOrigin-RevId: 964944564
2026-08-14 16:19:00 -07:00
Samuel Benzaquen
7bc3164ec0 Add a unit test in CppGeneratorTest to verify deterministic serialization of map options.
PiperOrigin-RevId: 964825321
2026-08-14 12:19:09 -07:00
Mikita Belahlazau
9c38514c4a Convert multiline string literals in descriptor_unittest.cc to raw strings.
Makes the test file more readable and enables auto-formatting.

PiperOrigin-RevId: 964816524
2026-08-14 12:01:48 -07:00
Mikita Belahlazau
887e99f2f6 Record source location for Any type_url in TextFormat::ParseInfoTree.
When parsing expanded Any syntax in TextFormat, the parser did not record the value and full spans for any_type_url_field in ParseInfoTree, leaving its values range empty and full range unclosed.

This change records the name, value, and full location spans for any_type_url_field (spanning the type URL token), and ensures skip_parsing does not write to a null field pointer.

Also added a test case for regular Any syntax. Which is likely used rarely, but good to have a test case anyway.

PiperOrigin-RevId: 964811845
2026-08-14 11:52:38 -07:00
Protobuf Team Bot
ea0cc34313 Move initialization of descriptor out of the generated file outer class to avoid circular static initialization issue (e.g. https://github.com/protocolbuffers/protobuf/issues/29012).
In OSS Java protobuf generation, this change wraps the file descriptor initialization inside a nested static class named `InternalDescriptors`. This prevents statically initializing the generated file's outer class when only its descriptor is accessed, which avoids premature loading of dependencies like `DescriptorsProto` and `JavaFeaturesProto`.

PiperOrigin-RevId: 964796532
2026-08-14 11:23:22 -07:00
Samuel Benzaquen
ace28407d0 Remove opt-out for the globals experiment.
It has been released and stable for a while.
We will start cleaning it up.

PiperOrigin-RevId: 964759065
2026-08-14 10:13:05 -07:00
yashanil98
93bb3d693c fix(protoc): correct plugin-not-found hint for exact-name plugins (#28039)
When a plugin is registered with an explicit path via `--plugin=name=path`, protoc runs it in `EXACT_NAME` mode and never searches the PATH, yet the not-found error still tells users to make the program available on their PATH. This selects the hint based on the search mode, so the PATH suggestion only appears for `SEARCH_PATH` lookups; for exact-name plugins it points at an absolute or working-directory-relative path instead.

Fixes #10302.

Tested on macOS: `ninja -C build protoc tests && ./build/tests --gtest_filter='*GeneratorPluginNotFound*'` -> 2 tests pass. The new `GeneratorPluginNotFoundInPath` test covers the `SEARCH_PATH` case; the existing `GeneratorPluginNotFound` test covers the `EXACT_NAME` case.

Closes #28039

COPYBARA_INTEGRATE_REVIEW=https://github.com/protocolbuffers/protobuf/pull/28039 from yashanil98:fix/issue-10302-plugin-exact-name-error 873912145f
PiperOrigin-RevId: 964756722
2026-08-14 10:07:57 -07:00
Protobuf Team Bot
070ffcd902 Fix SourceTreeDescriptorDatabase fallback to populate extension declarations
When a proto file is resolved from a fallback database (such as via
--descriptor_set_in in the compiler), SourceTreeDescriptorDatabase::FindFileByName
previously returned without calling ReadExtensionDeclarations. This caused
extension declaration metadata from external .txtpb files (such as
message_set_extensions.txtpb) to be missing on the resulting FileDescriptorProto,
silently disabling extension declaration validation.

This change ensures ReadExtensionDeclarations is invoked when resolving
descriptors from fallback_database_, preserving extension declaration enforcement.
Also regenerates protoc_minimal release binaries and signatures via manual_release.sh.

PiperOrigin-RevId: 964735907
2026-08-14 09:28:33 -07:00
yashanil98
6ac0b13685 fix(cmake): do not override a parent-set CMAKE_MSVC_RUNTIME_LIBRARY (#28525)
When protobuf is built as a static library through add_subdirectory or FetchContent, its top-level CMakeLists.txt set CMAKE_MSVC_RUNTIME_LIBRARY unconditionally, overriding a value the enclosing project had already set. A parent that forces /MD in every configuration (CMAKE_MSVC_RUNTIME_LIBRARY=MultiThreadedDLL) would still get /MDd for the protobuf and Abseil targets in Debug, causing LNK2038 runtime-library mismatches (MDd_DynamicDebug vs MD_DynamicRelease).

This guards the assignment with `if (NOT DEFINED CMAKE_MSVC_RUNTIME_LIBRARY)`, so protobuf only picks a runtime library when the parent has not. Standalone builds are unchanged: with no parent value set, the same default is chosen from protobuf_MSVC_STATIC_RUNTIME as before.

Fixes #23173.

Test plan: the change is CMake logic, verified with cmake -P (no build needed). Modeling the guarded block, a pre-set CMAKE_MSVC_RUNTIME_LIBRARY is preserved (parent value wins), while an unset one still resolves to the static or DLL default per protobuf_MSVC_STATIC_RUNTIME. Reconfiguring the tree with cmake -S . -B build -G Ninja succeeds, confirming no syntax regression.

Closes #28525

COPYBARA_INTEGRATE_REVIEW=https://github.com/protocolbuffers/protobuf/pull/28525 from yashanil98:fix/issue-23173-msvc-runtime-override 13501be37c
PiperOrigin-RevId: 964437666
2026-08-13 20:06:18 -07:00
Protobuf Team Bot
5d9ce4859e Auto-generate files after cl/964422854 2026-08-14 02:31:23 +00:00
Protobuf Team Bot
07e0a39f1b Internal change.
PiperOrigin-RevId: 964422854
2026-08-13 19:20:58 -07:00
Protobuf Team Bot
cba090367e Internal change.
PiperOrigin-RevId: 964417298
2026-08-13 19:04:34 -07:00
Protobuf Team Bot
42ceed172e Internal change.
PiperOrigin-RevId: 964378413
2026-08-13 17:17:49 -07:00
Protobuf Team Bot
6e6f4048c4 Internal Change
PiperOrigin-RevId: 964360922
2026-08-13 16:37:00 -07:00
Protobuf Team Bot
917934ce44 Auto-generate files after cl/964346542 2026-08-13 23:18:51 +00:00
Clayton Knittel
3420ad2527 Add [[gnu::nodebug]] to generated forwarding message stubs.
These methods don't do any actual work, so they won't generate any instructions after inlining. nodebug will not reduce debugging symbol coverage on this code, but will reduce linker overhead in binaries compiled with debug info once custom vtable is enabled.

PiperOrigin-RevId: 964346542
2026-08-13 16:08:26 -07:00
Protobuf Team Bot
528ec6b9e8 Automated rollback of commit 3c13af10fa.
PiperOrigin-RevId: 964327862
2026-08-13 15:33:20 -07:00
Protobuf Team Bot
3116a408b6 Auto-generate files after cl/964304643 2026-08-13 21:58:08 +00:00
Clayton Knittel
b4479d1d0b Add [[gnu::nodebug]] and always inline Serialize/Clear/ByteSizeLong/destroying delete stubs.
PiperOrigin-RevId: 964304643
2026-08-13 14:47:39 -07:00
Protobuf Team Bot
aa2364ea8c Internal change.
PiperOrigin-RevId: 964276286
2026-08-13 13:56:52 -07:00
Clayton Knittel
6b336e7038 Internal change.
PiperOrigin-RevId: 964200763
2026-08-13 11:35:08 -07:00
Protobuf Team Bot
090f4cbb88 Internal change
PiperOrigin-RevId: 964178362
2026-08-13 10:58:44 -07:00
Protobuf Team Bot
0eafd3c3e4 Internal change.
PiperOrigin-RevId: 964172133
2026-08-13 10:53:40 -07:00
Protobuf Team Bot
838d639d29 Internal change.
PiperOrigin-RevId: 964172029
2026-08-13 10:51:28 -07:00
Protobuf Team Bot
3c13af10fa Internal change.
PiperOrigin-RevId: 964153546
2026-08-13 10:13:50 -07:00
Protobuf Team Bot
e1c5f3ac47 rust protobuf matchers: Add a partially matcher to mirror C++
It is common to want to match only a subset of fields in large protobufs, and doing that in rust right now requires manually clearing out the fields in the `actual` message that we don't care about. This is a pain, and a worse experience when compared to C++.

Like in C++, when doing partial matching, only fields set in the expected protobuf message are compared, while extra fields set only in the actual message are ignored.

When using the C++ kernel we leverage `proto2::util::MessageDifferencer`, and for the UPB kernel we use the `kUpb_CompareOption_Partial` option.

PiperOrigin-RevId: 964125682
2026-08-13 09:24:36 -07:00
Protobuf Team Bot
02a9c9dec8 Fix messageset conformance for pure Python to match Py-C++ and Py-upb
MessageSet is a legacy affordance holdover from pre-proto2 days. Unlike the rest of Protobuf, it has first-wins instead of last-wins semantic in the case of duplicate ids or values within the same message set entry.

No serializer would ever write such sequences, but the same hypothetical byte sequence being parsed differently by two implementations is undesirable.

Note that other nonconformance fixes would commonly be held to breaking change releases to avoid any possible disruption of single-language users who may be relying on it as a load-bearing bug. However, the nature of this particular case is such that there is little reason to hold it back.

PiperOrigin-RevId: 964043226
2026-08-13 06:25:58 -07:00
Clayton Knittel
d0be1f2cb0 Change Reflection::GetDefaultMessageInstance to Reflection::GetMessageClassData.
`Reflection::GetMessageClassData` now has to call `GetClassData` on the prototype returned from the message factory, as the `MessageFactory` interface only has a `GetPrototype` method. We could add a `GetClassData` method to the generated message factory, but we already cache the `ClassData` pointer in the `FieldDescriptor` for fields from the generated factory. We couldn't add a `GetClassData` to dynamic factories, as `ClassData` is `internal` and dynamic factories have a public interface that users can override.

This cl includes a refactor of `LazyField::InternalWrite` to accept `ClassData` instead of a `MessageLite` prototype, and changes the cached prototype to `ClassData` in `FieldDescriptor`.

PiperOrigin-RevId: 963758127
2026-08-12 17:50:31 -07:00
Eric Salo
7b59c75e36 protobuf: enable group recursion limit flag
PiperOrigin-RevId: 963709933
2026-08-12 16:06:12 -07:00
Protobuf Team Bot
0cb030f1ad Auto-generate files after cl/963694337 2026-08-12 22:43:36 +00:00
Samuel Benzaquen
ad90aff2bf Move all tc table crosslink to use ClassData.
Merge the `FastMt` and `FastMd` functions into just `FastMc`. Adds a single predicted branch on top of `FastMt` but halves the amount of code. This should improve icache usage.

We also simplify the code for `MpMessage` to get to the `ClassData`. Now we only have two options: `ClassData*` for most fields and `ClassData**` for weak entries.

PiperOrigin-RevId: 963694337
2026-08-12 15:35:12 -07:00
Runze Wang
97fcd43558 Re-export to google-protobuf crate in 0.x.y for 36.0 and above
New crates are in https://crates.io/search?q=google-protobuf

PiperOrigin-RevId: 963684439
2026-08-12 15:12:23 -07:00
Tony Liao
66d62e385d Add JSON and CPP option protos to C++ toolchain blacklisted_protos
Add `//:json_enumvalue_options_proto`, `//:json_options_proto`, and
`//:cpp_file_options_proto` to `blacklisted_protos` in
`proto_lang_toolchain(name = "cc_toolchain")`.

The generated C++ sources for these option protos (e.g.,
`json_enumvalue_options.pb.cc`) are built directly into the core protobuf C++
runtime library (`libprotobuf.so`). Without being listed in `blacklisted_protos`,
any downstream `cc_proto_library` target depending on protos that import these
options will generate and compile duplicate `.pb.cc` objects into separate
shared libraries (e.g., `libjson_enumvalue_options_proto.so`), causing
ODR violations, especially under ASAN mode.

PiperOrigin-RevId: 963673828
2026-08-12 14:52:22 -07:00
Protobuf Team Bot
011fbe69e9 Auto-generate files after PR #28553 2026-08-12 19:45:18 +00:00
arshsmith
085b305c25 check sub array bounds before indexing in upb_MiniTable_Link (#28553)
upb_MiniTable_Link reads sub_tables[msg_count] (and sub_enums[enum_count]) before comparing the index against the caller-supplied length, so a mini table with more message or closed-enum fields than the array holds reads one past the end before the count check fires. This is the too-short-array case the header documents should just return false, and it's reachable whenever the array is sized from a different mini table than the one being linked. Move the length check ahead of the array access at both sites; the regression test builds a two-message-field table and links it against a one-element array, which trips ASAN before the change.

Closes #28553

COPYBARA_INTEGRATE_REVIEW=https://github.com/protocolbuffers/protobuf/pull/28553 from arshsmith1:minitable-link-bounds 04231a5a6a
PiperOrigin-RevId: 963598486
2026-08-12 12:34:45 -07:00
Protobuf Team Bot
91b86b0535 Publish Protobuf SECURITY.md threat model documentation
PiperOrigin-RevId: 963583960
2026-08-12 12:08:39 -07:00
Tony Liao
bae5b79a43 Cache custom JSON enum names in JsonParser using Lazy.
Custom JSON enum names are defined in descriptor options and looked up
when parsing JSON strings. Instead of performing a linear scan over
Values on each lookup, this change adds a ConcurrentDictionary with
Lazy<Dictionary> to JsonParser to lazily construct and cache the JSON
name to EnumValueDescriptor lookup table per EnumDescriptor on first
access.

Lazy provides thread-safe, lock-free reads on all subsequent accesses.

PiperOrigin-RevId: 963583475
2026-08-12 12:05:11 -07:00
Runze Wang
e8bd2b5dcc Remove iterator trait implementations for RepeatedMutIter
Use inherent next()/next_back()/len() API instead.

PiperOrigin-RevId: 963506746
2026-08-12 09:57:23 -07:00
Protobuf Team Bot
e49cfc58ea Auto-generate files after cl/963493738 2026-08-12 16:46:18 +00:00
Protobuf Team Bot
8b7fbb5927 Automated rollback of commit 7023abcb48.
PiperOrigin-RevId: 963495450
2026-08-12 09:39:10 -07:00
Tony Liao
692daead2a csharp: add support for custom json strings for enum values
PiperOrigin-RevId: 963493738
2026-08-12 09:35:57 -07:00
Samuel Benzaquen
4fb7ff55fc Fix some code to be more compatible with force-split configurations.
PiperOrigin-RevId: 963485585
2026-08-12 09:18:48 -07:00
Protobuf Team Bot
c2cbda5b47 Auto-generate files after PR #28900 2026-08-12 16:08:15 +00:00
Protobuf Team Bot
f5fba07925 Auto-generate files after cl/963471731 2026-08-12 16:04:41 +00:00
carlos-al
9c66da89e9 fix: [upb] roll back extensions after failed file addition (#28900)
## Summary

  This PR fixes a use-after-free in upb’s failed file-definition rollback.

  ## Analysis

  When adding a file fails, `remove_filedef()` removes definitions belonging to that file from the symbol table.

  Extensions are also registered separately in the `DefPool` extension table. These entries were not removed by the existing rollback.

  The failed file’s builder arena was then discarded while the extension table still contained pointers to its `FieldDef` objects. Subsequent extension enumeration could therefore access definitions from the freed arena.

  ## The Fix

  Remove extension-table entries belonging to the rejected file as part of `remove_filedef()`, before the builder arena is discarded.

  The extension registry already rolls back its own partial batch insertion, so no changes there are required.

  ## Testing

  - Added regression coverage using a rejected file containing duplicate extension numbers
  - Confirmed that the test fails before the fix because two extensions remain in the pool
  - Confirmed that the test passes after the fix with no retained extensions
  - Ran `//upb/reflection:reflection_test`
  - Ran the supported μpb test suite: 75 tests passed and 2 were skipped

Closes #28900

COPYBARA_INTEGRATE_REVIEW=https://github.com/protocolbuffers/protobuf/pull/28900 from carlos-al:fix/upb-def-pool-extension-rollback 286e84200a
PiperOrigin-RevId: 963474026
2026-08-12 08:57:54 -07:00
Protobuf Team Bot
22677ce80d upb/message/compare: Add support for partial equality comparisons
... and add a fuzz test verifying that we see the same results as for
the cpp kernel.

PiperOrigin-RevId: 963471731
2026-08-12 08:53:40 -07:00
Protobuf Team Bot
837a9ebe5d internal change
PiperOrigin-RevId: 963441921
2026-08-12 07:53:12 -07:00
Tony Liao
1b27892b8b Support custom JSON enum names in PHP
This CL adds support for the Edition 2026 custom JSON enum name feature (pb.enumvalue.json) in PHP Protobuf.

Note that we don't need extension caching similar to C++ or Java because our PHP code generator collects custom JSON names at protoc compile time and passes them to DescriptorPool::internalAddGeneratedFile(), populating EnumValueDescriptor and EnumDescriptor during descriptor registration.

Tested with PHP unit tests across pure-PHP and C-extension modes.

PiperOrigin-RevId: 963411589
2026-08-12 06:45:04 -07:00
Protobuf Team Bot
0939462046 Auto-generate files after cl/963394074 2026-08-12 13:14:09 +00:00
Protobuf Team Bot
05ff89ea93 Don't ignore upb_Arena_Malloc-fail in 0-sized allocation.
In reality this will never occur in production, but it can occur under asan or when we are injecting allocation failures for testing purposes.

PiperOrigin-RevId: 963394074
2026-08-12 06:03:25 -07:00
Protobuf Team Bot
b67d2697ae Add tests for int64 varint 10th byte bug.
This is the test for an issue where if the 10th byte was 0x81 (a non-zero value with  was accidentally included in cl/962791052 and submitted, which was intended to be submitted separately.

PiperOrigin-RevId: 963393786
2026-08-12 06:00:36 -07:00
Samuel Benzaquen
3594d5ce74 Fix offset ptr test.
The pointer and the pointee can't be declared on their own because then there
is no guarantee they are located close enough in memory.

This test was failing with hwasan.

PiperOrigin-RevId: 963187392
2026-08-11 21:24:52 -07:00
Eric Salo
0fff4dec59 protobuf: improve staleness test regeneration to reduce confusion
This change updates `regenerate_stale_files.sh` to always execute a direct fix and refactors `staleness_test_lib.py` to support cleaner output during regeneration without sacrificing debugging info.

Motivation:
Automatic staleness tests are run to regenerate stale files on non-bazel environments (like GHA). When these files change, the tests "fail" to trigger regeneration. This causes constant confusion for developers as they look like test failures rather than "Working As Intended" regeneration triggers.

Details:
1.  **`regenerate_stale_files.sh`**: Updated to always build the staleness tests via `bazel build` and execute them directly with `--fix --print-diffs`, avoiding the confusing "FAIL" output of `bazel test`. This script is primarily used by automation (like GHA) where this behavior is desired by default.
2.  **`staleness_test_lib.py`**: Refactored diff generation into a shared helper `_GetDiffErrors`. Both `CheckFilesMatch` (testing) and `FixFiles` (fixing) use this helper. Added a `print_diffs` parameter to `FixFiles` so diffs are only printed when explicitly requested (e.g., in `regenerate_stale_files.sh`), preventing double-printing if run manually.
3.  **Tone Improvement**: Updated the message for missing files during fixing to be less alarming ("Creating missing file" instead of "File does not exist").

### Output Comparison

**New Automation Output**:
Clean execution without `AssertionError` boilerplate, but preserves actionable diffs.

```
+ ./bazel-bin/upb/reflection/descriptor_upb_proto_staleness_test --fix --print-diffs
Creating missing file upb/reflection/stage0/descriptor_upb_proto.h
File upb/reflection/descriptor_upb_proto.c is out of date:
--- upb/reflection/descriptor_upb_proto.c.generated
+++ upb/reflection/descriptor_upb_proto.c
@@ -45,6 +45,7 @@
 #include "upb/reflection/descriptor_upb_proto.h"

 UPB_NOINLINE const upb_MiniTable* google_protobuf_FileDescriptorSet_msg_init() {
+  // Added a new field
   return &google_protobuf_FileDescriptorSet_msg_init_table;
 }
```

**Traditional Test Failure (Manual Runs)**:
Verbose, traditional test failure (for manual runs via `bazel test`).

```
+ bazel test upb/reflection:descriptor_upb_proto_staleness_test
...
FAIL: upb/reflection:descriptor_upb_proto_staleness_test (Exit 1)
================================================================================
AssertionError: Files out of date!

To fix run THIS command:
  bazel-bin/upb/reflection/descriptor_upb_proto_staleness_test --fix

Errors:
  File upb/reflection/descriptor_upb_proto.c is out of date:
--- upb/reflection/descriptor_upb_proto.c.generated
+++ upb/reflection/descriptor_upb_proto.c
...
```
PiperOrigin-RevId: 963179635
2026-08-11 21:03:35 -07:00
Hiroshi SHIBATA
dce0d24702 Fix google-protobuf gem source build on the mswin platform (#28433)
`gem install google-protobuf --platform ruby` fails on Windows with the native mswin toolchain (`x64-mswin64_140`, `cl.exe` and `nmake`). `Init_protobuf_c` in `protobuf.c` is annotated with the GCC-style `__attribute__((visibility("default")))`, which `cl.exe` cannot parse and rejects with a cascade of C2143/C2091 syntax errors. In addition, `extconf.rb` passes GCC-only flags (`-std=gnu99`, `-O3`, `-fvisibility=hidden`) that `cl.exe` does not understand.

This change replaces the attribute with Ruby's portable `RUBY_FUNC_EXPORTED` macro, which expands to `extern __declspec(dllexport)` under MSVC and to `__attribute__((__visibility__("default"))) extern` under GCC/Clang, so the symbol stays exported when the extension is built with `-fvisibility=hidden`. It also gives mswin its own `$CFLAGS` branch. `-std:c11` is required there because the MSVC atomics fallback in upb only uses its `_Generic` based implementation when `__STDC_VERSION__` is at least 201112L. The pre-C11 fallback returns `void*` from `upb_Atomic_Load`, and mswin Ruby compiles extensions with `-we4047` by default, which turns those conversion warnings into hard errors.

Verified on Windows 11 with Ruby 4.0.5 (`x64-mswin64_140`) and Visual Studio 2022 Build Tools (MSVC 14.51). Building the extension in-tree succeeds, and a gem built from the released 4.35.1 sources with this patch applied installs successfully and passes a `Struct` and `Timestamp` encode/decode round-trip. Precompiled `x64-mingw-ucrt` gems are unaffected because MinGW keeps using the existing GCC branch.

Generated with [Claude Code](https://claude.com/claude-code)

Closes #28433

COPYBARA_INTEGRATE_REVIEW=https://github.com/protocolbuffers/protobuf/pull/28433 from hsbt:claude/elated-goldwasser-3862b4 7d533bab6c
PiperOrigin-RevId: 963158243
2026-08-11 20:03:36 -07:00
Tony Liao
e788b3ce3d Fix PHP update_reserved_words.sh formatting and CI idempotency test
Fix the GitHub Actions CI failure in
`UpdateReservedTest::testBashScriptIdempotency` introduced by PR #27456.

### Problem:

`update_reserved_words.sh` generated array formatting that differed from
the repository's checked-in files, causing the strict idempotency test
to fail:
1. Column padding used a single global max width across all columns
   instead of calculating padding per column.
2. Generated array line lengths in multiple files exceeded 80
   characters.
3. Proto test files had slight formatting differences compared to the
   script's one-liner output.

### Solution:

- `update_reserved_words.sh`:
  * Updated `format_columns()` to calculate padding per-column in pure
    Bash, matching standard C/C++ array alignment without requiring
    external tools.
  * Adjusted array column counts (`names.c` to 4, `php_generator.cc` to
    5, `GPBUtil.php` to 3) so lines stay strictly within 80 characters.
- `GPBUtil.php` & proto test files:
  * Synced formatting to match the updated script output byte-for-byte.

PiperOrigin-RevId: 963153840
2026-08-11 19:53:43 -07:00
Brent Shaffer
f0a3f38321 feat(php): script for updating php reserved words (#27456)
See https://github.com/googleapis/google-cloud-php/issues/9193

`protoc` is generating the invalid class name `Object` when it should be prefixed with `PB` to prevent a conflict with PHP reserved words. I've submitted a fix for this in #27475

This PR introduces the script `php/update_reserved_words.sh` which updates the library in the **8 different classfiles** which all have various ways this logic is defined. Hopefully this makes these things easier for us to maintain in the future.

**NOTE**: prefixing constants with PB has been unnecessary since PHP 7, so we can and should open those up to every word but `class` in the next major version. I've added a comment so we (hopefully) don't forget

```sh
$ bash php/update_reserved_words.sh
Updated src/google/protobuf/compiler/php/names.cc
Updated php/ext/google/protobuf/names.c
Updated src/google/protobuf/compiler/php/php_generator.cc
Updated php/tests/proto/test_reserved_message_lower.proto
Updated php/tests/proto/test_reserved_message_upper.proto
Updated php/tests/proto/test_reserved_enum_lower.proto
Updated php/tests/proto/test_reserved_enum_upper.proto
Updated php/tests/proto/test_reserved_enum_value_lower.proto
Updated php/tests/proto/test_reserved_enum_value_upper.proto
Updated php/tests/GeneratedClassTest.php
Updated php/src/Google/Protobuf/Internal/GPBUtil.php
```

Closes #27456

COPYBARA_INTEGRATE_REVIEW=https://github.com/protocolbuffers/protobuf/pull/27456 from bshaffer:php-update-reserved-words 522d93f1c1
PiperOrigin-RevId: 962903274
2026-08-11 11:46:11 -07:00
Protobuf Team Bot
6d03e4f090 Clean up varint encoder experiment, the 'new' arm has won for all cases.
PiperOrigin-RevId: 962791052
2026-08-11 08:20:45 -07:00
Protobuf Team Bot
dd3d3e82fc Automatically traverse proto_library exports for Kotlin code generation.
Aligns Kotlin proto rules with `java_proto_library`, letting Kotlin gencode resolve exported proto targets from `proto_library.exports`.

PiperOrigin-RevId: 962600951
2026-08-11 00:04:51 -07:00
Protobuf Team Bot
45b99dc2a9 Automatically traverse proto_library exports for Kotlin code generation.
Aligns Kotlin proto rules with `java_proto_library`, letting Kotlin gencode resolve exported proto targets from `proto_library.exports`.

PiperOrigin-RevId: 962536667
2026-08-10 21:03:36 -07:00
Protobuf Team Bot
a362a3b2fc Update hard-coded bazel version numbers in the CI workflows.
#test-continuous

PiperOrigin-RevId: 962521143
2026-08-10 20:14:02 -07:00
Protobuf Team Bot
50f810693c Internal change.
PiperOrigin-RevId: 962434750
2026-08-10 16:36:53 -07:00
Protobuf Team Bot
86dfa627be Migrate upb_MessageUnknown calls in upb tests to use upb_Message_NextUnknown2.
PiperOrigin-RevId: 962412486
2026-08-10 15:51:42 -07:00
Protobuf Team Bot
7023abcb48 Bypass dynamicMethod for getParserForType and getDefaultInstanceForType in Java Lite.
Directly invoke getParserForClass and getDefaultInstance in GeneratedMessageLite instead of routing through dynamicMethod. This builds on the work added in cl/944139195.

This allows removing the GET_PARSER and GET_DEFAULT_INSTANCE switch cases from dynamicMethod in compiler/java/lite/message.cc and removing the corresponding enum values from MethodToInvoke.

Additionally, updates the Samsung bug fallback path in GeneratedMessageLite.getDefaultInstance to allocate an instance via UnsafeUtil without calling method getters on the uninitialized object, triggering static initialization (<clinit>) safely without reflection or method call cycles.

PiperOrigin-RevId: 962355079
2026-08-10 14:05:24 -07:00
Protobuf Team Bot
89081325d7 Handle more ignored return values in upb
PiperOrigin-RevId: 962325948
2026-08-10 13:14:40 -07:00
Samuel Benzaquen
825d5be550 Replace atexit call with global destructor.
Rust does not like `atexit`.

PiperOrigin-RevId: 962277188
2026-08-10 11:46:43 -07:00
Runze Wang
b1b5f993e8 Enable inherent next() and next_back() API for RepeatedMutIter besides trait implementation.
This is in preparation for removing the impl Iterator on RepeatedMutIter, since we intend to make it a lending iterator which the std Iterator trait does not support.

PiperOrigin-RevId: 962265415
2026-08-10 11:25:24 -07:00
Protobuf Team Bot
081ecdd861 Migrate Java(Lite|Mutable|)ProtoLibraryTest.testProtoLibraryInterop to Starlark-based analysis tests.
PiperOrigin-RevId: 962226467
2026-08-10 10:21:27 -07:00
Samuel Benzaquen
958a78d900 Fix LazyField::MergeFrom to take into account custom pool/factory.
PiperOrigin-RevId: 962189115
2026-08-10 09:15:02 -07:00
Protobuf Team Bot
13a30ee71d internal changes
PiperOrigin-RevId: 962187573
2026-08-10 09:10:30 -07:00
TrendVidia
c27007fc25 Add custom option numbers for use by ProtoWire (#28919)
Reserves a contiguous block of custom option numbers — **1314–1363** — for **ProtoWire** (https://protowire.org), an open interchange stack (text/binary codecs, schema-extension compiler, validation engine) built on protobuf descriptors.

> **2026-08-02 update:** originally requested as 1311–1360; rebased and shifted to **1314–1363** after #28790 (proto2mcp, 1311–1313) merged while this PR was awaiting merge post-approval. No other changes.

### This re-files #27290

#27290 was **approved** by @esrauchg and then closed automatically, not on the merits: its head fork was deleted during an account migration on my side, which GitHub treats as closing the PR. It cannot be reopened, because the head repository no longer exists. Apologies for the churn — this PR is the same one-line-per-entry change, rebased onto current `main`.

The content is unchanged from the approved state apart from the start number; `1314–1363` is free (the registry currently ends at `1313`, proto2mcp).

### Why a block of 50

Per @haberman's request on the original PR, the entry was moved off the contested number and starts after the ranges claimed in the meantime (1307–1313: proto2type, protoc-gen-openapi, Motif, Teleport, proto2mcp).

Since the first version of the request (10 numbers for two annotation groups), the project's published option surface has grown to five orthogonal families, all currently parked in the internal 50000+ space and being migrated to registered numbers ahead of an IETF draft submission:

| Family | Extendees | In use | Growth headroom |
| --- | --- | --- | --- |
| PXF text-format annotations (`pxf.*`) | FieldOptions | 3 | +2 |
| SBE binary-format annotations (`sbe.*`) | File/Message/FieldOptions | 5 | +5 |
| Schema-extension carriers (`protowire.schema.v1.*`) | all 8 Options messages (one shared number) + FileOptions | 5 | +5 |
| Validation constraints (`protocheck.*`) | Field/Message/OneofOptions | 3 | +5 |
| OpenAPI generation options | Method/ServiceOptions | 0 | +5 |

That's 16 numbers in active published use with a documented path to ~40, hence the request for 50.

Happy to trim if that exceeds what you're comfortable granting in one row — same offer as on the original PR.

Closes #28919

COPYBARA_INTEGRATE_REVIEW=https://github.com/protocolbuffers/protobuf/pull/28919 from trendvidia:protowire-options-range a3d24a95ff
PiperOrigin-RevId: 961811298
2026-08-09 12:21:58 -07:00
Protobuf Team Bot
eed5007774 Extract generated Java method printing in map_field.cc into dedicated private generator functions on ImmutableMapFieldGenerator.
PiperOrigin-RevId: 961479429
2026-08-08 12:13:35 -07:00
Jeremy Daer
7d7d6ab836 Ruby: fix use-after-free of map keys aliasing a temporary String (#29026)
Fixes #29023.

`Map#[]=` and `Message.new(map_field: {...})` build the map key as a `upb_StringView`
aliasing a Ruby String, then convert the value before `upb_Map_Set` copies the key. The
value conversion allocates, so it can trigger GC inside that window.

The aliased String is frequently a **temporary**: `Convert_RubyToUpb` replaces the caller's
object when the key is a Symbol (via `to_s`) or a String not already tagged UTF-8 (via
`Convert_CheckStringUtf8`), and nothing references the result once it returns. When GC
collects it, the freed block goes straight back to the next `upb_Arena_Malloc`, which
memcpys the *value* into it — leaving a silently corrupted key holding unrelated heap bytes,
tagged UTF-8 while containing invalid UTF-8, which then propagates into `encode`/`to_json`.

## The fix

Pass the arena at both insertion sites, so the key is copied before anything can allocate.

The lookup paths (`Map_index`, `Map_has_key`, `Map_delete`) keep the `NULL` fast path — they
consume the key immediately with no allocation in between, which is exactly the precondition
`Convert_StringData`'s comment describes. I reworded that comment, since it read as though
the aliasing were unconditionally safe; it holds for three of its five callers and not for
the two that insert.

Cost is one arena allocation per insert for string-typed keys. Non-string keys don't reach
`Convert_StringData` at all.

## Trigger

Needs both:

- a key that is a **Symbol**, or a String not already tagged UTF-8 — `ASCII-8BIT` is the
  common case for anything read from a socket, a file, `Marshal`, or `String#pack`; and
- a value whose conversion allocates (a Symbol, or a non-UTF-8 String).

Plain UTF-8 keys are unaffected, which is presumably why this has gone unnoticed.

## Verification

Reproduces under **ordinary GC**, no `GC.stress` required — one corrupted key across 150k
iterations (0/50k, 0/50k, 1/50k), versus 100/100 with stress. That second number is an
existence proof rather than a rate.

Added regression tests to `ruby/tests/gc_test.rb` covering string keys, Symbol keys, and the
map-field kwarg path. Verified red/green against the same tree:

| ext build | new tests |
|---|---|
| unpatched `main` | 3 tests, **3 failures** |
| with this change | 3 tests, 300 assertions, **0 failures** |

Full Ruby suite green with the change on ruby 4.0.6 / arm64-darwin — `basic.rb` (133 tests,
157,864 assertions), `basic_proto2.rb` (93), `repeated_field_test.rb` (40),
`encode_decode_test.rb`, `memory_test.rb`, `object_cache_test.rb`, `well_known_types_test.rb`,
`service_test.rb`, `oom_test.rb`, `multi_level_nesting_test.rb` — 0 failures, 0 errors.

Reported separately via the channel in `SECURITY.md`, since this is a memory-safety issue in
an OT0 repository.

Closes #29026

COPYBARA_INTEGRATE_REVIEW=https://github.com/protocolbuffers/protobuf/pull/29026 from jeremy:ruby-map-key-use-after-free e11cc7dfe2
PiperOrigin-RevId: 961236703
2026-08-07 19:44:44 -07:00
Protobuf Team Bot
3ad6d39dfc Internal change
PiperOrigin-RevId: 961187753
2026-08-07 16:57:51 -07:00
Protobuf Team Bot
313966da6e Extract generated Java method printing in string_field.cc into dedicated private generator functions on ImmutableStringFieldGenerator, ImmutableStringOneofFieldGenerator, and RepeatedImmutableStringFieldGenerator.
PiperOrigin-RevId: 961163755
2026-08-07 16:00:04 -07:00
Vitaly Goldshteyn
3e67e13993 Update IsCompletelyEmpty() to check if flat_capacity() is 0 instead of comparing map_.flat against kEmptyKeyValue. This helps to avoid problemns in dynamic linkage, where different libraries may have their own version of this variable.
PiperOrigin-RevId: 961135439
2026-08-07 14:59:42 -07:00
Protobuf Team Bot
338190979e Auto-generate files after cl/961053716 2026-08-07 19:21:04 +00:00
Jason Aragorn Tobias Lunn
b2e184385f Extract Python naming helper functions into a separate names library.
PiperOrigin-RevId: 961053716
2026-08-07 12:10:27 -07:00
Protobuf Team Bot
620c9cf483 Disable lazy parsing for extensions on descriptor.proto messages.
PiperOrigin-RevId: 960920493
2026-08-07 07:36:45 -07:00
Protobuf Team Bot
3445511e7a Extract generated Java method printing in primitive_field.cc into dedicated private generator functions on ImmutablePrimitiveFieldGenerator, ImmutablePrimitiveOneofFieldGenerator, and RepeatedImmutablePrimitiveFieldGenerator.
PiperOrigin-RevId: 960896522
2026-08-07 06:36:34 -07:00
Vitaly Goldshteyn
075b97c2d3 Move flat_capacity and flat_size inside allocated data in ExtensionSet.
Move flat_capacity and flat_size into the allocated array/rep data structure for ExtensionSet:
- For flat case, store flat_capacity and flat_size in flat[0] (the first KeyValue element). This fit into padding of `KeyValue`.
- For large case, store flat_capacity and flat_size in LargeRep struct matching the offset layout of KeyValue ({int first; uint16_t flat_capacity; uint16_t flat_size; LargeMap large;}), storing LargeMap by value inside LargeRep.
- ExtensionSet now consists of a single AllocatedData pointer (8 bytes), reducing its memory footprint from 16 bytes to 8 bytes.

PiperOrigin-RevId: 960796498
2026-08-07 02:18:49 -07:00
Protobuf Team Bot
68cb3eaca7 Extract generated Java method printing in enum_field.cc into dedicated private generator functions on ImmutableEnumFieldGenerator, ImmutableEnumOneofFieldGenerator, and RepeatedImmutableEnumFieldGenerator.
PiperOrigin-RevId: 960655947
2026-08-06 20:19:55 -07:00
Protobuf Team Bot
18ca7a50c1 Automated rollback of commit 0343196277.
PiperOrigin-RevId: 960652455
2026-08-06 20:08:19 -07:00
Protobuf Team Bot
94c7e8ebc1 Auto-generate files after cl/960627263 2026-08-07 02:08:48 +00:00
Protobuf Team Bot
c0a57498c6 Allocation fault injection tests for upb encode and decode
PiperOrigin-RevId: 960627263
2026-08-06 18:58:07 -07:00
Protobuf Team Bot
2787402df4 Simplify has-bit template variable names in Java immutable generators.
Since builder and message bit indices are now unified (single bit_index_), suffixing has-bit template variables with `_builder` or `_message` is redundant.

Simplify variable names across Java immutable field generators:
- `set_has_field_bit_builder` -> `set_has_field_bit`
- `get_has_field_bit_builder` -> `get_has_field_bit`
- `clear_has_field_bit_builder` -> `clear_has_field_bit`
- `is_field_present_message` -> `is_field_present`
- `is_other_field_present_message` -> `is_other_field_present`
- Remove unused `set_has_field_bit_message` in string_field.cc.

PiperOrigin-RevId: 960593828
2026-08-06 17:36:09 -07:00
Protobuf Team Bot
f23e709bcf Auto-generate files after cl/960555713 2026-08-06 23:32:03 +00:00
Ada Zhang
bff6c119b1 Introduces a public upb_MessageUnknown_Encode API to serialize const struct upb_Extension* into bytes.
PiperOrigin-RevId: 960555713
2026-08-06 16:16:08 -07:00
Samuel Benzaquen
0343196277 Internal change
PiperOrigin-RevId: 960303813
2026-08-06 08:05:03 -07:00
Protobuf Team Bot
de3eafeda5 Auto-generate files after cl/959880585 2026-08-05 21:59:29 +00:00
Protobuf Team Bot
817d6b1fad Internal
PiperOrigin-RevId: 959880585
2026-08-05 14:49:06 -07:00
Eric Salo
77eb569b42 Apply protoc depth limit of nested messages also to group types.
PiperOrigin-RevId: 959843342
2026-08-05 13:40:50 -07:00
Protobuf Team Bot
acaaf9187d Add conformance tests for MessageSet duplicates-within-one-entry handling.
Unlike other cases, MessageSet has the decision that for duplicate ids/payloads is "first wins" (neither last-wins nor merge-semantics like most cases in Protobuf).

The special MessageSet wire format encoding was intended to retain compatibility with data written pre-2008 and so has this oddity.

PiperOrigin-RevId: 959738838
2026-08-05 10:34:05 -07:00
Runze Wang
8c137c4e09 internal change
PiperOrigin-RevId: 959737239
2026-08-05 10:29:52 -07:00
Protobuf Team Bot
b5ec8626b9 Internal Change.
PiperOrigin-RevId: 959702786
2026-08-05 09:29:45 -07:00
Samuel Benzaquen
c799f4d308 Standarize the "can I use a lot of memory" check for tests and disable them for
sanitizers.

Sanitizers make these tests flaky or flat out fail in some configurations
becuause they become too slow and need way more memory.

PiperOrigin-RevId: 959678930
2026-08-05 08:39:07 -07:00
Samuel Benzaquen
a80ee75adb Remove Prepare call from fields that are not supported on Split.
PiperOrigin-RevId: 959670553
2026-08-05 08:23:15 -07:00
Protobuf Team Bot
fc01f49b72 Internal Change.
PiperOrigin-RevId: 959387407
2026-08-04 20:47:06 -07:00
Protobuf Team Bot
f11e6f301a Auto-generate files after cl/959372170 2026-08-05 03:12:27 +00:00
Ada Zhang
1a486b330c Fix a bug that we check the existence of canonical extensions when trying to get/create a canonical/non-canonical extension for both extension types in _upb_Message_GetOrCreateExtensionWithTag.
PiperOrigin-RevId: 959372170
2026-08-04 20:01:47 -07:00
afbrock
8b350fc187 Reserve extension numbers 1364-1373 for Flyte (#29013)
Requesting a block of custom option numbers for [Flyte](https://github.com/flyteorg/flyte), an open source workflow orchestration platform.

* Project: Flyte
* Website: https://github.com/flyteorg/flyte
* Requested: 1364-1373

### Why

Flyte's IDL (`flyteidl2`) is published to the Buf Schema Registry, PyPI and npm, so its descriptors regularly share a descriptor pool with third-party protos. We currently declare a `desc` field option in the 50000-99999 private range, which has collided with another published extension claiming the same tag on `google.protobuf.FieldOptions`. That collision fails extension registration at import time for anyone importing both schemas. Moving to a globally unique number from this registry is the correct fix.

We are requesting a block of ten rather than a single number because `flyteidl2` is a large and actively evolving schema, and we would rather not come back for a second request. This follows the precedent of similarly sized projects in the registry.

### Note on the requested range

We deliberately skipped 1314-1363, which is claimed by the currently open #28919. Starting at 1364 avoids conflicting with that pending request. Happy to renumber if the maintainers would prefer a different block, or if #28919 does not land.

Closes #29013

COPYBARA_INTEGRATE_REVIEW=https://github.com/protocolbuffers/protobuf/pull/29013 from afbrock:flyte-extension-numbers 200b042128
PiperOrigin-RevId: 959367111
2026-08-04 19:44:37 -07:00
Protobuf Team Bot
1f449c5a9c Internal Change.
PiperOrigin-RevId: 959242556
2026-08-04 14:52:53 -07:00
Protobuf Team Bot
caa4c0c8d9 Update CI docker images to use latest supported versions of Bazel
Update the GitHub Actions CI tests to use the latest versions of the images, which include versions 8.7.0 and 9.2.0 of bazel and a few language specific updates.

#test-continuous

Note: The Continuous Linux TSAN test failure is pre-existing and currently broken at HEAD
PiperOrigin-RevId: 959198290
2026-08-04 13:38:35 -07:00
Tony Liao
dd9d2ad02d [ObjC] Carry recursion depth across MessageSet item parsing (#27571)
## Summary

`GPBMessage::parseMessageSet:` reads each MessageSet item's payload bytes into
a separate buffer (because the type-id and payload tags can appear in any
order), then allocates a fresh `GPBCodedInputStream` to decode that buffer. The
fresh stream's `state_.recursionDepth` starts at `0` even when the parent
stream is already several MessageSet items deep, so a chain of nested
MessageSet items grows the native call stack without ever tripping the
documented `kDefaultRecursionLimit` (100). Other parser entry points that
recurse on the same stream (`readGroup:`, `readMessage:`, `readMapEntry:`,
`SkipToEndGroupInternal`) already increment and check `recursionDepth`; the
MessageSet path was the only spot where depth tracking did not cross the stream
boundary.

This change adds a package-private `-initWithData:parentRecursionDepth:`
initializer to `GPBCodedInputStream` that seeds the child stream's depth from
the parent's and runs `CheckRecursionLimit` before parsing begins. To prevent
memory leaks if `CheckRecursionLimit` raises an exception during
initialization, the check is wrapped in a `@try/@catch` block that releases
`self`. `parseMessageSet:` uses that initializer, so depth tracking carries
across the fresh stream. This mirrors the depth-inheritance done by the C++
`ParseContext` spawn helper.

Regression coverage: `testParseMessageSetRecursionDepthCarriedFromParent` in
`GPBWireFormatTests` builds MessageSet-of-MessageSet payloads (each layer is
`MSetMessage -> MSetMessageExtension1.recursive -> MSetMessage -> ...`, adding
2 to the recursion depth per layer). It verifies that 50 layers (depth 100,
`kDefaultRecursionLimit`) parses successfully, while 51 layers (depth 101,
`kDefaultRecursionLimit + 1`) fails with
`GPBCodedInputStreamErrorRecursionDepthExceeded`. Existing
`testErrorRecursionDepthReached` and the rest of `GPBWireFormatTests` continue
to pass unchanged.

## Test plan

- Existing ObjC test suite passes (`GPBWireFormatTests`,
  `GPBMessageTests+Serialization`, `GPBCodedInputStreamTests`,
  `GPBUnknownFieldsTest`).
- New `testParseMessageSetRecursionDepthCarriedFromParent` passes for both 50
  layers (passing at kDefaultRecursionLimit) and 51 layers (failing at
  kDefaultRecursionLimit + 1).

Closes #27571

PiperOrigin-RevId: 959041690
2026-08-04 08:41:24 -07:00
Samuel Benzaquen
42c88bf5ce Change DefPool Find methods to take absl::string_view.
PiperOrigin-RevId: 958995646
2026-08-04 06:58:50 -07:00
Vitaly Goldshteyn
81fcdf44c5 Change ExtensionSet flat capacity growth factor from 4x to 2x.
This reduces memory overhead when resizing the flat array in ExtensionSet by growing the capacity by a factor of 2 instead of 4.

PiperOrigin-RevId: 958651834
2026-08-03 16:58:49 -07:00
Vitaly Goldshteyn
42e27e00f5 Fix uint16_t capacity truncation bug in ExtensionSet::GrowCapacity
In ExtensionSet::GrowCapacity, auto new_flat_capacity was deduced as uint16_t from flat_capacity_. When merging a large extension set (>2**16 elements), quadrupling new_flat_capacity (16384 * 4 = 65536) wrapped back to 0 in uint16_t, causing an infinite loop.

This change explicitly sets new_flat_capacity type to size_t to prevent truncation. A unit test MergeLargeExtensionSetToEmpty is added to extension_set_unittest.cc to cover this case.

PiperOrigin-RevId: 958634496
2026-08-03 16:21:48 -07:00
Protobuf Team Bot
deb792c460 Auto-generate files after cl/958511623 2026-08-03 19:28:34 +00:00
Samuel Benzaquen
4e7b3d8142 Implement 32-bit offset-based pointers for descriptor types.
Almost all the memory for the descriptors of a .proto file are allocated in a single flat allocation that is limited in size to 2GiB. As such, we can change crosslinking pointers to be 32-bit offset pointers.

This significantly reduces the size of the descriptor objects.

PiperOrigin-RevId: 958511623
2026-08-03 12:20:30 -07:00
Protobuf Team Bot
51dedb854d Auto-generate files after cl/958447202 2026-08-03 17:36:17 +00:00
Mikita Belahlazau
b38629a337 Disable option sub-location mapping in open-source builds.
We are considering changing the format of locations for options in SourceCodeInfo as the current format conflicts with dot-notation options format and can't be extended to cover them well.

Once we update format and make sure it works well for all type of options we'll re-enable it for opensource version.

PiperOrigin-RevId: 958447202
2026-08-03 10:26:38 -07:00
Protobuf Team Bot
0c9ba64990 Kotlinc 2.4 language version update pre-work.
Fix impossible is checks that are guaranteed to always returns false.

PiperOrigin-RevId: 958436856
2026-08-03 10:12:49 -07:00
Protobuf Team Bot
0e436a47e8 Update conformance tests with updated relaxed duplicate key handling in ProtoJSON
The spec has been relaxed such that the preferred behavior is last-wins, and parse-failure if last-wins is not implementable. The conformance test is updated correspondingly to pass under either of those permissible behaviors.

https://github.com/protocolbuffers/protobuf/issues/28791

PiperOrigin-RevId: 957979215
2026-08-02 09:58:52 -07:00
Protobuf Team Bot
e5fbe9531a Auto-generate files after cl/957685462 2026-08-01 19:20:06 +00:00
Mike Kruskal
71e45486e3 Silence bad error when option dependencies are missing in the filesystem but present in input descriptor sets.
This particular error was already firing twice, and the one we're removing is noisy and unnecessary.  This also shrinks descriptor sets produced by protoc to not include transitive option dependencies.  We only need to pass direct option dependencies to code generators, which is why this path was added in the first place

PiperOrigin-RevId: 957685462
2026-08-01 12:11:19 -07:00
brucearctor
c74a2ae4b3 Add proto2mcp to global extension registry (1311-1313) (#28790)
## Extension Registration Request

**Project:** proto2mcp
**Website:** https://github.com/protocgen/proto2mcp
**Requested Extensions:** 1311-1313

### About proto2mcp

proto2mcp is a protoc/buf plugin that generates [MCP (Model Context Protocol)](https://modelcontextprotocol.io/) servers from Protobuf service definitions. It enables existing gRPC/ConnectRPC services to be securely exposed as LLM tools with:

- Automatic JSON Schema generation from proto messages
- Multitenancy support via interceptor middleware
- `buf.validate` constraint mapping for LLM input validation
- ConnectRPC client forwarding

### Extension Usage

proto2mcp uses custom options on three descriptor types:

| Extension | Number | Purpose |
|---|---|---|
| `google.protobuf.MethodOptions` | 1311 | Per-method MCP tool configuration (name override, description, skip, hints) |
| `google.protobuf.ServiceOptions` | 1312 | Per-service MCP configuration (tool name prefix, description) |
| `google.protobuf.FileOptions` | 1313 | Per-file MCP configuration (skip entire file) |

### Example

```protobuf
import "protocgen/mcp/v1/options.proto";

service PatientService {
  option (protocgen.mcp.v1.service) = {
    tool_name_prefix: "Patient"
    description: "Patient management operations"
  };

  rpc GetPatient(GetPatientRequest) returns (GetPatientResponse) {
    option (protocgen.mcp.v1.method) = {
      description: "Retrieves a patient record by ID"
      read_only: true
    };
  }
}
```

### Related

proto2mcp is part of the [protocgen](https://github.com/protocgen) ecosystem, alongside [proto2type](https://github.com/protocgen/proto2type).

Closes #28790

COPYBARA_INTEGRATE_REVIEW=https://github.com/protocolbuffers/protobuf/pull/28790 from brucearctor:add-proto2mcp-extension 5724a815b6
PiperOrigin-RevId: 957514481
2026-07-31 23:39:16 -07:00
Matthew Wear
ae3f25c964 ruby: make bigdecimal a development dependency (#28928)
Fixes #28927

I ran into this while packaging the OpenTelemetry Ruby auto-instrumentation as a prebuilt gem bundle (see #28927 for the full write up). The tl;dr: `bigdecimal` is only used by the test suite, so it only needs to be a development dependency. The only references are:

8baed752ce/ruby/tests/common_tests.rb (L9)

8baed752ce/ruby/tests/common_tests.rb (L1708)

As a runtime dependency it causes pain for anyone vendoring the gem. `bigdecimal` is a native extension with no precompiled build, so it has to be compiled from source for each Ruby ABI, making it the one gem that stops a prebuilt bundle from working across Ruby versions, despite never being loaded at runtime.

This PR moves `bigdecimal` from a runtime to a development dependency. For consistency it also moves `bigdecimal` into the `test` group in the Gemfile, since that's the only environment that needs it.

Closes #28928

COPYBARA_INTEGRATE_REVIEW=https://github.com/protocolbuffers/protobuf/pull/28928 from mwear:ruby-bigdecimal-dev-dependency 6fb8ee4fad
PiperOrigin-RevId: 957450742
2026-07-31 19:47:08 -07:00
Protobuf Team Bot
b790ca9a4b Auto-generate files after cl/957382561 2026-07-31 23:31:50 +00:00
Dave MacLachlan
8a178c26fd Use #include instead of #import for <stdint.h> in GPBBootstrap.h.
Changes the import of the standard C header `<stdint.h>` to a standard `#include` directive.

PiperOrigin-RevId: 957385929
2026-07-31 16:27:26 -07:00
Jason Aragorn Tobias Lunn
713b6a4a24 Add json_options.proto and json_enumvalue_options.proto and/or gencode derived from them to release artifacts
* `protoc`: Included in zips alongside binary
* Java: Generated classes have been added to the Maven `util` artifact
* Ruby: Generated classes have been added to gems
* CMake: `.proto` files are included in installation

PiperOrigin-RevId: 957382561
2026-07-31 16:20:59 -07:00
Protobuf Team Bot
a5412936c7 Annotate extension names in hpb generator for Kythe metadata.
PiperOrigin-RevId: 957381097
2026-07-31 16:16:26 -07:00
Protobuf Team Bot
c5cbcf787f Extract generated Java method printing in message_field.cc into dedicated private generator functions on ImmutableMessageFieldGenerator, ImmutableMessageOneofFieldGenerator, and RepeatedImmutableMessageFieldGenerator.
PiperOrigin-RevId: 957369913
2026-07-31 15:50:26 -07:00
Protobuf Team Bot
fabd22a454 Fix reachable CHECK in JSON unparser for empty Value in Any.
PiperOrigin-RevId: 957309778
2026-07-31 13:40:40 -07:00
Protobuf Team Bot
8acef15ff3 gtest_matchers_impl.rs: Reorder the file a bit and add more comments
This makes it easier to find the thing people are actually interested in - `proto_eq`.

PiperOrigin-RevId: 957308502
2026-07-31 13:35:21 -07:00
Joshua Haberman
8a04a804c9 Internal change
PiperOrigin-RevId: 957304273
2026-07-31 13:25:20 -07:00
Thalha Ahmed
15de228074 Validate language-specific namespace options in code generators (#28667)
## Summary

Add input validation for language-specific namespace/package options (`php_namespace`, `php_metadata_namespace`, `ruby_package`, `csharp_namespace`) in their respective code generators.

These options are currently emitted directly into generated source code without character validation. Specially crafted `.proto` files can inject arbitrary code into generated PHP, Ruby, or C# output.

Fixes #28679

## Changes

- **PHP generator**: Validates `php_namespace` and `php_metadata_namespace` — denies injection-enabling characters (`;`, `{}`, `()`, quotes, `$`, etc.) while allowing Unicode identifiers
- **Ruby generator + RBS generator**: Validates `ruby_package` — same denylist approach
- **C# generator**: Validates `csharp_namespace` — same denylist approach

Each generator rejects invalid options with a clear error message before emitting code.

## Motivation

When processing untrusted `.proto` files (e.g., from third-party dependencies, shared proto registries, or CI pipelines), these options can contain characters like semicolons, braces, or backticks that break out of the intended code structure. Validating at generation time prevents this class of injection.

## Testing

The denied character sets match characters that can never be valid in a namespace/package identifier in any of the target languages. Unicode identifiers are allowed. Existing `.proto` files with valid namespace options are unaffected.

Closes #28667

COPYBARA_INTEGRATE_REVIEW=https://github.com/protocolbuffers/protobuf/pull/28667 from thalha-a9:fix/validate-codegen-namespace-options b2f333a411
PiperOrigin-RevId: 957224133
2026-07-31 10:50:53 -07:00
Protobuf Team Bot
7c02abb54a Auto-generate files after cl/957163354 2026-07-31 16:00:30 +00:00
Ada Zhang
77f5b6bd09 Expose the upb_Extension struct as a public API in unknown_fields.h.
PiperOrigin-RevId: 957163354
2026-07-31 08:49:56 -07:00
Clayton Knittel
ea6ec8d5b1 Remove forward declarations of deleted WeakFieldMap.
PiperOrigin-RevId: 956905765
2026-07-30 21:40:56 -07:00
Protobuf Team Bot
668f9d6a7b Catch groups with large tags during unknown dispatch.
PiperOrigin-RevId: 956898315
2026-07-30 21:14:07 -07:00
Protobuf Team Bot
b861e63899 Internal change.
PiperOrigin-RevId: 956802533
2026-07-30 16:38:26 -07:00
Protobuf Team Bot
2a5f909e91 Auto-generate files after cl/956766618 2026-07-30 22:39:44 +00:00
Protobuf Team Bot
fb3b72f296 Internal Change.
PiperOrigin-RevId: 956766618
2026-07-30 15:29:44 -07:00
Jason Aragorn Tobias Lunn
d33f914118 Reject custom JSON enum value options in the PHP generator.
PiperOrigin-RevId: 956738027
2026-07-30 14:33:08 -07:00
Protobuf Team Bot
8baed752ce Auto-generate files after cl/956632937 2026-07-30 18:29:41 +00:00
Tony Liao
8111a7473d json/upb: Implement json EnumValueName for upb
PiperOrigin-RevId: 956632937
2026-07-30 11:19:11 -07:00
Protobuf Team Bot
2a36520396 fix missed oom handling in unset required
PiperOrigin-RevId: 956610684
2026-07-30 10:42:17 -07:00
yashanil98
706656afeb fix(cpp): take EpsCopyInputStream::PopLimit token by rvalue reference (#28619)
EpsCopyInputStream::LimitToken guards its payload with ASan memory poisoning (poisoned when empty, unpoisoned while it holds a live token). PopLimit accepted the token by value:

```cpp
[[nodiscard]] bool PopLimit(LimitToken delta) { ... std::move(delta).token() ... }
```

With a by-value parameter, the compiler can place the parameter in the same stack slot as the moved-from caller token. The move assignment then poisons the moved-from token, i.e. the very slot the parameter occupies, and PopLimit reads it via `token()`, which ASan reports as a use-after-poison abort. This reproduces before `main()` during static descriptor initialization when protobuf is built with `-fsanitize=address` (reported on aarch64 in #27298), e.g.:

```
ERROR: AddressSanitizer: use-after-poison READ of size 4
  #0 EpsCopyInputStream::PopLimit(EpsCopyInputStream::LimitToken)
  #1 ParseContext::ParseLengthDelimitedInlined(...)
  ...
  Memory access is inside this variable: agg.tmp  (a LimitToken temporary)
```

Take the token by rvalue reference (`LimitToken&& delta`) instead. This removes the extra by-value copy and the shared-slot hazard: the token binds directly to the callers object, which is unpoisoned while live. All three callers (`ParseLengthDelimitedInlined`, `ParseWithLengthInlined`, `ParseContext::ParseMessage`) already pass `std::move(old)`, and the body already consumes the token as an rvalue, so behavior is unchanged.

Fixes #27298.

Test plan: the bug reproduces only under ASan (poisoning is a no-op otherwise) and protobuf has no in-repo ASan-poisoning regression harness for the parser, so this is verified by (1) the change being a by-value to rvalue-reference signature refactor with no behavioral change, all callers already moving the token, and (2) a full CMake/Ninja build plus the parsing test suites staying green: `tests --gtest_filter=*TcTable*:*Parse*:*WireFormat*:*Reflection*:*ExtensionSet*:*DynamicMessage*:*Arena*` passes (~3000 tests, 0 failures). I do not have the reporters ASan+aarch64 toolchain to run the exact repro.

Closes #28619

COPYBARA_INTEGRATE_REVIEW=https://github.com/protocolbuffers/protobuf/pull/28619 from yashanil98:fix/issue-27298-limittoken-poison 93a3d332f3
PiperOrigin-RevId: 956314017
2026-07-30 00:00:05 -07:00
Protobuf Team Bot
cfe0723d8a Handle alloc failure in field_message.
PiperOrigin-RevId: 956248784
2026-07-29 21:03:00 -07:00
Joshua Haberman
36389c23f2 Internal change
PiperOrigin-RevId: 956132585
2026-07-29 15:55:57 -07:00
Protobuf Team Bot
457e112357 Auto-generate files after cl/956112101 2026-07-29 22:22:56 +00:00
Protobuf Team Bot
bbe3b9e4f2 Handle return values in cpp code in upb/hpb
PiperOrigin-RevId: 956112101
2026-07-29 15:12:49 -07:00
Protobuf Team Bot
a772068fea Auto-generate files after cl/956087593 2026-07-29 21:34:38 +00:00
Protobuf Team Bot
01033aca05 Add more oom test coverage and fix errors on copy
PiperOrigin-RevId: 956087593
2026-07-29 14:24:43 -07:00
Protobuf Team Bot
6ca4388f09 Add upb_Message_SetNonCanonicalExtension public API.
PiperOrigin-RevId: 956070017
2026-07-29 13:53:52 -07:00
Protobuf Team Bot
b97149ff4f Auto-generate files after cl/956061501 2026-07-29 20:50:21 +00:00
Protobuf Team Bot
4838f0d46f Don't enforce that the return value of upb_Arena_Fuse is used; this only fails if an initial block is in use, and in that case it's reasonable to assume that the program is managing those lifetimes manually.
PiperOrigin-RevId: 956061501
2026-07-29 13:39:58 -07:00
Protobuf Team Bot
e80f5fbcfd Update hpb message_lock.cc to use upb_Message_FindUnknown2 API.
PiperOrigin-RevId: 956035609
2026-07-29 12:47:42 -07:00
Protobuf Team Bot
60f509fa40 Auto-generate files after cl/955926792 2026-07-29 16:41:03 +00:00
Ada Zhang
33bca9296f Use upb_TaggedAuxPtr_IsNull helper in upb/message/message.h.
PiperOrigin-RevId: 955926792
2026-07-29 09:30:54 -07:00
kuchazi-yy
b5d2e8db22 fix(python): reject mismatched CopyToProto targets (#28666)
Fixes #28665

Closes #28666

COPYBARA_INTEGRATE_REVIEW=https://github.com/protocolbuffers/protobuf/pull/28666 from kuchazi-yy:fix/python-copy-to-proto-type-check 70df03d3b1
PiperOrigin-RevId: 955861788
2026-07-29 07:09:05 -07:00
Krasimir Georgiev
aed6a821d1 Add required_providers to proto aspect
PiperOrigin-RevId: 955838256
2026-07-29 06:10:06 -07:00
Protobuf Team Bot
43b6c37509 Handle ruby allocation failures gracefully
Prior to this change, the custom alloc function used with arenas would internally longjmp on allocation failure, which would then leak memory (as upb does not expect or permit longjmp from an alloc function, and has no way to free intermediate allocations).

PiperOrigin-RevId: 955635829
2026-07-28 21:08:09 -07:00
Protobuf Team Bot
90257a0983 Internal change
PiperOrigin-RevId: 955548742
2026-07-28 17:03:23 -07:00
Protobuf Team Bot
b593483f36 Internal change.
PiperOrigin-RevId: 955525137
2026-07-28 16:09:48 -07:00
Protobuf Team Bot
3273dca565 Remove redundant binary decoders from Java and Java Lite conformance testees
These testees run N different parse paths and see if they all agree. Many of them have been collapsed down to the same parse paths and so are just wasting time rerunning the same paths and seeing if it gives the same result again.

In reality there's only 2 parse paths left, but this is only going down to 4 in the testee for now (there's the extra quirk of just first doing a copy on some inputs).

PiperOrigin-RevId: 955496333
2026-07-28 15:13:25 -07:00
Joshua Haberman
2f32a3efb2 Refactor protobuf flag abstraction layer to custom flag targets
Instead of having rules depend on both native and Starlark versions of flags and reconciling them inside the rule implementation, this change moves the resolution logic into custom build setting flag targets (`compat_bool_flag` and `compat_string_list_flag`) defined in `third_party/protobuf/bazel/private/compat_flag.bzl`.

Key details:
- `compat_bool_flag`: Defines a string build setting flag target with a "default" sentinel value. When un-set on the command line, it falls back dynamically to reading native options on `ctx.fragments.proto` or default values, providing a boolean `BuildSettingInfo`.
- `compat_string_list_flag`: Defines a string-list build setting flag target that reconciles explicit Starlark build settings with `ctx.fragments.proto` and default values.
- Rules reference the flag targets directly (without separate helper `_compat` targets or `config_setting` rules).
- Replaces `native_bool_flag.bzl` with `compat_flag.bzl`.

PiperOrigin-RevId: 955468205
2026-07-28 14:22:18 -07:00
Joshua Haberman
462509e64f Add unit tests for Starlark flag behavior in bazel_proto_library_tests
PiperOrigin-RevId: 955429259
2026-07-28 13:17:13 -07:00
Michael Hoisie
54fe86b091 Avoid UTF8 length calculations in ArrayEncoder.writeStringNoTag
Previously, for strings whose length prefix could span more than one varint
byte, the encoder walked the string twice: Utf8.encodedLength to size the
prefix, then Utf8.encode to write the bytes. Update this logic to just write
the string in one pass and avoid calling Utf8.encodedLength.

For ServerProcessor, the current optimal String.getBytes(UTF_8) is called. For
MobileProcessor, the string is written to the buffer directly with no
additional allocation first, and then the length is written as the prefix.
This approach is faster for mobile than Utf8.encodedLength, which requires
iterating over the string character by character. This approach is also
guaranteed to not overrun the buffer, because the buffer was already sized
using Utf8.encodedLength.

Message                   Runtime   Before(ns)  After(ns) Speedup
------------------------  -------   ---------  ---------  -------
google_message1 (228 B)   JVM           253.8      199.4   1.26x
google_message1           ART           460.9      407.3   1.13x
google_message2 (85 KB)   JVM          156309     130485   1.25x
google_message2           ART          201538     178130   1.13x

PiperOrigin-RevId: 955379320
2026-07-28 11:43:42 -07:00
Protobuf Team Bot
21bfc8ad38 Auto-generate files after cl/955347939 2026-07-28 18:04:47 +00:00
Protobuf Team Bot
b95796f8c2 Fix Java Lite EOF conformance issue when hitting EOF early in stream parsing.
This is achieved by making the recently-added `pushLimitBeforeMessage` and `popLimitAfterMessage` package-protected so that it can be used by CodedInputStreamReader which was otherwise doing its own pushing-and-popping without properly checking these boundary conditions.

PiperOrigin-RevId: 955353136
2026-07-28 10:59:47 -07:00
Protobuf Team Bot
785c35862d Internal change.
PiperOrigin-RevId: 955347939
2026-07-28 10:53:41 -07:00
Protobuf Team Bot
6d7f56cbac Auto-generate files after cl/955260241 2026-07-28 15:19:20 +00:00
Ada Zhang
8f0e127cde Support non-canonical extensions in upb_Message_IsEqual.
PiperOrigin-RevId: 955262798
2026-07-28 08:08:48 -07:00
Ada Zhang
2ac75aab07 Support non-canonical extensions in message copy/freeze/encode operations.
PiperOrigin-RevId: 955260241
2026-07-28 08:04:18 -07:00
Protobuf Team Bot
6f2e31b2b8 Auto-generate files after cl/955047292 2026-07-28 06:26:07 +00:00
Protobuf Team Bot
efa7be94db Disable fasttable when executing 32bit decoder on 64bit cpu.
PiperOrigin-RevId: 955047292
2026-07-27 23:15:59 -07:00
Protobuf Team Bot
1e4949d09b Automated Code Change
PiperOrigin-RevId: 955037668
2026-07-27 22:53:11 -07:00
Protobuf Team Bot
232f2fbd50 Auto-generate files after cl/955022274 2026-07-28 05:21:33 +00:00
Protobuf Team Bot
ad6a7e8b64 Check return values and handle alloc failures in python
PiperOrigin-RevId: 955022274
2026-07-27 22:11:16 -07:00
Protobuf Team Bot
a0c493ce55 Propagate recursion limit when parsing MessageSet extensions.
PiperOrigin-RevId: 954943638
2026-07-27 18:27:35 -07:00
Protobuf Team Bot
a045f8497e Add LazyStringArrayList specific equals method
Check instanceof LazyStringArrayList as that'll be the most common case and it's cheap (a pointer on the klass) rather than a loop on the set of interfaces.

PiperOrigin-RevId: 954927009
2026-07-27 17:47:51 -07:00
Protobuf Team Bot
545f3bafe4 Auto-generate files after cl/954919110 2026-07-28 00:36:08 +00:00
Ada Zhang
65cf893e66 Handle cleared extensions in upb_Message_DeepClone and upb_Message_ShallowCopy.
PiperOrigin-RevId: 954919110
2026-07-27 17:25:50 -07:00
Protobuf Team Bot
3b45e7a88c Optimize ProtobufArrayList.equals by checking instanceof ProtobufArrayList early
I think it's most common that we're comparing protos against protos, where we'll be comparing ProtobufArrayLists against ProtobufArrayLists.

It's faster to check instanceof SomeFinalClass (a pointer comparison) than to check instanceof SomeInterface (walk a set of interfaces)

PiperOrigin-RevId: 954892499
2026-07-27 16:30:21 -07:00
Rachel Goldfinger
a5ac4e924a Fix potential OOMs from gigantic allocations in packed primitive, string reading, and MessageSet paths.
PiperOrigin-RevId: 954799315
2026-07-27 13:30:14 -07:00
Samuel Benzaquen
160c306671 Fix use-after-free when oneof switches during MergeFromString.
We parse into a temporary message first to detect oneof switches before modifying the target message, and release the wrappers for switching oneof fields in the target message.

PiperOrigin-RevId: 954778098
2026-07-27 12:50:24 -07:00
Protobuf Team Bot
baa02c14da Auto-generate files after cl/954750025 2026-07-27 19:03:34 +00:00
Protobuf Team Bot
572ca36fd7 Omit GET_MEMOIZED_IS_INITIALIZED in Java Lite for messages without required fields.
Messages without required fields omit GET_MEMOIZED_IS_INITIALIZED and SET_MEMOIZED_IS_INITIALIZED switch cases from dynamicMethod to minimize gencode size.

For those messages, dynamicMethod returns null, skipping memoization and delegating directly to MessageSchema.isInitialized(), which evaluates to true in O(1) time.

PiperOrigin-RevId: 954754880
2026-07-27 12:02:55 -07:00
Joshua Haberman
5d717fd0a9 Fix a bug in LazyField where parsing with a custom DescriptorPool or MessageFactory failed or lost extension data (b/519244881).
Strategy:
- New Representation (PROTOBUF_INTERNAL_LAZY_FIELD_REFACTOR): Extend the inner heap object (InnerMessageWithPool) to store DescriptorPool* and MessageFactory* pointers alongside unparsed data, identified by spare tag bits on the inner pointer. If a parse or merge occurs with a differing pool or factory, LazyField::_InternalParse detects the mismatch and forces an eager parse.
- Legacy Representation (#else): Because the legacy layout cannot store custom pool pointers without extra heap wrappers, any parse attempt with a custom pool is treated as a mismatch and immediately falls back to an eager parse.
PiperOrigin-RevId: 954750025
2026-07-27 11:53:29 -07:00
Runze Wang
8ce2a36efd Escape all non-alnum chars in Rust module names
PiperOrigin-RevId: 954736047
2026-07-27 11:28:51 -07:00
Samuel Benzaquen
fa52ce297c Fix some preprocessor checks.
PiperOrigin-RevId: 954719006
2026-07-27 10:58:14 -07:00
Samuel Benzaquen
9eb63e4459 Cast the other side of the expression to unsigned.
The allocation will likely fail inside the allocator, but we won't return an invalid pointer.

PiperOrigin-RevId: 954660635
2026-07-27 09:08:46 -07:00
Samuel Benzaquen
785d988985 Use amortized growth when appending concatenated literals.
PiperOrigin-RevId: 954649619
2026-07-27 08:43:51 -07:00
Protobuf Team Bot
7bdbfcd927 Add @ForLiteOnly and Lite-only Javadoc to Lite-only classes.
PiperOrigin-RevId: 954642441
2026-07-27 08:27:14 -07:00
Protobuf Team Bot
f8dfd63322 Add conformance tests for Timestamp parsing
In general, runtimes also expose Timestamp parsing by utils but it is conformance-testable via JSON.

Timestamp format is RFC3339 which looks like `1970-01-01T00:00:00Z` (for UTC timestamps) or `1970-01-02T01:00:00+02:00` (with timezone).

There's actually two different reasons why a Timestamp format might be invalid.

RFC3339 spec has some bright line rules as follows:

- All of the segments must be the expected fixed width (eg: month is always 2 digits, 1970-01-01 and not 1970-1-1).
- Year must be [0001 .. 9999]
- Month must be [01 .. 12]
- Day must be valid for the relevant month, including that Feb 29 is only legal in leap years.
- The literal `T` comes next (spec ambiguous if `t` is also allowed, not tested in this change)
- Hour must be [00..23]
- Minute must be [00..59]
- Second must be [00..59]
- Subseconds are unconstrained precision
- Timezone must be Z for UTC or else formatted with HH:MM where HH is [00..23] and MM is [00..59].

Protobuf has a few extra effective constraints compared to RFC3339 though, which are _mostly_ academic:

- We disallow subsecond resolution has more than 9 decimal digits
- Some RFC3339 timestamps which are not-UTC-timezone in year 1 or year 9999 are not valid in Protobuf [*reason explained below]

Note that GoProto uses a std RFC3339 parser and does implement these bonus restrictions rules on top.

* The reason is that `0001-01-01T00:00:00+00:01` is a legal RFC3339 timestamp, but is BCE in UTC timezone. This is an oddity: we otherwise say parsers should accept RFC3339 timestamps with any timezone, but must serialize as UTC. This timestamp is not legally representable in RFC3339 in UTC, and the google.protobuf.Timestamp field secs is documented that `-62135596800` is the minimum legal value, but this timestamp is earlier than that. Because this situation only occurs at the years 1 and 9999 its not plausibly a concern on real user data, its only an oddity that you must either reject this legal RFC3339 timestamp at parse time, or else accept it but produce an in-memory google.protobuf.Timestamp which is officially 'invalid' and cannot be printed back out.

PiperOrigin-RevId: 954603113
2026-07-27 06:54:18 -07:00
Protobuf Team Bot
a105c7ef15 Close risk of RustProto UB in the face of a set Cord-typed field.
In Rust, enums are always closed, such that its UB to construct one that isn't the corresponding name. This is true even for #[non_exhaustive] #[repr(C)] enums.

If FFI provides such an enum, its always immediate UB in Rust if it reaches a case with no name.

PiperOrigin-RevId: 954588991
2026-07-27 06:26:08 -07:00
Clayton Knittel
c4be7483cb Use ClassData instead of a prototype throughout lazy field / extensions when possible.
`New` is more efficient on ClassData than on a prototype, as `New` on the prototype has to first load the class data through the prototype.

There's also a small optimization in `LazyField::MergeFromMessage` which avoids loading the class data twice. The redundancy was made more obvious by this refactor.

PiperOrigin-RevId: 953889072
2026-07-25 09:22:11 -07:00
Protobuf Team Bot
b7491e2dc3 Auto-generate files after cl/953801430 2026-07-25 09:56:59 +00:00
Mikita Belahlazau
c251d1ab57 Implement GetSourceLocation for sub-fields and names of aggregate options.
This change enables source location recording for individual fields specified
within an aggregate option (e.g., `option (my_opt) = { field_a: 123 }`). With this change SourceCodeInfo will contain locations of `field_a` and `123`.

PiperOrigin-RevId: 953801430
2026-07-25 02:49:07 -07:00
Joshua Haberman
44fa35f860 Fix potential Py_DECREF(NULL) crash in PythonMessageMutator destructor.
In 'PythonMessageMutator::~PythonMessageMutator()', 'PyBytes_FromStringAndSize' can return 'nullptr' if memory allocation fails or string length overflows. Calling 'Py_DECREF(py_wire)' and 'PyObject_CallMethod' when 'py_wire' is 'nullptr' results in a NULL-pointer dereference crash.

Add a null check for 'py_wire' before calling 'PyObject_CallMethod' and 'Py_DECREF'.

PiperOrigin-RevId: 953616147
2026-07-24 16:57:59 -07:00
Joshua Haberman
414e4142cd Sync sub-objects in PyUpb_Message_MergeFromString even when decode fails.
In 'PyUpb_Message_MergeFromString', 'upb_Decode' may partially mutate or populate sub-messages on the parent message before failing with a decode error status. Skipping 'PyUpb_Message_SyncSubobjs' when 'status != kUpb_DecodeStatus_Ok' leaves stub sub-object wrappers unsynced in 'unset_subobj_map', causing duplicate keys in 'ObjCache' on subsequent access and leading to heap-use-after-free.

Move 'PyUpb_Message_SyncSubobjs(self)' before the decode status check in 'PyUpb_Message_MergeFromString' so any sub-message wrappers modified during decoding are synced properly.

Add 'testMergeFromStringDecodeErrorSync' to 'third_party/py/google/protobuf/internal/message_test.py' to verify that stub sub-objects remain synced and intact after a failed 'MergeFromString'.

PiperOrigin-RevId: 953615725
2026-07-24 16:53:12 -07:00
Samuel Benzaquen
95a1e90ce0 Add a hard limit on the number of errors and warnings we generate.
This prevents pathological inputs from wasting too much time/space on error
output.

PiperOrigin-RevId: 953593292
2026-07-24 15:59:54 -07:00
Protobuf Team Bot
61b31adf84 Auto-generate files after cl/953580288 2026-07-24 22:34:48 +00:00
Samuel Benzaquen
bd3142f3e3 Fix consistency issue with MessageSet parsing when order of fields is inversed.
Some paths were not taking into account all the required nesting.

PiperOrigin-RevId: 953580288
2026-07-24 15:24:28 -07:00
Samuel Benzaquen
74feca102c Fix redaction logic to skip unknown open enum values.
PiperOrigin-RevId: 953573455
2026-07-24 15:08:33 -07:00
Runze Wang
e0337ad29e Inline hot methods on Map and in generated code
These methods are one-to-three line wrappers delegating to underlying map implementations (upb/cpp_kernel). Without `#[inline]`, the compiler will not cross crate boundaries, resulting in many physical function call overheads for otherwise fully optimal code in hot loops on Map values.

PiperOrigin-RevId: 953537646
2026-07-24 13:50:52 -07:00
Samuel Benzaquen
fcc343eac8 Enforce bound checking in some functions in FieldDescriptor.
This enum value is user provided and they might have bugs.

PiperOrigin-RevId: 953513855
2026-07-24 12:59:32 -07:00
Protobuf Team Bot
3094f87854 Auto-generate files after cl/953447806 2026-07-24 18:00:16 +00:00
Joshua Haberman
beb01ec89a Fix upb wire decoder accepting field number 0.
Reject field_number 0 tags in _upb_WireReader_SkipValueForceInline.
Protocol Buffer wire format requires field numbers to be positive integers
(1 to 536,870,911). Previously, _upb_WireReader_SkipValueForceInline lacked a
(tag >> 3) == 0 check, allowing upb to accept and round-trip illegal field 0
tags in empty messages, unknown groups, and MessageSet items.

PiperOrigin-RevId: 953447806
2026-07-24 10:50:37 -07:00
Samuel Benzaquen
b8859ce994 Fix stack overflow on very deep public dependency chains.
PiperOrigin-RevId: 953438319
2026-07-24 10:32:41 -07:00
Protobuf Team Bot
d03f760689 internal changes
PiperOrigin-RevId: 953407098
2026-07-24 09:33:35 -07:00
Samuel Benzaquen
8080b024a7 Fix error generation for very large inputs in TextFormat::Parser.
PiperOrigin-RevId: 953364578
2026-07-24 07:52:21 -07:00
Konstantin Pavlov
732618dc70 Polish perfomance of TextFormat::Printer::Print (#28518)
Relates: https://github.com/protocolbuffers/protobuf/issues/23288

Closes #28518

COPYBARA_INTEGRATE_REVIEW=https://github.com/protocolbuffers/protobuf/pull/28518 from kpavlov00:TextFormat-Printer-Print-tail-perfomance-polish 813bb98103
PiperOrigin-RevId: 953303748
2026-07-24 05:04:08 -07:00
Edoardo Spadolini
e96bfb2169 Reserve extension 1310 for the Teleport API module (#28769)
This adds an entry to the global extension registry (`docs/options.md`) reserving extension number 1310 for Teleport.

* Project: Teleport
* Website: https://goteleport.com
* Extension number: 1310

Closes #28769

COPYBARA_INTEGRATE_REVIEW=https://github.com/protocolbuffers/protobuf/pull/28769 from espadolini:reserve-extension-teleport e0ee846d2a
PiperOrigin-RevId: 953095349
2026-07-23 20:01:45 -07:00
Jason Aragorn Tobias Lunn
4bd1598566 Upgrade plugins to support edition 2026
PiperOrigin-RevId: 952932907
2026-07-23 13:47:26 -07:00
Tony Liao
cb440834fd Document Python & PHP non-conformance where booleans are accepted by int and float fields.
PiperOrigin-RevId: 952905948
2026-07-23 12:51:55 -07:00
Rachel Goldfinger
6a31b747f2 Add deprecation warning for Reflection::GetEnum() and Reflection::GetRepeatedEnum().
PiperOrigin-RevId: 952843763
2026-07-23 10:47:56 -07:00
Samuel Benzaquen
be5dad556d Add overflow protection for very large containers.
These will now deterministically terminate instead of triggering undefined
behavior.

PiperOrigin-RevId: 952817921
2026-07-23 10:00:11 -07:00
Protobuf Team Bot
6d040c27a9 Fix memory safety issues in PHP Message object destruction.
PiperOrigin-RevId: 952812117
2026-07-23 09:52:52 -07:00
Karen Wu
9d632771bc This change moves several tests from JavaLiteProtoLibraryTest.java to Starlark-based analysis tests in java_lite_proto_library_tests.bzl
PiperOrigin-RevId: 952808292
2026-07-23 09:47:44 -07:00
Clayton Knittel
3c0275c485 Add private AddByClassData to RepeatedPtrField.
PiperOrigin-RevId: 952716824
2026-07-23 06:12:45 -07:00
Protobuf Team Bot
8815f682d8 Auto-generate files after cl/952535247 2026-07-23 06:06:35 +00:00
Ada Zhang
34abf03809 Move the upb_MessageUnknown and upb_Message_DeleteUnknownStatus definitions to unknown_fields.h.
PiperOrigin-RevId: 952535247
2026-07-22 22:56:33 -07:00
Runze Wang
b67d62ecb4 internal change
PiperOrigin-RevId: 952340336
2026-07-22 14:45:08 -07:00
Jason Aragorn Tobias Lunn
ee50197f3a Add disk space checks in between steps of Linux Release job to help pinpoint where flaky out-of-disk space errors originate.
PiperOrigin-RevId: 952338223
2026-07-22 14:40:57 -07:00
Samuel Benzaquen
d9097da9f8 Correctly calculate the varint size of very large containers.
PiperOrigin-RevId: 952306260
2026-07-22 13:44:41 -07:00
Karen Wu
106f0f1be3 This change moves several tests from JavaLiteProtoLibraryTest.java to Starlark-based analysis tests in java_lite_proto_library_tests.bzl
PiperOrigin-RevId: 952303689
2026-07-22 13:39:55 -07:00
Joshua Haberman
feaa31c4d7 [Py/FreeThreading] Fixed remaining race conditions in Dealloc()
This change modifies all remaining `Dealloc()` functions to use `EraseIfEqual` if they were not already. This prevents the same race that was fixed for descriptors in cl/874084218.

PiperOrigin-RevId: 952273589
2026-07-22 12:43:18 -07:00
Evan Brown
b067e70a04 Rollback using CRC for hashing in proto map and use absl::HashOf again.
The performance win doesn't justify the complexity of maintaining a separate hash function.

We also rotate the salt for more random iteration order (RandomOrdering tests didn't pass otherwise).

PiperOrigin-RevId: 952270605
2026-07-22 12:36:06 -07:00
Karen Wu
9a5a50290f This change moves several tests from JavaLiteProtoLibraryTest.java to Starlark-based analysis tests in java_lite_proto_library_tests.bzl
PiperOrigin-RevId: 952232264
2026-07-22 11:23:39 -07:00
Jason Aragorn Tobias Lunn
63df0c298b Remove fallback behavior
PiperOrigin-RevId: 952219463
2026-07-22 11:10:10 -07:00
Jason Aragorn Tobias Lunn
32e4fa8de9 Upgrade the release_ruleset.yaml workflow from v7.3.0 to v7.7.0.
PiperOrigin-RevId: 952216803
2026-07-22 11:05:08 -07:00
Karen Wu
1c1032a6a5 This change moves several tests from JavaProtoLibraryTest.java to Starlark-based analysis tests in java_proto_library_tests
PiperOrigin-RevId: 952153616
2026-07-22 09:05:06 -07:00
Samuel Benzaquen
4de1860d20 Fix CordInputStream for huge cord chunks.
PiperOrigin-RevId: 952140260
2026-07-22 08:43:13 -07:00
Protobuf Team Bot
9f6ebb28ea Store first-touch of message on parse as an immutable message instead of with SingleFieldBuilder overhead.
PiperOrigin-RevId: 951713968
2026-07-21 14:57:57 -07:00
Samuel Benzaquen
df1394eabb Fix parse table generation for very large messages.
PiperOrigin-RevId: 951577679
2026-07-21 10:48:20 -07:00
Protobuf Team Bot
aa6c04683e Internal change.
PiperOrigin-RevId: 951555088
2026-07-21 10:13:00 -07:00
Tony Liao
6e5ed56773 Conformance test suite for JSON parsing of a single-element array.
PiperOrigin-RevId: 951528475
2026-07-21 09:19:19 -07:00
Protobuf Team Bot
1aaaaaec9f Inline MapEntryLite default instances in generated Java Lite code.
This change inlines the creation of MapEntryLite default instances directly into the objects array in dynamicMethod(BUILD_MESSAGE_INFO). This eliminates the need to generate separate DefaultEntryHolder static helper classes (for message-valued maps) or static default entry fields (for primitive-valued maps), reducing bytecode size and class count.

PiperOrigin-RevId: 951523195
2026-07-21 09:07:55 -07:00
Samuel Benzaquen
56a40d3758 Fix EncodedDescriptorDatabase::Add to properly reject duplicate file names.
PiperOrigin-RevId: 951514771
2026-07-21 08:52:55 -07:00
Samuel Benzaquen
9bb4aebaf9 Replace calls of Reflection::GetEnum/GetRepeatedEnum with GetEnumValue/GetRepeatedEnumValue when we only care about the value.
It is more efficient this way.

PiperOrigin-RevId: 951514413
2026-07-21 08:49:12 -07:00
Protobuf Team Bot
d1d263a827 Explicitly set our minimum library versions to ensure syn gets [>=2 <3] to fix our GHA tests
Note that this change should really be a noop: "2" already is intended to mean ">=2,<3" in cargo semver. I'm not clear why spelling this out is necessary but it empirically is.

In a future change we should may want to bump to syn 3.x instead, but we use googletest and googletest latest release has a syn 2.x dep today

PiperOrigin-RevId: 951512460
2026-07-21 08:45:42 -07:00
Protobuf Team Bot
65f520debd Auto-generate files after cl/951499285 2026-07-21 15:29:21 +00:00
Samuel Benzaquen
0a4f9bc4c6 Fix name printing in platforms with signed char.
PiperOrigin-RevId: 951499285
2026-07-21 08:19:00 -07:00
Protobuf Team Bot
e9aa0183c7 Auto-generate files after cl/951099608 2026-07-20 23:07:13 +00:00
Protobuf Team Bot
a13f6b6ecf Add volatile to init_array asm
Strictly speaking we want it to always emit this without guessing about whether it thinks there are side effects. Clang and gcc already emit this because they see it taking a function pointer, but this should be more robust.

PiperOrigin-RevId: 951099608
2026-07-20 15:56:58 -07:00
Protobuf Team Bot
c587029752 Auto-generate files after cl/951053200 2026-07-20 21:37:27 +00:00
Mikita Belahlazau
5557ce1f7e Internal change
PiperOrigin-RevId: 951053200
2026-07-20 14:27:43 -07:00
Samuel Benzaquen
6402879057 Remove unnecessary cast when calculating ByteSize.
We want the full `size_t` to properly reject it early.

PiperOrigin-RevId: 951024190
2026-07-20 13:35:21 -07:00
Protobuf Team Bot
4bb2c61094 Internal change.
PiperOrigin-RevId: 951011798
2026-07-20 13:13:44 -07:00
Protobuf Team Bot
bf735f2bba Auto-generate files after cl/950998569 2026-07-20 20:01:10 +00:00
Protobuf Team Bot
ad1064c841 Fix the behavior of GetOrCreateMutableMessage on fields in oneofs
Before this, for a field in a oneof, GetOrCreateMutableMessage would read the union value without making sure it was the right case first, effectively casting blindly.

This would result in a crash in RustProto if you set any field in a oneof and then read the mutable-getter of a message-typed field in the same oneof.

PiperOrigin-RevId: 950998569
2026-07-20 12:50:45 -07:00
Protobuf Team Bot
8eb950cb85 Fix Rust GHA build by enabling "full" feature for syn.
We must have been accidentally inheriting this feature being enabled from one of our deps, who have since turned off the "full" feature causing a break.

PiperOrigin-RevId: 950977436
2026-07-20 12:08:03 -07:00
Protobuf Team Bot
ed612a8b43 Remove total_bytes_limit from pure PHP CodedInputStream.
This limit has no public api to override to a different limit: it is only ever set to the 'default' of 32 MB but has actually just not applied at all in many cases.

If we 'fix the bug' by making it so this limit does apply, it would break any users who may be successfully parsing data arbitrarily larger than 32 MB with no issue today due to hitting a case where limit is consistently not applied. By contrast, removing this doesn't formally break any preexisting users, and realigns the behavior to match PHP-upb as well as the default behavior in all of our other supported runtimes.

Note that gRPC-PHP will also already enforce a 4mb limit by default before passing the data to Protobuf, so the only people who could be exposed to this topic either way would need to be either intentionally bumping up the gRPC limit or not using gRPC at all.

In general the need to have a limit within CodedInputStream is very weak in this case compared to other languages: since PHP only parses off of a string and not a stream, it trivial for application code to apply a limit with an if before the parse starts.

PiperOrigin-RevId: 950914431
2026-07-20 10:24:15 -07:00
Samuel Benzaquen
8ad1ef74dd Enable GLOBALS mode in all compilation modes.
PiperOrigin-RevId: 950840381
2026-07-20 08:02:42 -07:00
Clayton Knittel
bcd3166b94 Pass the element default instance to Add in RepeatedPtrFieldAccessor.
Constructing the element using the user-provided to-be-added value is error prone, as it allows users to add a message of an unrelated type to repeated fields.

With this change, if the `value` to be added is an unrelated type, `CopyFrom` will crash in `Message::CopyFrom`'s `CHECK_EQ(from.GetDescriptor(), descriptor)`.

PiperOrigin-RevId: 950631755
2026-07-19 23:54:19 -07:00
Mikita Belahlazau
26ae04feca Move proto identifier casing and naming helpers to naming_style.h
Extract ToCamelCase, ToJsonName, EnumValueToPascalCase, and their
assertion size helpers from descriptor.cc to naming_style.h and
naming_style.cc under proto2::internal namespace as a preparation
step for splitting DescriptorBuilder.

PiperOrigin-RevId: 950488920
2026-07-19 14:40:43 -07:00
Protobuf Team Bot
c07d90c745 Auto-generate files after cl/949999958 2026-07-18 09:33:02 +00:00
Mikita Belahlazau
fcd6b8a9fd Extract OptionInterpreter to option_interpreter.h and option_interpreter.cc
* option_interpreter.h is extracted from descriptor_builder.h
* option_interpreter.cc is extracted from descriptor.cc

PiperOrigin-RevId: 949999958
2026-07-18 02:22:40 -07:00
Clayton Knittel
baeb5723ee Make MessageLite + Message destructors protected when custom VTable is on.
The custom vtable experiment changes the `MessageLite` destructor from virtual to a no-op. Calling it directly outside of protobuf will not behave consistently before/after this experiment, so it should be hidden.

This will catch code that calls `~MessageLite()` directly on a buffer, which could cause memory leaks if custom VTable is enabled.

Custom VTable is only available with destroying deletes, and destroying deletes forward `delete my_message_ptr` to the destroying delete operator. With VTable disabled, there is no destroying delete operator, and the `MessageLite` virtual destructor is called instead, so we can only hide these destructors with custom VTable on.

Note that there is a "bug" in the C++ spec that allows compilers to require a visible normal destructor when calling the destroying delete operator. GCC does not implement this check, and Clang fixed this in [v20.1](https://releases.llvm.org/20.1.0/tools/clang/docs/ReleaseNotes.html#bug-fixes-in-this-version). I've conditionally made these constructors protected for compiler configurations we know don't have this bug.

PiperOrigin-RevId: 949757854
2026-07-17 14:20:41 -07:00
Jason Aragorn Tobias Lunn
14d12e2723 Internal change
PiperOrigin-RevId: 949737599
2026-07-17 13:38:18 -07:00
Joshua Haberman
59ab79a8fa Added GCC 10 test and removed GCC <10 tests from GHA.
Per our support matrix, remove GitHub Actions matrix entries testing GCC versions prior to GCC 10 (7.5, 9.1, 9.5) in test_cpp.yml, and added a GCC 10.4 test.

PiperOrigin-RevId: 949721084
2026-07-17 13:05:38 -07:00
Rachel Goldfinger
c64603bc4e Update Ruby Docker image for aarch64 tests.
PiperOrigin-RevId: 949709833
2026-07-17 12:43:33 -07:00
Protobuf Team Bot
b472eb92ff Auto-generate files after cl/949697167 2026-07-17 19:26:48 +00:00
Protobuf Team Bot
b29e83c8fb Internal change
PiperOrigin-RevId: 949697167
2026-07-17 12:16:56 -07:00
Tony Liao
d6fc95d0c3 (Second try) Cache the custom JSON names of enum fields upon first lookup.
Benchmark                                                     Mode  Cnt    Score   Error  Units
JsonFormatBenchmark.benchmarkParseJsonCustom                  avgt   50    3.974 ± 0.037  us/op
JsonFormatBenchmark.benchmarkParseJsonDefault                 avgt   50    3.837 ± 0.114  us/op
JsonFormatBenchmark.benchmarkParseJsonUnknown                 avgt   50   33.699 ± 0.256  us/op
JsonFormatBenchmark.benchmarkParseJsonUnknownIgnored          avgt   50   26.216 ± 0.167  us/op
JsonFormatBenchmark.benchmarkParseRepeatedJsonCustom          avgt   50   20.698 ± 0.457  us/op
JsonFormatBenchmark.benchmarkParseRepeatedJsonDefault         avgt   50   12.277 ± 0.112  us/op
JsonFormatBenchmark.benchmarkParseRepeatedJsonUnknownIgnored  avgt   50  364.327 ± 5.504  us/op

Benchmark                                                     Mode  Cnt    Score   Error  Units
JsonFormatBenchmark.benchmarkParseJsonCustom                  avgt   50    5.049 ± 0.057  us/op
JsonFormatBenchmark.benchmarkParseJsonDefault                 avgt   50    3.879 ± 0.072  us/op
JsonFormatBenchmark.benchmarkParseJsonUnknown                 avgt   50   33.157 ± 0.378  us/op
JsonFormatBenchmark.benchmarkParseJsonUnknownIgnored          avgt   50   26.461 ± 0.151  us/op
JsonFormatBenchmark.benchmarkParseRepeatedJsonCustom          avgt   50   14.664 ± 0.085  us/op
JsonFormatBenchmark.benchmarkParseRepeatedJsonDefault         avgt   50   12.230 ± 0.101  us/op
JsonFormatBenchmark.benchmarkParseRepeatedJsonUnknownIgnored  avgt   50  350.246 ± 5.642  us/op

PiperOrigin-RevId: 949670944
2026-07-17 11:26:05 -07:00
Protobuf Team Bot
d932381f90 Internal change
PiperOrigin-RevId: 949649367
2026-07-17 10:45:24 -07:00
Rachel Goldfinger
a848d6a337 Specify platform for Docker run in Ruby tests.
PiperOrigin-RevId: 949620500
2026-07-17 09:52:22 -07:00
Samuel Benzaquen
ea1a3d62ef Fixes for GLOBALS mode.
Fix designated initializer use.
Fix bootstrap Init() to initialize the whole global.

PiperOrigin-RevId: 949619513
2026-07-17 09:48:49 -07:00
Protobuf Team Bot
65429e343d Pre-size collections when parsing packed repeated fields to avoid over-allocation.
PiperOrigin-RevId: 949610352
2026-07-17 09:29:58 -07:00
Tony Liao
6ef18f6071 Automated rollback of commit 7db08e8f1b.
PiperOrigin-RevId: 949606118
2026-07-17 09:18:44 -07:00
cpovirk
927dead4c8 Delete unused refillCallback and associated types.
They were introduced along with a Google-internal usage in cl/47874747. That usage was removed in cl/791705426.

PiperOrigin-RevId: 949521950
2026-07-17 06:03:18 -07:00
Protobuf Team Bot
6d5557a46f Auto-generate files after cl/949190424 2026-07-16 22:07:39 +00:00
Protobuf Team Bot
654e980895 Fix failure under thinlto
PiperOrigin-RevId: 949190424
2026-07-16 14:57:28 -07:00
Protobuf Team Bot
79756f62ab Auto-generate files after cl/949108864 2026-07-16 19:36:32 +00:00
Protobuf Team Bot
1e4863aa6d Add static assert on linker array names to avoid the surprise limit on mach-o
PiperOrigin-RevId: 949108864
2026-07-16 12:27:01 -07:00
Tony Liao
6155df9cca Additional unit tests verifying ignoringUnknownFields behavior on non-string primitives.
PiperOrigin-RevId: 949064971
2026-07-16 11:07:22 -07:00
Sandy Zhang
42b1e8ed8e internal change
PiperOrigin-RevId: 949045769
2026-07-16 10:30:48 -07:00
Protobuf Team Bot
caa55cbeb3 Further cleanup of experimental runtime.
PiperOrigin-RevId: 948949657
2026-07-16 07:04:15 -07:00
Protobuf Team Bot
48a0e0936e Open-source the ProGuard assumeLiteRuntime=true rule.
Open-source Protobuf users should benefit from bypassing full runtime inheritance checks in the lite runtime on startup paths.

PiperOrigin-RevId: 948783493
2026-07-16 00:03:59 -07:00
Protobuf Team Bot
f849b03c4c Automated Code Change
PiperOrigin-RevId: 948756509
2026-07-15 22:57:21 -07:00
Protobuf Team Bot
d781b31418 Optimize GeneratedMessageLite.isMutable.
Checking if the high bit is set is equivalent to checking if the value is negative. This change avoids a bitwise AND instruction in the generated assembly.

Before/After:

```
boolean FizzBuzz.isMutable() [20 bytes]
    0x000040c0    ldr w0, [x1, #12]
    0x000040c4    and w0, w0, #0x80000000   <--- THIS INSTRUCTION CAN GO
    0x000040c8    cmp w0, #0x0 (0)
    0x000040cc    cset w0, ne
    0x000040d0    ret

boolean FizzBuzz.isMutable2() [16 bytes]
    0x000040e0    ldr w0, [x1, #12]
    0x000040e4    cmp w0, #0x0 (0)
    0x000040e8    cset w0, lt
    0x000040ec    ret
```

PiperOrigin-RevId: 948755487
2026-07-15 22:53:35 -07:00
Protobuf Team Bot
917911a3bb Auto-generate files after cl/948707011 2026-07-16 03:54:03 +00:00
Protobuf Team Bot
52f68d2e34 Reference constructor name by reference rather than string in an asm block, because some things like dfsan alter the function name during compilation. Also did some manual reading and only enabled this on compiler versions where it'll always work (tested in godbolt)
PiperOrigin-RevId: 948707011
2026-07-15 20:43:49 -07:00
Protobuf Team Bot
dbe1410096 Split large mergeFrom methods in Java immutable builders into smaller sub-methods.
PiperOrigin-RevId: 948612144
2026-07-15 16:35:11 -07:00
Clayton Knittel
710c70bcb3 Add MergeToFrom method to ClassData, which is a faster alternative to MessageLite::CheckTypeAndMergeFrom.
PiperOrigin-RevId: 948594576
2026-07-15 16:01:15 -07:00
Rachel Goldfinger
7c77f295c7 Fix memory leaks in PHP Protobuf C extension.
PiperOrigin-RevId: 948499805
2026-07-15 13:02:21 -07:00
Protobuf Team Bot
1a06ad89e7 Optimize GeneratedMessage.getAllFields by using fields sorted by number.
PiperOrigin-RevId: 948474555
2026-07-15 12:14:18 -07:00
Clayton Knittel
cd28d3e186 Statically load ClassData in GetClassData when the concrete type of a message is known.
PiperOrigin-RevId: 948473106
2026-07-15 12:10:40 -07:00
Samuel Benzaquen
e9e2415586 Add overflow protection for very large containers.
These will now deterministically terminate instead of triggering undefined
behavior.

PiperOrigin-RevId: 948414308
2026-07-15 10:32:55 -07:00
Protobuf Team Bot
b1bdc1c684 Internal Change
PiperOrigin-RevId: 948353073
2026-07-15 08:35:16 -07:00
Protobuf Team Bot
aae12eab72 Internal change.
PiperOrigin-RevId: 948285437
2026-07-15 05:53:29 -07:00
Protobuf Team Bot
6128a90a69 Improve length checks in JavaLite in the face of overlong length prefixes.
PiperOrigin-RevId: 948256971
2026-07-15 04:35:56 -07:00
Protobuf Team Bot
bbe28f23d3 Automated rollback of commit ea0e67a9ca.
PiperOrigin-RevId: 948225784
2026-07-15 03:19:53 -07:00
Protobuf Team Bot
9c3a5143de Auto-generate files after cl/948094363 2026-07-15 05:08:57 +00:00
Runze Wang
dbd4729824 Allow UPB identifiers to start with digits to match C++ DescriptorPool.
C++ DescriptorPool::BuildFile() accepts package names and symbol names that start with digits (e.g. package: "0"). Previously, UPB's identifier validator required path components to start with a letter, causing UPB to reject descriptors accepted by C++.

PiperOrigin-RevId: 948094363
2026-07-14 21:58:01 -07:00
Tony Liao
736b238729 New unittest case to validate Java parseJson behavior with 1-element numbers.
PiperOrigin-RevId: 948086203
2026-07-14 21:38:37 -07:00
Protobuf Team Bot
cc2ba7bdd3 Automated Code Change
PiperOrigin-RevId: 948050035
2026-07-14 20:02:52 -07:00
Matthew Hawkins
2ec58f6358 Reserve extension number 1309 for Motif (#28166)
This adds an entry to the global extension registry (`docs/options.md`)
reserving extension number 1309 for Motif.

* Project: Motif
* Website: https://motif.io
* Extension number: 1309

Closes #28166

COPYBARA_INTEGRATE_REVIEW=https://github.com/protocolbuffers/protobuf/pull/28166 from pubmodmatt:add-motif-extension 2d770e5e95
PiperOrigin-RevId: 948047634
2026-07-14 19:55:29 -07:00
Protobuf Team Bot
400cb8cce2 Auto-generate files after cl/947866259 2026-07-14 20:28:12 +00:00
Clayton Knittel
25e2bb7ca3 Implement Clear as a free function for generated messages.
This matches the pattern used for `_InternalSerialize`, `MergeImpl`, and `ByteSizeLongImpl`.

PiperOrigin-RevId: 947866259
2026-07-14 13:18:07 -07:00
Sandy Zhang
88d6fd37bc Fix Copybara leak for protobuf and add leakr checks.
Exclude utf8validation tests from being exported to OSS and add leakr checks for google3/third_party paths to prevent future leaks.

PiperOrigin-RevId: 947861625
2026-07-14 13:10:27 -07:00
Rachel Goldfinger
5f47275d2e Add github_user_id to BCR metadata template and remove Hong Shin.
PiperOrigin-RevId: 947851531
2026-07-14 12:52:25 -07:00
Charlie Beattie
0b1b3fa234 Internal change.
PiperOrigin-RevId: 947803839
2026-07-14 11:25:48 -07:00
Protobuf Team Bot
3bc006d2c1 Auto-generate files after cl/947760935 2026-07-14 17:31:32 +00:00
Sandy Zhang
5ddbde2d44 internal change
PiperOrigin-RevId: 947760935
2026-07-14 10:21:18 -07:00
Tetsuya Odaira
a04a9435f1 docs: add bleRPC to third-party RPC implementations (#28331)
## What

Adds **bleRPC** to `docs/third_party.md` under **RPC Implementations**.

This page invites projects to "send us a pull request to update this page," so here is one.

## About the project

[bleRPC](https://github.com/tdaira/blerpc) (https://blerpc.net) is an open-source RPC framework that carries Protocol Buffers messages over **Bluetooth Low Energy** (GATT). It uses:

- **nanopb** for on-device encode/decode (nRF / Zephyr firmware),
- generated clients for **Python, Kotlin, Swift, Dart, and TypeScript** (from `.proto`),
- a small container/command framing layer for BLE MTUs, with optional end-to-end encryption.

It's Apache-2.0 licensed. Added to the active list; not affiliated with or endorsed by Google, per the page's disclaimer.

Closes #28331

COPYBARA_INTEGRATE_REVIEW=https://github.com/protocolbuffers/protobuf/pull/28331 from tdaira:add-blerpc-rpc-impl e543445676
PiperOrigin-RevId: 947754563
2026-07-14 10:12:42 -07:00
Rachel Goldfinger
6555452be3 Upgrade ruby/setup-ruby to the latest version to be compatible with node 24.
PiperOrigin-RevId: 947738508
2026-07-14 09:50:22 -07:00
Tony Liao
1868179cb1 New unittest case to validate C++ parseJson behavior with 1-element arrays.
PiperOrigin-RevId: 947738453
2026-07-14 09:46:47 -07:00
Protobuf Team Bot
5916749838 Internal
PiperOrigin-RevId: 947668613
2026-07-14 07:25:05 -07:00
Protobuf Team Bot
750e6be4b2 Optimize Java Lite Enum Verifier Codegen by introducing Parametric Verifiers
Introduce reusable `SequentialEnumVerifier` and `BitmaskEnumVerifier` in the runtime and instantiate them inline within the generated message schema to eliminate custom nested verifier classes and enable stripping unused enum classes.

PiperOrigin-RevId: 947467062
2026-07-13 23:31:11 -07:00
Protobuf Team Bot
44a1a0bbc3 Auto-generate files after PR #28231 2026-07-14 05:43:50 +00:00
arshsmith
65fccf3b06 reject mini_tables whose presence index overflows int16_t (#28231)
The MiniDescriptor decoder stores a field's presence in an int16_t, where a positive value is a hasbit index and a negative value is a negated oneof case offset. `upb_MtDecoder_AssignHasbits` hands out incrementing hasbit indices with no upper bound (the required-field loop right above it has a cap, but the hasbit loop does not), and `upb_MtDecoder_AssignOffsets` writes `~case_offset` into the same field. A descriptor with more than ~32704 presence fields, or a oneof whose case lands past INT16_MAX, wraps the value so a plain scalar field is silently reclassified as a oneof member (or the reverse), and accessing it then reads or writes at the wrong offset. Both messages still pass the existing 65535-byte size cap, so the corrupt mini_table is accepted. Add the missing range checks at both sites, matching the existing "Too many required fields" guard.

Closes #28231

COPYBARA_INTEGRATE_REVIEW=https://github.com/protocolbuffers/protobuf/pull/28231 from arshsmith1:minitable-presence-int16-overflow 1737f298f3
PiperOrigin-RevId: 947444116
2026-07-13 22:33:28 -07:00
Protobuf Team Bot
b0b22dd281 Use ConcurrentMap in GeneratedMessageLite parser registry to avoid unsafe Java 8 API usage.
PiperOrigin-RevId: 947412307
2026-07-13 21:08:29 -07:00
Mark Hansen
352d73a92e s/Type/ExtensionT/ in GeneratedMessageLite
Fixes a minor style guide nit that generics should end in single
uppercase chars.

PiperOrigin-RevId: 947399879
2026-07-13 20:34:08 -07:00
Mark Hansen
b1a0d1bb8f Make generic types in GeneratedMessageLite end with single char
This fixes a minor style guide nit.

PiperOrigin-RevId: 947391075
2026-07-13 20:07:48 -07:00
Kor Nielsen
b2671496b8 Don't use deprecated @rules_rust//crate_universe:extension.bzl (#28289)
The correct path is `@rules_rust//crate_universe:extensions.bzl`, and the other path will be removed in a future rules_rust release.

Closes #28289

COPYBARA_INTEGRATE_REVIEW=https://github.com/protocolbuffers/protobuf/pull/28289 from korran:fix/crate-universe 97c399c25e
PiperOrigin-RevId: 947388727
2026-07-13 20:02:12 -07:00
Protobuf Team Bot
ec4703bbd0 Optimize Java Lite Enum Verifier Codegen by introducing Parametric Verifiers
Introduce reusable `SequentialEnumVerifier` and `BitmaskEnumVerifier` in the runtime and instantiate them inline within the generated message schema to eliminate custom nested verifier classes and enable stripping unused enum classes.

PiperOrigin-RevId: 947383511
2026-07-13 19:49:04 -07:00
Brian M. Carr
87102bc215 Add engine-public/protoc-gen-openapi to options documentation (#28284)
Add options to various FileDescriptorProto types to provide override capabilities to a protoc compiler that generates OAS 3.1 specs.

The  available annotations can be found [here](https://github.com/engine-public/protoc-gen-openapi/blob/main/model/src/main/proto/engine/protoc/openapi/annotations.proto#L143-L169).  They provide a mix of direct OAS definition, overrides, and syntactic sugar to make annotating gRPC services compile-time consistent with the output specs.

Closes #28284

COPYBARA_INTEGRATE_REVIEW=https://github.com/protocolbuffers/protobuf/pull/28284 from engine-public:engine-protoc-gen-openapi-options 0a8d36df61
PiperOrigin-RevId: 947381308
2026-07-13 19:42:43 -07:00
Mark Hansen
e92b2f0d9c s/BuilderType/BuilderT/ in GeneratedMessageLite
This fixes a minor style guide issue where generic classes should end in
a single uppercase chart.

We could have gone with 'B' but there are so many generics in here that
it seems reasonable to keep a longer name.

PiperOrigin-RevId: 947378949
2026-07-13 19:37:29 -07:00
Mark Hansen
54c6d2e34b s/MessageType/MessageT in GeneratedMessageLite
Fixes style guide rule that generic types should end in a single
uppercase char.

I could have made this `M` but it feels like there's enough generics in here that I narrowly chose the larger name.

PiperOrigin-RevId: 947370402
2026-07-13 19:11:48 -07:00
Tony Liao
e5cfe139bc New unittest case to validate Java parseJson behavior with 1-element arrays.
In Java, it seems like the existing behavior is that we allow
single-element arrays to be parsed into a non-repeated field.

In `public final class JsonArray extends JsonElement implements Iterable<JsonElement>`:
```
  @Override
  public String getAsString() {
    return getAsSingleElement().getAsString();
  }
```

TBH I don't know if this behavior is necessarily _desired_, but here is
a unit test to validate this behavior so that we don't accidentally
break it without intending to.

PiperOrigin-RevId: 947320631
2026-07-13 17:03:49 -07:00
Mark Hansen
9b0d074ea6 Unnecessarily suppressed warnings: unchecked
PiperOrigin-RevId: 947315237
2026-07-13 16:49:57 -07:00
Samuel Benzaquen
f0bc0d7503 Use the PROTOBUF_ENABLE_STABLE_EXPERIMENTS flag to turn on the old layouts.
This way we can keep test coverage for them while they exist.

PiperOrigin-RevId: 947249438
2026-07-13 14:39:14 -07:00
Protobuf Team Bot
e1acb1a02e Optimize Java Lite Map Field Codegen by removing DefaultEntryHolder
Inline the default entry construction directly into the `BUILD_MESSAGE_INFO` case of `dynamicMethod` to save class definitions.

PiperOrigin-RevId: 947211513
2026-07-13 13:29:08 -07:00
Tony Liao
7db08e8f1b Automated rollback of commit 7a39a4e313.
PiperOrigin-RevId: 947163030
2026-07-13 12:02:07 -07:00
Sandy Zhang
a596ea688e Rename spelling for isSortedAndDedupped to isSortedAndDeduped in SmallSortedMap.
PiperOrigin-RevId: 947161688
2026-07-13 11:57:23 -07:00
Protobuf Team Bot
255635a7fa Auto-generate files after cl/947129093 2026-07-13 18:03:08 +00:00
Protobuf Team Bot
687c7d5892 Optimize GeneratedMessageLite parser registry to reduce memory footprint.
PiperOrigin-RevId: 947129093
2026-07-13 10:53:31 -07:00
Runze Wang
4db27e1f33 Add UPB support for FileDescriptorProto.option_dependency.
This change adds API and implementation to read and write the option_dependency field from/to proto2.FileDescriptorProto in upb reflection.

PiperOrigin-RevId: 947120641
2026-07-13 10:43:20 -07:00
Protobuf Team Bot
774721742b Auto-generate files after cl/947071987 2026-07-13 16:16:12 +00:00
Protobuf Team Bot
27e4846f28 Automated Code Change
PiperOrigin-RevId: 947071987
2026-07-13 09:06:01 -07:00
Protobuf Team Bot
bba54ac9ba Fix type confusion in PHP protobuf extension when message initializer array has integer keys
`'0'` as a key is automatically converted to `0`, so we need to explicitly stringify the keys back to handle that case correctly.

Original issue report from adalogics

PiperOrigin-RevId: 947066825
2026-07-13 08:54:59 -07:00
Tony Liao
52e15dc46c Automated rollback of commit 0acf2a471d.
PiperOrigin-RevId: 947052114
2026-07-13 08:21:28 -07:00
Rachel Goldfinger
740fdc768a Add release branch 36.x
PiperOrigin-RevId: 947039280
2026-07-13 07:53:09 -07:00
Keegan Carruthers-Smith
00538a473f fix: declare protoc authenticity action toolchain (#28328)
The --incompatible_auto_exec_groups flag requires Starlark actions to declare whether their executable/tools come from an action toolchain. This is not a Bazel default today, but it is exposed through strict preset configurations and is intended to catch rules that rely on implicit action toolchain inference.

protoc_authenticity runs protoc from protobuf's proto toolchain, but the validation action does not declare that action toolchain. Declare the matching proto toolchain so the action's toolchain behavior is explicit without changing its inputs or execution model.

Closes #28328

COPYBARA_INTEGRATE_REVIEW=https://github.com/protocolbuffers/protobuf/pull/28328 from keegancsmith:k/auto-exec-groups-protoc-authenticity ca89641ab5
PiperOrigin-RevId: 947023276
2026-07-13 07:21:12 -07:00
yashanil98
7772bbf6e3 fix(cmake): guard uninitialized variable reads in module compatibility shim (#28426)
The backwards-compatibility loop at the bottom of protobuf-module.cmake.in maps each camel-case output variable to its uppercase alias with set(${UPPER} ${${Camel}}), but does not check the source is defined first. Configuring a consumer with --warn-uninitialized then reports uninitialized reads for the optional variables (Protobuf_SRC_ROOT_FOLDER, Protobuf_IMPORT_DIRS, Protobuf_DEBUG, and the *_DEBUG library variables).

The sibling loop just above, which maps in the other direction, already guards with if(DEFINED ${UPPER}). This applies the same guard to the second loop, which the earlier fix in #1778 missed.

Fixes #19683.

Test plan: reproduced the warning and confirmed the fix with plain cmake, no build required. Extracting the loop into a script and running `cmake -P block.cmake --warn-uninitialized` reports 5 uninitialized-variable warnings before the change and 0 after. Behavior is unchanged when the variables are defined: the uppercase alias is still set.

Closes #28426

COPYBARA_INTEGRATE_REVIEW=https://github.com/protocolbuffers/protobuf/pull/28426 from yashanil98:fix/issue-19683-cmake-uninitialized-vars b84e7f11b6
PiperOrigin-RevId: 947022521
2026-07-13 07:17:22 -07:00
Mark Hansen
2288b33629 Unnecessarily suppressed warnings: unchecked
PiperOrigin-RevId: 946931584
2026-07-13 03:44:03 -07:00
Mark Hansen
5de373b683 Don't fully qualify function that doesn't need to be
Fixes a minor warning.

PiperOrigin-RevId: 946910209
2026-07-13 02:55:38 -07:00
Protobuf Team Bot
5820d6bbbe Automated Code Change
PiperOrigin-RevId: 946759447
2026-07-12 20:37:03 -07:00
Runze Wang
52e82c810c Emit future warning when mutating GetOptions() in OSS
PiperOrigin-RevId: 946657065
2026-07-12 13:41:24 -07:00
Eric Salo
a1e10dfd69 protobuf: add support for Go prototiller in codegen tests
PiperOrigin-RevId: 946073156
2026-07-10 23:37:14 -07:00
Tony Liao
0acf2a471d Cache the custom JSON names of enum fields upon first lookup.
I got the following benchmark runs on my local machine.

Without optimizations:
Benchmark                                                     Mode  Cnt    Score   Error  Units
JsonFormatBenchmark.benchmarkParseJsonCustom                  avgt   50    3.829 ± 0.047  us/op
JsonFormatBenchmark.benchmarkParseJsonDefault                 avgt   50    3.545 ± 0.045  us/op
JsonFormatBenchmark.benchmarkParseJsonUnknown                 avgt   50   31.244 ± 0.307  us/op
JsonFormatBenchmark.benchmarkParseJsonUnknownIgnored          avgt   50   25.471 ± 0.236  us/op
JsonFormatBenchmark.benchmarkParseRepeatedJsonCustom          avgt   50   20.142 ± 0.103  us/op
JsonFormatBenchmark.benchmarkParseRepeatedJsonDefault         avgt   50   12.158 ± 0.131  us/op
JsonFormatBenchmark.benchmarkParseRepeatedJsonUnknownIgnored  avgt   50  352.305 ± 1.611  us/op

With optimizations:
Benchmark                                                     Mode  Cnt    Score   Error  Units
JsonFormatBenchmark.benchmarkParseJsonCustom                  avgt   50    5.002 ± 0.140  us/op
JsonFormatBenchmark.benchmarkParseJsonDefault                 avgt   50    3.893 ± 0.104  us/op
JsonFormatBenchmark.benchmarkParseJsonUnknown                 avgt   50   32.142 ± 0.340  us/op
JsonFormatBenchmark.benchmarkParseJsonUnknownIgnored          avgt   50   25.492 ± 0.281  us/op
JsonFormatBenchmark.benchmarkParseRepeatedJsonCustom          avgt   50   14.361 ± 0.039  us/op
JsonFormatBenchmark.benchmarkParseRepeatedJsonDefault         avgt   50   12.053 ± 0.041  us/op
JsonFormatBenchmark.benchmarkParseRepeatedJsonUnknownIgnored  avgt   50  344.182 ± 3.338  us/op

PiperOrigin-RevId: 946047761
2026-07-10 22:08:11 -07:00
Tony Liao
2737dfcc03 Add Java microbenchmark for custom JSON name parsing.
PiperOrigin-RevId: 946046272
2026-07-10 22:04:21 -07:00
Protobuf Team Bot
7a12b7edff Auto-generate files after cl/945965992 2026-07-11 00:31:56 +00:00
Clayton Knittel
5fe1a68149 Internal change.
PiperOrigin-RevId: 945965992
2026-07-10 17:22:02 -07:00
Protobuf Team Bot
cb2c93944e Auto-generate files after cl/945959296 2026-07-11 00:09:26 +00:00
Protobuf Team Bot
8d75c2aeea Optimize UPB_CONSTRUCTOR for ELF with COMDAT deduplication
Changes the UPB_CONSTRUCTOR macro for ELF platforms to use COMDAT-grouped assembly for .init_array. This allows the linker to deduplicate the constructor pointer entries to exactly one copy, eliminating binary bloat and preventing the weak constructor from being executed multiple times at startup.

PiperOrigin-RevId: 945959296
2026-07-10 17:01:44 -07:00
Tony Liao
7a39a4e313 json/java: add json_name enumval support
PiperOrigin-RevId: 945901714
2026-07-10 14:51:06 -07:00
Samuel Benzaquen
e71940f7c9 Remove WeakFieldMap from C++ protobuf runtime and compiler.
Treat weak fields like normal fields in layout, storing them as base pointers to preserve weak linking.

PiperOrigin-RevId: 945872647
2026-07-10 13:45:49 -07:00
Protobuf Team Bot
e8df82eaef Fix visibility of reflection_cc
PiperOrigin-RevId: 945856808
2026-07-10 13:10:14 -07:00
Protobuf Team Bot
4665f8f1fc Optimize TextFormatEscaper.escapeText (redux).
This uses the approach that we added for ProtoJSON escaping of having a lookup table of characters. Unlike JSON however we still need a bailout handling of any non-ascii characters, because people are relying on UTF-8-escapes (which doesn't make too much sense objectively, but is entrenched behavior).

Ballpark this should reduce TextFormat (including DebugString) printing by ~10%.

PiperOrigin-RevId: 945842756
2026-07-10 12:39:48 -07:00
Protobuf Team Bot
51df91d19a Optimize Java Lite Parser Registry with Centralized Cache
Consolidate the parser map and parser cache into a single parserMap in GeneratedMessageLite.java, and eagerly register DefaultInstanceBasedParser during registerDefaultInstance.
Add @DoNotInline to parser helper methods to prevent code size explosion due to AppReduce inlining.

PiperOrigin-RevId: 945832122
2026-07-10 12:21:24 -07:00
Runze Wang
927c504eea Emit deprecation warning when comparing descriptor containers with unrecognized types in OSS
PiperOrigin-RevId: 945830705
2026-07-10 12:16:37 -07:00
rgoldfinger6
4b269eb436 Updating version.json and repo version numbers to: 37.0-dev (#28425)
NOTE: This should be reviewed and imported via Copybara per the normal PR review process.

Closes #28425

PiperOrigin-RevId: 945675238
2026-07-10 06:22:59 -07:00
Ada Zhang
b7c5ce1d3c Support non-canonical extensions in message promotions (upb_Message_GetOrPromoteExtension, upb_MiniTable_PromoteUnknownToMessage, upb_MiniTable_PromoteUnknownToMessageArray, upb_MiniTable_PromoteUnknownToMap).
PiperOrigin-RevId: 945453462
2026-07-09 20:30:06 -07:00
Protobuf Team Bot
2b0b5066bd Expand visibility of alias, needed for grpc update
PiperOrigin-RevId: 945374887
2026-07-09 16:32:31 -07:00
Jason Aragorn Tobias Lunn
604527297c Internal change
PiperOrigin-RevId: 945344501
2026-07-09 15:23:53 -07:00
Protobuf Team Bot
e22cabffa4 Auto-generate files after cl/945282190 2026-07-09 20:35:22 +00:00
Protobuf Team Bot
3692b2bb22 Optimize UPB_CONSTRUCTOR for ELF with COMDAT deduplication
Changes the UPB_CONSTRUCTOR macro for ELF platforms to use COMDAT-grouped assembly for .init_array. This allows the linker to deduplicate the constructor pointer entries to exactly one copy, eliminating binary bloat and preventing the weak constructor from being executed multiple times at startup.

PiperOrigin-RevId: 945282190
2026-07-09 13:27:29 -07:00
747 changed files with 47539 additions and 26072 deletions

View file

@ -4,110 +4,122 @@
{
"email": "protobuf-packages@google.com",
"github": "protobuf-team-bot",
"github_user_id": 105450428,
"name": "Protobuf Team"
},
{
"email": "sandyzhang@google.com",
"github": "zhangskz",
"github_user_id": 89936743,
"name": "Sandy Zhang"
},
{
"email": "mkruskal@google.com",
"github": "mkruskal-google",
"github_user_id": 62662355,
"name": "Mike Kruskal"
},
{
"email": "gberg@google.com",
"github": "googleberg",
"github_user_id": 107155935,
"name": "Jerry Berg"
},
{
"email": "deannagarcia@google.com",
"github": "deannagarcia",
"github_user_id": 69992229,
"name": "Deanna Garcia",
"do_not_notify": true
},
{
"email": "esrauch@google.com",
"github": "esrauchg",
"github_user_id": 140440793,
"name": "Em Rauch",
"do_not_notify": true
},
{
"email": "haberman@google.com",
"github": "haberman",
"github_user_id": 1270,
"name": "Josh Haberman",
"do_not_notify": true
},
{
"email": "hongshin@google.com",
"github": "honglooker",
"name": "Hong Shin",
"do_not_notify": true
},
{
"email": "jatl@google.com",
"github": "JasonLunn",
"github_user_id": 778854,
"name": "Jason Lunn",
"do_not_notify": true
},
{
"email": "jieluo@google.com",
"github": "anandolee",
"github_user_id": 11618033,
"name": "Jie Luo",
"do_not_notify": true
},
{
"email": "salo@google.com",
"github": "salo",
"github_user_id": 152465,
"name": "Eric Salo",
"do_not_notify": true
},
{
"email": "sangki@google.com",
"github": "jguamie",
"github_user_id": 35405521,
"name": "John Lee",
"do_not_notify": true
},
{
"email": "sbenza@google.com",
"github": "sbenzaquen",
"github_user_id": 14094653,
"name": "Samuel Benzaquen",
"do_not_notify": true
},
{
"email": "shaod@google.com",
"github": "shaod2",
"github_user_id": 67387070,
"name": "Dennis Shao",
"do_not_notify": true
},
{
"email": "tonyliaoss@google.com",
"github": "tonyliaoss",
"github_user_id": 1459994,
"name": "Tony Liao",
"do_not_notify": true
},
{
"email": "rgoldfinger@google.com",
"github": "rgoldfinger6",
"github_user_id": 94469227,
"name": "Rachel Goldfinger",
"do_not_notify": true
},
{
"email": "jamiepilgrim@google.com",
"github": "pilgrimmemoirs",
"github_user_id": 8316393,
"name": "Jamie Pilgrim",
"do_not_notify": true
},
{
"email": "karenwuz@google.com",
"github": "karenwuz",
"github_user_id": 242015323,
"name": "Karen Wu",
"do_not_notify": true
},
{
"email": "runze@google.com",
"github": "runzw",
"github_user_id": 78052475,
"name": "Runze Wang",
"do_not_notify": true
}

View file

@ -16,7 +16,7 @@ permissions:
contents: write
jobs:
release:
uses: bazel-contrib/.github/.github/workflows/release_ruleset.yaml@v7.3.0
uses: bazel-contrib/.github/.github/workflows/release_ruleset.yaml@v7.7.0
with:
release_files: protobuf-*.bazel.tar.gz
prerelease: ${{ contains(inputs.tag_name, '-rc') }}

View file

@ -20,43 +20,16 @@ git archive --format=tar --prefix=${PREFIX}/ ${TAG} > $ARCHIVE_TMP
# Delete the placeholder file
tar --file $ARCHIVE_TMP --delete $INTEGRITY_FILE
# Use jq to translate GitHub Releases json into a Starlark object
filter_releases=$(cat <<'EOF'
# Read the file assets already present on the release
reduce .assets[] as $a (
# Start with an empty dictionary, and for each asset, add
{}; . + {
# The format required in starlark, i.e. "release-name": "deadbeef123"
($a.name): ($a.digest | sub("^sha256:"; ""))
}
)
EOF
)
mkdir -p "$(dirname "$INTEGRITY_FILE")"
# Fetch release payload once
RELEASE_API_URL="https://api.github.com/repos/protocolbuffers/protobuf/releases/tags/${TAG}"
RELEASE_JSON=$(curl -sSL "$RELEASE_API_URL")
# Extract the download URL for tool_integrity.bzl if it exists
# Extract the download URL for tool_integrity.bzl
INTEGRITY_ASSET_URL=$(echo "$RELEASE_JSON" | jq -r '.assets[] | select(.name=="tool_integrity.bzl") | .browser_download_url')
# Check if the asset was found (jq emits "null" or empty if missing)
if [[ -n "$INTEGRITY_ASSET_URL" && "$INTEGRITY_ASSET_URL" != "null" ]]; then
echo "Found pre-computed tool_integrity.bzl asset! Downloading."
curl -sSL -o "${INTEGRITY_FILE}" "$INTEGRITY_ASSET_URL"
else
echo "No pre-computed tool_integrity.bzl found. Falling back to dynamic API dictionary assembly."
cat >"${INTEGRITY_FILE}" <<EOF
"""Generated during release by release_prep.sh"""
RELEASE_VERSION="${TAG}"
RELEASED_BINARY_INTEGRITY = $(
echo "$RELEASE_JSON" | jq -f <(echo "$filter_releases")
)
EOF
fi
curl -sSL -o "${INTEGRITY_FILE}" "$INTEGRITY_ASSET_URL"
# Append that generated file back into the archive
tar --file $ARCHIVE_TMP --append ${INTEGRITY_FILE}

View file

@ -66,11 +66,38 @@ ln -sf "$TAR" "$TEST_DIR/.mock_bin/tar"
ln -sf "$(rlocation ${JQ_BIN#"external/"})" "$TEST_DIR/.mock_bin/jq"
##############################
# Fixture: mock curl returning a GitHub Releases API response
# Fixture: mock curl returning GitHub Releases API response & handling asset downloads
# Handles two cases:
# 1) When -o flag is provided, mocks downloading the integrity file .bzl,
# writing to path specified by the flag
# 2) Otherwise, mocks retrieving the GitHub Releases API JSON, writing to stdout
##############################
cat > "$TEST_DIR/.mock_bin/curl" <<'MOCK'
#!/usr/bin/env bash
cat <<'JSON'
outfile=""
while [[ $# -gt 0 ]]; do
case "$1" in
-o)
outfile="$2"
shift 2
;;
*)
shift
;;
esac
done
if [[ -n "$outfile" ]]; then
cat <<'BZL' > "$outfile"
RELEASE_VERSION="v99.0"
RELEASED_BINARY_INTEGRITY = {
"protoc-99.0-linux-x86_64.zip": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"protoc-99.0-osx-aarch_64.zip": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
"protoc-99.0-win64.zip": "cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc",
}
BZL
else
cat <<'JSON'
{
"assets": [
{
@ -84,10 +111,15 @@ cat <<'JSON'
{
"name": "protoc-99.0-win64.zip",
"digest": "sha256:cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc"
},
{
"name": "tool_integrity.bzl",
"browser_download_url": "https://github.com/protocolbuffers/protobuf/releases/download/v99.0/tool_integrity.bzl"
}
]
}
JSON
fi
MOCK
chmod +x "$TEST_DIR/.mock_bin/curl"
export PATH="$TEST_DIR/.mock_bin:$PATH"

View file

@ -52,7 +52,7 @@ jobs:
# commit.
uses: protocolbuffers/protobuf-ci/bazel@v5
with:
version: 9.0.0 # Bazel version
version: 9.2.0 # Bazel version
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
bazel-cache: staleness
bash: >

View file

@ -26,7 +26,7 @@ jobs:
fail-fast: false
matrix:
runner: [ ubuntu, windows, macos ]
bazelversion: [ '8.6.0', '9.0.0' ]
bazelversion: [ '8.7.0', '9.2.0' ]
bzlmod: [ true, false ]
toolchain_resolution:
# Default flags, uses from prebuilt protoc
@ -36,7 +36,7 @@ jobs:
# Uses protoc from source.
- "--@com_google_protobuf//bazel/flags:prefer_prebuilt_protoc=false"
exclude:
- bazelversion: '9.0.0'
- bazelversion: '9.2.0'
bzlmod: false
runs-on: ${{ matrix.runner }}-latest
name: ${{ matrix.continuous-only && inputs.continuous-prefix || '' }} Examples ${{ matrix.runner }} ${{ matrix.bazelversion }}${{ matrix.bzlmod && ' (bzlmod)' || '' }} ${{ matrix.toolchain_resolution && ' (toolchain resolution)' || '' }}
@ -94,7 +94,7 @@ jobs:
- name: Run tests
uses: protocolbuffers/protobuf-ci/bazel-docker@v5
with:
image: us-docker.pkg.dev/protobuf-build/containers/common/linux/bazel:9.0.0-9dca0d9417f43f5f1e97e59969fb0f3e6ae3bd9c
image: us-docker.pkg.dev/protobuf-build/containers/common/linux/bazel:9.2.0-4d8e80ef93b0219fb907af9dd4596b92946995d8
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
bazel-cache: "bazel-tests"
bazel: test //bazel/...
@ -117,4 +117,4 @@ jobs:
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
bazel-cache: "bazel-tests-${{ matrix.runner }}"
bazel: test //bazel/...
version: 8.6.0
version: 8.7.0

View file

@ -37,25 +37,25 @@ jobs:
- { name: No-RTTI, flags: --cxxopt=-fno-rtti, continuous-only: true }
include:
# Set defaults
- image: us-docker.pkg.dev/protobuf-build/containers/test/linux/sanitize:8.0.1-a6ca8ba8e77d63471b4ad05f8643e1fc58b30e12
- image: us-docker.pkg.dev/protobuf-build/containers/test/linux/sanitize:8.7.0-5bb1a8fdfc30f8c21c1b38cf053d2db9fca865a7
- targets: //pkg/... //src/... //third_party/utf8_range/... //conformance:conformance_framework_tests
# Override cases with custom images
- config: { name: "Bazel8", flags: --cxxopt="-Wno-self-assign-overloaded" }
cache_key: Bazel8
image: "us-docker.pkg.dev/protobuf-build/containers/common/linux/bazel:8.6.0-9dca0d9417f43f5f1e97e59969fb0f3e6ae3bd9c"
image: "us-docker.pkg.dev/protobuf-build/containers/common/linux/bazel:8.7.0-4d8e80ef93b0219fb907af9dd4596b92946995d8"
targets: "//src/... //third_party/utf8_range/..."
- config: { name: "Bazel9", flags: "--cxxopt=-Wno-self-assign-overloaded" }
cache_key: Bazel9
image: "us-docker.pkg.dev/protobuf-build/containers/common/linux/bazel:9.0.0-9dca0d9417f43f5f1e97e59969fb0f3e6ae3bd9c"
image: "us-docker.pkg.dev/protobuf-build/containers/common/linux/bazel:9.2.0-4d8e80ef93b0219fb907af9dd4596b92946995d8"
targets: "//src/... //third_party/utf8_range/..."
- config: { name: "TCMalloc" }
cache_key: TcMalloc
image: "us-docker.pkg.dev/protobuf-build/containers/test/linux/tcmalloc:8.0.1-a6ca8ba8e77d63471b4ad05f8643e1fc58b30e12"
image: "us-docker.pkg.dev/protobuf-build/containers/test/linux/tcmalloc:8.7.0-5bb1a8fdfc30f8c21c1b38cf053d2db9fca865a7 "
targets: "//src/... //third_party/utf8_range/..."
- config: { name: "aarch64", flags: "--platforms=//build_defs:linux-aarch_64" }
cache_key: aarch64-bazel8
targets: "//src/... //src/google/protobuf/compiler:protoc_aarch64_test //third_party/utf8_range/..."
image: "us-docker.pkg.dev/protobuf-build/containers/test/linux/emulation:8.0.1-aarch64-a6ca8ba8e77d63471b4ad05f8643e1fc58b30e12"
image: "us-docker.pkg.dev/protobuf-build/containers/test/linux/emulation:8.7.0-aarch64-5bb1a8fdfc30f8c21c1b38cf053d2db9fca865a7 "
name: ${{ matrix.config.continuous-only && inputs.continuous-prefix || '' }} Linux ${{ matrix.config.name }}
runs-on: ${{ matrix.config.runner || 'ubuntu-latest' }}
steps:
@ -64,6 +64,15 @@ jobs:
uses: protocolbuffers/protobuf-ci/checkout@v5
with:
ref: ${{ inputs.safe-checkout }}
- name: Prime the cache
if: ${{ !matrix.config.continuous-only || inputs.continuous-run }}
uses: protocolbuffers/protobuf-ci/bazel-docker@v5
with:
image: ${{ matrix.image }}
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
bazel-cache: cpp_linux/${{ matrix.cache_key }}
bazel: fetch ${{ matrix.targets }} ${{ matrix.config.flags }}
exclude-targets: ${{ matrix.exclude-targets }}
- name: Run tests
if: ${{ !matrix.config.continuous-only || inputs.continuous-run }}
uses: protocolbuffers/protobuf-ci/bazel-docker@v5
@ -78,12 +87,7 @@ jobs:
strategy:
fail-fast: false # Don't cancel all jobs if one fails.
matrix:
version: ['7.5', '9.1', '9.5', '13.1']
include:
- version: 9.1
continuous-only: true
- version: 9.5
continuous-only: true
version: ['10.5', '13.4']
name: ${{ matrix.config.continuous-only && inputs.continuous-prefix || '' }} Linux GCC ${{ matrix.version }}
runs-on: ubuntu-latest
steps:
@ -92,11 +96,19 @@ jobs:
if: ${{ !matrix.config.continuous-only || inputs.continuous-run }}
with:
ref: ${{ inputs.safe-checkout }}
- name: Prime the cache
uses: protocolbuffers/protobuf-ci/bazel-docker@v5
if: ${{ !matrix.config.continuous-only || inputs.continuous-run }}
with:
image: us-docker.pkg.dev/protobuf-build/containers/test/linux/gcc:8.7.0-${{ matrix.version }}-5bb1a8fdfc30f8c21c1b38cf053d2db9fca865a7
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
bazel-cache: cpp_linux/gcc-${{ matrix.version }}
bazel: fetch //pkg/... //src/... //third_party/utf8_range/... //conformance:conformance_framework_tests
- name: Run tests
uses: protocolbuffers/protobuf-ci/bazel-docker@v5
if: ${{ !matrix.config.continuous-only || inputs.continuous-run }}
with:
image: us-docker.pkg.dev/protobuf-build/containers/test/linux/gcc:8.0.1-${{ matrix.version }}-e78301df86b3e4c46ec9ac4d98be00e19305d8f3
image: us-docker.pkg.dev/protobuf-build/containers/test/linux/gcc:8.7.0-${{ matrix.version }}-5bb1a8fdfc30f8c21c1b38cf053d2db9fca865a7
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
bazel-cache: cpp_linux/gcc-${{ matrix.version }}
bazel: test //pkg/... //src/... //third_party/utf8_range/... //conformance:conformance_framework_tests
@ -112,30 +124,46 @@ jobs:
name: ${{ matrix.continuous-only && inputs.continuous-prefix || '' }} Linux Release ${{ matrix.arch }}
runs-on: ubuntu-22-4core
steps:
- name: Check initial disk space
if: ${{ !matrix.continuous-only || inputs.continuous-run }}
shell: bash
run: df -h
- name: Checkout pending changes
if: ${{ !matrix.continuous-only || inputs.continuous-run }}
uses: protocolbuffers/protobuf-ci/checkout@v5
with:
ref: ${{ inputs.safe-checkout }}
- name: Check disk space after checkout
if: ${{ !matrix.continuous-only || inputs.continuous-run }}
shell: bash
run: df -h
- name: Cross compile protoc for ${{ matrix.arch }}
if: ${{ !matrix.continuous-only || inputs.continuous-run }}
id: cross-compile
uses: protocolbuffers/protobuf-ci/cross-compile-protoc@v5
with:
image: us-docker.pkg.dev/protobuf-build/containers/common/linux/bazel:8.6.0-9dca0d9417f43f5f1e97e59969fb0f3e6ae3bd9c
image: us-docker.pkg.dev/protobuf-build/containers/common/linux/bazel:8.7.0-4d8e80ef93b0219fb907af9dd4596b92946995d8
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
architecture: linux-${{ matrix.arch }}
- name: Check disk space after cross compile
if: ${{ !matrix.continuous-only || inputs.continuous-run }}
shell: bash
run: df -h
- name: Setup sccache
if: ${{ !matrix.continuous-only || inputs.continuous-run }}
uses: protocolbuffers/protobuf-ci/sccache@v5
with:
cache-prefix: linux-release-${{ matrix.arch }}
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
- name: Check disk space after setup sccache
if: ${{ !matrix.continuous-only || inputs.continuous-run }}
shell: bash
run: df -h
- name: Run tests
if: ${{ !matrix.continuous-only || inputs.continuous-run }}
uses: protocolbuffers/protobuf-ci/docker@v5
with:
image: us-docker.pkg.dev/protobuf-build/containers/test/linux/emulation:8.0.1-${{ matrix.arch }}-a6ca8ba8e77d63471b4ad05f8643e1fc58b30e12
image: us-docker.pkg.dev/protobuf-build/containers/test/linux/emulation:8.7.0-${{ matrix.arch }}-5bb1a8fdfc30f8c21c1b38cf053d2db9fca865a7
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
entrypoint: bash
command: >
@ -148,6 +176,10 @@ jobs:
cmake --build . --parallel 20;
ctest --no-tests=error --parallel 20;
sccache -s"
- name: Check disk space after run tests
if: ${{ !matrix.continuous-only || inputs.continuous-run }}
shell: bash
run: df -h
linux-cmake:
strategy:
@ -291,7 +323,7 @@ jobs:
with:
name: installed_files_${{ matrix.build }}
path: ${{ matrix.build }}
- name: Compare against golden
run: |
set +e
@ -371,7 +403,7 @@ jobs:
if: ${{ !matrix.continuous-only || inputs.continuous-run }}
uses: protocolbuffers/protobuf-ci/docker@v5
with:
image: us-docker.pkg.dev/protobuf-build/containers/test/linux/gcc:8.0.1-12.2-168f9c9d015a0fa16611e1e9eede796fe9bfbb69
image: us-docker.pkg.dev/protobuf-build/containers/test/linux/gcc:8.7.0-12.5-5bb1a8fdfc30f8c21c1b38cf053d2db9fca865a7
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
entrypoint: bash
command: >-
@ -454,7 +486,7 @@ jobs:
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
bazel: ${{ matrix.bazel }}
bazel-cache: cpp_${{ matrix.cache_key }}
version: ${{ matrix.bazel_version || '8.0.1' }}
version: ${{ matrix.bazel_version || '8.7.0' }}
non-linux-cmake:
strategy:
@ -527,7 +559,7 @@ jobs:
if: ${{ matrix.install-flags && (!matrix.continuous-only || inputs.continuous-run) }}
uses: protocolbuffers/protobuf-ci/bash@v5
with:
bazel-version: 8.0.1
bazel-version: 8.7.0
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
command: >-
cmake . -DCMAKE_CXX_STANDARD=17 -Dprotobuf_BUILD_TESTS=ON ${{ matrix.install-flags }}
@ -554,7 +586,7 @@ jobs:
uses: protocolbuffers/protobuf-ci/bash@v5
with:
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
bazel-version: 8.0.1
bazel-version: 8.7.0
command: >-
cmake . -DCMAKE_CXX_STANDARD=17 -Dprotobuf_BUILD_TESTS=ON ${{ matrix.flags }}
${{ env.SCCACHE_CMAKE_FLAGS }} -Dprotobuf_ALLOW_CCACHE=ON
@ -593,7 +625,7 @@ jobs:
if: ${{ inputs.continuous-run }}
uses: protocolbuffers/protobuf-ci/bazel-docker@v5
with:
image: us-docker.pkg.dev/protobuf-build/containers/common/linux/bazel:9.0.0-7932bf8b25fb76a111e7257d151a6a58d5c3c671
image: us-docker.pkg.dev/protobuf-build/containers/common/linux/bazel:9.2.0-4d8e80ef93b0219fb907af9dd4596b92946995d8
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
bazel-cache: cpp_linux/abseil_head
bazel: test //src/... --override_module=abseil-cpp=abseil-cpp-head

View file

@ -27,7 +27,7 @@ jobs:
- name: Run tests
uses: protocolbuffers/protobuf-ci/docker@v5
with:
image: us-docker.pkg.dev/protobuf-build/containers/test/linux/csharp:9.0.0-3.1.415-8.0.100-a6ca8ba8e77d63471b4ad05f8643e1fc58b30e12
image: us-docker.pkg.dev/protobuf-build/containers/test/linux/csharp:9.2.0-3.1.415-8.0.100-5bb1a8fdfc30f8c21c1b38cf053d2db9fca865a7
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
entrypoint: /bin/bash
command: >-
@ -43,7 +43,7 @@ jobs:
- name: Run conformance tests
uses: protocolbuffers/protobuf-ci/bazel-docker@v5
with:
image: us-docker.pkg.dev/protobuf-build/containers/test/linux/csharp:9.0.0-3.1.415-8.0.100-a6ca8ba8e77d63471b4ad05f8643e1fc58b30e12
image: us-docker.pkg.dev/protobuf-build/containers/test/linux/csharp:9.2.0-3.1.415-8.0.100-5bb1a8fdfc30f8c21c1b38cf053d2db9fca865a7
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
bazel-cache: csharp_linux
bazel: test //csharp:conformance_test --action_env=PATH --action_env=DOTNET_CLI_TELEMETRY_OPTOUT=1 --test_env=DOTNET_CLI_HOME=/home/bazel
@ -65,7 +65,7 @@ jobs:
- name: Run tests
uses: protocolbuffers/protobuf-ci/bash@v5
with:
bazel-version: 9.0.0
bazel-version: 9.2.0
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
command: |
dotnet build csharp/src/Google.Protobuf.sln

View file

@ -22,7 +22,7 @@ jobs:
include:
- targets: "//hpb/... //hpb_generator/..."
- image: "us-docker.pkg.dev/protobuf-build/containers/common/linux/bazel:9.0.0-9dca0d9417f43f5f1e97e59969fb0f3e6ae3bd9c"
- image: "us-docker.pkg.dev/protobuf-build/containers/common/linux/bazel:9.2.0-4d8e80ef93b0219fb907af9dd4596b92946995d8"
- bazel_cmd: "test"
name: Linux ${{ matrix.config.name }}

View file

@ -30,27 +30,27 @@ jobs:
include:
- name: OpenJDK 8
cache_key: '8'
image: us-docker.pkg.dev/protobuf-build/containers/test/linux/java:9.0.0-11-a6ca8ba8e77d63471b4ad05f8643e1fc58b30e12
image: us-docker.pkg.dev/protobuf-build/containers/test/linux/java:9.2.0-11-5bb1a8fdfc30f8c21c1b38cf053d2db9fca865a7
# TODO: b/318555165 - enable the layering check. Currently it does
# not work correctly with the toolchain in this Docker image.
targets: //java/... //java/internal:java_version --features=-layering_check
flags: --java_language_version=8
- name: OpenJDK 11
cache_key: '11'
image: us-docker.pkg.dev/protobuf-build/containers/test/linux/java:9.0.0-11-a6ca8ba8e77d63471b4ad05f8643e1fc58b30e12
image: us-docker.pkg.dev/protobuf-build/containers/test/linux/java:9.2.0-11-5bb1a8fdfc30f8c21c1b38cf053d2db9fca865a7
targets: //java/... //java/internal:java_version //compatibility/...
continuous-only: true
- name: OpenJDK 17
cache_key: '17'
image: us-docker.pkg.dev/protobuf-build/containers/test/linux/java:9.0.0-17-a6ca8ba8e77d63471b4ad05f8643e1fc58b30e12
image: us-docker.pkg.dev/protobuf-build/containers/test/linux/java:9.2.0-17-5bb1a8fdfc30f8c21c1b38cf053d2db9fca865a7
targets: //java/... //java/internal:java_version //compatibility/...
- name: OpenJDK 21 bazel 8
cache_key: 'bazel8'
image: us-docker.pkg.dev/protobuf-build/containers/test/linux/java:8.6.0-21-a6ca8ba8e77d63471b4ad05f8643e1fc58b30e12
image: us-docker.pkg.dev/protobuf-build/containers/test/linux/java:8.7.0-21-5bb1a8fdfc30f8c21c1b38cf053d2db9fca865a7
targets: //java/... //java/internal:java_version //compatibility/...
- name: OpenJDK 21
cache_key: '21'
image: us-docker.pkg.dev/protobuf-build/containers/test/linux/java:9.0.0-21-a6ca8ba8e77d63471b4ad05f8643e1fc58b30e12
image: us-docker.pkg.dev/protobuf-build/containers/test/linux/java:9.2.0-21-5bb1a8fdfc30f8c21c1b38cf053d2db9fca865a7
targets: //java/... //java/internal:java_version //compatibility/...
# TODO: b/395623141 - restore this test once runtime uses / emulates aarch64.
# - name: aarch64
@ -105,7 +105,7 @@ jobs:
- name: Generate maven artifacts with bazel and install using maven
uses: protocolbuffers/protobuf-ci/bazel-docker@v5
with:
image: us-docker.pkg.dev/protobuf-build/containers/test/linux/java:9.0.0-11-a6ca8ba8e77d63471b4ad05f8643e1fc58b30e12
image: us-docker.pkg.dev/protobuf-build/containers/test/linux/java:9.2.0-11-5bb1a8fdfc30f8c21c1b38cf053d2db9fca865a7
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
bazel-cache: java_linux/11
bash: |

View file

@ -70,7 +70,7 @@ jobs:
CODE_SIGN_IDENTITY: "-"
with:
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
bazel-version: 9.0.0
bazel-version: 9.2.0
command: |
xcodebuild \
-project "objectivec/${{ matrix.xc_project }}" \
@ -113,7 +113,7 @@ jobs:
if: ${{ !matrix.continuous-only || inputs.continuous-run }}
uses: protocolbuffers/protobuf-ci/bazel@v5
with:
version: 9.0.0 # Bazel version
version: 9.2.0 # Bazel version
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
bazel-cache: cocoapods/${{ matrix.XCODE }}
bash: |
@ -161,7 +161,7 @@ jobs:
if: ${{ !matrix.config.continuous-only || inputs.continuous-run }}
uses: protocolbuffers/protobuf-ci/bazel@v5
with:
version: 9.0.0 # Bazel version
version: 9.2.0 # Bazel version
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
bazel: ${{ matrix.config.bazel_action }} ${{ matrix.config.flags }} ${{ matrix.bazel_targets }}
bazel-cache: objc_${{ matrix.platform }}_${{ matrix.config.name }}

View file

@ -65,7 +65,7 @@ jobs:
if: ${{ !matrix.continuous-only || inputs.continuous-run }}
uses: protocolbuffers/protobuf-ci/bazel-docker@v5
with:
image: us-docker.pkg.dev/protobuf-build/containers/test/linux/php:9.0.0-${{ matrix.version }}-a6ca8ba8e77d63471b4ad05f8643e1fc58b30e12
image: us-docker.pkg.dev/protobuf-build/containers/test/linux/php:9.2.0-${{ matrix.version }}-5bb1a8fdfc30f8c21c1b38cf053d2db9fca865a7
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
bazel-cache: php_linux/${{ matrix.version }}
bash: |
@ -115,7 +115,7 @@ jobs:
id: cross-compile
uses: protocolbuffers/protobuf-ci/cross-compile-protoc@v5
with:
image: us-docker.pkg.dev/protobuf-build/containers/common/linux/bazel:9.0.0-9dca0d9417f43f5f1e97e59969fb0f3e6ae3bd9c
image: us-docker.pkg.dev/protobuf-build/containers/common/linux/bazel:9.2.0-4d8e80ef93b0219fb907af9dd4596b92946995d8
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
architecture: linux-i386
@ -147,7 +147,7 @@ jobs:
id: cross-compile
uses: protocolbuffers/protobuf-ci/cross-compile-protoc@v5
with:
image: us-docker.pkg.dev/protobuf-build/containers/common/linux/bazel:9.0.0-9dca0d9417f43f5f1e97e59969fb0f3e6ae3bd9c
image: us-docker.pkg.dev/protobuf-build/containers/common/linux/bazel:9.2.0-4d8e80ef93b0219fb907af9dd4596b92946995d8
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
architecture: linux-aarch64
@ -204,7 +204,7 @@ jobs:
uses: protocolbuffers/protobuf-ci/bash@v5
with:
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
bazel-version: 9.0.0
bazel-version: 9.2.0
# TODO this shouldn't be necessary, remove it
bazel-flags: --xcode_version_config=//.github:host_xcodes_macos15
command: |
@ -220,6 +220,6 @@ jobs:
uses: protocolbuffers/protobuf-ci/bazel@v5
with:
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
version: 9.0.0 # Bazel version
version: 9.2.0 # Bazel version
bazel-cache: php_macos15/${{ matrix.version }}
bazel: test //php:conformance_test //php:conformance_test_c --action_env=PATH --test_env=PATH --xcode_version_config=//.github:host_xcodes_macos15

View file

@ -35,7 +35,7 @@ jobs:
- name: Package extension
uses: protocolbuffers/protobuf-ci/bazel@v5
with:
version: 9.0.0 # Bazel version
version: 9.2.0 # Bazel version
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
bazel-cache: php_ext/${{ matrix.version }}
bash: >

View file

@ -50,7 +50,7 @@ jobs:
targets: //python/... //python:aarch64_test
# TODO Enable this once conformance tests are fixed.
flags: --define=use_fast_cpp_protos=true --test_tag_filters=-conformance
image: us-docker.pkg.dev/protobuf-build/containers/test/linux/emulation:8.0.1-aarch64-a6ca8ba8e77d63471b4ad05f8643e1fc58b30e12
image: us-docker.pkg.dev/protobuf-build/containers/test/linux/emulation:8.7.0-aarch64-5bb1a8fdfc30f8c21c1b38cf053d2db9fca865a7
name: ${{ matrix.continuous-only && inputs.continuous-prefix || '' }} Linux ${{ matrix.type }} ${{ matrix.version }} ${{ matrix.nobzlmod && 'No Bzlmod' || '' }}
runs-on: ubuntu-latest
@ -64,7 +64,7 @@ jobs:
if: ${{ !matrix.continuous-only || inputs.continuous-run }}
uses: protocolbuffers/protobuf-ci/bazel-docker@v5
with:
image: ${{ matrix.image || format('us-docker.pkg.dev/protobuf-build/containers/test/linux/python:9.0.0-{0}-7932bf8b25fb76a111e7257d151a6a58d5c3c671', matrix.version) }}
image: ${{ matrix.image || format('us-docker.pkg.dev/protobuf-build/containers/test/linux/python:9.2.0-{0}-5bb1a8fdfc30f8c21c1b38cf053d2db9fca865a7 ', matrix.version) }}
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
bazel-cache: python_linux/${{ matrix.type }}_${{ matrix.version }}
bazel: test ${{ matrix.targets }} ${{ matrix.flags }} ${{ matrix.nobzlmod && '--noenable_bzlmod' || '' }} --test_env=KOKORO_PYTHON_VERSION
@ -115,7 +115,7 @@ jobs:
env:
KOKORO_PYTHON_VERSION: ${{ matrix.version }}
with:
version: 9.0.0 # Bazel version
version: 9.2.0 # Bazel version
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
bazel-cache: python_macos/${{ matrix.type }}_${{ matrix.version }}
bazel: >-

View file

@ -13,7 +13,7 @@ jobs:
strategy:
fail-fast: false
matrix:
branch: [25.x, 29.x, 33.x, 34.x, 35.x]
branch: [25.x, 33.x, 35.x, 36.x]
runs-on: ubuntu-latest
permissions:
actions: write

View file

@ -36,12 +36,12 @@ jobs:
- { name: Ruby 3.4, ruby: ruby-3.4.1, continuous-only: true }
- { name: Ruby 4.0, ruby: ruby-4.0.0, ffi: NATIVE }
- { name: Ruby 4.0, ruby: ruby-4.0.0, ffi: FFI }
- { name: Ruby 4.0 bazel 8, ruby: ruby-4.0.0, ffi: NATIVE, image: 'us-docker.pkg.dev/protobuf-build/containers/test/linux/ruby:8.6.0-ruby-4.0.0-856ad422dddd3b8fbd85e36129496b37bba174ef' }
- { name: Ruby 4.0 bazel 8, ruby: ruby-4.4.4, ffi: FFI, image: 'us-docker.pkg.dev/protobuf-build/containers/test/linux/ruby:8.6.0-ruby-4.0.0-856ad422dddd3b8fbd85e36129496b37bba174ef' }
- { name: Ruby 4.0 bazel 8, ruby: ruby-4.0.0, ffi: NATIVE, image: 'us-docker.pkg.dev/protobuf-build/containers/test/linux/ruby:8.7.0-ruby-4.0.0-5bb1a8fdfc30f8c21c1b38cf053d2db9fca865a7 ' }
- { name: Ruby 4.0 bazel 8, ruby: ruby-4.4.4, ffi: FFI, image: 'us-docker.pkg.dev/protobuf-build/containers/test/linux/ruby:8.7.0-ruby-4.0.0-5bb1a8fdfc30f8c21c1b38cf053d2db9fca865a7 ' }
- { name: JRuby 9.4, ruby: jruby-9.4.9.0, ffi: NATIVE }
- { name: JRuby 9.4, ruby: jruby-9.4.9.0, ffi: FFI }
- { name: JRuby 9.4 bazel 8, ruby: jruby-9.4.9.0, ffi: NATIVE, image: 'us-docker.pkg.dev/protobuf-build/containers/test/linux/ruby:8.6.0-jruby-9.4.9.0-856ad422dddd3b8fbd85e36129496b37bba174ef' }
- { name: JRuby 9.4 bazel 8, ruby: jruby-9.4.9.0, ffi: FFI, image: 'us-docker.pkg.dev/protobuf-build/containers/test/linux/ruby:8.6.0-jruby-9.4.9.0-856ad422dddd3b8fbd85e36129496b37bba174ef' }
- { name: JRuby 9.4 bazel 8, ruby: jruby-9.4.9.0, ffi: NATIVE, image: 'us-docker.pkg.dev/protobuf-build/containers/test/linux/ruby:8.7.0-jruby-9.4.9.0-5bb1a8fdfc30f8c21c1b38cf053d2db9fca865a7 ' }
- { name: JRuby 9.4 bazel 8, ruby: jruby-9.4.9.0, ffi: FFI, image: 'us-docker.pkg.dev/protobuf-build/containers/test/linux/ruby:8.7.0-jruby-9.4.9.0-5bb1a8fdfc30f8c21c1b38cf053d2db9fca865a7 ' }
name: ${{ matrix.continuous-only && inputs.continuous-prefix || '' }} Linux ${{ matrix.name }} ${{ matrix.ffi == 'FFI' && ' FFI' || '' }}
runs-on: ubuntu-latest
@ -55,7 +55,7 @@ jobs:
if: ${{ !matrix.continuous-only || inputs.continuous-run }}
uses: protocolbuffers/protobuf-ci/bazel-docker@v5
with:
image: ${{ matrix.image || format('us-docker.pkg.dev/protobuf-build/containers/test/linux/ruby:9.0.0-{0}-9fc33a0c378b5affd3c85d3f5ae4f330993048f7', matrix.ruby) }}
image: ${{ matrix.image || format('us-docker.pkg.dev/protobuf-build/containers/test/linux/ruby:9.2.0-{0}-5bb1a8fdfc30f8c21c1b38cf053d2db9fca865a7 ', matrix.ruby) }}
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
bazel-cache: ruby_linux/${{ matrix.ruby }}
bazel: test //ruby/... //ruby/tests:ruby_version --test_env=KOKORO_RUBY_VERSION --test_env=BAZEL=true ${{ matrix.ffi == 'FFI' && '--//ruby:ffi=enabled --test_env=PROTOCOL_BUFFERS_RUBY_IMPLEMENTATION=FFI' || '' }}
@ -81,7 +81,7 @@ jobs:
id: cross-compile
uses: protocolbuffers/protobuf-ci/cross-compile-protoc@v5
with:
image: us-docker.pkg.dev/protobuf-build/containers/common/linux/bazel:8.6.0-9dca0d9417f43f5f1e97e59969fb0f3e6ae3bd9c
image: us-docker.pkg.dev/protobuf-build/containers/common/linux/bazel:8.7.0-4d8e80ef93b0219fb907af9dd4596b92946995d8
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
architecture: linux-i386
@ -114,7 +114,7 @@ jobs:
id: cross-compile
uses: protocolbuffers/protobuf-ci/cross-compile-protoc@v5
with:
image: us-docker.pkg.dev/protobuf-build/containers/common/linux/bazel:8.6.0-9dca0d9417f43f5f1e97e59969fb0f3e6ae3bd9c
image: us-docker.pkg.dev/protobuf-build/containers/common/linux/bazel:8.7.0-4d8e80ef93b0219fb907af9dd4596b92946995d8
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
architecture: linux-aarch64
@ -122,8 +122,9 @@ jobs:
if: ${{ inputs.continuous-run }}
uses: protocolbuffers/protobuf-ci/docker@v5
with:
image: arm64v8/ruby:3.2.11-bookworm
image: ruby:3.2.11-bookworm
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
platform: linux/arm64
command: >-
/bin/bash -cex '
gem install bundler -v 2.6.6;
@ -160,7 +161,7 @@ jobs:
- name: Pin Ruby version
if: ${{ !matrix.continuous-only || inputs.continuous-run }}
uses: ruby/setup-ruby@ae195bbe749a7cef685ac729197124a48305c1cb # v1.276.0
uses: ruby/setup-ruby@6e5d382445ae5590b7449d8b3bc8cb1c2c27f617 # v1.317.0
with:
ruby-version: ${{ matrix.version }}
@ -172,7 +173,7 @@ jobs:
if: ${{ !matrix.continuous-only || inputs.continuous-run }}
uses: protocolbuffers/protobuf-ci/bazel@v5
with:
version: 9.0.0 # Bazel version
version: 9.2.0 # Bazel version
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
bazel-cache: ruby_macos/${{ matrix.version }}
bazel: test //ruby/... --test_env=KOKORO_RUBY_VERSION=${{ matrix.version }} --test_env=BAZEL=true ${{ matrix.ffi == 'FFI' && '--//ruby:ffi=enabled --test_env=PROTOCOL_BUFFERS_RUBY_IMPLEMENTATION=FFI' || '' }}
@ -191,12 +192,12 @@ jobs:
- { name: Ruby 3.4, ruby: ruby-3.4.1, continuous-only: true }
- { name: Ruby 4.0, ruby: ruby-4.0.0, ffi: NATIVE }
- { name: Ruby 4.0, ruby: ruby-4.0.0, ffi: FFI }
- { name: Ruby 4.0 bazel 8, ruby: ruby-4.0.0, ffi: NATIVE, image: 'us-docker.pkg.dev/protobuf-build/containers/test/linux/ruby:8.6.0-ruby-4.0.0-856ad422dddd3b8fbd85e36129496b37bba174ef' }
- { name: Ruby 4.0 bazel 8, ruby: ruby-4.4.4, ffi: FFI, image: 'us-docker.pkg.dev/protobuf-build/containers/test/linux/ruby:8.6.0-ruby-4.0.0-856ad422dddd3b8fbd85e36129496b37bba174ef' }
- { name: Ruby 4.0 bazel 8, ruby: ruby-4.0.0, ffi: NATIVE, image: 'us-docker.pkg.dev/protobuf-build/containers/test/linux/ruby:8.7.0-ruby-4.0.0-5bb1a8fdfc30f8c21c1b38cf053d2db9fca865a7 ' }
- { name: Ruby 4.0 bazel 8, ruby: ruby-4.4.4, ffi: FFI, image: 'us-docker.pkg.dev/protobuf-build/containers/test/linux/ruby:8.7.0-ruby-4.0.0-5bb1a8fdfc30f8c21c1b38cf053d2db9fca865a7 ' }
- { name: JRuby 9.4, ruby: jruby-9.4.9.0, ffi: NATIVE }
- { name: JRuby 9.4, ruby: jruby-9.4.9.0, ffi: FFI, continuous-only: true }
- { name: JRuby 9.4 bazel 8, ruby: jruby-9.4.9.0, ffi: NATIVE, image: 'us-docker.pkg.dev/protobuf-build/containers/test/linux/ruby:8.6.0-jruby-9.4.9.0-856ad422dddd3b8fbd85e36129496b37bba174ef' }
- { name: JRuby 9.4 bazel 8, ruby: jruby-9.4.9.0, ffi: FFI, image: 'us-docker.pkg.dev/protobuf-build/containers/test/linux/ruby:8.6.0-jruby-9.4.9.0-856ad422dddd3b8fbd85e36129496b37bba174ef' }
- { name: JRuby 9.4 bazel 8, ruby: jruby-9.4.9.0, ffi: NATIVE, image: 'us-docker.pkg.dev/protobuf-build/containers/test/linux/ruby:8.7.0-jruby-9.4.9.0-5bb1a8fdfc30f8c21c1b38cf053d2db9fca865a7 ' }
- { name: JRuby 9.4 bazel 8, ruby: jruby-9.4.9.0, ffi: FFI, image: 'us-docker.pkg.dev/protobuf-build/containers/test/linux/ruby:8.7.0-jruby-9.4.9.0-5bb1a8fdfc30f8c21c1b38cf053d2db9fca865a7 ' }
name: ${{ matrix.continuous-only && inputs.continuous-prefix || '' }} Install ${{ matrix.name }}${{ matrix.ffi == 'FFI' && ' FFI' || '' }}
runs-on: ubuntu-latest
steps:
@ -209,7 +210,7 @@ jobs:
if: ${{ !matrix.continuous-only || inputs.continuous-run }}
uses: protocolbuffers/protobuf-ci/bazel-docker@v5
with:
image: ${{ matrix.image || format('us-docker.pkg.dev/protobuf-build/containers/test/linux/ruby:9.0.0-{0}-9fc33a0c378b5affd3c85d3f5ae4f330993048f7', matrix.ruby) }}
image: ${{ matrix.image || format('us-docker.pkg.dev/protobuf-build/containers/test/linux/ruby:9.2.0-{0}-5bb1a8fdfc30f8c21c1b38cf053d2db9fca865a7 ', matrix.ruby) }}
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
bazel-cache: ruby_install/${{ matrix.ruby }}_${{ matrix.bazel }}
bash: >

View file

@ -24,7 +24,7 @@ jobs:
include:
- targets: "//rust/... //src/google/protobuf/compiler/rust/..."
- image: "us-docker.pkg.dev/protobuf-build/containers/common/linux/bazel:9.0.0-9dca0d9417f43f5f1e97e59969fb0f3e6ae3bd9c"
- image: "us-docker.pkg.dev/protobuf-build/containers/common/linux/bazel:9.2.0-4d8e80ef93b0219fb907af9dd4596b92946995d8"
- bazel_cmd: "test"
# Override cases with custom images
@ -73,4 +73,4 @@ jobs:
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
bazel: run //rust/release_crates:cargo_test
bazel-cache: windows-cargo
version: 9.0.0
version: 9.2.0

View file

@ -30,8 +30,8 @@ jobs:
config:
- { name: "Fastbuild" }
- { name: "Optimized", flags: "-c opt", continuous-only: true }
- { name: "GCC Optimized", flags: "-c opt --force_pic --java_runtime_version=remotejdk_11 --copt=\"-Wno-error=maybe-uninitialized\"", image: "us-docker.pkg.dev/protobuf-build/containers/test/linux/gcc:8.0.1-12.2-12e21b8dda91028bc14212a3ab582c7c4d149fac" }
- { name: "GCC Static", flags: "-c opt --dynamic_mode=off --java_runtime_version=remotejdk_11 --copt=\"-Wno-error=maybe-uninitialized\"", image: "us-docker.pkg.dev/protobuf-build/containers/test/linux/gcc:8.0.1-12.2-12e21b8dda91028bc14212a3ab582c7c4d149fac", continuous-only: true }
- { name: "GCC Optimized", flags: "-c opt --force_pic --java_runtime_version=remotejdk_11 --copt=\"-Wno-error=maybe-uninitialized\" --copt=\"-Wno-error=deprecated-declarations\" --copt=\"-Wno-error=array-bounds\"", image: "us-docker.pkg.dev/protobuf-build/containers/test/linux/gcc:8.7.0-12.5-5bb1a8fdfc30f8c21c1b38cf053d2db9fca865a7 " }
- { name: "GCC Static", flags: "-c opt --dynamic_mode=off --java_runtime_version=remotejdk_11 --copt=\"-Wno-error=maybe-uninitialized\" --copt=\"-Wno-error=deprecated-declarations\" --copt=\"-Wno-error=array-bounds\"", image: "us-docker.pkg.dev/protobuf-build/containers/test/linux/gcc:8.7.0-12.5-5bb1a8fdfc30f8c21c1b38cf053d2db9fca865a7 ", continuous-only: true }
- { name: "ASAN", flags: "--config=asan -c dbg", exclude-targets: "-//benchmarks:benchmark -//python/...", runner: ubuntu-22-4core }
- { name: "UBSAN", flags: "--config=ubsan -c dbg", exclude-targets: "-//benchmarks:benchmark -//python/... -//lua/...", continuous-only: true }
- { name: "32-bit", flags: "--copt=-m32 --linkopt=-m32", exclude-targets: "-//benchmarks:benchmark -//python/..." }
@ -51,7 +51,7 @@ jobs:
if: ${{ !matrix.config.continuous-only || inputs.continuous-run }}
uses: protocolbuffers/protobuf-ci/bazel-docker@v5
with:
image: ${{ matrix.config.image || 'us-docker.pkg.dev/protobuf-build/containers/test/linux/sanitize:8.0.1-a6ca8ba8e77d63471b4ad05f8643e1fc58b30e12' }}
image: ${{ matrix.config.image || 'us-docker.pkg.dev/protobuf-build/containers/test/linux/sanitize:8.7.0-5bb1a8fdfc30f8c21c1b38cf053d2db9fca865a7 ' }}
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
bazel-cache: upb-bazel
bazel: test //benchmarks/... //lua/... //python/... //upb/... //upb_generator/... ${{ matrix.config.flags }}
@ -74,7 +74,7 @@ jobs:
bazel-cache: "upb-bazel-windows"
# TODO: Enable python tests here once rules_python supports Windows better.
bazel: test //upb/... //upb_generator/...
version: 9.0.0
version: 9.2.0
exclude-targets: -//python:conformance_test -//upb/reflection:def_builder_test
macos:
@ -103,7 +103,7 @@ jobs:
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
bazel-cache: "upb-bazel-macos"
bazel: ${{ matrix.config.bazel-command }} ${{ matrix.config.flags }} //benchmarks/... //lua/... //python/... //upb/... //upb_generator/...
version: 9.0.0
version: 9.2.0
build_wheels:
name: Build Wheels

View file

@ -506,6 +506,12 @@ alias(
visibility = ["//visibility:public"],
)
alias(
name = "json_enumvalue_options_proto_srcs",
actual = "//src/google/protobuf:json_enumvalue_options_proto_srcs",
visibility = ["//visibility:public"],
)
alias(
name = "json_enumvalue_options_cc_proto",
actual = "//src/google/protobuf:json_enumvalue_options_cc_proto",
@ -596,7 +602,9 @@ proto_lang_toolchain(
blacklisted_protos = [
"//:compiler_plugin_proto",
"//:cpp_features_proto",
"//:cpp_file_options_proto",
"//:descriptor_proto",
"//:json_enumvalue_options_proto",
],
command_line = "--cpp_out=$(OUT)",
plugin = "//src/google/protobuf/compiler/cpp:protoc-gen-cpp",

View file

@ -91,7 +91,7 @@ if (protobuf_BUILD_SHARED_LIBS)
endif ()
# Version metadata
set(protobuf_VERSION_STRING "7.36.0")
set(protobuf_VERSION_STRING "7.37.0")
set(protobuf_DESCRIPTION "Protocol Buffers")
set(protobuf_CONTACT "protobuf@googlegroups.com")
@ -238,10 +238,17 @@ if (protobuf_BUILD_SHARED_LIBS)
else (protobuf_BUILD_SHARED_LIBS)
set(protobuf_SHARED_OR_STATIC "STATIC")
set(ABSL_MSVC_STATIC_RUNTIME ${protobuf_MSVC_STATIC_RUNTIME})
if (protobuf_MSVC_STATIC_RUNTIME)
set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreaded$<$<CONFIG:Debug>:Debug>)
else()
set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreaded$<$<CONFIG:Debug>:Debug>DLL)
# Only choose an MSVC runtime library if the enclosing project has not already
# set one. When protobuf is consumed via add_subdirectory/FetchContent, the
# parent may set CMAKE_MSVC_RUNTIME_LIBRARY explicitly (for example to force
# /MD in every configuration); overriding it here causes runtime-library
# mismatches such as LNK2038 (MDd_DynamicDebug vs MD_DynamicRelease).
if (NOT DEFINED CMAKE_MSVC_RUNTIME_LIBRARY)
if (protobuf_MSVC_STATIC_RUNTIME)
set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreaded$<$<CONFIG:Debug>:Debug>)
else()
set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreaded$<$<CONFIG:Debug>:Debug>DLL)
endif()
endif()
endif (protobuf_BUILD_SHARED_LIBS)

View file

@ -3,7 +3,7 @@
module(
name = "protobuf",
version = "36.0-dev", # Automatically updated on release
version = "37.0-dev", # Automatically updated on release
bazel_compatibility = [">=8.0.0"],
compatibility_level = 1,
repo_name = "com_google_protobuf",
@ -19,19 +19,16 @@ bazel_dep(name = "apple_support", version = "2.3.0", repo_name = "build_bazel_ap
# Unused but must be pinned to avoid old broken versions
bazel_dep(name = "rules_proto", version = "7.1.0")
#ifndef PROTO2_OPENSOURCE
# LINT.IfChange
#endif // PROTO2_OPENSOURCE
# protoc dependencies
bazel_dep(name = "abseil-cpp", version = "20250512.1")
bazel_dep(name = "rules_cc", version = "0.2.18")
bazel_dep(name = "zlib", version = "1.3.1.bcr.5")
#ifndef PROTO2_OPENSOURCE
# LINT.ThenChange(//depot/google3/third_party/protobuf/compiler/notices.h)
#endif // PROTO2_OPENSOURCE
# other dependencies
bazel_dep(name = "bazel_features", version = "1.33.0", repo_name = "proto_bazel_features")
proto_bazel_features = use_repo_rule("//bazel/private/oss:proto_bazel_features.bzl", "proto_bazel_features")
proto_bazel_features(name = "proto_bazel_features")
bazel_dep(name = "bazel_skylib", version = "1.9.0")
bazel_dep(name = "jsoncpp", version = "1.9.6.bcr.2")
bazel_dep(name = "rules_java", version = "8.6.1")
@ -39,7 +36,7 @@ bazel_dep(name = "rules_jvm_external", version = "6.7")
bazel_dep(name = "rules_kotlin", version = "2.3.20")
bazel_dep(name = "rules_license", version = "1.0.0")
bazel_dep(name = "rules_pkg", version = "1.0.1")
bazel_dep(name = "rules_python", version = "1.6.0")
bazel_dep(name = "rules_python", version = "2.3.0")
bazel_dep(name = "rules_rust", version = "0.69.0")
bazel_dep(name = "rules_ruby", version = "0.20.1", dev_dependency = True)
@ -75,6 +72,7 @@ ruby.toolchain(
version = "system",
)
use_repo(ruby, "ruby")
ruby.bundle_fetch(
name = "protobuf_bundle",
gem_checksums = {
@ -193,10 +191,10 @@ rust.toolchain(
versions = ["1.85.0"],
)
crate = use_extension("@rules_rust//crate_universe:extension.bzl", "crate")
crate = use_extension("@rules_rust//crate_universe:extensions.bzl", "crate")
crate.spec(
package = "googletest",
version = ">0.0.0",
version = "0.14.2",
)
crate.spec(
package = "linkme",
@ -204,15 +202,16 @@ crate.spec(
)
crate.spec(
package = "paste",
version = ">=1",
version = "1.0.15",
)
crate.spec(
package = "quote",
version = ">=1",
version = "1.0.38",
)
crate.spec(
features = ["full"],
package = "syn",
version = ">=2",
version = ">=2, <3",
)
crate.from_specs()
use_repo(crate, crate_index = "crates")
@ -266,7 +265,6 @@ protobuf_maven_dev.install(
use_repo(protobuf_maven_dev, "protobuf_maven_dev")
bazel_dep(name = "googletest", version = "1.17.0.bcr.2", dev_dependency = True)
bazel_dep(name = "rules_buf", version = "0.3.0", dev_dependency = True)
bazel_dep(name = "rules_testing", version = "0.9.0", dev_dependency = True)
bazel_dep(
name = "abseil-py",
@ -306,18 +304,6 @@ archive_override(
urls = ["https://github.com/protocolbuffers/protobuf/releases/download/v25.0/protobuf-25.0.tar.gz"],
)
bazel_dep(name = "com_google_protobuf_previous_release", version = "33.0", dev_dependency = True)
archive_override(
module_name = "com_google_protobuf_previous_release",
integrity = "sha256-y8U2BkcGtijc/lB77zhu8+IhTVY2V2EilvF4GqFV7gc=",
patch_strip = 1,
patches = [
"@com_google_protobuf//:patches/protobuf_v33/0001-Update-module-name.patch",
],
strip_prefix = "protobuf-33.0",
urls = ["https://github.com/protocolbuffers/protobuf/releases/download/v33.0/protobuf-33.0.tar.gz"],
)
# Register C++ toolchains for cross-compilation. These are used for compiling release binaries of
# protoc and the Python extension. They are disabled unless --//toolchain:release=true is passed.
register_toolchains(
@ -360,3 +346,58 @@ bazel_dep(name = "jq.bzl", version = "0.6.1", dev_dependency = True)
jq = use_extension("@jq.bzl//jq:extensions.bzl", "toolchains", dev_dependency = True)
use_repo(jq, "jq_toolchains")
flag_alias(
name = "experimental_proto_descriptor_sets_include_source_info",
starlark_flag = "@//bazel/flags:experimental_proto_descriptor_sets_include_source_info",
)
flag_alias(
name = "experimental_protoc_opts",
starlark_flag = "@//bazel/flags:protocopt",
)
flag_alias(
name = "protocopt",
starlark_flag = "@//bazel/flags:protocopt",
)
flag_alias(
name = "proto_compiler",
starlark_flag = "@//bazel/flags:proto_compiler",
)
flag_alias(
name = "proto_toolchain_for_cc",
starlark_flag = "@//bazel/flags/cc:proto_toolchain_for_cc",
)
flag_alias(
name = "proto_toolchain_for_java",
starlark_flag = "@//bazel/flags/java:proto_toolchain_for_java",
)
flag_alias(
name = "proto_toolchain_for_javalite",
starlark_flag = "@//bazel/flags/java:proto_toolchain_for_javalite",
)
flag_alias(
name = "strict_proto_deps",
starlark_flag = "@//bazel/flags:strict_proto_deps",
)
flag_alias(
name = "strict_public_imports",
starlark_flag = "@//bazel/flags:strict_public_imports",
)
flag_alias(
name = "cc_proto_library_header_suffixes",
starlark_flag = "@//bazel/flags/cc:cc_proto_library_header_suffixes",
)
flag_alias(
name = "cc_proto_library_source_suffixes",
starlark_flag = "@//bazel/flags/cc:cc_proto_library_source_suffixes",
)

View file

@ -5,7 +5,7 @@
# dependent projects use the :git notation to refer to the library.
Pod::Spec.new do |s|
s.name = 'Protobuf'
s.version = '5.36.0'
s.version = '5.37.0'
s.summary = 'Protocol Buffers v.3 runtime library for Objective-C.'
s.homepage = 'https://github.com/protocolbuffers/protobuf'
s.license = 'BSD-3-Clause'

View file

@ -1,4 +1,401 @@
To report security concerns or vulnerabilities within protobuf, please use
Google's official channel for reporting these.
# Security Policy
https://bughunters.google.com/report
This document describes the security model, threat boundaries, and security
recommendations for Protobuf. It is intended to help developers understand what
security guarantees Protobuf provides, and how to safely parse and serialize
messages.
--------------------------------------------------------------------------------
## Reporting a Vulnerability
If you believe you have discovered a security vulnerability in Protobuf, please
report it via
[Google's official vulnerability disclosure channel](https://bughunters.google.com/report).
For reports that do not meet the criteria or bar for the Google Vulnerability
Reward Program (VRP) but are still security-sensitive, you can privately report
them by opening a
[draft GitHub Security Advisory](https://github.com/protocolbuffers/protobuf/security/advisories/new).
If an issue relates to something which is listed as Best Effort or Out of Threat
Model below, please open a
[public issue](https://github.com/protocolbuffers/protobuf/issues) instead.
--------------------------------------------------------------------------------
## Best Practices
* Handle `.proto` files as "code" by default, similarly to the handling of
`.java` or `.cc` files. Executing untrusted code can potentially be a supply
chain attack vector.
* Prefer to use the binary wire format encoding where possible: all
Google-maintained Protobuf implementations treat binary wire format parsing
as the primary use case to handle untrusted inputs. Other formats are
considered secondary.
* **Apply Defensive limits:** Prefer to have a layer that applies defensive
limits or custom filtering around the Protobuf parse: for example gRPC
enforces a 4 MiB payload limit by default. We recommend having sensible
limits defensively applied on all untrusted inputs.
* While all Google maintained Protobuf implementations are considered to be
intended to be used with untrusted inputs, not all runtimes are equally
hardened:
* **JavaProto** (including the Kotlin bindings) is recommended as the
default implementation for the best security posture, as it benefits
from the JVM's memory safety guarantees.
* **C++Proto** is recommended for applications requiring optimal
performance, and has been extensively fuzzed and hardened such that
Google uses it without sandboxing to parse untrusted binary format
inputs in critical surfaces. When using C++, developers must remain
aware of native memory management risks.
* In languages that have multiple supported implementations, strongly
prefer to use the default implementation for best security. The
non-default implementations are generally supported for more exotic
use-cases and may not have as much hardening attention. The default
Python and PHP runtimes use a C extension that has been hardened more
than the fallback behaviors that that do not use any C extension.
* **Use latest releases:** Ensure that the generated code and the runtime
library version match exactly and are kept up to date with the latest patch
release. Certain obscure and low severity issues may only be patched on the
latest release.
## Threat Model and Security Boundaries
Protobuf is a serialization format designed to parse data efficiently. Depending
on the input format, language runtime, and integration context, different parts
of the Protobuf ecosystem are hardened against adversarial inputs.
Our threat model divides surfaces into three tiers:
### Proactively Hardened
These surfaces are fully supported and hardened against adversarial inputs.
* Security vulnerabilities identified in these paths are treated with high
priority, actively fixed, and issued CVEs.
* Where necessary, certain patches that are technically breaking may be done
if it is inherently necessary to close a security issue. This also includes
that gencode-runtime version compatibility guarantees may be broken if it is
strictly necessary to close a security issue (see documentation
[here](https://protobuf.dev/support/cross-version-runtime-guarantee/#exception)).
These cases are rare and we will avoid this wherever it is possible to close
the security concern without a breaking change.
* Google trusts these surfaces enough to use in sensitive, publicly exposed
endpoints without sandboxing.
### Reactively hardened
The Protobuf team welcomes bug reports and pull requests to improve the
hardening of these surfaces. However, we typically will not break backwards
compatibility guarantees to address security issues in these areas (especially
for lower severity risks).
Defensive hardening is applied to these surfaces, but with weaker guarantees
compared to our hardened surfaces.
* Serious security issues are still highly prioritized for fixing on these
surfaces.
* We do not break backwards compatibility guarantees to address lower severity
issues on these surfaces outside of major version bumps. In some cases this
means low-impact known issues may even be left open if they inherently
cannot be closed without a breaking change. Serious issues (like RCE) would
still be urgently addressed.
* When using these surfaces on potentially malicious inputs, especially
security sensitive usages are recommended to consider application-level
isolation (such as sandboxing) or other defensive handling.
### Outside of CVE Threat Model (Best-Effort Hardened)
These are surfaces where Protobuf libraries are not as hardened against
adversarial inputs.
Outside of threat model does not mean we do not care at all about
security-relevant behaviors on these surfaces: we still apply defensive
hardening where feasible, and welcome reports on these surfaces. However, as
these surfaces are expected to be used with trusted inputs, the higher priority
for those cases is other topics including stability, performance, and developer
ergonomics.
## Proactively Hardened
### Parsing of Binary Wire Format Encoded Data **(Primary Use Case)**
This is considered the primary surface of security concern in Protobuf
libraries.
In this use case, the `.proto` schema files, the compiler (`protoc`), and the
generated code are fully trusted. The incoming binary wire format bytes are
untrusted and may be adversarial.
The parsing library will safely process or reject any arbitrary byte stream
without exposing the server to memory corruption, out-of-bounds reads/writes, or
remote code execution (RCE).
Note that the intended surface here is only parsing: once a message is in-memory
it is treated as a trusted object in our threat model. For that reason,
serialization or any other in-memory handling of parsed objects is not
considered a surface within the threat model. For example, parsing an untrusted
wire format payload should not be able to reach uncontrolled recursion, but
serializing an arbitrarily in-memory object may. This is similar in nature to
how modern browsers do not throw `RangeError` on `JSON.parse()`, but do on
`JSON.stringify()`.
### Parsing of ProtoJSON Format
[ProtoJSON](https://protobuf.dev/programming-guides/json/) allows using `.proto`
schemas with standard JSON encoding. This is considered an ancillary supported
encoding, and the binary format should be preferred where feasible.
Under the same threat model as publicly exposed binary wire format services,
ProtoJSON parsing is intended to be used with untrusted inputs. ProtoJSON
serialization is similarly not considered within the threat model risks.
--------------------------------------------------------------------------------
## Reactively Hardened
These areas are defensive against malicious inputs, but application-level
defense (such as sandboxing) is recommended.
### Parsing Text Format
Text Format is designed for local debugging, testing, and managing trusted
configurations by developers. It is not intended to be used as an interchange
format and is not recommended to expose public services which consume Text
Format as an encoding.
Note: Text Format parsing currently does not enforce any depth limit in several
supported runtimes (they support opt-in depth limits). We cannot enforce a depth
limit by default without breaking backwards compatibility, but may begin to
enforce depth limits by default as part of a future breaking change release.
### Lite Runtimes (C++ Lite, Java Lite) Denial of Service Risks
Lite runtimes target mobile and web usage: they are optimized for those
constrained envirnoments, and prioritize small binary size at the expense of
other properties.
Lite runtimes are still intended to be used to parse untrusted inputs, but DoS
issues are considered to be much less severe in mobile contexts, as the
opportunity and impact of an attacker successfully freezing one app is low
compared to reducing the availability of a public service.
We still intend to mitigate such risks, but Lite gencode/runtimes are not
recommended for servers exposing public endpoints.
### 'Wrong Kind of Exception Thrown'
In memory-safe runtimes (Java, Go, Python, C#), reaching a catchable exception
or runtime error (such as `IndexOutOfBoundsException` or `StackOverflowError`)
instead of the declared exception (such as `InvalidProtocolBufferException`) is
treated as an important bug to fix, but is considered to be a minor security
concern relative to serious issues like native heap corruption, data leakage,
remote code execution, or DoS vectors from unbounded computation or memory use.
It is recommended that RPC handler code be defensive against unexpected
exceptions if they are exceptionally sensitive to such behavior.
## Outside of CVE Threat Model (Best-effort Hardened)
### `protoc` CLI
The `protoc` CLI is an offline developer tool. `.proto` files are considered
source code (equivalent to `.java` or `.cpp` source files).
A supported modality of the CLI is to parse untrusted `proto` files to emit
`FileDescriptors` which can enable further machine processing of the schemas.
While `protoc` is hardened on a best-effort basis for this use case, we
recommend using defensive validation and sandboxing whenever running `protoc`
against potentially malicious inputs.
Untrusted flags being passed to `protoc` is fully outside of our threat model:
CLI flags are never be adversarial and arbitrary behavior driven by CLI flags
may be working as intended.
Caution: Compiling and executing generated code from untrusted schemas is
functionally equivalent to compiling and running arbitrary third-party `.java`
or `.cpp` source code and executing it: there may be intentional language
features which act as intentional code injection into the generated code. You
must treat untrusted `.proto` files the same as any other programming language
code in terms of supply-chain risk in this way, and not blindly execute the
gencode which was generated off of untrusted `.proto` files.
### DynamicMessage on Untrusted Descriptors
Protobuf supports encoding schemas into a Protobuf message format (e.g.
`FileDescriptorSet` or `DescriptorProto`). These messages can be handled as any
other Protobuf type. Parsing untrusted binary-encoded DescriptorProto falls
within the "primary use-case" described above.
In addition to simply processing DescriptorProto, it is additionally possible in
most runtimes to use a type named `DynamicMessage` which allows for using
runtime-loaded descriptors instead of using generated code and to use that type
with the reflection APIs.
For use-cases sensetive to DoS risks, it is recommended to use `DynamicMessage`
only with trusted descriptors (via trusted side channel source / config pushes).
When using `DynamicMessage` with a descriptor sourced from an untrusted source,
you may need to validate and sanitize them as you would user provided SQL.
Caution: Usage of `DynamicMessage` with malicious descriptors reaching an RCE or
information leak would still be treated as a high priority issue. However, there
are inherently reachable cases of where malicious descriptors used with
`DynamicMessage` can reach behavior which may otherwise be considered a Denial
of Service risk under our primary threat model. For example, it will be
reachable to hit memory use which is O(N*M) where N is "# of messages observed
on the wire" and M is "size of the message definition". Since untrusted
descriptors gives an affordance for arbitrarily large message definitions, using
DynamicMessage with untrusted descriptors and untrusted binary format inherently
can have memory amplification risks.
### Adversarial Application Code
Violating runtime API constraints or passing invalid arguments directly to a C++
API is considered an application integration error rather than a library
vulnerability.
Protobuf libraries do harden against the impact of certain classes of mistakes
being worse; for example, we often will panic if we can detect that an out of
bounds memory reads will occur in some cases. This is considered
defense-in-depth and misuse is not considered a vulnerability.
Excepting the surfaces enumerated above as hardened, Protobuf APIs in
memory-safe languages reaching memory safety problems on 'bad' parameters is
considered an high priority bug, but typically not within scope for CVE
disclosure.
In languages like PHP, this means that use of PHP Protobuf in an unconstrained
multi-tenant system where malicious application code may try to attack other
jobs concurrently running is not within our threat model.
Examples:
* Passing negative or invalid buffer size parameters directly to
`ParseFromArray` in C++ is wrong application code. It may be hardened to
panic instead of risk out of bounds memory reads, but is not intended to be
gracefully handled as a malformed-wire-bytes input would be (following C++
idioms).
* In a memory language Python, if code like `msg.repeatedField[-2147483649]`
can reach a segfault, that is considered an important bug to fix, but it is
not considered to be within CVE scope.
### Differential Parsing (Gateway propagation of original payload)
Differential parsing is a risk stemming from by two different libraries parsing
the same data with different interpretations.
In some contexts and for some formats differential parsing is considered a
security-sensitive topic. The primary risk is around flows that would validate
in a gateway, forwarding the data unmodified, and then a backend handles the
original payload and interprets the data differently, bypassing the intended
checks.
The Protobuf binary format is explicitly designed for propagation of unknown
fields, where the gateway may not be aware of the content at all and forwarding
will result in the next server who has an updated version of the schema will
corresponding parse to a different interpretation because it is aware of those
fields.
Additionally, there may be certain edge-case byte sequences where a few
different interpretations which may be considered acceptable within spec. Google
maintained runtimes will never encode these sequences, but they may successfully
parse them.
When using ProtoJSON format, the underlying JSON format itself contains
significant inherent ambiguities (as noted in ECMA-404 and RFC-8259, including
that there is no spec around the handling of duplicate keys and numeric
precision). As ProtoJSON is built on top of that foundation, ProtoJSON inherits
these ambiguities where certain sequences may have multiple different spec
permissible implementations. Spec Protobuf implementations strongly attempt to
avoid ever encoding such sequences (including that they always quote large
int64s, and don't emit duplicate fields), but the parsing behavior may differ in
such sequences and ProtoJSON cannot spec behavior which is unimplementable when
using ecosystem of JSON parsers.
For both formats, an architecture where a gateway performs validation and
forwards the original user request to a second server which reparses the user's
request but presumes validation has already occurred is outside of our threat
model.
For best security practice, it is recommended to:
* Use a different set of messages schema for your public API and internal
messages. Besides the security benefits, this decoupling also allows for
easier evolution of your system, where public APIs often need to change
slowly but internal ones can evolve faster.
* Where you do propagate the same message type, always prefer for the gateway
to parse and reserialize instead of forwarding the original payload
verbatim, as this will commonly normalize edge case byte sequences.
* Wherever possible to have each microservice verify any relevant ACLs for
actions it is taking based on its interpretation of the request rather than
rely on gateway validation.
### Specific depth cap exceeded but without uncontrolled recursion
Protobuf parsers apply depth limits (which are configurable): the purpose of
these depth limits is to prevent resource exhaustion issues stemming from
uncontrolled recursion.
To generally maintain consistent and interoperable behavior, we intend these
depth limits to be consistent in behavior in what payloads will be accepted or
rejected for a given integer depth.
Issues where an edge case is successfully parsed which is deeper than the exact
intended limit, this is viewed as a simple bug as long as it does not expose
meaningful resource exhaustion risks.
We welcome reports and patches for issues of that nature, but do not view it as
a security concern and so these issues can be filed via our public GitHub Issues
flow.
### Canonical Representation and Signature Verification
There is **no canonical representation** of Protobuf messages.
* **Deterministic Serialization:** Many runtimes support deterministic
serialization, which guarantees that a given build of a binary will
serialize the same message to the same sequence of bytes. However,
deterministic does not mean canonical: rebuilding the binary, changing the
compiler version, or minor schema modifications can legally result in an
alternate serialized byte representation that would have the same
interpretation when parsed. For more details, see
[Protobuf Serialization is Not Canonical](https://protobuf.dev/programming-guides/serialization-not-canonical/).
* **Recommendation:** Do not use the serialized byte output of Protobuf
messages to compute stable cryptographic signatures. You may still sign a
given encoded byte sequence, knowing that there are other byte sequences
that would be equally valid representations of the same message. If you need
a stable signature of a given message, you must define and implement your
own canonicalization specification over the parsed message fields and not
over the encoded messages.
### Risks if wire bytes are modified in-transit
In terms of transport security, Protobuf is functionally equivalent to a
plaintext format: the encoding has no built-in signing or other integrity
features.
Best practice is to transport Protobuf encoded data over https. If signing or
other integrity features are needed, it is expected to be done in the layers
built top of the Protobuf libraries.
### API surfaces which not intended for direct public use
Protobuf has APIs which are not advertised or intended for direct public use.
These APIs may have non-obvious invariants for how they must be used.
Most notably, `upb` is a library which is used as an implementation detail API
of our other Protobuf libraries to use. `upb` itself is a highly optimized C
library which requires callers maintain invariants to be sound.
Security issues may arise if our language-specific runtimes which use `upb` do
not maintain those necessary invariants, or if `upb` has reachable bad behavior
when all intended invariants are maintained. However, it is not considered not a
security topic if arbitrary bad behavior may be reachable if `upb` APIs are
directly misused (including that `upb's` APIs accept MiniDescriptors/MiniTables
which are considered trusted types, and so will have arbitrary behavior if those
types do not meet the intended invariants).

View file

@ -262,29 +262,6 @@ http_archive(
url = "https://github.com/bazelbuild/rules_testing/releases/download/v0.9.0/rules_testing-v0.9.0.tar.gz",
)
# For checking breaking changes to well-known types from the previous release version.
http_archive(
name = "com_google_protobuf_previous_release",
integrity = "sha256-EKDVjzmhqQnpXgDougtbHcZNApl/dBFRlTorNln254w=",
strip_prefix = "protobuf-29.0",
urls = ["https://github.com/protocolbuffers/protobuf/releases/download/v29.0/protobuf-29.0.tar.gz"],
)
http_archive(
name = "rules_buf",
integrity = "sha256-Hr64Q/CaYr0E3ptAjEOgdZd1yc+cBjp7OG1wzuf3DIs=",
strip_prefix = "rules_buf-0.3.0",
urls = [
"https://github.com/bufbuild/rules_buf/archive/refs/tags/v0.3.0.zip",
],
)
load("@rules_buf//buf:repositories.bzl", "rules_buf_dependencies", "rules_buf_toolchains")
rules_buf_dependencies()
rules_buf_toolchains(version = "v1.32.1")
register_toolchains(
"//toolchain:osx-x86_64-toolchain",
"//toolchain:osx-aarch_64-toolchain",

View file

@ -74,6 +74,19 @@ def _get_import_path(proto_file):
return repo_path
def _output_directory(proto_info, root):
"""Returns the physical output directory path for generated proto files.
This computes the correct directory path, correctly routing outputs into the virtual imports
directory if the `proto_library` uses `import_prefix` or `strip_import_prefix`.
Args:
proto_info: (ProtoInfo) The ProtoInfo provider from the proto_library.
root: (File|root) The root directory (e.g., `ctx.bin_dir` or `ctx.genfiles_dir`) under which
the generated files should be placed.
Returns:
(str) The physical output directory path.
"""
proto_source_root = proto_info.proto_source_root
if proto_source_root.startswith(root.path):
#TODO: remove this branch when bin_dir is removed from proto_source_root
@ -344,6 +357,7 @@ proto_common = struct(
experimental_should_generate_code = _experimental_should_generate_code,
experimental_filter_sources = _experimental_filter_sources,
get_import_path = _get_import_path,
output_directory = _output_directory,
ProtoLangToolchainInfo = ProtoLangToolchainInfo,
INCOMPATIBLE_ENABLE_PROTO_TOOLCHAIN_RESOLUTION = toolchains.INCOMPATIBLE_ENABLE_PROTO_TOOLCHAIN_RESOLUTION,
INCOMPATIBLE_PASS_TOOLCHAIN_TYPE = True,

View file

@ -1,5 +1,6 @@
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
load("@bazel_skylib//rules:common_settings.bzl", "bool_flag", "string_flag", "string_list_flag")
load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")
load("//bazel/private:compat_flag.bzl", "compat_bool_flag", "compat_label_flag", "compat_string_list_flag")
package(
default_applicable_licenses = ["//:license"],
@ -25,20 +26,24 @@ filegroup(
],
)
bool_flag(
compat_bool_flag(
name = "experimental_proto_descriptor_sets_include_source_info",
build_setting_default = False,
fragment_field = "experimental_proto_descriptorsets_include_source_info",
scope = "universal",
)
label_flag(
compat_label_flag(
name = "proto_compiler",
build_setting_default = "@bazel_tools//tools/proto:protoc",
executable = True,
fragment_field = "proto_compiler",
)
string_list_flag(
compat_string_list_flag(
name = "protocopt",
build_setting_default = [],
fragment_field = "experimental_protoc_opts",
scope = "universal",
)
@ -75,39 +80,45 @@ config_setting(
)
# TODO: deprecate this flag.
string_flag(
compat_bool_flag(
name = "strict_proto_deps",
build_setting_default = "error",
build_setting_default = True,
fragment_field = "strict_proto_deps",
scope = "universal",
values = [
"off",
"OFF",
"warn",
"WARN",
"error",
"ERROR",
"strict",
"STRICT",
"default",
"DEFAULT",
],
values = {
False: [
"off",
"OFF",
],
True: [
"warn",
"WARN",
"error",
"ERROR",
"strict",
"STRICT",
],
},
)
# TODO: deprecate this flag.
string_flag(
compat_bool_flag(
name = "strict_public_imports",
build_setting_default = "off",
build_setting_default = False,
fragment_field = "strict_public_imports",
scope = "universal",
values = [
"off",
"OFF",
"warn",
"WARN",
"error",
"ERROR",
"strict",
"STRICT",
"default",
"DEFAULT",
],
values = {
False: [
"off",
"OFF",
],
True: [
"warn",
"WARN",
"error",
"ERROR",
"strict",
"STRICT",
],
},
)

View file

@ -1,5 +1,6 @@
load("@bazel_skylib//rules:common_settings.bzl", "bool_flag", "string_list_flag")
load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")
load("@rules_shell//shell:sh_binary.bzl", "sh_binary")
load("//bazel/private:compat_flag.bzl", "compat_label_flag", "compat_string_list_flag")
package(
default_applicable_licenses = ["//:license"],
@ -8,9 +9,10 @@ package(
exports_files(["BUILD"])
label_flag(
compat_label_flag(
name = "proto_toolchain_for_cc",
build_setting_default = "@bazel_tools//tools/proto:cc_toolchain",
fragment_field = "proto_toolchain_for_cc",
)
alias(
@ -19,14 +21,16 @@ alias(
deprecation = "Use //bazel/flags:protocopt instead.",
)
string_list_flag(
compat_string_list_flag(
name = "cc_proto_library_header_suffixes",
build_setting_default = [".pb.h"],
fragment_field = "cc_proto_library_header_suffixes",
scope = "universal",
)
string_list_flag(
compat_string_list_flag(
name = "cc_proto_library_source_suffixes",
build_setting_default = [".pb.cc"],
fragment_field = "cc_proto_library_source_suffixes",
scope = "universal",
)

View file

@ -8,75 +8,22 @@ visibility([
"//third_party/grpc/bazel",
])
# Maps flag names to their native reference
_FLAGS = {
"protocopt": struct(
native = lambda ctx: getattr(ctx.fragments.proto, "experimental_protoc_opts"),
default = [],
),
"experimental_proto_descriptor_sets_include_source_info": struct(
native = lambda ctx: getattr(ctx.attr, "_experimental_proto_descriptor_sets_include_source_info_native")[BuildSettingInfo].value,
default = False,
),
"proto_compiler": struct(native = lambda ctx: getattr(ctx.attr, "_proto_compiler_native")[BuildSettingInfo].value, default = "@bazel_tools//tools/proto:protoc"),
"strict_proto_deps": struct(
native = lambda ctx: getattr(ctx.attr, "_strict_proto_deps_native")[BuildSettingInfo].value,
default = "error",
),
"strict_public_imports": struct(
native = lambda ctx: getattr(ctx.attr, "_strict_public_imports_native")[BuildSettingInfo].value,
default = "off",
),
"cc_proto_library_header_suffixes": struct(
native = lambda ctx: getattr(ctx.fragments.proto, "cc_proto_library_header_suffixes"),
default = [".pb.h"],
),
"cc_proto_library_source_suffixes": struct(
native = lambda ctx: getattr(ctx.fragments.proto, "cc_proto_library_source_suffixes"),
default = [".pb.cc"],
),
"proto_toolchain_for_java": struct(
native = lambda ctx: "//:java_toolchain",
default = "//:java_toolchain",
),
"proto_toolchain_for_javalite": struct(
native = lambda ctx: "//:javalite_toolchain",
default = "//:javalite_toolchain",
),
"proto_toolchain_for_cc": struct(
native = lambda ctx: "//:cc_toolchain",
default = "//:cc_toolchain",
),
}
def get_flag_value(ctx, flag_name):
"""Returns the value of the given flag in Starlark if it's set, otherwise reads the Java flag value, if the proto fragment exists.
"""Returns the value of the given flag attribute from rule context.
Args:
ctx: The rule context.
flag_name: The name of the flag to get the value for.
Returns:
The value of the flag.
The value of the flag. If the value is a list, returns a mutable copy.
"""
# We probably got here from toolchains.find_toolchain. Leave the attribute alone.
if flag_name not in _FLAGS:
return getattr(ctx.attr, "_" + flag_name)
starlark_flag = getattr(ctx.attr, "_" + flag_name)
# Label flags don't have a BuildSettingInfo, just get the value.
if "toolchain" in flag_name:
starlark_flag_is_set = starlark_flag.label != _FLAGS[flag_name].default
starlark_value = starlark_flag
else:
starlark_flag_is_set = starlark_flag[BuildSettingInfo].value != _FLAGS[flag_name].default
starlark_value = starlark_flag[BuildSettingInfo].value
# Starlark flags take precedence over native flags.
# Also of course, use the Starlark value if the proto fragment no longer exists.
if starlark_flag_is_set or not hasattr(ctx.fragments, "proto"):
return starlark_value
else:
return _FLAGS[flag_name].native(ctx)
attr_val = getattr(ctx.attr, "_" + flag_name)
if BuildSettingInfo in attr_val:
val = attr_val[BuildSettingInfo].value
if type(val) == "list":
return list(val)
return val
if type(attr_val) == "list":
return list(attr_val)
return attr_val

View file

@ -1,7 +1,10 @@
load("//bazel/private:compat_flag.bzl", "compat_label_flag")
package(
default_applicable_licenses = ["//:license"],
default_visibility = [
"//bazel/private:__pkg__",
"//bazel/tests:__subpackages__",
"//devtools/blaze/exoblaze/mac/integration:__subpackages__",
"//devtools/blaze/integration:__subpackages__",
],
@ -11,12 +14,14 @@ exports_files(
["BUILD"],
)
label_flag(
compat_label_flag(
name = "proto_toolchain_for_java",
build_setting_default = "@bazel_tools//tools/proto:java_toolchain",
fragment_field = "proto_toolchain_for_java",
)
label_flag(
compat_label_flag(
name = "proto_toolchain_for_javalite",
build_setting_default = "@bazel_tools//tools/proto:javalite_toolchain",
fragment_field = "proto_toolchain_for_javalite",
)

View file

@ -1,5 +1,4 @@
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
load(":native_bool_flag.bzl", "native_bool_flag")
package(default_applicable_licenses = ["//:license"])
@ -168,32 +167,9 @@ bzl_library(
],
)
native_bool_flag(
name = "experimental_proto_descriptor_sets_include_source_info",
flag = "experimental_proto_descriptor_sets_include_source_info",
match_value = "true",
visibility = ["//bazel:__subpackages__"],
)
native_bool_flag(
name = "strict_proto_deps",
flag = "strict_proto_deps",
match_value = "off",
result = False,
visibility = ["//bazel:__subpackages__"],
)
native_bool_flag(
name = "strict_public_imports",
flag = "strict_public_imports",
match_value = "off",
result = False,
visibility = ["//bazel:__subpackages__"],
)
bzl_library(
name = "native_bool_flag_bzl",
srcs = ["native_bool_flag.bzl"],
name = "compat_flag_bzl",
srcs = ["compat_flag.bzl"],
visibility = ["//visibility:private"],
deps = ["@bazel_skylib//rules:common_settings"],
)
@ -203,8 +179,8 @@ filegroup(
testonly = True,
srcs = [
"BUILD",
":compat_flag_bzl",
":java_proto_library_bzl",
":native_bool_flag_bzl",
":toolchain_helpers_bzl",
"//bazel:for_bazel_tests",
"//bazel/private/oss/toolchains:for_bazel_tests",

View file

@ -0,0 +1,292 @@
# Protocol Buffers - Google's data interchange format
# Copyright 2008 Google Inc. All rights reserved.
#
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file or at
# https://developers.google.com/open-source/licenses/bsd
"""Helper rules and macros for custom proto flags."""
load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo")
load("@rules_cc//cc/common:cc_info.bzl", "CcInfo")
load("@rules_java//java/common:java_info.bzl", "JavaInfo")
load("@rules_java//java/common:proguard_spec_info.bzl", "ProguardSpecInfo")
load("//bazel/common:proto_lang_toolchain_info.bzl", "ProtoLangToolchainInfo")
load("//bazel/private:native.bzl", "HAS_NATIVE_PROTO_FLAGS")
def _compat_bool_rule_impl(ctx):
starlark_val = ctx.build_setting_value
# 1. Starlark flag takes precedence if explicitly passed (not "default")
if starlark_val != "default":
if starlark_val in ctx.attr.true_values:
return [BuildSettingInfo(value = True)]
if starlark_val in ctx.attr.false_values:
return [BuildSettingInfo(value = False)]
allowed = ctx.attr.true_values + ctx.attr.false_values + ["default"]
fail("Invalid value '%s' for flag %s. Allowed values are: %s" % (
starlark_val,
ctx.label,
allowed,
))
# 2. Native flag fallback (if HAS_NATIVE_PROTO_FLAGS and present on ctx.fragments.proto)
if HAS_NATIVE_PROTO_FLAGS and hasattr(ctx.fragments, "proto") and ctx.attr.fragment_field:
if hasattr(ctx.fragments.proto, ctx.attr.fragment_field):
native_val = getattr(ctx.fragments.proto, ctx.attr.fragment_field)()
if native_val == True or native_val in ctx.attr.true_values:
return [BuildSettingInfo(value = True)]
if native_val == False or native_val in ctx.attr.false_values:
return [BuildSettingInfo(value = False)]
# 3. Default fallback
return [BuildSettingInfo(value = ctx.attr.default_value)]
_compat_bool_rule = rule(
implementation = _compat_bool_rule_impl,
build_setting = config.string(flag = True),
fragments = ["proto"] if HAS_NATIVE_PROTO_FLAGS else [],
attrs = {
"fragment_field": attr.string(),
"true_values": attr.string_list(default = []),
"false_values": attr.string_list(default = []),
"default_value": attr.bool(default = False),
"scope": attr.string(),
},
)
def compat_bool_flag(
*,
name,
fragment_field = None,
build_setting_default = False,
values = None,
**kwargs):
"""Creates a custom build setting flag reconciling Starlark/fragments.
Args:
name: The target name for the Starlark build setting flag.
fragment_field: The field name in ctx.fragments.proto (e.g. "strict_proto_deps"), if any.
build_setting_default: Fallback default boolean value if neither Starlark nor fragment is set.
values: Dict mapping booleans (True/False) to lists of accepted string flag values.
Defaults to {True: ["true", "TRUE", "1"], False: ["false", "FALSE", "0"]}.
**kwargs: Additional rule arguments (such as `scope`).
"""
if values == None:
values = {
True: ["true", "TRUE", "1"],
False: ["false", "FALSE", "0"],
}
true_vals = values.get(True, [])
false_vals = values.get(False, [])
starlark_true_vals = [v for v in true_vals if v != "default"]
starlark_false_vals = [v for v in false_vals if v != "default"]
_compat_bool_rule(
name = name,
build_setting_default = "default",
fragment_field = fragment_field,
true_values = starlark_true_vals,
false_values = starlark_false_vals,
default_value = build_setting_default,
**kwargs
)
def _compat_string_list_rule_impl(ctx):
starlark_val = ctx.build_setting_value
# 1. Starlark flag takes precedence if explicitly passed (not empty)
if starlark_val:
return [BuildSettingInfo(value = starlark_val)]
# 2. Native flag fallback (if HAS_NATIVE_PROTO_FLAGS and present on ctx.fragments.proto)
if HAS_NATIVE_PROTO_FLAGS and hasattr(ctx.fragments, "proto") and ctx.attr.fragment_field:
if hasattr(ctx.fragments.proto, ctx.attr.fragment_field):
val = getattr(ctx.fragments.proto, ctx.attr.fragment_field)
if type(val) == "list":
return [BuildSettingInfo(value = val)]
else:
return [BuildSettingInfo(value = val())]
# 3. Default fallback
return [BuildSettingInfo(value = ctx.attr.default_value)]
_compat_string_list_rule = rule(
implementation = _compat_string_list_rule_impl,
build_setting = config.string_list(flag = True, repeatable = True),
fragments = ["proto"] if HAS_NATIVE_PROTO_FLAGS else [],
attrs = {
"fragment_field": attr.string(),
"default_value": attr.string_list(default = []),
"scope": attr.string(),
},
)
def compat_string_list_flag(
*,
name,
fragment_field = None,
build_setting_default = None,
**kwargs):
"""Creates a custom string-list build setting reconciling Starlark/fragments.
Args:
name: The target name for the Starlark build setting flag.
fragment_field: The field name in ctx.fragments.proto (e.g. "experimental_protoc_opts"), if any.
build_setting_default: Fallback default string list value if neither Starlark nor fragment is set.
**kwargs: Additional rule arguments (such as `scope`).
"""
default_vals = build_setting_default if build_setting_default != None else []
_compat_string_list_rule(
name = name,
build_setting_default = default_vals,
fragment_field = fragment_field,
default_value = default_vals,
**kwargs
)
def _forward_providers(ctx, label_val, target = None, extra_providers = []):
if target == None:
target = ctx.attr.default_value
providers = [BuildSettingInfo(value = label_val)] + extra_providers
if ProtoLangToolchainInfo in target:
providers.append(target[ProtoLangToolchainInfo])
if target[ProtoLangToolchainInfo].runtime and JavaInfo in target[ProtoLangToolchainInfo].runtime:
providers.append(target[ProtoLangToolchainInfo].runtime[JavaInfo])
if target[ProtoLangToolchainInfo].runtime and ProguardSpecInfo in target[ProtoLangToolchainInfo].runtime:
providers.append(target[ProtoLangToolchainInfo].runtime[ProguardSpecInfo])
if JavaInfo in target:
providers.append(target[JavaInfo])
if ProguardSpecInfo in target:
providers.append(target[ProguardSpecInfo])
if CcInfo in target:
providers.append(target[CcInfo])
return providers
def _compat_label_rule_impl(ctx):
target = ctx.attr.default_value
label_val = target.label
starlark_val = ctx.build_setting_value
# 1. Starlark flag takes precedence if explicitly passed (not "default")
if starlark_val != "default":
label_val = Label(starlark_val)
# 2. Native flag fallback (if HAS_NATIVE_PROTO_FLAGS and _native_target present on ctx.attr)
elif HAS_NATIVE_PROTO_FLAGS and hasattr(ctx.attr, "_native_target") and ctx.attr._native_target:
native_target = ctx.attr._native_target
if native_target.label != target.label:
target = native_target
label_val = native_target.label
return _forward_providers(ctx, label_val, target = target)
def _compat_executable_label_rule_impl(ctx):
target = ctx.attr.default_value
label_val = target.label
starlark_val = ctx.build_setting_value
if starlark_val != "default":
label_val = Label(starlark_val)
elif HAS_NATIVE_PROTO_FLAGS and hasattr(ctx.attr, "_native_target") and ctx.attr._native_target:
native_target = ctx.attr._native_target
if native_target.label != target.label:
target = native_target
label_val = native_target.label
extra_providers = []
if DefaultInfo in target:
def_info = target[DefaultInfo]
if def_info.files_to_run and def_info.files_to_run.executable:
orig_exec = def_info.files_to_run.executable
symlink = ctx.actions.declare_file(orig_exec.basename)
ctx.actions.symlink(
output = symlink,
target_file = orig_exec,
is_executable = True,
)
extra_providers.append(DefaultInfo(
files = depset([symlink]),
runfiles = def_info.default_runfiles,
executable = symlink,
))
return _forward_providers(ctx, label_val, target = target, extra_providers = extra_providers)
_COMMON_LABEL_FLAG_ATTRS = {
"fragment_field": attr.string(),
"default_value": attr.label(),
"runtime": attr.label(),
"scope": attr.string(),
}
def _make_label_rule(fragment_name, executable = False):
attrs = dict(_COMMON_LABEL_FLAG_ATTRS)
if HAS_NATIVE_PROTO_FLAGS and fragment_name:
attrs["_native_target"] = attr.label(
default = configuration_field(fragment = "proto", name = fragment_name),
)
return rule(
implementation = _compat_executable_label_rule_impl if executable else _compat_label_rule_impl,
build_setting = config.string(flag = True),
executable = executable,
fragments = ["proto"] if HAS_NATIVE_PROTO_FLAGS and fragment_name else [],
attrs = attrs,
)
_compat_label_rule_compiler = _make_label_rule("proto_compiler", executable = False)
_compat_executable_label_rule_compiler = _make_label_rule("proto_compiler", executable = True)
_compat_label_rule_cc = _make_label_rule("proto_toolchain_for_cc", executable = False)
_compat_label_rule_java = _make_label_rule("proto_toolchain_for_java", executable = False)
_compat_label_rule_javalite = _make_label_rule("proto_toolchain_for_java_lite", executable = False)
_compat_label_rule_default = _make_label_rule(None, executable = False)
_compat_executable_label_rule_default = _make_label_rule(None, executable = True)
_LABEL_RULES = {
("proto_compiler", False): _compat_label_rule_compiler,
("proto_compiler", True): _compat_executable_label_rule_compiler,
("proto_toolchain_for_cc", False): _compat_label_rule_cc,
("proto_toolchain_for_java", False): _compat_label_rule_java,
("proto_toolchain_for_javalite", False): _compat_label_rule_javalite,
(None, False): _compat_label_rule_default,
(None, True): _compat_executable_label_rule_default,
}
def compat_label_flag(
*,
name,
fragment_field = None,
build_setting_default = None,
executable = False,
**kwargs):
"""Creates a custom label build setting reconciling Starlark/fragments.
Args:
name: The target name for the Starlark build setting flag.
fragment_field: The field name in ctx.fragments.proto, if any.
build_setting_default: Fallback default label target.
executable: Whether the label setting points to an executable target.
**kwargs: Additional rule arguments (such as `scope`).
"""
if fragment_field != None and (fragment_field, executable) not in _LABEL_RULES:
fail("Unsupported fragment_field '%s' for compat_label_flag. Supported values are: %s" % (
fragment_field,
sorted([k[0] for k in _LABEL_RULES.keys() if k[0] != None]),
))
rule_func = _LABEL_RULES.get((fragment_field, executable), _LABEL_RULES[(None, executable)])
rule_func(
name = name,
build_setting_default = "default",
fragment_field = fragment_field or "",
default_value = build_setting_default,
runtime = build_setting_default,
**kwargs
)

View file

@ -74,7 +74,7 @@ java_proto_aspect = aspect(
attrs = (
toolchains.if_legacy_toolchain({
"_aspect_java_proto_toolchain": attr.label(
default = "//bazel/flags/java:proto_toolchain_for_java",
default = Label("//bazel/flags/java:proto_toolchain_for_java"),
),
})
),
@ -161,7 +161,7 @@ rules to generate Java code for.
"licenses": attr.license() if hasattr(attr, "license") else attr.string_list(),
} | toolchains.if_legacy_toolchain({
"_aspect_java_proto_toolchain": attr.label(
default = "//bazel/flags/java:proto_toolchain_for_java",
default = Label("//bazel/flags/java:proto_toolchain_for_java"),
),
}), # buildifier: disable=attr-licenses (attribute called licenses)
provides = [JavaInfo],

View file

@ -1,3 +1,6 @@
"""Renames toplevel symbols so they can be exported in Starlark under the same name"""
native_proto_common = proto_common_do_not_use
load("@proto_bazel_features//:features.bzl", "bazel_features")
native_proto_common = getattr(native, "proto_common", None)
HAS_NATIVE_PROTO_FLAGS = bazel_features.rules.has_proto_fragment

View file

@ -1,35 +0,0 @@
# Protocol Buffers - Google's data interchange format
# Copyright 2008 Google Inc. All rights reserved.
#
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file or at
# https://developers.google.com/open-source/licenses/bsd
"""
A helper rule that reads a native boolean flag.
"""
load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo")
def _impl(ctx):
return [BuildSettingInfo(value = ctx.attr.value)]
_native_bool_flag_rule = rule(
implementation = _impl,
attrs = {"value": attr.bool()},
)
def native_bool_flag(*, name, flag, match_value = "true", result = True, **kwargs):
_native_bool_flag_rule(
name = name,
value = select({
name + "_setting": result,
"//conditions:default": not result,
}),
**kwargs
)
native.config_setting(
name = name + "_setting",
values = {flag: match_value},
visibility = ["//visibility:private"],
)

View file

@ -7,11 +7,11 @@
#
"""Bazel's implementation of cc_proto_library"""
load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo")
load("@rules_cc//cc:find_cc_toolchain.bzl", "use_cc_toolchain")
load("@rules_cc//cc/common:cc_info.bzl", "CcInfo")
load("//bazel/common:proto_common.bzl", "proto_common")
load("//bazel/common:proto_info.bzl", "ProtoInfo")
load("//bazel/flags:flags.bzl", "get_flag_value")
load("//bazel/private:cc_proto_support.bzl", "cc_proto_compile_and_link")
load("//bazel/private:toolchain_helpers.bzl", "toolchains")
@ -30,7 +30,6 @@ def _get_output_files(actions, proto_info, suffixes):
))
return result
# TODO: Make this code actually work.
def _get_strip_include_prefix(ctx, proto_info):
proto_root = proto_info.proto_source_root
if proto_root == "." or proto_root == ctx.label.workspace_root:
@ -59,8 +58,8 @@ def _aspect_impl(target, ctx):
if should_generate_code:
if len(proto_info.direct_sources) != 0:
source_suffixes = get_flag_value(ctx, "cc_proto_library_source_suffixes")
header_suffixes = get_flag_value(ctx, "cc_proto_library_header_suffixes")
source_suffixes = ctx.attr._cc_proto_library_source_suffixes[BuildSettingInfo].value
header_suffixes = ctx.attr._cc_proto_library_header_suffixes[BuildSettingInfo].value
sources = _get_output_files(ctx.actions, proto_info, source_suffixes)
headers = _get_output_files(ctx.actions, proto_info, header_suffixes)
header_provider = _ProtoCcHeaderInfo(headers = depset(headers))
@ -194,7 +193,7 @@ rules to generate C++ code for.""",
),
} | toolchains.if_legacy_toolchain({
"_proto_toolchain_for_cc": attr.label(
default = "//bazel/flags/cc:proto_toolchain_for_cc",
default = Label("//bazel/flags/cc:proto_toolchain_for_cc"),
),
}),
provides = [CcInfo],

View file

@ -16,6 +16,7 @@ _PROTO_BAZEL_FEATURES = """bazel_features = struct(
),
rules = struct(
analysis_tests_can_transition_on_experimental_incompatible_flags = {analysis_tests_can_transition_on_experimental_incompatible_flags},
has_proto_fragment = {has_proto_fragment},
),
globals = struct(
PackageSpecificationInfo = {PackageSpecificationInfo},
@ -40,6 +41,7 @@ def _proto_bazel_features_impl(rctx):
protobuf_on_allowlist = major_version_int > 7
ProtoInfo = "ProtoInfo" if major_version_int < 8 else "None"
cc_proto_aspect = "cc_proto_aspect" if major_version_int < 8 else "None"
has_proto_fragment = major_version_int < 9
rctx.file("BUILD.bazel", """
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
@ -58,6 +60,7 @@ exports_files(["features.bzl"])
cc_proto_aspect = cc_proto_aspect,
analysis_tests_can_transition_on_experimental_incompatible_flags =
"True" if major_version_int > 8 or (major_version_int == 8 and minor_version_int >= 2) else "False",
has_proto_fragment = repr(has_proto_fragment),
))
proto_bazel_features = repository_rule(

View file

@ -19,6 +19,7 @@ def _protoc_authenticity_impl(ctx):
mnemonic = "ProtocAuthenticityCheck",
outputs = [validation_output],
tools = [proto_lang_toolchain_info.proto_compiler],
toolchain = toolchains.PROTO_TOOLCHAIN,
command = """\
{protoc} --version > {validation_output}
grep -q -e "-dev$" {validation_output} && {{

View file

@ -7,11 +7,11 @@
#
"""Implementation of the proto_lang_toolchain rule."""
load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo")
load("@proto_bazel_features//:features.bzl", "bazel_features")
load("//bazel/common:proto_common.bzl", "proto_common")
load("//bazel/common:proto_info.bzl", "ProtoInfo")
load("//bazel/common:proto_lang_toolchain_info.bzl", "ProtoLangToolchainInfo")
load("//bazel/flags:flags.bzl", "get_flag_value")
load("//bazel/private:toolchain_helpers.bzl", "toolchains")
def _rule_impl(ctx):
@ -34,7 +34,7 @@ def _rule_impl(ctx):
protoc_opts = ctx.toolchains[toolchains.PROTO_TOOLCHAIN].proto.protoc_opts
else:
proto_compiler = ctx.attr._proto_compiler.files_to_run
protoc_opts = get_flag_value(ctx, "protocopt")
protoc_opts = list(ctx.attr._protocopt[BuildSettingInfo].value)
if ctx.attr.protoc_minimal_do_not_use:
proto_compiler = ctx.attr.protoc_minimal_do_not_use.files_to_run
@ -150,14 +150,14 @@ Deprecated. Alias for <code>denylisted_protos</code>. Will be removed in a futur
executable = True,
),
"_protocopt": attr.label(
default = "//bazel/flags:protocopt",
default = Label("//bazel/flags:protocopt"),
),
} | ({} if proto_common.INCOMPATIBLE_ENABLE_PROTO_TOOLCHAIN_RESOLUTION else {
"_proto_compiler": attr.label(
cfg = "exec",
executable = True,
allow_files = True,
default = "//bazel/flags:proto_compiler",
default = Label("//bazel/flags:proto_compiler"),
),
}),
provides = [ProtoLangToolchainInfo],

View file

@ -9,10 +9,10 @@ Implementation of proto_library rule.
"""
load("@bazel_skylib//lib:paths.bzl", "paths")
load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo")
load("@proto_bazel_features//:features.bzl", "bazel_features")
load("//bazel/common:proto_common.bzl", "proto_common")
load("//bazel/common:proto_info.bzl", "ProtoInfo")
load("//bazel/flags:flags.bzl", "get_flag_value")
load("//bazel/private:toolchain_helpers.bzl", "toolchains")
DIRECT_DEPS_FLAG_TEMPLATE = (
@ -177,15 +177,13 @@ def _write_descriptor_set(ctx, proto_info, deps, option_deps, exports, descripto
args = ctx.actions.args()
if get_flag_value(ctx, "experimental_proto_descriptor_sets_include_source_info"):
if ctx.attr._experimental_proto_descriptor_sets_include_source_info[BuildSettingInfo].value:
args.add("--include_source_info")
args.add("--retain_options")
strict_deps = get_flag_value(ctx, "strict_proto_deps")
strict_proto_deps = ctx.attr._strict_proto_deps[BuildSettingInfo].value
# Need to check for off because the starlark flag value doesn't have the sneaky
# mapping from "off" to false.
if strict_deps and strict_deps != "off":
if strict_proto_deps:
if proto_info.direct_sources:
# Direct sources can be option imported in addition to `deps`.
strict_importable_sources = depset(
@ -226,11 +224,7 @@ def _write_descriptor_set(ctx, proto_info, deps, option_deps, exports, descripto
# Set `-option_dependencies_violation_msg=`
args.add(ctx.label, format = OPTION_DEPS_FLAG_TEMPLATE)
strict_imports = get_flag_value(ctx, "strict_public_imports")
# Need to check for off because the starlark flag value doesn't have the sneaky
# mapping from "off" to false.
if strict_imports and strict_imports != "OFF":
if ctx.attr._strict_public_imports[BuildSettingInfo].value:
public_import_protos = depset(transitive = [export.check_deps_sources for export in exports])
if not public_import_protos:
# This line is necessary to trigger the check.
@ -255,7 +249,7 @@ def _write_descriptor_set(ctx, proto_info, deps, option_deps, exports, descripto
mnemonic = "GenProtoDescriptorSet",
progress_message = "Generating Descriptor Set proto_library %{label}",
proto_compiler = ctx.executable._proto_compiler,
protoc_opts = get_flag_value(ctx, "protocopt"),
protoc_opts = ctx.attr._protocopt[BuildSettingInfo].value,
plugin = None,
)
@ -391,32 +385,21 @@ for use with MessageSet.
),
# buildifier: disable=attr-license (calling attr.license())
"licenses": attr.license() if hasattr(attr, "license") else attr.string_list(),
"_experimental_proto_descriptor_sets_include_source_info_native": attr.label(
default = "//bazel/private:experimental_proto_descriptor_sets_include_source_info",
),
"_experimental_proto_descriptor_sets_include_source_info": attr.label(
default = "//bazel/flags:experimental_proto_descriptor_sets_include_source_info",
),
"_strict_proto_deps_native": attr.label(
default =
"//bazel/private:strict_proto_deps",
default = Label("//bazel/flags:experimental_proto_descriptor_sets_include_source_info"),
),
"_strict_proto_deps": attr.label(
default =
"//bazel/flags:strict_proto_deps",
),
"_strict_public_imports_native": attr.label(
default = "//bazel/private:strict_public_imports",
default = Label("//bazel/flags:strict_proto_deps"),
),
"_strict_public_imports": attr.label(
default = "//bazel/flags:strict_public_imports",
default = Label("//bazel/flags:strict_public_imports"),
),
} | toolchains.if_legacy_toolchain({
"_proto_compiler": attr.label(
cfg = "exec",
executable = True,
allow_files = True,
default = "//src/google/protobuf/compiler:protoc_minimal",
default = Label("//src/google/protobuf/compiler:protoc_minimal"),
),
}), # buildifier: disable=attr-licenses (attribute called licenses)
fragments = [

View file

@ -7,9 +7,9 @@
#
"""A Starlark implementation of the proto_toolchain rule."""
load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo")
load("//bazel/common:proto_common.bzl", "proto_common")
load("//bazel/common:proto_lang_toolchain_info.bzl", "ProtoLangToolchainInfo")
load("//bazel/flags:flags.bzl", "get_flag_value")
load("//bazel/private:toolchain_helpers.bzl", "toolchains")
def _impl(ctx):
@ -25,7 +25,7 @@ def _impl(ctx):
plugin = None,
runtime = None,
proto_compiler = ctx.attr.proto_compiler.files_to_run,
protoc_opts = get_flag_value(ctx, "protocopt"),
protoc_opts = list(ctx.attr._protocopt[BuildSettingInfo].value),
progress_message = ctx.attr.progress_message,
mnemonic = ctx.attr.mnemonic,
**(dict(toolchain_type = toolchains.PROTO_TOOLCHAIN) if proto_common.INCOMPATIBLE_PASS_TOOLCHAIN_TYPE else {})

View file

@ -15,7 +15,6 @@ the migration is finished, the helpers can be removed.
"""
load("//bazel/common:proto_lang_toolchain_info.bzl", "ProtoLangToolchainInfo")
load("//bazel/flags:flags.bzl", "get_flag_value")
load("//bazel/private:native.bzl", "native_proto_common")
_incompatible_toolchain_resolution = getattr(native_proto_common, "INCOMPATIBLE_ENABLE_PROTO_TOOLCHAIN_RESOLUTION", False)
@ -27,7 +26,7 @@ def _find_toolchain(ctx, legacy_attr, toolchain_type):
fail("No toolchains registered for '%s'." % toolchain_type)
return toolchain.proto
else:
return get_flag_value(ctx, legacy_attr)[ProtoLangToolchainInfo]
return getattr(ctx.attr, "_" + legacy_attr)[ProtoLangToolchainInfo]
def _use_toolchain(toolchain_type):
if _incompatible_toolchain_resolution:

View file

@ -28,6 +28,7 @@ def bazel_proto_library_test_suite(name):
_test_strip_import_prefix_without_deps,
_test_strict_public_imports_enabled,
_test_strict_public_imports_disabled,
_test_strict_public_imports_default,
_test_strict_public_imports_transitive_exports,
_test_strip_import_prefix_with_deps,
_test_exported_stripped_import_prefixes,
@ -45,6 +46,8 @@ def bazel_proto_library_test_suite(name):
_test_proto_library_without_sources,
_test_proto_library_with_generated_sources,
_test_proto_library_with_mixed_sources,
_test_strict_proto_deps_starlark_override_native,
_test_strict_proto_deps_starlark_off_native_on,
]
# Flipping experimental flag in test requires Bazel 8
@ -297,6 +300,7 @@ def _test_descriptor_set_output_strict_deps_disabled_impl(env, target):
action = env.expect.that_target(target).action_generating(
"{package}/{name}-descriptor-set.proto.bin",
)
action.argv().not_contains("--direct_dependencies")
action.argv().not_contains_predicate(matching.str_matches("--direct_dependencies_violation_msg=*"))
@ -357,6 +361,22 @@ def _test_strict_public_imports_disabled_impl(env, target):
)
action.argv().not_contains("--allowed_public_imports=")
def _test_strict_public_imports_default(name):
util.helper_target(proto_library, name = name + "_foo", srcs = ["foo.proto"])
analysis_test(
name = name,
target = name + "_foo",
impl = _test_strict_public_imports_default_impl,
)
def _test_strict_public_imports_default_impl(env, target):
action = env.expect.that_target(target).action_generating(
"{package}/{name}-descriptor-set.proto.bin",
)
action.argv().not_contains("--allowed_public_imports=")
def _test_strict_public_imports_transitive_exports(name):
util.helper_target(
proto_library,
@ -649,7 +669,10 @@ def _test_experimental_proto_descriptor_sets_include_source_info(name):
name = name,
target = name + "_a_proto",
impl = _test_experimental_proto_descriptor_sets_include_source_info_impl,
config_settings = {"@@//bazel/flags:experimental_proto_descriptor_sets_include_source_info": True},
config_settings = {
"//command_line_option:experimental_proto_descriptor_sets_include_source_info": "true",
"@@//bazel/flags:experimental_proto_descriptor_sets_include_source_info": "true",
},
)
def _test_experimental_proto_descriptor_sets_include_source_info_impl(env, target):
@ -773,3 +796,27 @@ def _test_proto_library_with_mixed_sources_impl(env, target):
target.label.package + "/a.proto",
target.label.package + "/generated2.proto",
])
def _test_strict_proto_deps_starlark_override_native(name):
util.helper_target(proto_library, name = name + "_foo", srcs = ["foo.proto", "bar.proto"])
analysis_test(
name = name,
target = name + "_foo",
impl = _test_descriptor_set_output_strict_deps_strict_impl,
config_settings = {
"@@//bazel/flags:strict_proto_deps": "error",
},
)
def _test_strict_proto_deps_starlark_off_native_on(name):
util.helper_target(proto_library, name = name + "_foo", srcs = ["foo.proto"])
analysis_test(
name = name,
target = name + "_foo",
impl = _test_descriptor_set_output_strict_deps_disabled_impl,
config_settings = {
"@@//bazel/flags:strict_proto_deps": "off",
},
)

View file

@ -0,0 +1,46 @@
load("@rules_testing//lib:util.bzl", "PREVENT_IMPLICIT_BUILDING_TAGS")
load("//bazel:java_lite_proto_library.bzl", "java_lite_proto_library")
load("//bazel:proto_library.bzl", "proto_library")
load("//bazel/tests:java_lite_proto_library_tests/test_utils.bzl", "java_info_subject_factory")
load("//bazel/tests:proto_bzl_test_suite.bzl", "bzl_test_suite")
load(":tests.bzl", "TESTS")
package(default_applicable_licenses = ["//:license"])
proto_library(
name = "baz_proto",
srcs = ["baz.proto"],
tags = PREVENT_IMPLICIT_BUILDING_TAGS,
)
proto_library(
name = "bar_proto",
srcs = ["bar.proto"],
tags = PREVENT_IMPLICIT_BUILDING_TAGS,
deps = [":baz_proto"],
)
java_lite_proto_library(
name = "bar_java_proto_lite",
tags = PREVENT_IMPLICIT_BUILDING_TAGS,
deps = ["bar_proto"],
)
proto_library(
name = "foo_proto",
srcs = ["foo.proto"],
tags = PREVENT_IMPLICIT_BUILDING_TAGS,
deps = [":bar_proto"],
)
java_lite_proto_library(
name = "foo_java_proto_lite",
tags = PREVENT_IMPLICIT_BUILDING_TAGS,
deps = [":foo_proto"],
)
bzl_test_suite(
name = "tests",
provider_subject_factories = [java_info_subject_factory],
tests = TESTS,
)

View file

@ -0,0 +1,30 @@
"""Tests that a java_lite_proto_library only provides direct jars corresponding on the
* proto_library rules it directly depends on, excluding anything that the proto_library rules
* depends on themselves. This does not concern strict-deps in the compilation of the generated
* Java code itself, only compilation of regular code in java_library/java_binary and similar
* rules."""
load("@rules_java//java/common:java_info.bzl", "JavaInfo")
def _test_foo_correctly_defines_direct_jars(env, target):
java_info = env.expect.that_target(target).provider(JavaInfo)
java_info.compile_jars().contains_exactly([
"{package}/libfoo_proto-lite-hjar.jar",
])
java_info.source_jars().contains_exactly([
"{package}/foo_proto-lite-src.jar",
])
def _test_bar_correctly_defines_direct_jars(env, target):
java_info = env.expect.that_target(target).provider(JavaInfo)
java_info.compile_jars().contains_exactly([
"{package}/libbar_proto-lite-hjar.jar",
])
java_info.source_jars().contains_exactly([
"{package}/bar_proto-lite-src.jar",
])
TESTS = {
":foo_java_proto_lite": [_test_foo_correctly_defines_direct_jars],
":bar_java_proto_lite": [_test_bar_correctly_defines_direct_jars],
}

View file

@ -0,0 +1,32 @@
load("@rules_testing//lib:util.bzl", "PREVENT_IMPLICIT_BUILDING_TAGS")
load("//bazel:java_lite_proto_library.bzl", "java_lite_proto_library")
load("//bazel:proto_library.bzl", "proto_library")
load("//bazel/tests:java_lite_proto_library_tests/test_utils.bzl", "java_info_subject_factory")
load("//bazel/tests:proto_bzl_test_suite.bzl", "bzl_test_suite")
load(":tests.bzl", "TESTS")
package(default_applicable_licenses = ["//:license"])
proto_library(
name = "bar_proto",
srcs = ["bar.proto"],
tags = PREVENT_IMPLICIT_BUILDING_TAGS,
)
proto_library(
name = "foo_proto",
tags = PREVENT_IMPLICIT_BUILDING_TAGS,
deps = [":bar_proto"],
)
java_lite_proto_library(
name = "foo_java_proto_lite",
tags = PREVENT_IMPLICIT_BUILDING_TAGS,
deps = [":foo_proto"],
)
bzl_test_suite(
name = "tests",
provider_subject_factories = [java_info_subject_factory],
tests = TESTS,
)

View file

@ -0,0 +1,18 @@
"""
Tests that a java_proto_library only provides direct jars corresponding on the proto_library
rules it directly depends on, excluding anything that the proto_library rules depends on
themselves. This does not concern strict-deps in the compilation of the generated Java code
itself, only compilation of regular code in java_library/java_binary and similar rules.
"""
load("@rules_java//java/common:java_info.bzl", "JavaInfo")
def _test_correctly_defines_direct_jars_alias_proto(env, target):
java_info = env.expect.that_target(target).provider(JavaInfo)
java_info.compile_jars().contains_exactly([
"{package}/libbar_proto-lite-hjar.jar",
])
TESTS = {
":foo_java_proto_lite": [_test_correctly_defines_direct_jars_alias_proto],
}

View file

@ -0,0 +1,25 @@
load("@rules_testing//lib:util.bzl", "PREVENT_IMPLICIT_BUILDING_TAGS")
load("//bazel:java_lite_proto_library.bzl", "java_lite_proto_library")
load("//bazel:proto_library.bzl", "proto_library")
load("//bazel/tests:java_proto_library_tests/test_utils.bzl", "java_info_subject_factory")
load("//bazel/tests:proto_bzl_test_suite.bzl", "bzl_test_suite")
load(":tests.bzl", "TESTS")
package(default_applicable_licenses = ["//:license"])
proto_library(
name = "empty_proto",
tags = PREVENT_IMPLICIT_BUILDING_TAGS,
)
java_lite_proto_library(
name = "empty_java_proto_lite",
tags = PREVENT_IMPLICIT_BUILDING_TAGS,
deps = [":empty_proto"],
)
bzl_test_suite(
name = "tests",
provider_subject_factories = [java_info_subject_factory],
tests = TESTS,
)

View file

@ -0,0 +1,10 @@
"""Tests for empty srcs interop."""
load("@rules_java//java/common:java_info.bzl", "JavaInfo")
def _test_empty_srcs(env, target):
env.expect.that_target(target).has_provider(JavaInfo)
TESTS = {
":empty_java_proto_lite": [_test_empty_srcs],
}

View file

@ -0,0 +1,61 @@
load("@rules_java//java:java_library.bzl", "java_library")
load("@rules_testing//lib:util.bzl", "PREVENT_IMPLICIT_BUILDING_TAGS")
load("//bazel:java_lite_proto_library.bzl", "java_lite_proto_library")
load("//bazel:proto_library.bzl", "proto_library")
load("//bazel/tests:java_lite_proto_library_tests/test_utils.bzl", "java_info_subject_factory")
load("//bazel/tests:proto_bzl_test_suite.bzl", "bzl_test_suite")
load(":tests.bzl", "TESTS")
package(default_applicable_licenses = ["//:license"])
proto_library(
name = "exported1",
srcs = ["exported1.proto"],
tags = PREVENT_IMPLICIT_BUILDING_TAGS,
)
proto_library(
name = "exported2",
srcs = ["exported2.proto"],
tags = PREVENT_IMPLICIT_BUILDING_TAGS,
)
proto_library(
name = "notexported",
srcs = ["notexported.proto"],
tags = PREVENT_IMPLICIT_BUILDING_TAGS,
)
proto_library(
name = "top",
srcs = ["top.proto"],
tags = PREVENT_IMPLICIT_BUILDING_TAGS,
exports = [
":exported1",
":exported2",
],
deps = [
":exported1",
":exported2",
":notexported",
],
)
java_lite_proto_library(
name = "java_proto_lite",
tags = PREVENT_IMPLICIT_BUILDING_TAGS,
deps = [":top"],
)
java_library(
name = "java_lib",
srcs = ["Foo.java"],
tags = PREVENT_IMPLICIT_BUILDING_TAGS,
deps = [":java_proto_lite"],
)
bzl_test_suite(
name = "tests",
provider_subject_factories = [java_info_subject_factory],
tests = TESTS,
)

View file

@ -0,0 +1,15 @@
"""Tests for java_lite_proto_library exports."""
load("@rules_java//java/common:java_info.bzl", "JavaInfo")
def _test_java_lib_depends_on_exports(env, target):
java_info = env.expect.that_target(target).provider(JavaInfo)
java_info.transitive_compile_time_jars_in_package().contains_at_least([
"{package}/libtop-lite-hjar.jar",
"{package}/libexported1-lite-hjar.jar",
"{package}/libexported2-lite-hjar.jar",
])
TESTS = {
":java_lib": [_test_java_lib_depends_on_exports],
}

View file

@ -0,0 +1,26 @@
load("@rules_testing//lib:util.bzl", "PREVENT_IMPLICIT_BUILDING_TAGS")
load("//bazel:java_lite_proto_library.bzl", "java_lite_proto_library")
load("//bazel:proto_library.bzl", "proto_library")
load("//bazel/tests:java_proto_library_tests/test_utils.bzl", "java_info_subject_factory")
load("//bazel/tests:proto_bzl_test_suite.bzl", "bzl_test_suite")
load(":tests.bzl", "TESTS")
package(default_applicable_licenses = ["//:license"])
proto_library(
name = "file_proto",
srcs = ["file.proto"],
tags = PREVENT_IMPLICIT_BUILDING_TAGS,
)
java_lite_proto_library(
name = "file_java_proto_lite",
tags = PREVENT_IMPLICIT_BUILDING_TAGS,
deps = [":file_proto"],
)
bzl_test_suite(
name = "tests",
provider_subject_factories = [java_info_subject_factory],
tests = TESTS,
)

View file

@ -0,0 +1,10 @@
"""Tests tracking Java interop behaviors."""
load("@rules_java//java/common:java_info.bzl", "JavaInfo")
def _test_java_protos_exposes_java_provider(env, target):
env.expect.that_target(target).has_provider(JavaInfo)
TESTS = {
":file_java_proto_lite": [_test_java_protos_exposes_java_provider],
}

View file

@ -0,0 +1,26 @@
load("@rules_testing//lib:util.bzl", "PREVENT_IMPLICIT_BUILDING_TAGS")
load("//bazel:java_lite_proto_library.bzl", "java_lite_proto_library")
load("//bazel:proto_library.bzl", "proto_library")
load("//bazel/tests:java_proto_library_tests/test_utils.bzl", "java_info_subject_factory")
load("//bazel/tests:proto_bzl_test_suite.bzl", "bzl_test_suite")
load(":tests.bzl", "TESTS")
package(default_applicable_licenses = ["//:license"])
proto_library(
name = "file_proto",
srcs = ["file.proto"],
tags = PREVENT_IMPLICIT_BUILDING_TAGS,
)
java_lite_proto_library(
name = "file_java_proto_lite",
tags = PREVENT_IMPLICIT_BUILDING_TAGS,
deps = [":file_proto"],
)
bzl_test_suite(
name = "tests",
provider_subject_factories = [java_info_subject_factory],
tests = TESTS,
)

View file

@ -0,0 +1,10 @@
"""Tests tracking Java interop behaviors."""
load("@rules_java//java/common:java_info.bzl", "JavaInfo")
def _test_interop(env, target):
env.expect.that_target(target).has_provider(JavaInfo)
TESTS = {
":file_java_proto_lite": [_test_interop],
}

View file

@ -33,6 +33,10 @@ def _java_info_subject(info, *, meta):
_filter_inpackage(self.actual.transitive_source_jars, meta.ctx.label),
meta = self.meta.derive("transitive_source_jars_in_package()"),
),
source_jars = lambda *a, **k: subjects.depset_file(
self.actual.source_jars,
meta = self.meta.derive("source_jars()"),
),
transitive_runtime_jars = lambda *a, **k: subjects.depset_file(
self.actual.transitive_runtime_jars,
meta = self.meta.derive("transitive_runtime_jars()"),
@ -45,6 +49,10 @@ def _java_info_subject(info, *, meta):
_filter_inpackage(self.actual.transitive_compile_time_jars, meta.ctx.label),
meta = self.meta.derive("transitive_compile_time_jars_in_package()"),
),
compile_jars = lambda *a, **k: subjects.depset_file(
self.actual.compile_jars,
meta = self.meta.derive("compile_jars()"),
),
)
return public

View file

@ -0,0 +1,25 @@
load("@rules_testing//lib:util.bzl", "PREVENT_IMPLICIT_BUILDING_TAGS")
load("//bazel:java_proto_library.bzl", "java_proto_library")
load("//bazel:proto_library.bzl", "proto_library")
load("//bazel/tests:java_proto_library_tests/test_utils.bzl", "java_info_subject_factory")
load("//bazel/tests:proto_bzl_test_suite.bzl", "bzl_test_suite")
load(":tests.bzl", "TESTS")
package(default_applicable_licenses = ["//:license"])
proto_library(
name = "empty_proto",
tags = PREVENT_IMPLICIT_BUILDING_TAGS,
)
java_proto_library(
name = "empty_java_proto",
tags = PREVENT_IMPLICIT_BUILDING_TAGS,
deps = [":empty_proto"],
)
bzl_test_suite(
name = "tests",
provider_subject_factories = [java_info_subject_factory],
tests = TESTS,
)

View file

@ -0,0 +1,10 @@
"""Tests for empty srcs interop."""
load("@rules_java//java/common:java_info.bzl", "JavaInfo")
def _test_empty_srcs(env, target):
env.expect.that_target(target).has_provider(JavaInfo)
TESTS = {
":empty_java_proto": [_test_empty_srcs],
}

View file

@ -0,0 +1,26 @@
load("@rules_testing//lib:util.bzl", "PREVENT_IMPLICIT_BUILDING_TAGS")
load("//bazel:java_proto_library.bzl", "java_proto_library")
load("//bazel:proto_library.bzl", "proto_library")
load("//bazel/tests:java_proto_library_tests/test_utils.bzl", "java_info_subject_factory")
load("//bazel/tests:proto_bzl_test_suite.bzl", "bzl_test_suite")
load(":tests.bzl", "TESTS")
package(default_applicable_licenses = ["//:license"])
proto_library(
name = "file_proto",
srcs = ["file.proto"],
tags = PREVENT_IMPLICIT_BUILDING_TAGS,
)
java_proto_library(
name = "file_java_proto",
tags = PREVENT_IMPLICIT_BUILDING_TAGS,
deps = [":file_proto"],
)
bzl_test_suite(
name = "tests",
provider_subject_factories = [java_info_subject_factory],
tests = TESTS,
)

View file

@ -0,0 +1,10 @@
"""Tests tracking Java interop behaviors."""
load("@rules_java//java/common:java_info.bzl", "JavaInfo")
def _test_interop(env, target):
env.expect.that_target(target).has_provider(JavaInfo)
TESTS = {
":file_java_proto": [_test_interop],
}

View file

@ -0,0 +1,26 @@
load("@rules_testing//lib:util.bzl", "PREVENT_IMPLICIT_BUILDING_TAGS")
load("//bazel:java_proto_library.bzl", "java_proto_library")
load("//bazel:proto_library.bzl", "proto_library")
load("//bazel/tests:java_proto_library_tests/test_utils.bzl", "java_info_subject_factory")
load("//bazel/tests:proto_bzl_test_suite.bzl", "bzl_test_suite")
load(":tests.bzl", "TESTS")
package(default_applicable_licenses = ["//:license"])
proto_library(
name = "file_proto",
srcs = ["file.proto"],
tags = PREVENT_IMPLICIT_BUILDING_TAGS,
)
java_proto_library(
name = "file_java_proto",
tags = PREVENT_IMPLICIT_BUILDING_TAGS,
deps = [":file_proto"],
)
bzl_test_suite(
name = "tests",
provider_subject_factories = [java_info_subject_factory],
tests = TESTS,
)

View file

@ -0,0 +1,10 @@
"""Tests tracking Java interop behaviors."""
load("@rules_java//java/common:java_info.bzl", "JavaInfo")
def _test_java_protos_exposes_java_provider(env, target):
env.expect.that_target(target).has_provider(JavaInfo)
TESTS = {
":file_java_proto": [_test_java_protos_exposes_java_provider],
}

View file

@ -0,0 +1,29 @@
load("@rules_testing//lib:util.bzl", "PREVENT_IMPLICIT_BUILDING_TAGS")
# load("//bazel:java_proto_library.bzl", "java_proto_library")s
load("//bazel:proto_library.bzl", "proto_library")
load("//bazel/tests:java_proto_library_tests/test_utils.bzl", "JAVA_PROTO_TESTING_ASPECT", "java_info_subject_factory")
load("//bazel/tests:proto_bzl_test_suite.bzl", "bzl_test_suite")
load(":tests.bzl", "TESTS")
package(default_applicable_licenses = ["//:license"])
proto_library(
name = "foo_proto",
srcs = ["foo.proto"],
tags = PREVENT_IMPLICIT_BUILDING_TAGS,
)
proto_library(
name = "baz_proto",
srcs = ["baz.proto"],
tags = PREVENT_IMPLICIT_BUILDING_TAGS,
deps = [":foo_proto"],
)
bzl_test_suite(
name = "tests",
provider_subject_factories = [java_info_subject_factory],
testing_aspect = JAVA_PROTO_TESTING_ASPECT,
tests = TESTS,
)

View file

@ -0,0 +1,22 @@
"""Tests for same version compiler arguments."""
load("@rules_java//java/common:java_info.bzl", "JavaInfo")
def _test_same_version_compiler_arguments(env, target):
genproto = env.expect.that_target(target).action_named("GenProto")
genproto.argv().contains("{package}/baz.proto")
genproto.argv().contains_at_least([
"--java_out={bindir}/{package}/baz_proto-speed-src.jar",
"-I.",
"{package}/baz.proto",
]).in_order()
genproto.argv().not_contains("--java_out=shared,immutable:{bindir}/{package}/foo_proto-speed-src.jar")
java_info = env.expect.that_target(target).provider(JavaInfo)
java_info.transitive_runtime_jars().contains_at_least([
"{package}/libbaz_proto-speed.jar",
"java/core/libcore.jar",
])
TESTS = {
":baz_proto": [_test_same_version_compiler_arguments],
}

View file

@ -7,11 +7,13 @@
#
"""Tests for `proto_common.compile` function."""
load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo")
load("@rules_testing//lib:analysis_test.bzl", "analysis_test", "test_suite")
load("@rules_testing//lib:truth.bzl", "matching")
load("@rules_testing//lib:util.bzl", "util")
load("//bazel:proto_library.bzl", "proto_library")
load("//bazel/tests/testdata:compile_rule.bzl", "compile_rule")
load("//bazel/toolchains:proto_lang_toolchain.bzl", "proto_lang_toolchain")
protocol_compiler = "/protoc"
@ -34,9 +36,18 @@ def proto_common_compile_test_suite(name):
_test_compile_additional_inputs,
_test_compile_resource_set,
_test_compile_protoc_opts,
_test_compile_protoc_opts_starlark,
_test_compile_direct_generated_protos,
_test_compile_indirect_generated_protos,
_test_compile_override_progress_message,
_test_proto_compiler_flag_override,
_test_proto_compiler_native_flag_override,
_test_proto_toolchain_for_cc_flag_override,
_test_proto_toolchain_for_cc_native_flag_override,
_test_proto_toolchain_for_java_flag_override,
_test_proto_toolchain_for_java_native_flag_override,
_test_proto_toolchain_for_javalite_flag_override,
_test_proto_toolchain_for_javalite_native_flag_override,
],
)
@ -291,7 +302,25 @@ def _test_compile_protoc_opts(name):
analysis_test(
name = name,
target = name + "_compile",
config_settings = {"//command_line_option:protocopt": ["--foo", "--bar"]},
config_settings = {
"//command_line_option:protocopt": ["--foo", "--bar"],
},
impl = _test_compile_protoc_opts_impl,
)
def _test_compile_protoc_opts_starlark(name):
util.helper_target(
compile_rule,
name = name + "_compile",
proto_dep = ":simple_proto",
)
analysis_test(
name = name,
target = name + "_compile",
config_settings = {
"@@//bazel/flags:protocopt": ["--foo", "--bar"],
},
impl = _test_compile_protoc_opts_impl,
)
@ -393,3 +422,185 @@ def _test_compile_override_progress_message(name):
def _test_compile_override_progress_message_impl(env, target):
action = env.expect.that_target(target).action_named("MyMnemonic")
env.expect.that_str(repr(action.actual)).contains("My custom progress message //")
def _dummy_compiler_impl(ctx):
exe = ctx.actions.declare_file(ctx.label.name)
ctx.actions.write(exe, "#!/bin/sh\nexit 0\n", is_executable = True)
return [DefaultInfo(executable = exe, files = depset([exe]))]
_dummy_compiler = rule(
implementation = _dummy_compiler_impl,
executable = True,
)
def _test_proto_compiler_flag_override(name):
util.helper_target(
_dummy_compiler,
name = name + "_custom_compiler",
)
analysis_test(
name = name,
target = "@//bazel/flags:proto_compiler",
impl = _test_proto_compiler_flag_override_impl,
config_settings = {
"@@//bazel/flags:proto_compiler": "//bazel/tests:" + name + "_custom_compiler",
},
)
def _test_proto_compiler_flag_override_impl(env, target):
env.expect.that_target(target).has_provider(BuildSettingInfo)
val = target[BuildSettingInfo].value
env.expect.that_str(str(val)).contains("_custom_compiler")
def _test_proto_compiler_native_flag_override(name):
util.helper_target(
_dummy_compiler,
name = name + "_custom_compiler_native",
)
analysis_test(
name = name,
target = "@//bazel/flags:proto_compiler",
impl = _test_proto_compiler_native_flag_override_impl,
config_settings = {
"//command_line_option:proto_compiler": str(Label("//bazel/tests:" + name + "_custom_compiler_native")),
},
)
def _test_proto_compiler_native_flag_override_impl(env, target):
env.expect.that_target(target).has_provider(BuildSettingInfo)
val = target[BuildSettingInfo].value
env.expect.that_str(str(val)).contains("_custom_compiler_native")
def _test_proto_toolchain_for_cc_flag_override(name):
util.helper_target(
proto_lang_toolchain,
name = name + "_custom_cc_toolchain",
command_line = "$(OUT)",
mnemonic = "CustomCcMnemonic",
)
analysis_test(
name = name,
target = "@//bazel/flags/cc:proto_toolchain_for_cc",
impl = _test_proto_toolchain_for_cc_flag_override_impl,
config_settings = {
"@@//bazel/flags/cc:proto_toolchain_for_cc": "//bazel/tests:" + name + "_custom_cc_toolchain",
},
)
def _test_proto_toolchain_for_cc_flag_override_impl(env, target):
env.expect.that_target(target).has_provider(BuildSettingInfo)
val = target[BuildSettingInfo].value
env.expect.that_str(str(val)).contains("_custom_cc_toolchain")
def _test_proto_toolchain_for_cc_native_flag_override(name):
util.helper_target(
proto_lang_toolchain,
name = name + "_custom_cc_toolchain_native",
command_line = "$(OUT)",
mnemonic = "CustomCcMnemonicNative",
)
analysis_test(
name = name,
target = "@//bazel/flags/cc:proto_toolchain_for_cc",
impl = _test_proto_toolchain_for_cc_native_flag_override_impl,
config_settings = {
"//command_line_option:proto_toolchain_for_cc": str(Label("//bazel/tests:" + name + "_custom_cc_toolchain_native")),
},
)
def _test_proto_toolchain_for_cc_native_flag_override_impl(env, target):
env.expect.that_target(target).has_provider(BuildSettingInfo)
val = target[BuildSettingInfo].value
env.expect.that_str(str(val)).contains("_custom_cc_toolchain_native")
def _test_proto_toolchain_for_java_flag_override(name):
util.helper_target(
proto_lang_toolchain,
name = name + "_custom_java_toolchain",
command_line = "$(OUT)",
mnemonic = "CustomJavaMnemonic",
)
analysis_test(
name = name,
target = "@//bazel/flags/java:proto_toolchain_for_java",
impl = _test_proto_toolchain_for_java_flag_override_impl,
config_settings = {
"@@//bazel/flags/java:proto_toolchain_for_java": "//bazel/tests:" + name + "_custom_java_toolchain",
},
)
def _test_proto_toolchain_for_java_flag_override_impl(env, target):
env.expect.that_target(target).has_provider(BuildSettingInfo)
val = target[BuildSettingInfo].value
env.expect.that_str(str(val)).contains("_custom_java_toolchain")
def _test_proto_toolchain_for_java_native_flag_override(name):
util.helper_target(
proto_lang_toolchain,
name = name + "_custom_java_toolchain_native",
command_line = "$(OUT)",
mnemonic = "CustomJavaMnemonicNative",
)
analysis_test(
name = name,
target = "@//bazel/flags/java:proto_toolchain_for_java",
impl = _test_proto_toolchain_for_java_native_flag_override_impl,
config_settings = {
"//command_line_option:proto_toolchain_for_java": str(Label("//bazel/tests:" + name + "_custom_java_toolchain_native")),
},
)
def _test_proto_toolchain_for_java_native_flag_override_impl(env, target):
env.expect.that_target(target).has_provider(BuildSettingInfo)
val = target[BuildSettingInfo].value
env.expect.that_str(str(val)).contains("_custom_java_toolchain_native")
def _test_proto_toolchain_for_javalite_flag_override(name):
util.helper_target(
proto_lang_toolchain,
name = name + "_custom_javalite_toolchain",
command_line = "$(OUT)",
mnemonic = "CustomJavaLiteMnemonic",
)
analysis_test(
name = name,
target = "@//bazel/flags/java:proto_toolchain_for_javalite",
impl = _test_proto_toolchain_for_javalite_flag_override_impl,
config_settings = {
"@@//bazel/flags/java:proto_toolchain_for_javalite": "//bazel/tests:" + name + "_custom_javalite_toolchain",
},
)
def _test_proto_toolchain_for_javalite_flag_override_impl(env, target):
env.expect.that_target(target).has_provider(BuildSettingInfo)
val = target[BuildSettingInfo].value
env.expect.that_str(str(val)).contains("_custom_javalite_toolchain")
def _test_proto_toolchain_for_javalite_native_flag_override(name):
util.helper_target(
proto_lang_toolchain,
name = name + "_custom_javalite_toolchain_native",
command_line = "$(OUT)",
mnemonic = "CustomJavaLiteMnemonicNative",
)
analysis_test(
name = name,
target = "@//bazel/flags/java:proto_toolchain_for_javalite",
impl = _test_proto_toolchain_for_javalite_native_flag_override_impl,
config_settings = {
"//command_line_option:proto_toolchain_for_javalite": str(Label("//bazel/tests:" + name + "_custom_javalite_toolchain_native")),
},
)
def _test_proto_toolchain_for_javalite_native_flag_override_impl(env, target):
env.expect.that_target(target).has_provider(BuildSettingInfo)
val = target[BuildSettingInfo].value
env.expect.that_str(str(val)).contains("_custom_javalite_toolchain_native")

View file

@ -102,6 +102,7 @@ cc_test(
"//upb/mini_table",
"//upb/reflection",
"//upb/reflection:internal",
"//upb/reflection:reflection_cc",
"//upb/wire",
"@abseil-cpp//absl/container:flat_hash_set",
"@abseil-cpp//absl/log:absl_check",

View file

@ -20,7 +20,6 @@ if (echo "$previous_commit_title" | grep -q "^Auto-generate files"); then
fi
export BAZEL=bazelisk
export USE_BAZEL_VERSION=8.0.1
./regenerate_stale_files.sh

View file

@ -15,7 +15,6 @@ set(rules_proto-version "7.1.0")
set(abseil-cpp-version "20250512.1")
set(rules_cc-version "0.2.18")
set(zlib-version "1.3.1")
set(bazel_features-version "1.33.0")
set(bazel_skylib-version "1.9.0")
set(jsoncpp-version "1.9.6")
set(rules_java-version "8.6.1")
@ -23,7 +22,7 @@ set(rules_jvm_external-version "6.7")
set(rules_kotlin-version "2.3.20")
set(rules_license-version "1.0.0")
set(rules_pkg-version "1.0.1")
set(rules_python-version "1.6.0")
set(rules_python-version "2.3.0")
set(rules_rust-version "0.69.0")
set(rules_ruby-version "0.20.1")
set(rules_fuzzing-version "0.5.3")
@ -31,14 +30,12 @@ set(rules_shell-version "0.6.1")
set(platforms-version "0.0.11")
set(re2-version "2024-07-02")
set(googletest-version "1.17.0")
set(rules_buf-version "0.3.0")
set(rules_testing-version "0.9.0")
set(abseil-py-version "2.1.0")
set(lua-version "5.4.6")
set(googleapis-version "0.0.0-20240819-fe8ba054a")
set(google_benchmark-version "1.9.2")
set(com_google_protobuf_v25-version "25.0")
set(com_google_protobuf_previous_release-version "33.0")
set(jq.bzl-version "0.6.1")

View file

@ -87,6 +87,9 @@ class ModuleFileFunctions(object):
def register_toolchains(self, *args, **kwargs):
pass
def flag_alias(self, *args, **kwargs):
pass
def use_repo(self, *args, **kwargs):
pass

View file

@ -98,15 +98,8 @@ include(${protobuf_SOURCE_DIR}/src/file_lists.cmake)
set(protobuf_HEADERS
${libprotobuf_hdrs}
${libprotoc_public_hdrs}
${wkt_protos_files}
${cpp_file_options_proto_proto_srcs}
${json_enumvalue_options_proto_proto_srcs}
${cpp_features_proto_proto_srcs}
${descriptor_proto_proto_srcs}
${plugin_proto_proto_srcs}
${c_sharp_features_proto_proto_srcs}
${java_features_proto_proto_srcs}
${go_features_proto_proto_srcs}
${release_all_options_protos_files}
)
if (protobuf_BUILD_LIBUPB)
list(APPEND protobuf_HEADERS ${libupb_hdrs})
@ -115,6 +108,8 @@ if (protobuf_BUILD_LIBUPB)
FILES
${protobuf_SOURCE_DIR}/upb/reflection/cmake/google/protobuf/descriptor.upb.h
${protobuf_SOURCE_DIR}/upb/reflection/cmake/google/protobuf/descriptor.upb_minitable.h
${protobuf_SOURCE_DIR}/upb/reflection/cmake/google/protobuf/json_enumvalue_options.upb.h
${protobuf_SOURCE_DIR}/upb/reflection/cmake/google/protobuf/json_enumvalue_options.upb_minitable.h
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/google/protobuf
COMPONENT protobuf-headers
)

View file

@ -35,6 +35,7 @@ google/protobuf/compiler/php/names.h
google/protobuf/compiler/plugin.h
google/protobuf/compiler/plugin.pb.h
google/protobuf/compiler/plugin.proto
google/protobuf/compiler/python/names.h
google/protobuf/compiler/retention.h
google/protobuf/compiler/scc.h
google/protobuf/compiler/subprocess.h
@ -45,6 +46,7 @@ google/protobuf/cpp_features.pb.h
google/protobuf/cpp_features.proto
google/protobuf/cpp_file_options.pb.h
google/protobuf/cpp_file_options.proto
google/protobuf/cpp_options.proto
google/protobuf/descriptor.h
google/protobuf/descriptor.pb.h
google/protobuf/descriptor.proto
@ -95,6 +97,9 @@ google/protobuf/java_features.proto
google/protobuf/json/json.h
google/protobuf/json_enumvalue_options.pb.h
google/protobuf/json_enumvalue_options.proto
google/protobuf/json_enumvalue_options.upb.h
google/protobuf/json_enumvalue_options.upb_minitable.h
google/protobuf/json_options.proto
google/protobuf/map.h
google/protobuf/map_entry.h
google/protobuf/map_field.h
@ -107,6 +112,8 @@ google/protobuf/metadata.h
google/protobuf/metadata_lite.h
google/protobuf/micro_string.h
google/protobuf/naming_style.h
google/protobuf/offset_ptr.h
google/protobuf/option_interpreter.h
google/protobuf/os_macros_restore.inc
google/protobuf/os_macros_undef.inc
google/protobuf/parse_context.h
@ -129,6 +136,7 @@ google/protobuf/serial_arena.h
google/protobuf/service.h
google/protobuf/source_context.pb.h
google/protobuf/source_context.proto
google/protobuf/static_message_factory.h
google/protobuf/string_block.h
google/protobuf/struct.pb.h
google/protobuf/struct.proto
@ -206,12 +214,12 @@ upb/mini_table/message.h
upb/mini_table/sub.h
upb/port/atomic.h
upb/port/def.inc
upb/port/overflow.h
upb/port/sanitizers.h
upb/port/undef.inc
upb/port/vsnprintf_compat.h
upb/reflection/common.h
upb/reflection/def.h
upb/reflection/def.hpp
upb/reflection/def_pool.h
upb/reflection/def_type.h
upb/reflection/descriptor_bootstrap.h
@ -221,8 +229,8 @@ upb/reflection/enum_value_def.h
upb/reflection/extension_range.h
upb/reflection/field_def.h
upb/reflection/file_def.h
upb/reflection/json_enumvalue_options_bootstrap.h
upb/reflection/message.h
upb/reflection/message.hpp
upb/reflection/message_def.h
upb/reflection/message_reserved_range.h
upb/reflection/method_def.h
@ -239,6 +247,7 @@ upb/wire/decode_fast/combinations.h
upb/wire/decode_fast/data.h
upb/wire/decode_fast/select.h
upb/wire/encode.h
upb/wire/encode_extension.h
upb/wire/eps_copy_input_stream.h
upb/wire/reader.h
upb/wire/types.h

View file

@ -9,6 +9,9 @@ set(bootstrap_sources
${bootstrap_cmake_dir}/google/protobuf/descriptor.upb.h
${bootstrap_cmake_dir}/google/protobuf/descriptor.upb_minitable.h
${bootstrap_cmake_dir}/google/protobuf/descriptor.upb_minitable.c
${bootstrap_cmake_dir}/google/protobuf/json_enumvalue_options.upb.h
${bootstrap_cmake_dir}/google/protobuf/json_enumvalue_options.upb_minitable.h
${bootstrap_cmake_dir}/google/protobuf/json_enumvalue_options.upb_minitable.c
)
# Note: upb does not support shared library builds, and is intended to be

View file

@ -184,6 +184,8 @@ foreach(Camel
Protobuf_LITE_LIBRARY
Protobuf_LITE_LIBRARY_DEBUG
)
string(TOUPPER ${Camel} UPPER)
set(${UPPER} ${${Camel}})
if(DEFINED ${Camel})
string(TOUPPER ${Camel} UPPER)
set(${UPPER} ${${Camel}})
endif()
endforeach()

View file

@ -1,4 +1,3 @@
load("@rules_buf//buf:defs.bzl", "buf_breaking_test")
load("@rules_java//java:java_library.bzl", "java_library")
# Simple build tests for compatibility of gencode from previous major versions
@ -23,122 +22,3 @@ java_library(
visibility = ["//java/core:__pkg__"],
deps = ["@com_google_protobuf_v25//java/core"],
)
# Breaking change detection for well-known types and descriptor.proto.
buf_breaking_test(
name = "any_proto_breaking",
against = "@com_google_protobuf_previous_release//:any_proto",
config = ":buf.yaml",
targets = ["//:any_proto"],
)
buf_breaking_test(
name = "api_proto_breaking",
against = "@com_google_protobuf_previous_release//:api_proto",
config = ":buf.yaml",
targets = ["//:api_proto"],
)
buf_breaking_test(
name = "descriptor_proto_breaking",
against = "@com_google_protobuf_previous_release//:descriptor_proto",
config = ":buf.yaml",
targets = ["//:descriptor_proto"],
)
buf_breaking_test(
name = "duration_proto_breaking",
against = "@com_google_protobuf_previous_release//:duration_proto",
config = ":buf.yaml",
targets = ["//:duration_proto"],
)
buf_breaking_test(
name = "empty_proto_breaking",
against = "@com_google_protobuf_previous_release//:empty_proto",
config = ":buf.yaml",
targets = ["//:empty_proto"],
)
buf_breaking_test(
name = "field_mask_proto_breaking",
against = "@com_google_protobuf_previous_release//:field_mask_proto",
config = ":buf.yaml",
targets = ["//:field_mask_proto"],
)
buf_breaking_test(
name = "source_context_proto_breaking",
against = "@com_google_protobuf_previous_release//:source_context_proto",
config = ":buf.yaml",
targets = ["//:source_context_proto"],
)
buf_breaking_test(
name = "struct_proto_breaking",
against = "@com_google_protobuf_previous_release//:struct_proto",
config = ":buf.yaml",
targets = ["//:struct_proto"],
)
buf_breaking_test(
name = "timestamp_proto_breaking",
against = "@com_google_protobuf_previous_release//:timestamp_proto",
config = ":buf.yaml",
targets = ["//:timestamp_proto"],
)
buf_breaking_test(
name = "type_proto_breaking",
against = "@com_google_protobuf_previous_release//:type_proto",
config = ":buf.yaml",
targets = ["//:type_proto"],
)
buf_breaking_test(
name = "wrappers_proto_breaking",
against = "@com_google_protobuf_previous_release//:wrappers_proto",
config = ":buf.yaml",
targets = ["//:wrappers_proto"],
)
buf_breaking_test(
name = "compiler_plugin_proto_breaking",
against = "@com_google_protobuf_previous_release//:compiler_plugin_proto",
config = ":buf.yaml",
targets = ["//:compiler_plugin_proto"],
)
buf_breaking_test(
name = "cpp_features_proto_breaking",
against = "@com_google_protobuf_previous_release//:cpp_features_proto",
config = ":buf.yaml",
targets = ["//:cpp_features_proto"],
)
buf_breaking_test(
name = "java_features_proto_breaking",
against = "@com_google_protobuf_previous_release//:java_features_proto",
config = ":buf.yaml",
targets = ["//:java_features_proto"],
)
test_suite(
name = "proto_breaking",
tests = [
"any_proto_breaking",
"api_proto_breaking",
"compiler_plugin_proto_breaking",
"cpp_features_proto_breaking",
"descriptor_proto_breaking",
"duration_proto_breaking",
"empty_proto_breaking",
"field_mask_proto_breaking",
"java_features_proto_breaking",
"source_context_proto_breaking",
"struct_proto_breaking",
"timestamp_proto_breaking",
"type_proto_breaking",
"wrappers_proto_breaking",
],
)

View file

@ -1 +0,0 @@
version: v1

View file

@ -145,6 +145,7 @@ cc_library(
"//src/google/protobuf",
"//src/google/protobuf:protobuf_lite",
"//src/google/protobuf/json",
"//src/google/protobuf/util:differencer",
"//src/google/protobuf/util:type_resolver",
"@abseil-cpp//absl/log:absl_check",
"@abseil-cpp//absl/log:absl_log",

View file

@ -7,7 +7,6 @@
import com.google.protobuf.AbstractMessage;
import com.google.protobuf.ByteString;
import com.google.protobuf.CodedInputStream;
import com.google.protobuf.ExtensionRegistry;
import com.google.protobuf.InvalidProtocolBufferException;
import com.google.protobuf.Parser;
@ -73,11 +72,8 @@ class ConformanceJava {
private enum BinaryDecoderType {
BYTE_STRING_DECODER,
BYTE_ARRAY_DECODER,
ARRAY_BYTE_BUFFER_DECODER,
READONLY_ARRAY_BYTE_BUFFER_DECODER,
DIRECT_BYTE_BUFFER_DECODER,
READONLY_DIRECT_BYTE_BUFFER_DECODER,
INPUT_STREAM_DECODER;
}
@ -87,34 +83,20 @@ class ConformanceJava {
throws InvalidProtocolBufferException {
switch (type) {
case BYTE_STRING_DECODER:
case BYTE_ARRAY_DECODER:
return parser.parseFrom(bytes, extensions);
case ARRAY_BYTE_BUFFER_DECODER:
{
ByteBuffer buffer = ByteBuffer.allocate(bytes.size());
bytes.copyTo(buffer);
buffer.flip();
return parser.parseFrom(CodedInputStream.newInstance(buffer), extensions);
}
case READONLY_ARRAY_BYTE_BUFFER_DECODER:
{
return parser.parseFrom(
CodedInputStream.newInstance(bytes.asReadOnlyByteBuffer()), extensions);
return parser.parseFrom(buffer, extensions);
}
case DIRECT_BYTE_BUFFER_DECODER:
{
ByteBuffer buffer = ByteBuffer.allocateDirect(bytes.size());
bytes.copyTo(buffer);
buffer.flip();
return parser.parseFrom(CodedInputStream.newInstance(buffer), extensions);
}
case READONLY_DIRECT_BYTE_BUFFER_DECODER:
{
ByteBuffer buffer = ByteBuffer.allocateDirect(bytes.size());
bytes.copyTo(buffer);
buffer.flip();
return parser.parseFrom(
CodedInputStream.newInstance(buffer.asReadOnlyBuffer()), extensions);
return parser.parseFrom(buffer, extensions);
}
case INPUT_STREAM_DECODER:
{

View file

@ -7,7 +7,6 @@
import com.google.protobuf.AbstractMessageLite;
import com.google.protobuf.ByteString;
import com.google.protobuf.CodedInputStream;
import com.google.protobuf.ExtensionRegistryLite;
import com.google.protobuf.InvalidProtocolBufferException;
import com.google.protobuf.MessageLite;
@ -70,11 +69,8 @@ class ConformanceJavaLite {
private enum BinaryDecoderType {
BYTE_STRING_DECODER,
BYTE_ARRAY_DECODER,
ARRAY_BYTE_BUFFER_DECODER,
READONLY_ARRAY_BYTE_BUFFER_DECODER,
DIRECT_BYTE_BUFFER_DECODER,
READONLY_DIRECT_BYTE_BUFFER_DECODER,
INPUT_STREAM_DECODER;
}
@ -87,34 +83,20 @@ class ConformanceJavaLite {
throws InvalidProtocolBufferException {
switch (type) {
case BYTE_STRING_DECODER:
case BYTE_ARRAY_DECODER:
return parser.parseFrom(bytes, extensions);
case ARRAY_BYTE_BUFFER_DECODER:
{
ByteBuffer buffer = ByteBuffer.allocate(bytes.size());
bytes.copyTo(buffer);
buffer.flip();
return parser.parseFrom(CodedInputStream.newInstance(buffer), extensions);
}
case READONLY_ARRAY_BYTE_BUFFER_DECODER:
{
return parser.parseFrom(
CodedInputStream.newInstance(bytes.asReadOnlyByteBuffer()), extensions);
return parser.parseFrom(buffer, extensions);
}
case DIRECT_BYTE_BUFFER_DECODER:
{
ByteBuffer buffer = ByteBuffer.allocateDirect(bytes.size());
bytes.copyTo(buffer);
buffer.flip();
return parser.parseFrom(CodedInputStream.newInstance(buffer), extensions);
}
case READONLY_DIRECT_BYTE_BUFFER_DECODER:
{
ByteBuffer buffer = ByteBuffer.allocateDirect(bytes.size());
bytes.copyTo(buffer);
buffer.flip();
return parser.parseFrom(
CodedInputStream.newInstance(buffer.asReadOnlyBuffer()), extensions);
return parser.parseFrom(buffer, extensions);
}
case INPUT_STREAM_DECODER:
{

View file

@ -40,6 +40,7 @@
#include "google/protobuf/test_messages_proto3.pb.h"
#include "google/protobuf/text_format.h"
#include "google/protobuf/unknown_field_set.h"
#include "google/protobuf/util/message_differencer.h"
#include "google/protobuf/util/type_resolver_util.h"
#include "google/protobuf/wire_format_lite.h"
@ -498,6 +499,64 @@ void BinaryAndJsonConformanceSuite::RunMessageSetTests() {
})pb"
// clang-format on
);
// [type_id, value, type_id (different)] -> first type_id and value honored.
RunValidBinaryProtobufTest<TestAllTypesProto2>(
absl::StrCat("ValidMessageSetEncoding.DuplicateDifferentTypeId"),
RECOMMENDED,
len(500,
group(
1,
absl::StrCat(
field(2, WireFormatLite::WIRETYPE_VARINT, varint(4135312)),
len(3, field(9, WireFormatLite::WIRETYPE_VARINT, varint(99))),
field(2, WireFormatLite::WIRETYPE_VARINT, varint(1547769))))),
// clang-format off
R"pb(message_set_correct: {
[protobuf_test_messages.proto2
.TestAllTypesProto2.MessageSetCorrectExtension2]: { i: 99 }
})pb"
// clang-format on
);
// [type_id, value, value] -> first value honored, no merge.
RunValidBinaryProtobufTest<TestAllTypesProto2>(
absl::StrCat("ValidMessageSetEncoding.DuplicateValue"), RECOMMENDED,
len(500,
group(
1,
absl::StrCat(
field(2, WireFormatLite::WIRETYPE_VARINT, varint(4135312)),
len(3, field(9, WireFormatLite::WIRETYPE_VARINT, varint(99))),
len(3,
field(9, WireFormatLite::WIRETYPE_VARINT, varint(88)))))),
// clang-format off
R"pb(message_set_correct: {
[protobuf_test_messages.proto2
.TestAllTypesProto2.MessageSetCorrectExtension2]: { i: 99 }
})pb"
// clang-format on
);
// [value, type_id, value] -> first value honored, no merge.
RunValidBinaryProtobufTest<TestAllTypesProto2>(
absl::StrCat("ValidMessageSetEncoding.DuplicateValueOutOfOrder"),
RECOMMENDED,
len(500,
group(
1,
absl::StrCat(
len(3, field(9, WireFormatLite::WIRETYPE_VARINT, varint(99))),
field(2, WireFormatLite::WIRETYPE_VARINT, varint(4135312)),
len(3,
field(9, WireFormatLite::WIRETYPE_VARINT, varint(88)))))),
// clang-format off
R"pb(message_set_correct: {
[protobuf_test_messages.proto2
.TestAllTypesProto2.MessageSetCorrectExtension2]: { i: 99 }
})pb"
// clang-format on
);
}
void BinaryAndJsonConformanceSuite::RunRecursionLimitTests() {
@ -844,6 +903,66 @@ void BinaryAndJsonConformanceSuiteImpl<MessageType>::ExpectParseFailureForJson(
}
}
template <typename MessageType>
void BinaryAndJsonConformanceSuiteImpl<MessageType>::
RunValidJsonTestOrParseFailure(const std::string& test_name,
ConformanceLevel level,
const std::string& input_json,
const std::string& equivalent_text_format) {
MessageType prototype;
ConformanceRequestSetting setting(
level, ::conformance::JSON, ::conformance::PROTOBUF,
::conformance::JSON_TEST, prototype, test_name, input_json);
const ConformanceRequest& request = setting.GetRequest();
ConformanceResponse response;
std::string effective_test_name =
absl::StrCat(setting.ConformanceLevelToString(level), ".",
SyntaxIdentifier(), ".JsonInput.", test_name);
if (!suite_.RunTest(effective_test_name, request, &response)) {
return;
}
TestStatus test;
test.set_name(effective_test_name);
if (response.result_case() == ConformanceResponse::kParseError) {
suite_.ReportSuccess(test);
} else if (response.result_case() == ConformanceResponse::kSkipped) {
suite_.ReportSkip(test, request, response);
} else {
std::unique_ptr<Message> reference_message(setting.NewTestMessage());
ABSL_CHECK(TextFormat::ParseFromString(equivalent_text_format,
reference_message.get()))
<< "Failed to parse data for test case: " << setting.GetTestName()
<< ", data: " << equivalent_text_format;
std::unique_ptr<Message> test_message(setting.NewTestMessage());
bool parsed = false;
if (response.result_case() == ConformanceResponse::kProtobufPayload) {
parsed = test_message->ParseFromString(response.protobuf_payload());
}
if (!parsed) {
test.set_failure_message("Malformed protobuf response");
suite_.ReportFailure(test, level, request, response);
return;
}
util::MessageDifferencer differencer;
util::DefaultFieldComparator field_comparator;
field_comparator.set_treat_nan_as_equal(true);
differencer.set_field_comparator(&field_comparator);
std::string differences;
differencer.ReportDifferencesToString(&differences);
if (differencer.Compare(*reference_message, *test_message)) {
suite_.ReportSuccess(test);
} else {
test.set_failure_message(
"Should have failed to parse or matched expected output but did "
"not.");
suite_.ReportFailure(test, level, request, response);
}
}
}
template <typename MessageType>
void BinaryAndJsonConformanceSuiteImpl<MessageType>::
ExpectSerializeFailureForJson(const std::string& test_name,
@ -2369,22 +2488,27 @@ void BinaryAndJsonConformanceSuiteImpl<
ExpectParseFailureForJson(
"MissingCommaMultiline", RECOMMENDED,
"{\n \"optionalInt32\": 1\n \"optionalInt64\": 2\n}");
// Duplicated field names are not allowed.
ExpectParseFailureForJson("FieldNameDuplicate", RECOMMENDED,
R"({
"optionalNestedMessage": {"a": 1},
"optionalNestedMessage": {}
})");
ExpectParseFailureForJson("FieldNameDuplicateDifferentCasing1", RECOMMENDED,
R"({
"optional_nested_message": {"a": 1},
"optionalNestedMessage": {}
})");
ExpectParseFailureForJson("FieldNameDuplicateDifferentCasing2", RECOMMENDED,
R"({
"optionalNestedMessage": {"a": 1},
"optional_nested_message": {}
})");
// Duplicated field names have either last-wins or parse failure.
RunValidJsonTestOrParseFailure("FieldNameDuplicate", RECOMMENDED,
R"({
"optionalNestedMessage": {"a": 1},
"optionalNestedMessage": {}
})",
"optional_nested_message: {}");
RunValidJsonTestOrParseFailure("FieldNameDuplicateDifferentCasing1",
RECOMMENDED,
R"({
"optional_nested_message": {"a": 1},
"optionalNestedMessage": {}
})",
"optional_nested_message: {}");
RunValidJsonTestOrParseFailure("FieldNameDuplicateDifferentCasing2",
RECOMMENDED,
R"({
"optionalNestedMessage": {"a": 1},
"optional_nested_message": {}
})",
"optional_nested_message: {}");
// Serializers should use lowerCamelCase by default.
RunValidJsonTestWithValidator("FieldNameInLowerCamelCase", REQUIRED,
R"({
@ -2525,6 +2649,12 @@ void BinaryAndJsonConformanceSuiteImpl<
ExpectParseFailureForJson("Uint64FieldNotInteger", REQUIRED,
R"({"optionalUint64": "0.5"})");
// Parser reject boolean values for integer fields.
ExpectParseFailureForJson("Int32FieldTrueValue", REQUIRED,
R"({"optionalInt32": true})");
ExpectParseFailureForJson("Int32FieldFalseValue", REQUIRED,
R"({"optionalInt32": false})");
// Parser reject non-numeric string values.
ExpectParseFailureForJson("Int32FieldStringValuePartiallyNumeric", REQUIRED,
R"({"optionalInt32": "12abc"})");
@ -2696,6 +2826,12 @@ void BinaryAndJsonConformanceSuiteImpl<
ExpectParseFailureForJson("FloatFieldStringValuePartiallyNumericUnicode",
REQUIRED, R"({"optionalFloat": "1234"})");
// Parser reject boolean values for float fields.
ExpectParseFailureForJson("FloatFieldTrueValue", REQUIRED,
R"({"optionalFloat": true})");
ExpectParseFailureForJson("FloatFieldFalseValue", REQUIRED,
R"({"optionalFloat": false})");
// Double fields.
RunValidJsonTest("DoubleFieldMinPositiveValue", REQUIRED,
R"({"optionalDouble": 2.22507e-308})",
@ -2761,6 +2897,12 @@ void BinaryAndJsonConformanceSuiteImpl<
ExpectParseFailureForJson("DoubleFieldStringValueNonNumeric", REQUIRED,
R"({"optionalDouble": "abc"})");
// Parser reject boolean values for double fields.
ExpectParseFailureForJson("DoubleFieldTrueValue", REQUIRED,
R"({"optionalDouble": true})");
ExpectParseFailureForJson("DoubleFieldFalseValue", REQUIRED,
R"({"optionalDouble": false})");
// Enum fields.
RunValidJsonTest("EnumField", REQUIRED, R"({"optionalNestedEnum": "FOO"})",
"optional_nested_enum: FOO");
@ -2789,6 +2931,17 @@ void BinaryAndJsonConformanceSuiteImpl<
R"({"optionalNestedEnum": 0})", "optional_nested_enum: FOO");
RunValidJsonTest("EnumFieldNumericValueNonZero", REQUIRED,
R"({"optionalNestedEnum": 1})", "optional_nested_enum: BAR");
// Arrays are not allowed for non-repeated enum fields.
ExpectParseFailureForJson("EnumFieldSingleElementArrayEnumName", REQUIRED,
R"({"optionalNestedEnum": ["FOO"]})");
ExpectParseFailureForJson("EnumFieldSingleElementArrayNumericValue", REQUIRED,
R"({"optionalNestedEnum": [2]})");
// Booleans are not allowed for enum fields.
ExpectParseFailureForJson("EnumFieldTrueValue", REQUIRED,
R"({"optionalNestedEnum": true})");
ExpectParseFailureForJson("EnumFieldFalseValue", REQUIRED,
R"({"optionalNestedEnum": false})");
if (run_proto3_tests_) {
// Unknown enum values are represented as numeric values.
@ -2854,8 +3007,12 @@ void BinaryAndJsonConformanceSuiteImpl<
"optional_nested_message: {a: 1234}");
// Oneof fields.
ExpectParseFailureForJson("OneofFieldDuplicate", REQUIRED,
R"({"oneofUint32": 1, "oneofString": "test"})");
RunValidJsonTestOrParseFailure("OneofFieldDuplicate", REQUIRED,
R"({"oneofUint32": 1, "oneofString": "test"})",
"oneof_string: \"test\"");
RunValidJsonTestOrParseFailure("OneofFieldDuplicate2", REQUIRED,
R"({"oneofString": "test", "oneofUint32": 1})",
"oneof_uint32: 1");
RunValidJsonTest("OneofFieldNullFirst", REQUIRED,
R"({"oneofUint32": null, "oneofString": "test"})",
"oneof_string: \"test\"");
@ -3376,6 +3533,71 @@ void BinaryAndJsonConformanceSuiteImpl<
return value["optionalTimestamp"].asString() ==
"1970-01-01T00:00:00.000000010Z";
});
// Out of bounds / invalid components should JSON parse fail
ExpectParseFailureForJson("TimestampJsonInputMonthTooLarge", REQUIRED,
R"({"optionalTimestamp": "1970-13-01T00:00:00Z"})");
ExpectParseFailureForJson("TimestampJsonInputMonthZero", REQUIRED,
R"({"optionalTimestamp": "1970-00-01T00:00:00Z"})");
ExpectParseFailureForJson("TimestampJsonInputDayTooLarge", REQUIRED,
R"({"optionalTimestamp": "1970-01-32T00:00:00Z"})");
ExpectParseFailureForJson("TimestampJsonInputDayZero", REQUIRED,
R"({"optionalTimestamp": "1970-01-00T00:00:00Z"})");
ExpectParseFailureForJson("TimestampJsonInputHourTooLarge", REQUIRED,
R"({"optionalTimestamp": "1970-01-01T24:00:00Z"})");
ExpectParseFailureForJson("TimestampJsonInputHourTooLarge25", REQUIRED,
R"({"optionalTimestamp": "1970-01-01T25:00:00Z"})");
ExpectParseFailureForJson("TimestampJsonInputMinuteTooLarge", REQUIRED,
R"({"optionalTimestamp": "1970-01-01T00:60:00Z"})");
ExpectParseFailureForJson("TimestampJsonInputSecondTooLarge", REQUIRED,
R"({"optionalTimestamp": "1970-01-01T00:00:60Z"})");
ExpectParseFailureForJson(
"TimestampJsonInputInvalidOffsetHour", REQUIRED,
R"({"optionalTimestamp": "1970-01-01T00:00:00+24:00"})");
ExpectParseFailureForJson(
"TimestampJsonInputInvalidOffsetMinute", REQUIRED,
R"({"optionalTimestamp": "1970-01-01T00:00:00+00:60"})");
ExpectParseFailureForJson(
"TimestampJsonInputOffsetBoundaryUnderflow", REQUIRED,
R"({"optionalTimestamp": "0001-01-01T00:00:00+00:01"})");
ExpectParseFailureForJson(
"TimestampJsonInputOffsetBoundaryOverflow", REQUIRED,
R"({"optionalTimestamp": "9999-12-31T23:59:59-00:01"})");
ExpectParseFailureForJson(
"TimestampJsonInputInvalidNanos", REQUIRED,
R"({"optionalTimestamp": "1970-01-01T00:00:00.1234567890Z"})");
ExpectParseFailureForJson(
"TimestampJsonInputInvalidCharsInNanos", REQUIRED,
R"({"optionalTimestamp": "1970-01-01T00:00:00.123aZ"})");
ExpectParseFailureForJson("TimestampJsonInputYearTooShort", REQUIRED,
R"({"optionalTimestamp": "999-01-01T00:00:00Z"})");
ExpectParseFailureForJson(
"TimestampJsonInputYearTooLong", REQUIRED,
R"({"optionalTimestamp": "00001-01-01T00:00:00Z"})");
ExpectParseFailureForJson("TimestampJsonInputMonthTooShort", REQUIRED,
R"({"optionalTimestamp": "1970-1-01T00:00:00Z"})");
ExpectParseFailureForJson("TimestampJsonInputDayTooShort", REQUIRED,
R"({"optionalTimestamp": "1970-01-1T00:00:00Z"})");
ExpectParseFailureForJson("TimestampJsonInputNonLeapFeb29", REQUIRED,
R"({"optionalTimestamp": "2001-02-29T00:00:00Z"})");
// Honoring time zones correctly
RunValidJsonTest("TimestampJsonInputLeapFeb29", REQUIRED,
R"({"optionalTimestamp": "2000-02-29T00:00:00Z"})",
"optional_timestamp: {seconds: 951782400}");
RunValidJsonTest("TimestampWithOffsetShiftsDay", REQUIRED,
R"({"optionalTimestamp": "1970-01-02T01:00:00+02:00"})",
"optional_timestamp: {seconds: 82800}");
RunValidJsonTest("TimestampWithOffsetBoundaryInBoundsMin", REQUIRED,
R"({"optionalTimestamp": "0001-01-01T00:00:00-00:01"})",
"optional_timestamp: {seconds: -62135596740}");
RunValidJsonTest("TimestampWithOffsetBoundaryInBoundsMax", REQUIRED,
R"({"optionalTimestamp": "9999-12-31T23:59:59+00:01"})",
"optional_timestamp: {seconds: 253402300739}");
RunValidJsonTest("TimestampWithComplexOffset", REQUIRED,
R"({"optionalTimestamp": "1970-01-01T00:00:00-11:30"})",
"optional_timestamp: {seconds: 41400}");
}
template <typename MessageType>

View file

@ -147,6 +147,9 @@ class BinaryAndJsonConformanceSuiteImpl {
void ExpectParseFailureForJson(const std::string& test_name,
ConformanceLevel level,
const std::string& input_json);
void RunValidJsonTestOrParseFailure(
const std::string& test_name, ConformanceLevel level,
const std::string& input_json, const std::string& equivalent_text_format);
void ExpectSerializeFailureForJson(const std::string& test_name,
ConformanceLevel level,
const std::string& text_format);

View file

@ -9,9 +9,9 @@
Recommended.*.JsonInput.BoolFieldDoubleQuotedFalse # Should have failed to parse, but didn't.
Recommended.*.JsonInput.BoolFieldDoubleQuotedTrue # Should have failed to parse, but didn't.
Recommended.*.JsonInput.FieldNameDuplicate # Should have failed to parse, but didn't.
Recommended.*.JsonInput.FieldNameDuplicateDifferentCasing1 # Should have failed to parse, but didn't.
Recommended.*.JsonInput.FieldNameDuplicateDifferentCasing2 # Should have failed to parse, but didn't.
Recommended.*.JsonInput.FieldNameDuplicate # Should have failed to parse or matched expected output but did not.
Recommended.*.JsonInput.FieldNameDuplicateDifferentCasing1 # Should have failed to parse or matched expected output but did not.
Recommended.*.JsonInput.FieldNameDuplicateDifferentCasing2 # Should have failed to parse or matched expected output but did not.
Recommended.*.JsonInput.FieldNameNotQuoted # Should have failed to parse, but didn't.
Recommended.*.JsonInput.MapFieldValueIsNull # Should have failed to parse, but didn't.
Recommended.*.JsonInput.RepeatedFieldMessageElementIsNull # Should have failed to parse, but didn't.
@ -34,6 +34,17 @@ Recommended.*.FieldMaskTooManyUnderscore.JsonOutput
Recommended.*.JsonInput.FieldMaskInvalidCharacter # Should have failed to parse, but didn't.
Required.*.JsonInput.SingleValueForRepeatedFieldInt32 # Should have failed to parse, but didn't.
Required.*.JsonInput.SingleValueForRepeatedFieldMessage # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputDayTooLarge # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputHourTooLarge # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputHourTooLarge25 # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputInvalidOffsetHour # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputInvalidOffsetMinute # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputMinuteTooLarge # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputMonthTooLarge # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputNonLeapFeb29 # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputOffsetBoundaryOverflow # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputOffsetBoundaryUnderflow # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputSecondTooLarge # Should have failed to parse, but didn't.
Required.*.ProtobufInput.BadTag_FieldNumberSlightlyTooHigh # Should have failed to parse, but didn't.
# TODO: Uncomment once conformance tests can express failures that are not expected to be fixed.
# Recommended.Editions_Proto2.ProtobufInput.RejectInvalidUtf8.String.MapKey # Should have failed to parse, but didn't.

View file

@ -1,6 +1,3 @@
Recommended.*.JsonInput.FieldNameDuplicate # Should have failed to parse, but didn't.
Recommended.*.JsonInput.FieldNameDuplicateDifferentCasing1 # Should have failed to parse, but didn't.
Recommended.*.JsonInput.FieldNameDuplicateDifferentCasing2 # Should have failed to parse, but didn't.
Recommended.Proto2.JsonInput.FieldNameExtension.Validator
Recommended.Proto2.JsonInput.BytesFieldBase64Url.JsonOutput
Recommended.Proto2.JsonInput.BytesFieldBase64Url.ProtobufOutput

View file

@ -14,7 +14,6 @@ Recommended.*.JsonInput.BoolMapFieldKeyNotQuoted
Recommended.*.JsonInput.DoubleFieldInfinityNotQuoted # Should have failed to parse, but didn't.
Recommended.*.JsonInput.DoubleFieldNanNotQuoted # Should have failed to parse, but didn't.
Recommended.*.JsonInput.DoubleFieldNegativeInfinityNotQuoted # Should have failed to parse, but didn't.
Recommended.*.JsonInput.FieldNameDuplicate # Should have failed to parse, but didn't.
Recommended.*.JsonInput.FieldNameExtension.Validator # Expected JSON payload but got type 1
Recommended.*.JsonInput.FieldNameNotQuoted # Should have failed to parse, but didn't.
Recommended.*.JsonInput.FloatFieldInfinityNotQuoted # Should have failed to parse, but didn't.
@ -36,12 +35,30 @@ Recommended.*.FieldMaskPathsDontRoundTrip.JsonOutput
Recommended.*.FieldMaskTooManyUnderscore.JsonOutput # Should have failed to serialize, but didn't.
Recommended.*.JsonInput.FieldMaskInvalidCharacter # Should have failed to parse, but didn't.
Required.*.JsonInput.EnumFieldNotQuoted # Should have failed to parse, but didn't.
Required.*.JsonInput.EnumFieldSingleElementArrayEnumName # Should have failed to parse, but didn't.
Required.*.JsonInput.EnumFieldSingleElementArrayNumericValue # Should have failed to parse, but didn't.
Required.*.JsonInput.Int32FieldLeadingZero # Should have failed to parse, but didn't.
Required.*.JsonInput.Int32FieldNegativeWithLeadingZero # Should have failed to parse, but didn't.
Required.*.JsonInput.Int32FieldPlusSign # Should have failed to parse, but didn't.
Required.*.JsonInput.RepeatedFieldWrongElementTypeExpectingStringsGotBool # Should have failed to parse, but didn't.
Required.*.JsonInput.RepeatedFieldWrongElementTypeExpectingStringsGotInt # Should have failed to parse, but didn't.
Required.*.JsonInput.StringFieldNotAString # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputDayTooLarge # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputDayTooShort # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputDayZero # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputHourTooLarge # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputHourTooLarge25 # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputInvalidNanos # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputInvalidOffsetHour # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputInvalidOffsetMinute # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputMinuteTooLarge # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputMonthTooLarge # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputMonthTooShort # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputMonthZero # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputNonLeapFeb29 # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputSecondTooLarge # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputYearTooLong # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputYearTooShort # Should have failed to parse, but didn't.
Required.*.ProtobufInput.UnknownOrdering.ProtobufOutput # Unknown field mismatch
Required.*.ProtobufInput.BadTag_FieldNumberTooHigh # Should have failed to parse, but didn't.
Required.*.ProtobufInput.BadTag_FieldNumberSlightlyTooHigh # Should have failed to parse, but didn't.
@ -53,3 +70,6 @@ Required.*.ProtobufInput.BadTag_OverlongVarint
# Recommended.Proto2.ProtobufInput.RejectInvalidUtf8.String.Oneof # Should have failed to parse, but didn't.
# Recommended.Proto2.ProtobufInput.RejectInvalidUtf8.String.Repeated # Should have failed to parse, but didn't.
# Recommended.Proto2.ProtobufInput.RejectInvalidUtf8.String.Singular # Should have failed to parse, but didn't.
Recommended.Proto2.ProtobufInput.ValidMessageSetEncoding.DuplicateDifferentTypeId.ProtobufOutput # Output was not equivalent to reference message
Recommended.Proto2.ProtobufInput.ValidMessageSetEncoding.DuplicateValue.ProtobufOutput # Output was not equivalent to reference message
Recommended.Proto2.ProtobufInput.ValidMessageSetEncoding.DuplicateValueOutOfOrder.ProtobufOutput # Output was not equivalent to reference message

View file

@ -4,8 +4,6 @@
# By listing them here we can keep tabs on which ones are failing and be sure
# that we don't introduce regressions in other tests.
Required.*.ProtobufInput.PrematureEofInDelimitedDataForKnownNonRepeatedValue.MESSAGE # Should have failed to parse, but didn't.
Required.*.ProtobufInput.PrematureEofInDelimitedDataForKnownRepeatedValue.MESSAGE # Should have failed to parse, but didn't.
Required.*.ProtobufInput.BadTag_FieldNumberTooHigh # Should have failed to parse, but didn't.
Required.*.ProtobufInput.BadTag_FieldNumberSlightlyTooHigh # Should have failed to parse, but didn't.
Required.*.ProtobufInput.BadTag_OverlongVarint # Should have failed to parse, but didn't.
@ -17,3 +15,4 @@ Recommended.Editions.ProtobufInput.RejectInvalidUtf8.String.Extension
# Recommended.Proto2.ProtobufInput.RejectInvalidUtf8.String.Oneof # Should have failed to parse, but didn't.
# Recommended.Proto2.ProtobufInput.RejectInvalidUtf8.String.Repeated # Should have failed to parse, but didn't.
# Recommended.Proto2.ProtobufInput.RejectInvalidUtf8.String.Singular # Should have failed to parse, but didn't.
Recommended.Proto2.ProtobufInput.ValidMessageSetEncoding.DuplicateValue.ProtobufOutput # Output was not equivalent to reference message

View file

@ -11,7 +11,6 @@ Recommended.Proto2.JsonInput.BoolMapFieldKeyNotQuoted
Recommended.Proto2.JsonInput.DoubleFieldInfinityNotQuoted
Recommended.Proto2.JsonInput.DoubleFieldNanNotQuoted
Recommended.Proto2.JsonInput.DoubleFieldNegativeInfinityNotQuoted
Recommended.Proto2.JsonInput.FieldNameDuplicate
Recommended.Proto2.JsonInput.FieldNameExtension.Validator
Recommended.Proto2.JsonInput.FieldNameNotQuoted
Recommended.Proto2.JsonInput.FloatFieldInfinityNotQuoted
@ -39,7 +38,6 @@ Recommended.Proto3.JsonInput.DoubleFieldInfinityNotQuoted
Recommended.Proto3.JsonInput.DoubleFieldNanNotQuoted
Recommended.Proto3.JsonInput.DoubleFieldNegativeInfinityNotQuoted
Recommended.Proto3.JsonInput.FieldMaskInvalidCharacter
Recommended.Proto3.JsonInput.FieldNameDuplicate
Recommended.Proto3.JsonInput.FieldNameNotQuoted
Recommended.Proto3.JsonInput.FloatFieldInfinityNotQuoted
Recommended.Proto3.JsonInput.FloatFieldNanNotQuoted
@ -56,6 +54,8 @@ Recommended.Proto3.JsonInput.StringFieldUnpairedLowSurrogate
Recommended.Proto3.JsonInput.Uint32MapFieldKeyNotQuoted
Recommended.Proto3.JsonInput.Uint64MapFieldKeyNotQuoted
Required.Proto2.JsonInput.EnumFieldNotQuoted
Required.Proto2.JsonInput.EnumFieldSingleElementArrayEnumName
Required.Proto2.JsonInput.EnumFieldSingleElementArrayNumericValue
Required.Proto2.JsonInput.Int32FieldLeadingZero
Required.Proto2.JsonInput.Int32FieldNegativeWithLeadingZero
Required.Proto2.JsonInput.Int32FieldPlusSign
@ -63,6 +63,8 @@ Required.Proto2.JsonInput.RepeatedFieldWrongElementTypeExpectingStringsGotBool
Required.Proto2.JsonInput.RepeatedFieldWrongElementTypeExpectingStringsGotInt
Required.Proto2.JsonInput.StringFieldNotAString
Required.Proto3.JsonInput.EnumFieldNotQuoted
Required.Proto3.JsonInput.EnumFieldSingleElementArrayEnumName
Required.Proto3.JsonInput.EnumFieldSingleElementArrayNumericValue
Required.Proto3.JsonInput.Int32FieldLeadingZero
Required.Proto3.JsonInput.Int32FieldNegativeWithLeadingZero
Required.Proto3.JsonInput.Int32FieldPlusSign
@ -82,7 +84,6 @@ Recommended.Editions_Proto2.JsonInput.BoolMapFieldKeyNotQuoted
Recommended.Editions_Proto2.JsonInput.DoubleFieldInfinityNotQuoted
Recommended.Editions_Proto2.JsonInput.DoubleFieldNanNotQuoted
Recommended.Editions_Proto2.JsonInput.DoubleFieldNegativeInfinityNotQuoted
Recommended.Editions_Proto2.JsonInput.FieldNameDuplicate
Recommended.Editions_Proto2.JsonInput.FieldNameExtension.Validator
Recommended.Editions_Proto2.JsonInput.FieldNameNotQuoted
Recommended.Editions_Proto2.JsonInput.FloatFieldInfinityNotQuoted
@ -110,7 +111,6 @@ Recommended.Editions_Proto3.JsonInput.DoubleFieldInfinityNotQuoted
Recommended.Editions_Proto3.JsonInput.DoubleFieldNanNotQuoted
Recommended.Editions_Proto3.JsonInput.DoubleFieldNegativeInfinityNotQuoted
Recommended.Editions_Proto3.JsonInput.FieldMaskInvalidCharacter
Recommended.Editions_Proto3.JsonInput.FieldNameDuplicate
Recommended.Editions_Proto3.JsonInput.FieldNameNotQuoted
Recommended.Editions_Proto3.JsonInput.FloatFieldInfinityNotQuoted
Recommended.Editions_Proto3.JsonInput.FloatFieldNanNotQuoted
@ -127,6 +127,8 @@ Recommended.Editions_Proto3.JsonInput.StringFieldUnpairedLowSurrogate
Recommended.Editions_Proto3.JsonInput.Uint32MapFieldKeyNotQuoted
Recommended.Editions_Proto3.JsonInput.Uint64MapFieldKeyNotQuoted
Required.Editions_Proto2.JsonInput.EnumFieldNotQuoted
Required.Editions_Proto2.JsonInput.EnumFieldSingleElementArrayEnumName
Required.Editions_Proto2.JsonInput.EnumFieldSingleElementArrayNumericValue
Required.Editions_Proto2.JsonInput.Int32FieldLeadingZero
Required.Editions_Proto2.JsonInput.Int32FieldNegativeWithLeadingZero
Required.Editions_Proto2.JsonInput.Int32FieldPlusSign
@ -134,6 +136,8 @@ Required.Editions_Proto2.JsonInput.RepeatedFieldWrongElementTypeExpectingStrings
Required.Editions_Proto2.JsonInput.RepeatedFieldWrongElementTypeExpectingStringsGotInt
Required.Editions_Proto2.JsonInput.StringFieldNotAString
Required.Editions_Proto3.JsonInput.EnumFieldNotQuoted
Required.Editions_Proto3.JsonInput.EnumFieldSingleElementArrayEnumName
Required.Editions_Proto3.JsonInput.EnumFieldSingleElementArrayNumericValue
Required.Editions_Proto3.JsonInput.Int32FieldLeadingZero
Required.Editions_Proto3.JsonInput.Int32FieldNegativeWithLeadingZero
Required.Editions_Proto3.JsonInput.Int32FieldPlusSign
@ -154,3 +158,23 @@ Required.*.ProtobufInput.BadTag_OverlongVarint
# Recommended.Proto2.ProtobufInput.RejectInvalidUtf8.String.Oneof # Should have failed to parse, but didn't.
# Recommended.Proto2.ProtobufInput.RejectInvalidUtf8.String.Repeated # Should have failed to parse, but didn't.
# Recommended.Proto2.ProtobufInput.RejectInvalidUtf8.String.Singular # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputDayTooLarge # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputDayTooShort # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputDayZero # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputHourTooLarge # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputHourTooLarge25 # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputInvalidNanos # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputInvalidOffsetHour # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputInvalidOffsetMinute # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputMinuteTooLarge # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputMonthTooLarge # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputMonthTooShort # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputMonthZero # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputNonLeapFeb29 # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputSecondTooLarge # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputYearTooLong # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputYearTooShort # Should have failed to parse, but didn't.
Recommended.Proto2.ProtobufInput.ValidMessageSetEncoding.DuplicateDifferentTypeId.ProtobufOutput # Output was not equivalent to reference message
Recommended.Proto2.ProtobufInput.ValidMessageSetEncoding.DuplicateValue.ProtobufOutput # Output was not equivalent to reference message
Recommended.Proto2.ProtobufInput.ValidMessageSetEncoding.DuplicateValueOutOfOrder.ProtobufOutput # Output was not equivalent to reference message

View file

@ -1,6 +1,6 @@
Recommended.*.JsonInput.FieldNameDuplicate # Should have failed to parse, but didn't.
Recommended.*.JsonInput.FieldNameDuplicateDifferentCasing1 # Should have failed to parse, but didn't.
Recommended.*.JsonInput.FieldNameDuplicateDifferentCasing2 # Should have failed to parse, but didn't.
Recommended.*.JsonInput.FieldNameDuplicate # Should have failed to parse or matched expected output but did not.
Recommended.*.JsonInput.FieldNameDuplicateDifferentCasing1 # Should have failed to parse or matched expected output but did not.
Recommended.*.JsonInput.FieldNameDuplicateDifferentCasing2 # Should have failed to parse or matched expected output but did not.
Required.*.JsonInput.Int32FieldQuotedExponentialValue.* # Failed to parse input or produce output.
Required.*.JsonInput.AnyWithNoType.* # Failed to parse input or produce output.
# TODO: Uncomment once conformance tests can express failures that are not expected to be fixed.
@ -14,3 +14,16 @@ Required.*.JsonInput.AnyWithNoType.* # Fa
# Recommended.Proto2.ProtobufInput.RejectInvalidUtf8.String.Oneof # Should have failed to parse, but didn't.
# Recommended.Proto2.ProtobufInput.RejectInvalidUtf8.String.Repeated # Should have failed to parse, but didn't.
# Recommended.Proto2.ProtobufInput.RejectInvalidUtf8.String.Singular # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputDayTooLarge # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputDayZero # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputHourTooLarge # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputHourTooLarge25 # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputInvalidOffsetHour # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputInvalidOffsetMinute # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputMinuteTooLarge # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputMonthTooLarge # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputMonthZero # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputNonLeapFeb29 # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputOffsetBoundaryOverflow # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputSecondTooLarge # Should have failed to parse, but didn't.

View file

@ -3,4 +3,3 @@
#
# By listing them here we can keep tabs on which ones are failing and be sure
# that we don't introduce regressions in other tests.
Recommended.Proto2.ProtobufInput.EnforceDepthLimit.MessageSetExtension # Should have failed to parse, but didn't.

View file

@ -4,9 +4,8 @@ Recommended.*.FieldMaskTooManyUnderscore.JsonOutput
Recommended.*.JsonInput.BytesFieldBase64Url.JsonOutput
Recommended.*.JsonInput.BytesFieldBase64Url.ProtobufOutput
Recommended.*.JsonInput.FieldMaskInvalidCharacter
Recommended.*.JsonInput.FieldNameDuplicate # Should have failed to parse, but didn't.
Recommended.*.JsonInput.FieldNameDuplicateDifferentCasing1 # Should have failed to parse, but didn't.
Recommended.*.JsonInput.FieldNameDuplicateDifferentCasing2 # Should have failed to parse, but didn't.
Recommended.*.JsonInput.FieldNameDuplicateDifferentCasing1 # Should have failed to parse or matched expected output but did not.
Recommended.*.JsonInput.FieldNameDuplicateDifferentCasing2 # Should have failed to parse or matched expected output but did not.
Recommended.*.ProtobufInput.ValidDataOneofBinary.MESSAGE.Merge.ProtobufOutput
Recommended.*.ValueRejectInfNumberValue.JsonOutput # Should have failed to serialize, but didn't.
Recommended.*.ValueRejectNanNumberValue.JsonOutput # Should have failed to serialize, but didn't.
@ -17,7 +16,6 @@ Required.*.JsonInput.FloatFieldTooLarge
Required.*.JsonInput.FloatFieldTooSmall
Required.*.JsonInput.Int32FieldNotInteger
Required.*.JsonInput.Int64FieldNotInteger
Required.*.JsonInput.OneofFieldDuplicate
Required.*.JsonInput.OneofFieldNullSecond.JsonOutput
Required.*.JsonInput.OneofFieldNullSecond.ProtobufOutput
Required.*.JsonInput.RepeatedFieldWrongElementTypeExpectingStringsGotInt
@ -52,3 +50,23 @@ Required.*.ProtobufInput.BadTag_FieldNumberTooHigh
Required.*.ProtobufInput.BadTag_FieldNumberSlightlyTooHigh # Should have failed to parse, but didn't.
Required.*.ProtobufInput.BadTag_OverlongVarint # Should have failed to parse, but didn't.
Required.*.ProtobufInput.BadTag_VarintMoreThanTenBytes # Should have failed to parse, but didn't.
Required.*.JsonInput.DoubleFieldFalseValue # Should have failed to parse, but didn't.
Required.*.JsonInput.DoubleFieldTrueValue # Should have failed to parse, but didn't.
Required.*.JsonInput.FloatFieldFalseValue # Should have failed to parse, but didn't.
Required.*.JsonInput.FloatFieldTrueValue # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputDayTooLarge # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputDayTooShort # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputDayZero # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputHourTooLarge # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputHourTooLarge25 # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputInvalidOffsetHour # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputInvalidOffsetMinute # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputMinuteTooLarge # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputMonthTooLarge # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputMonthTooShort # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputMonthZero # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputNonLeapFeb29 # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputOffsetBoundaryOverflow # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputOffsetBoundaryUnderflow # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputSecondTooLarge # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputYearTooShort # Should have failed to parse, but didn't.

View file

@ -1,6 +1,6 @@
Recommended.*.JsonInput.FieldNameDuplicate # Should have failed to parse, but didn't.
Recommended.*.JsonInput.FieldNameDuplicateDifferentCasing1 # Should have failed to parse, but didn't.
Recommended.*.JsonInput.FieldNameDuplicateDifferentCasing2 # Should have failed to parse, but didn't.
Recommended.*.JsonInput.FieldNameDuplicate # Should have failed to parse or matched expected output but did not.
Recommended.*.JsonInput.FieldNameDuplicateDifferentCasing1 # Should have failed to parse or matched expected output but did not.
Recommended.*.JsonInput.FieldNameDuplicateDifferentCasing2 # Should have failed to parse or matched expected output but did not.
Recommended.Proto2.JsonInput.FieldNameExtension.Validator
Required.*.JsonInput.Int32FieldQuotedExponentialValue.* # Failed to parse input or produce output.
Required.Proto2.JsonInput.BoolFieldFalse.JsonOutput
@ -11,3 +11,15 @@ Required.Proto2.JsonInput.EnumFieldNumericValueZero.JsonOutput
Required.Proto2.JsonInput.EnumFieldNumericValueZero.ProtobufOutput
Required.Proto2.JsonInput.StoresDefaultPrimitive.Validator
Required.*.JsonInput.AnyWithNoType.*
Required.*.JsonInput.TimestampJsonInputDayTooLarge # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputDayZero # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputHourTooLarge # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputHourTooLarge25 # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputInvalidOffsetHour # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputInvalidOffsetMinute # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputMinuteTooLarge # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputMonthTooLarge # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputMonthZero # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputNonLeapFeb29 # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputOffsetBoundaryOverflow # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputSecondTooLarge # Should have failed to parse, but didn't.

View file

@ -1,5 +1,15 @@
Recommended.*.JsonInput.FieldNameDuplicateDifferentCasing1 # Should have failed to parse, but didn't.
Recommended.*.JsonInput.FieldNameDuplicateDifferentCasing2 # Should have failed to parse, but didn't.
Recommended.*.JsonInput.FieldNameDuplicateDifferentCasing1 # Should have failed to parse or matched expected output but did not.
Recommended.*.JsonInput.FieldNameDuplicateDifferentCasing2 # Should have failed to parse or matched expected output but did not.
Required.*.JsonInput.DoubleFieldFalseValue # Should have failed to parse, but didn't.
Required.*.JsonInput.DoubleFieldTrueValue # Should have failed to parse, but didn't.
Required.*.JsonInput.EnumFieldFalseValue # Should have failed to parse, but didn't.
Required.*.JsonInput.EnumFieldTrueValue # Should have failed to parse, but didn't.
Required.*.JsonInput.FloatFieldFalseValue # Should have failed to parse, but didn't.
Required.*.JsonInput.FloatFieldTrueValue # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputDayTooShort # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputInvalidOffsetHour # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputInvalidOffsetMinute # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputMonthTooShort # Should have failed to parse, but didn't.
Required.*.ProtobufInput.BadTag_FieldNumberTooHigh # Should have failed to parse, but didn't.
Required.*.ProtobufInput.BadTag_FieldNumberSlightlyTooHigh # Should have failed to parse, but didn't.
Required.*.ProtobufInput.BadTag_OverlongVarint # Should have failed to parse, but didn't.

View file

@ -7,8 +7,18 @@
# TODO: insert links to corresponding bugs tracking the issue.
# Should we use GitHub issues or the Google-internal bug tracker?
Recommended.*.JsonInput.FieldNameDuplicateDifferentCasing1 # Should have failed to parse, but didn't.
Recommended.*.JsonInput.FieldNameDuplicateDifferentCasing2 # Should have failed to parse, but didn't.
Recommended.*.JsonInput.FieldNameDuplicateDifferentCasing1 # Should have failed to parse or matched expected output but did not.
Recommended.*.JsonInput.FieldNameDuplicateDifferentCasing2 # Should have failed to parse or matched expected output but did not.
Required.*.JsonInput.DoubleFieldFalseValue # Should have failed to parse, but didn't.
Required.*.JsonInput.DoubleFieldTrueValue # Should have failed to parse, but didn't.
Required.*.JsonInput.EnumFieldFalseValue # Should have failed to parse, but didn't.
Required.*.JsonInput.EnumFieldTrueValue # Should have failed to parse, but didn't.
Required.*.JsonInput.FloatFieldFalseValue # Should have failed to parse, but didn't.
Required.*.JsonInput.FloatFieldTrueValue # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputDayTooShort # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputInvalidOffsetHour # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputInvalidOffsetMinute # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputMonthTooShort # Should have failed to parse, but didn't.
Required.*.ProtobufInput.BadTag_FieldNumberSlightlyTooHigh # Should have failed to parse, but didn't.
# TODO: Uncomment once conformance tests can express failures that are not expected to be fixed.
# Recommended.Editions_Proto2.ProtobufInput.RejectInvalidUtf8.String.MapKey # Should have failed to parse, but didn't.

View file

@ -1,5 +1,11 @@
Recommended.*.JsonInput.FieldNameDuplicateDifferentCasing1 # Should have failed to parse, but didn't.
Recommended.*.JsonInput.FieldNameDuplicateDifferentCasing2 # Should have failed to parse, but didn't.
Recommended.*.JsonInput.FieldNameDuplicateDifferentCasing1 # Should have failed to parse or matched expected output but did not.
Recommended.*.JsonInput.FieldNameDuplicateDifferentCasing2 # Should have failed to parse or matched expected output but did not.
Required.*.JsonInput.DoubleFieldFalseValue # Should have failed to parse, but didn't.
Required.*.JsonInput.DoubleFieldTrueValue # Should have failed to parse, but didn't.
Required.*.JsonInput.EnumFieldFalseValue # Should have failed to parse, but didn't.
Required.*.JsonInput.EnumFieldTrueValue # Should have failed to parse, but didn't.
Required.*.JsonInput.FloatFieldFalseValue # Should have failed to parse, but didn't.
Required.*.JsonInput.FloatFieldTrueValue # Should have failed to parse, but didn't.
# TODO: Uncomment once conformance tests can express failures that are not expected to be fixed.
# Recommended.Editions_Proto2.ProtobufInput.RejectInvalidUtf8.String.MapKey # Should have failed to parse, but didn't.
# Recommended.Editions_Proto2.ProtobufInput.RejectInvalidUtf8.String.MapValue # Should have failed to parse, but didn't.
@ -11,3 +17,8 @@ Recommended.*.JsonInput.FieldNameDuplicateDifferentCasing2 # Sh
# Recommended.Proto2.ProtobufInput.RejectInvalidUtf8.String.Oneof # Should have failed to parse, but didn't.
# Recommended.Proto2.ProtobufInput.RejectInvalidUtf8.String.Repeated # Should have failed to parse, but didn't.
# Recommended.Proto2.ProtobufInput.RejectInvalidUtf8.String.Singular # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputDayTooShort # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputInvalidOffsetHour # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputInvalidOffsetMinute # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputMonthTooShort # Should have failed to parse, but didn't.

View file

@ -1,6 +1,6 @@
Recommended.*.JsonInput.FieldNameDuplicate # Should have failed to parse, but didn't.
Recommended.*.JsonInput.FieldNameDuplicateDifferentCasing1 # Should have failed to parse, but didn't.
Recommended.*.JsonInput.FieldNameDuplicateDifferentCasing2 # Should have failed to parse, but didn't.
Recommended.*.JsonInput.FieldNameDuplicate # Should have failed to parse or matched expected output but did not.
Recommended.*.JsonInput.FieldNameDuplicateDifferentCasing1 # Should have failed to parse or matched expected output but did not.
Recommended.*.JsonInput.FieldNameDuplicateDifferentCasing2 # Should have failed to parse or matched expected output but did not.
Required.*.JsonInput.Int32FieldQuotedExponentialValue.* # Failed to parse input or produce output.
Required.*.JsonInput.AnyWithNoType.*
# TODO: Uncomment once conformance tests can express failures that are not expected to be fixed.
@ -14,3 +14,16 @@ Required.*.JsonInput.AnyWithNoType.*
# Recommended.Proto2.ProtobufInput.RejectInvalidUtf8.String.Oneof # Should have failed to parse, but didn't.
# Recommended.Proto2.ProtobufInput.RejectInvalidUtf8.String.Repeated # Should have failed to parse, but didn't.
# Recommended.Proto2.ProtobufInput.RejectInvalidUtf8.String.Singular # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputDayTooLarge # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputDayZero # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputHourTooLarge # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputHourTooLarge25 # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputInvalidOffsetHour # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputInvalidOffsetMinute # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputMinuteTooLarge # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputMonthTooLarge # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputMonthZero # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputNonLeapFeb29 # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputOffsetBoundaryOverflow # Should have failed to parse, but didn't.
Required.*.JsonInput.TimestampJsonInputSecondTooLarge # Should have failed to parse, but didn't.

View file

@ -15,7 +15,7 @@ load("//upb/cmake:build_defs.bzl", "staleness_test")
filegroup(
name = "c_sharp_features_proto_srcs",
srcs = ["google/protobuf/c_sharp_features.proto"],
visibility = ["//:__subpackages__"],
visibility = ["//src/google/protobuf:__pkg__"],
)
proto_library(

View file

@ -5,7 +5,7 @@
<title>Google Protocol Buffers tools</title>
<summary>Tools for Protocol Buffers - Google's data interchange format.</summary>
<description>See project site for more info.</description>
<version>3.36.0</version>
<version>3.37.0</version>
<authors>Google Inc.</authors>
<owners>protobuf-packages</owners>
<licenseUrl>https://github.com/protocolbuffers/protobuf/blob/main/LICENSE</licenseUrl>

View file

@ -46,6 +46,12 @@ $PROTOC -Isrc --csharp_out=csharp/src/Google.Protobuf \
src/google/protobuf/wrappers.proto \
src/google/protobuf/compiler/plugin.proto
# JSON options
$PROTOC -Isrc --csharp_out=csharp/src/Google.Protobuf \
--csharp_opt=file_extension=.pb.cs \
src/google/protobuf/json_options.proto \
src/google/protobuf/json_enumvalue_options.proto
# C# features
$PROTOC -Icsharp -Isrc --csharp_out=csharp/src/Google.Protobuf \
--csharp_opt=base_namespace=Google.Protobuf \
@ -88,7 +94,8 @@ $PROTOC -Isrc -I. -Ijava/core/src/main/resources/ \
src/google/protobuf/unittest_features.proto \
src/google/protobuf/unittest_legacy_features.proto \
src/google/protobuf/unittest_proto3_optional.proto \
src/google/protobuf/unittest_retention.proto
src/google/protobuf/unittest_retention.proto \
src/google/protobuf/json/json_enumval_custom_string.proto
# We can safely ignore the unused import warning as the
# purpose of the test is to work with the dependencies

View file

@ -0,0 +1,344 @@
// <auto-generated>
// Generated by the protocol buffer compiler. DO NOT EDIT!
// source: google/protobuf/json/json_enumval_custom_string.proto
// </auto-generated>
#pragma warning disable 1591, 0612, 3021, 8981
#region Designer generated code
using pb = global::Google.Protobuf;
using pbc = global::Google.Protobuf.Collections;
using pbr = global::Google.Protobuf.Reflection;
using scg = global::System.Collections.Generic;
namespace JsonEnumvalCustomString {
/// <summary>Holder for reflection information generated from google/protobuf/json/json_enumval_custom_string.proto</summary>
public static partial class JsonEnumvalCustomStringReflection {
#region Descriptor
/// <summary>File descriptor for google/protobuf/json/json_enumval_custom_string.proto</summary>
public static pbr::FileDescriptor Descriptor {
get { return descriptor; }
}
private static pbr::FileDescriptor descriptor;
static JsonEnumvalCustomStringReflection() {
byte[] descriptorData = global::System.Convert.FromBase64String(
string.Concat(
"CjVnb29nbGUvcHJvdG9idWYvanNvbi9qc29uX2VudW12YWxfY3VzdG9tX3N0",
"cmluZy5wcm90bxIaanNvbl9lbnVtdmFsX2N1c3RvbV9zdHJpbmcaImdvb2ds",
"ZS9wcm90b2J1Zi9qc29uX29wdGlvbnMucHJvdG8ihgIKBktuaWdodBIwCgVh",
"cm1vchgBIAEoDjIhLmpzb25fZW51bXZhbF9jdXN0b21fc3RyaW5nLkFybW9y",
"EjEKBmFybW9ycxgCIAMoDjIhLmpzb25fZW51bXZhbF9jdXN0b21fc3RyaW5n",
"LkFybW9yEkMKCWFybW9yX21hcBgDIAMoCzIwLmpzb25fZW51bXZhbF9jdXN0",
"b21fc3RyaW5nLktuaWdodC5Bcm1vck1hcEVudHJ5GlIKDUFybW9yTWFwRW50",
"cnkSCwoDa2V5GAEgASgJEjAKBXZhbHVlGAIgASgOMiEuanNvbl9lbnVtdmFs",
"X2N1c3RvbV9zdHJpbmcuQXJtb3I6AjgBKtgCCgVBcm1vchIRCg1BUk1PUl9V",
"TktOT1dOEAASIwoQQVJNT1JfR1JFQVRfSEVMTRABGg2yPgoKCGdyOCBoZWxt",
"EhAKDEFSTU9SX0dPUkdFVBACEhwKDkFSTU9SX0dBVU5UTEVUEAMaCLI+BQoD",
"YSJiEh0KC0FSTU9SX1BMQVRFEAQaDLI+CQoHInBsYXRlIhIVCgpBUk1PUl9D",
"T0lGEAUaBbI+AgoAEiMKDkFSTU9SX1BBVUxEUk9OEAYaD7I+DAoKcAlhdWwK",
"ZHJvbhIfCg1BUk1PUl9TQUJBVE9OEAcaDLI+CQoHc2FiYXRvbhIgCg5BUk1P",
"Ul9TT0xMRVJFVBAHGgyyPgkKB3NhYmF0b24SHgoSQVJNT1JfSEFDSElfTUFJ",
"X0RPEAgaBrI+AwoBOBIlCg1BUk1PUl9HUkVBVkVTEAkaErI+DwoNQVJNT1Jf",
"R1JFQVZFUxoCEAFiCGVkaXRpb25zcOoH"));
descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData,
new pbr::FileDescriptor[] { global::Pb.JsonOptionsReflection.Descriptor, },
new pbr::GeneratedClrTypeInfo(new[] {typeof(global::JsonEnumvalCustomString.Armor), }, null, new pbr::GeneratedClrTypeInfo[] {
new pbr::GeneratedClrTypeInfo(typeof(global::JsonEnumvalCustomString.Knight), global::JsonEnumvalCustomString.Knight.Parser, new[]{ "Armor", "Armors", "ArmorMap" }, null, null, null, new pbr::GeneratedClrTypeInfo[] { null, })
}));
}
#endregion
}
#region Enums
public enum Armor {
[pbr::OriginalName("ARMOR_UNKNOWN")] Unknown = 0,
[pbr::OriginalName("ARMOR_GREAT_HELM")] GreatHelm = 1,
[pbr::OriginalName("ARMOR_GORGET")] Gorget = 2,
[pbr::OriginalName("ARMOR_GAUNTLET")] Gauntlet = 3,
[pbr::OriginalName("ARMOR_PLATE")] Plate = 4,
[pbr::OriginalName("ARMOR_COIF")] Coif = 5,
[pbr::OriginalName("ARMOR_PAULDRON")] Pauldron = 6,
[pbr::OriginalName("ARMOR_SABATON")] Sabaton = 7,
[pbr::OriginalName("ARMOR_SOLLERET", PreferredAlias = false)] Solleret = 7,
[pbr::OriginalName("ARMOR_HACHI_MAI_DO")] HachiMaiDo = 8,
[pbr::OriginalName("ARMOR_GREAVES")] Greaves = 9,
}
#endregion
#region Messages
[global::System.Diagnostics.DebuggerDisplayAttribute("{ToString(),nq}")]
public sealed partial class Knight : pb::IMessage<Knight>
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
, pb::IBufferMessage
#endif
{
private static readonly pb::MessageParser<Knight> _parser = new pb::MessageParser<Knight>(() => new Knight());
private pb::UnknownFieldSet _unknownFields;
private int _hasBits0;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public static pb::MessageParser<Knight> Parser { get { return _parser; } }
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public static pbr::MessageDescriptor Descriptor {
get { return global::JsonEnumvalCustomString.JsonEnumvalCustomStringReflection.Descriptor.MessageTypes[0]; }
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
pbr::MessageDescriptor pb::IMessage.Descriptor {
get { return Descriptor; }
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public Knight() {
OnConstruction();
}
partial void OnConstruction();
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public Knight(Knight other) : this() {
_hasBits0 = other._hasBits0;
armor_ = other.armor_;
armors_ = other.armors_.Clone();
armorMap_ = other.armorMap_.Clone();
_unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public Knight Clone() {
return new Knight(this);
}
/// <summary>Field number for the "armor" field.</summary>
public const int ArmorFieldNumber = 1;
private readonly static global::JsonEnumvalCustomString.Armor ArmorDefaultValue = global::JsonEnumvalCustomString.Armor.Unknown;
private global::JsonEnumvalCustomString.Armor armor_;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public global::JsonEnumvalCustomString.Armor Armor {
get { if ((_hasBits0 & 1) != 0) { return armor_; } else { return ArmorDefaultValue; } }
set {
_hasBits0 |= 1;
armor_ = value;
}
}
/// <summary>Gets whether the "armor" field is set</summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public bool HasArmor {
get { return (_hasBits0 & 1) != 0; }
}
/// <summary>Clears the value of the "armor" field</summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public void ClearArmor() {
_hasBits0 &= ~1;
}
/// <summary>Field number for the "armors" field.</summary>
public const int ArmorsFieldNumber = 2;
private static readonly pb::FieldCodec<global::JsonEnumvalCustomString.Armor> _repeated_armors_codec
= pb::FieldCodec.ForEnum(18, x => (int) x, x => (global::JsonEnumvalCustomString.Armor) x);
private readonly pbc::RepeatedField<global::JsonEnumvalCustomString.Armor> armors_ = new pbc::RepeatedField<global::JsonEnumvalCustomString.Armor>();
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public pbc::RepeatedField<global::JsonEnumvalCustomString.Armor> Armors {
get { return armors_; }
}
/// <summary>Field number for the "armor_map" field.</summary>
public const int ArmorMapFieldNumber = 3;
private static readonly pbc::MapField<string, global::JsonEnumvalCustomString.Armor>.Codec _map_armorMap_codec
= new pbc::MapField<string, global::JsonEnumvalCustomString.Armor>.Codec(pb::FieldCodec.ForString(10, ""), pb::FieldCodec.ForEnum(16, x => (int) x, x => (global::JsonEnumvalCustomString.Armor) x, global::JsonEnumvalCustomString.Armor.Unknown), 26);
private readonly pbc::MapField<string, global::JsonEnumvalCustomString.Armor> armorMap_ = new pbc::MapField<string, global::JsonEnumvalCustomString.Armor>();
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public pbc::MapField<string, global::JsonEnumvalCustomString.Armor> ArmorMap {
get { return armorMap_; }
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public override bool Equals(object other) {
return Equals(other as Knight);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public bool Equals(Knight other) {
if (ReferenceEquals(other, null)) {
return false;
}
if (ReferenceEquals(other, this)) {
return true;
}
if (Armor != other.Armor) return false;
if(!armors_.Equals(other.armors_)) return false;
if (!ArmorMap.Equals(other.ArmorMap)) return false;
return Equals(_unknownFields, other._unknownFields);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public override int GetHashCode() {
int hash = 1;
if (HasArmor) hash ^= Armor.GetHashCode();
hash ^= armors_.GetHashCode();
hash ^= ArmorMap.GetHashCode();
if (_unknownFields != null) {
hash ^= _unknownFields.GetHashCode();
}
return hash;
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public override string ToString() {
return pb::JsonFormatter.ToDiagnosticString(this);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public void WriteTo(pb::CodedOutputStream output) {
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
output.WriteRawMessage(this);
#else
if (HasArmor) {
output.WriteRawTag(8);
output.WriteEnum((int) Armor);
}
armors_.WriteTo(output, _repeated_armors_codec);
armorMap_.WriteTo(output, _map_armorMap_codec);
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
#endif
}
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
if (HasArmor) {
output.WriteRawTag(8);
output.WriteEnum((int) Armor);
}
armors_.WriteTo(ref output, _repeated_armors_codec);
armorMap_.WriteTo(ref output, _map_armorMap_codec);
if (_unknownFields != null) {
_unknownFields.WriteTo(ref output);
}
}
#endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public int CalculateSize() {
int size = 0;
if (HasArmor) {
size += 1 + pb::CodedOutputStream.ComputeEnumSize((int) Armor);
}
size += armors_.CalculateSize(_repeated_armors_codec);
size += armorMap_.CalculateSize(_map_armorMap_codec);
if (_unknownFields != null) {
size += _unknownFields.CalculateSize();
}
return size;
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public void MergeFrom(Knight other) {
if (other == null) {
return;
}
if (other.HasArmor) {
Armor = other.Armor;
}
armors_.Add(other.armors_);
armorMap_.MergeFrom(other.armorMap_);
_unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public void MergeFrom(pb::CodedInputStream input) {
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
input.ReadRawMessage(this);
#else
uint tag;
while ((tag = input.ReadTag()) != 0) {
if ((tag & 7) == 4) {
// Abort on any end group tag.
return;
}
switch(tag) {
default:
_unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
break;
case 8: {
Armor = (global::JsonEnumvalCustomString.Armor) input.ReadEnum();
break;
}
case 18:
case 16: {
armors_.AddEntriesFrom(input, _repeated_armors_codec);
break;
}
case 26: {
armorMap_.AddEntriesFrom(input, _map_armorMap_codec);
break;
}
}
}
#endif
}
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
uint tag;
while ((tag = input.ReadTag()) != 0) {
if ((tag & 7) == 4) {
// Abort on any end group tag.
return;
}
switch(tag) {
default:
_unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
break;
case 8: {
Armor = (global::JsonEnumvalCustomString.Armor) input.ReadEnum();
break;
}
case 18:
case 16: {
armors_.AddEntriesFrom(ref input, _repeated_armors_codec);
break;
}
case 26: {
armorMap_.AddEntriesFrom(ref input, _map_armorMap_codec);
break;
}
}
}
}
#endif
}
#endregion
}
#endregion Designer generated code

View file

@ -18,6 +18,7 @@ using static Google.Protobuf.JsonParserTest; // For WrapInQuotes
using System.IO;
using Google.Protobuf.Collections;
using ProtobufUnittest;
using JsonEnumvalCustomString;
namespace Google.Protobuf
{
@ -957,6 +958,86 @@ namespace Google.Protobuf
AssertWriteValue(value, "{ 'FieldName13': 0 }");
}
[Test]
// No custom value.
[TestCase(Armor.Gorget, "ARMOR_GORGET")]
// Simple custom value.
[TestCase(Armor.GreatHelm, "gr8 helm")]
// Escaping of quotes mid-value.
[TestCase(Armor.Gauntlet, "a\\\"b")]
// Escaping of quotes at start and end.
[TestCase(Armor.Plate, "\\\"plate\\\"")]
// Empty string.
[TestCase(Armor.Coif, "")]
// Escaping of tab and newline.
[TestCase(Armor.Pauldron, "p\\taul\\ndron")]
// Aliased enum values.
[TestCase(Armor.Sabaton, "sabaton")]
[TestCase(Armor.Solleret, "sabaton")]
// Numeric string custom value.
[TestCase(Armor.HachiMaiDo, "8")]
// Custom value same as enum name.
[TestCase(Armor.Greaves, "ARMOR_GREAVES")]
public void Serialize(Armor value, string expectedSerializedJsonValue)
{
var msg = new Knight { Armor = value };
var actualJson = JsonFormatter.Default.Format(msg);
var expectedJson =
$"{{ \"armor\": \"{expectedSerializedJsonValue}\" }}";
Assert.AreEqual(expectedJson, actualJson);
}
[Test]
public void SerializeUnknownValue()
{
var msg = new Knight { Armor = (Armor) 12345 };
var actualJson = JsonFormatter.Default.Format(msg);
var expectedJson = $"{{ \"armor\": 12345 }}";
Assert.AreEqual(expectedJson, actualJson);
}
[Test]
public void IntegerFormatSettingOverridesCustomString()
{
var msg = new Knight { Armor = Armor.GreatHelm };
var settings = JsonFormatter.Settings.Default
.WithFormatEnumsAsIntegers(true);
var formatter = new JsonFormatter(settings);
var json = formatter.Format(msg);
Assert.AreEqual("{ \"armor\": 1 }", json);
}
[Test]
public void SerializeRepeated()
{
var msg = new Knight
{
Armors = { Armor.GreatHelm, Armor.Gorget, Armor.Gauntlet }
};
var actualJson = JsonFormatter.Default.Format(msg);
var expectedJson =
"{ \"armors\": [ \"gr8 helm\", \"ARMOR_GORGET\", \"a\\\"b\" ] }";
Assert.AreEqual(expectedJson, actualJson);
}
[Test]
public void SerializeMap()
{
var msg = new Knight
{
ArmorMap =
{
{ "primary", Armor.GreatHelm },
{ "secondary", Armor.Gorget }
}
};
var actualJson = JsonFormatter.Default.Format(msg);
AssertJson(
"{ 'armorMap': { 'primary': 'gr8 helm', 'secondary': 'ARMOR_GORGET' } }",
actualJson);
}
private static void AssertWriteValue(object value, string expectedJson, JsonFormatter.Settings settings = null)
{
var writer = new StringWriter { NewLine = "\n" };

View file

@ -17,6 +17,7 @@ using ProtobufUnittest;
using System;
using System.Linq;
using UnitTest.Issues.TestProtos;
using JsonEnumvalCustomString;
namespace Google.Protobuf
{
@ -1265,5 +1266,98 @@ namespace Google.Protobuf
Assert.AreEqual(0, message.MapBoolBool.Count);
Assert.AreEqual(0, message.MapStringNestedMessage.Count);
}
[Test]
[TestCase(Armor.Gorget, "ARMOR_GORGET")]
[TestCase(Armor.GreatHelm, "gr8 helm", "ARMOR_GREAT_HELM")]
[TestCase(Armor.Gauntlet, "a\\\"b", "ARMOR_GAUNTLET")]
[TestCase(Armor.Plate, "\\\"plate\\\"", "ARMOR_PLATE")]
[TestCase(Armor.Coif, "", "ARMOR_COIF")]
[TestCase(Armor.Pauldron, "p\\taul\\ndron", "ARMOR_PAULDRON")]
[TestCase(
Armor.Sabaton, "sabaton", "ARMOR_SABATON", "ARMOR_SOLLERET")]
[TestCase(
Armor.Solleret, "sabaton", "ARMOR_SOLLERET", "ARMOR_SABATON")]
[TestCase(Armor.HachiMaiDo, "8", "ARMOR_HACHI_MAI_DO")]
[TestCase(Armor.Greaves, "ARMOR_GREAVES")]
[TestCase(Armor.Unknown, "ARMOR_UNKNOWN")]
public void ParseString(Armor value, params string[] validJsonValues)
{
foreach (var validJsonValue in validJsonValues)
{
string json = $"{{ \"armor\": \"{validJsonValue}\" }}";
var parsed = JsonParser.Default.Parse<Knight>(json);
Assert.AreEqual(value, parsed.Armor);
}
}
[Test]
public void ParseInteger()
{
foreach (
var value in System.Enum.GetValues(typeof(Armor)).Cast<Armor>())
{
string json = $"{{ \"armor\": {(int) value} }}";
var parsed = JsonParser.Default.Parse<Knight>(json);
Assert.AreEqual(value, parsed.Armor);
}
}
[Test]
[TestCase("\"UNKNOWN_1\"")]
[TestCase("\"ARMOR_INVALID\"")]
[TestCase("\"A\\\"b\"")]
[TestCase("\"ARMOR_great_helm\"")]
[TestCase("\"GR8 HELM\"")]
[TestCase("true")]
[TestCase("123.456")]
[TestCase("{}")]
[TestCase("[ \"gr8 helm\" ]")]
[TestCase("[ \"ARMOR_GREAT_HELM\" ]")]
public void ParseInvalidValueFails(string jsonValue)
{
string json = $"{{ \"armor\": {jsonValue} }}";
Assert.Throws<InvalidProtocolBufferException>(
() => JsonParser.Default.Parse<Knight>(json));
}
[Test]
[TestCase("UNKNOWN_1")]
[TestCase("ARMOR_great_helm")]
[TestCase("GR8 HELM")]
public void ParseUnknownString_IgnoreUnknownFields(
string unrecognizedJsonValue)
{
var settings = JsonParser.Settings.Default
.WithIgnoreUnknownFields(true);
var parser = new JsonParser(settings);
string json = $"{{ \"armor\": \"{unrecognizedJsonValue}\" }}";
var parsed = parser.Parse<Knight>(json);
Assert.AreEqual(Armor.Unknown, parsed.Armor);
}
[Test]
public void ParseRepeated()
{
string json =
"{ \"armors\": [ \"gr8 helm\", \"ARMOR_GORGET\", \"a\\\"b\" ] }";
var parsed = JsonParser.Default.Parse<Knight>(json);
Assert.AreEqual(3, parsed.Armors.Count);
Assert.AreEqual(Armor.GreatHelm, parsed.Armors[0]);
Assert.AreEqual(Armor.Gorget, parsed.Armors[1]);
Assert.AreEqual(Armor.Gauntlet, parsed.Armors[2]);
}
[Test]
public void ParseMap()
{
string json =
"{ \"armorMap\": { \"primary\": \"gr8 helm\"," +
" \"secondary\": \"ARMOR_GORGET\" } }";
var parsed = JsonParser.Default.Parse<Knight>(json);
Assert.AreEqual(2, parsed.ArmorMap.Count);
Assert.AreEqual(Armor.GreatHelm, parsed.ArmorMap["primary"]);
Assert.AreEqual(Armor.Gorget, parsed.ArmorMap["secondary"]);
}
}
}

View file

@ -5,7 +5,7 @@
<Description>C# runtime library for Protocol Buffers - Google's data interchange format.</Description>
<Copyright>Copyright 2015, Google Inc.</Copyright>
<AssemblyTitle>Google Protocol Buffers</AssemblyTitle>
<VersionPrefix>3.36.0</VersionPrefix>
<VersionPrefix>3.37.0</VersionPrefix>
<LangVersion>10.0</LangVersion>
<Authors>Google Inc.</Authors>
<TargetFrameworks>netstandard2.0;net8.0</TargetFrameworks>

Some files were not shown because too many files have changed in this diff Show more