From 713b6a4a240e45e37ed2b6a47b3841a09be47637 Mon Sep 17 00:00:00 2001 From: Jason Aragorn Tobias Lunn Date: Fri, 31 Jul 2026 16:17:28 -0700 Subject: [PATCH] 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 --- cmake/install.cmake | 9 +-- cmake/installed_include_golden.txt | 2 + csharp/BUILD.bazel | 2 +- go/BUILD.bazel | 2 +- java/core/BUILD.bazel | 4 +- java/util/BUILD.bazel | 22 ++++-- java/util/generate-sources-build.xml | 10 +++ pkg/BUILD.bazel | 20 ++---- python/dist/BUILD.bazel | 26 ++----- python/dist/py_proto_library.bzl | 6 +- ruby/BUILD.bazel | 2 +- src/google/protobuf/BUILD.bazel | 93 ++++++++++++++++++++++++++ src/google/protobuf/json_options.proto | 2 + 13 files changed, 147 insertions(+), 53 deletions(-) create mode 100644 java/util/generate-sources-build.xml diff --git a/cmake/install.cmake b/cmake/install.cmake index 7864739cb8..3e0e16558f 100644 --- a/cmake/install.cmake +++ b/cmake/install.cmake @@ -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}) diff --git a/cmake/installed_include_golden.txt b/cmake/installed_include_golden.txt index b5a35ec2c0..24ecb27d75 100644 --- a/cmake/installed_include_golden.txt +++ b/cmake/installed_include_golden.txt @@ -45,6 +45,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 @@ -97,6 +98,7 @@ 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 diff --git a/csharp/BUILD.bazel b/csharp/BUILD.bazel index b21428baa6..4bca560c65 100644 --- a/csharp/BUILD.bazel +++ b/csharp/BUILD.bazel @@ -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( diff --git a/go/BUILD.bazel b/go/BUILD.bazel index 3dfdd21c1d..7390cdc0c4 100644 --- a/go/BUILD.bazel +++ b/go/BUILD.bazel @@ -3,7 +3,7 @@ load("//bazel:proto_library.bzl", "proto_library") filegroup( name = "go_features_proto_srcs", srcs = ["google/protobuf/go_features.proto"], - visibility = ["//:__subpackages__"], + visibility = ["//src/google/protobuf:__pkg__"], ) proto_library( diff --git a/java/core/BUILD.bazel b/java/core/BUILD.bazel index 2848de523b..c9982bdc9e 100644 --- a/java/core/BUILD.bazel +++ b/java/core/BUILD.bazel @@ -193,7 +193,7 @@ proto_library( "//:__pkg__", "//editions:__pkg__", "//java/__subpackages__", - "//pkg:__pkg__", + "//src/google/protobuf:__pkg__", ], deps = ["//:descriptor_proto"], ) @@ -211,8 +211,8 @@ filegroup( name = "java_features_proto_srcs", srcs = ["src/main/resources/google/protobuf/java_features.proto"], visibility = [ - "//pkg:__pkg__", "//python:__pkg__", + "//src/google/protobuf:__pkg__", ], ) diff --git a/java/util/BUILD.bazel b/java/util/BUILD.bazel index ed99cc84f0..d2d5c0108f 100644 --- a/java/util/BUILD.bazel +++ b/java/util/BUILD.bazel @@ -1,18 +1,28 @@ load("@rules_java//java:java_library.bzl", "java_library") +load("//:protobuf.bzl", "internal_gen_well_known_protos_java") load("//:protobuf_version.bzl", "PROTOBUF_JAVA_VERSION") load("//bazel:java_proto_library.bzl", "java_proto_library") load("//bazel:proto_library.bzl", "proto_library") load("//build_defs:java_opts.bzl", "protobuf_java_export", "protobuf_versioned_java_library") load("//java/internal:testing.bzl", "junit_tests") +internal_gen_well_known_protos_java( + name = "gen_language_neutral_protos_java", + deps = [ + "//:json_enumvalue_options_proto", + "//:json_options_proto", + ], +) + java_library( name = "util", srcs = glob([ "src/main/java/com/google/protobuf/util/*.java", - ]), + ]) + [ + ":gen_language_neutral_protos_java", + ], visibility = ["//visibility:public"], deps = [ - ":json_enumvalue_options_java_proto", "//java/core", "@maven//:com_google_code_findbugs_jsr305", "@maven//:com_google_code_gson_gson", @@ -24,14 +34,15 @@ protobuf_versioned_java_library( name = "util_bundle", srcs = glob([ "src/main/java/com/google/protobuf/util/*.java", - ]), + ]) + [ + ":gen_language_neutral_protos_java", + ], automatic_module_name = "com.google.protobuf.util", bundle_description = "Utilities for Protocol Buffers", bundle_name = "Protocol Buffers [Util]", bundle_symbolic_name = "com.google.protobuf.util", visibility = ["//visibility:public"], deps = [ - ":json_enumvalue_options_java_proto", "//java/core", "@maven//:com_google_code_findbugs_jsr305", "@maven//:com_google_code_gson_gson", @@ -45,6 +56,9 @@ protobuf_java_export( deploy_env = ["//java/core"], maven_coordinates = "com.google.protobuf:protobuf-java-util:%s" % PROTOBUF_JAVA_VERSION, pom_template = "pom_template.xml", + resources = [ + "//src/google/protobuf:json_options_proto_srcs", + ], tags = ["manual"], visibility = ["//java:__pkg__"], runtime_deps = [":util_bundle"], diff --git a/java/util/generate-sources-build.xml b/java/util/generate-sources-build.xml new file mode 100644 index 0000000000..c19809db70 --- /dev/null +++ b/java/util/generate-sources-build.xml @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/pkg/BUILD.bazel b/pkg/BUILD.bazel index f698c5db5e..2ddb85425f 100644 --- a/pkg/BUILD.bazel +++ b/pkg/BUILD.bazel @@ -13,14 +13,9 @@ package_naming( ) pkg_files( - name = "wkt_protos_files", + name = "release_all_options_protos_files", srcs = [ - "//:well_known_type_protos", - "//csharp:c_sharp_features_proto_srcs", - "//go:go_features_proto_srcs", - "//java/core:java_features_proto_srcs", - "//src/google/protobuf:cpp_features_proto_srcs", - "//src/google/protobuf:descriptor_proto_srcs", + "//src/google/protobuf:release_all_options_proto_srcs", ], prefix = "include/google/protobuf", visibility = ["//visibility:private"], @@ -92,7 +87,7 @@ pkg_zip( ":compiler_plugin_protos_files", ":protoc_files", ":protoc_readme", - ":wkt_protos_files", + ":release_all_options_protos_files", ], package_file_name = "protoc-{version}-{platform}.zip", package_variables = ":protobuf_pkg_naming", @@ -118,16 +113,9 @@ gen_file_lists( ":protoc-gen-upbdefs": "protoc-gen-upbdefs", ":protoc-gen-upb_minitable": "protoc-gen-upb_minitable", # Protos: - "//src/google/protobuf:well_known_type_protos": "wkt_protos", - "//src/google/protobuf:cpp_file_options_proto": "cpp_file_options_proto", - "//src/google/protobuf:cpp_features_proto": "cpp_features_proto", "//src/google/protobuf:descriptor_proto": "descriptor_proto", - "//src/google/protobuf:json_enumvalue_options_proto": "json_enumvalue_options_proto", - "//src/google/protobuf:json_enumvalue_options_cc_proto": "json_enumvalue_options_cc_proto", "//src/google/protobuf/compiler:plugin_proto": "plugin_proto", - "//csharp:c_sharp_features_proto": "c_sharp_features_proto", - "//java/core:java_features_proto": "java_features_proto,src/google/protobuf/compiler/java/", - "//go:go_features_proto": "go_features_proto,go/", + "//src/google/protobuf:release_all_options_proto_srcs": "release_all_options_protos", # Test libraries: ":common_test": "common_test", diff --git a/python/dist/BUILD.bazel b/python/dist/BUILD.bazel index 14703e546e..a87dfc4c85 100644 --- a/python/dist/BUILD.bazel +++ b/python/dist/BUILD.bazel @@ -26,21 +26,9 @@ py_dist_module( ) py_proto_library( - name = "well_known_proto_py_pb2", + name = "language_neutral_protos_py_pb2", deps = [ - "//:any_proto", - "//:api_proto", - "//:descriptor_proto", - "//:duration_proto", - "//:empty_proto", - "//:field_mask_proto", - "//:json_enumvalue_options_proto", - "//:json_options_proto", - "//:source_context_proto", - "//:struct_proto", - "//:timestamp_proto", - "//:type_proto", - "//:wrappers_proto", + "//src/google/protobuf:language_neutral_protos", ], ) @@ -246,9 +234,9 @@ selects.config_setting_group( ) pkg_files( - name = "generated_wkt", + name = "generated_bootstrap", srcs = [ - ":well_known_proto_py_pb2", + ":language_neutral_protos_py_pb2", "//src/google/protobuf:descriptor_upb_c_proto", "//src/google/protobuf:descriptor_upb_minitable_proto", "//src/google/protobuf:descriptor_upb_reflection_proto", @@ -315,7 +303,7 @@ pkg_tar( srcs = [ ":dist_source_files", ":filegroup_source_files", - ":generated_wkt", + ":generated_bootstrap", ":generated_wkt_compiler", ":utf8_range_source_files", "//python:python_source_files", @@ -409,9 +397,9 @@ py_wheel( }), version = PROTOBUF_PYTHON_VERSION, deps = [ + ":language_neutral_protos_py_pb2", ":message_mod", ":plugin_py_pb2", - ":well_known_proto_py_pb2", "//:python_srcs", ], ) @@ -449,8 +437,8 @@ py_wheel( }), version = PROTOBUF_PYTHON_VERSION, deps = [ + ":language_neutral_protos_py_pb2", ":plugin_py_pb2", - ":well_known_proto_py_pb2", "//:python_srcs", ], ) diff --git a/python/dist/py_proto_library.bzl b/python/dist/py_proto_library.bzl index 756ef6d2fb..46b00e6c41 100644 --- a/python/dist/py_proto_library.bzl +++ b/python/dist/py_proto_library.bzl @@ -105,7 +105,11 @@ def _py_proto_library_aspect_impl(target, ctx): [_get_real_short_path(file) for file in proto_sources], progress_message = "Generating Python protos for :" + ctx.label.name, ) - outs_depset = depset(srcs) + transitive_py_sources = [dep[PyInfo].transitive_sources for dep in ctx.rule.attr.deps if PyInfo in dep] if hasattr(ctx.rule.attr, "deps") else [] + outs_depset = depset( + direct = srcs, + transitive = transitive_py_sources, + ) return [ PyInfo(transitive_sources = outs_depset), ] diff --git a/ruby/BUILD.bazel b/ruby/BUILD.bazel index 8e1c85343c..8d2d1ab506 100755 --- a/ruby/BUILD.bazel +++ b/ruby/BUILD.bazel @@ -93,8 +93,8 @@ selects.config_setting_group( internal_copy_files( name = "copied_wkt_proto_files", srcs = [ - "//:well_known_type_protos", "//src/google/protobuf:descriptor_proto_srcs", + "//src/google/protobuf:language_neutral_proto_srcs", "//src/google/protobuf/compiler:plugin.proto", ], strip_prefix = "src", diff --git a/src/google/protobuf/BUILD.bazel b/src/google/protobuf/BUILD.bazel index a2fbf320b2..5235280e73 100644 --- a/src/google/protobuf/BUILD.bazel +++ b/src/google/protobuf/BUILD.bazel @@ -1237,6 +1237,99 @@ filegroup( visibility = ["//:__subpackages__"], ) +# TODO: Revisit location of aggregate rules +filegroup( + name = "language_neutral_proto_srcs", + srcs = [ + ":json_options_proto_srcs", + ":well_known_type_protos", + ], + visibility = [ + "//ruby:__pkg__", + ], +) + +filegroup( + name = "release_all_options_proto_srcs", + srcs = [ + ":cpp_release_options_proto_srcs", + ":descriptor_proto_srcs", + ":language_neutral_proto_srcs", + "//csharp:c_sharp_features_proto_srcs", + "//go:go_features_proto_srcs", + "//java/core:java_features_proto_srcs", + ], + visibility = [ + "//java/core:__pkg__", + "//pkg:__pkg__", + "//python/dist:__pkg__", + ], +) + +proto_library( + name = "language_neutral_protos", + srcs = [":language_neutral_proto_srcs"], + strip_import_prefix = "/src", + visibility = [ + "//python/dist:__pkg__", + ], + exports = [ + ":descriptor_proto", + ], + deps = [ + ":descriptor_proto", + ], +) + +proto_library( + name = "release_all_options_protos", + srcs = [], + strip_import_prefix = "/src", + visibility = [ + "//java/core:__pkg__", + "//pkg:__pkg__", + "//python/dist:__pkg__", + ], + exports = [ + ":cpp_release_options_protos", + ":descriptor_proto", + ":language_neutral_protos", + # TODO: Create //lang:lang_release_options_protos targets for each language and + # depend on those instead. + "//csharp:c_sharp_features_proto", + "//go:go_features_proto", + "//java/core:java_features_proto", + ], + deps = [ + ":cpp_release_options_protos", + ":descriptor_proto", + ":language_neutral_protos", + # TODO: Create //lang:lang_release_options_protos targets for each language and + # depend on those instead. + "//csharp:c_sharp_features_proto", + "//go:go_features_proto", + "//java/core:java_features_proto", + ], +) + +filegroup( + name = "cpp_release_options_proto_srcs", + srcs = glob(["cpp_*options.proto"]) + ["cpp_features.proto"], +) + +proto_library( + name = "cpp_release_options_protos", + srcs = [":cpp_release_options_proto_srcs"], + strip_import_prefix = "/src", + deps = [":descriptor_proto"], +) + +filegroup( + name = "json_options_proto_srcs", + srcs = glob(["json_*options.proto"]), + visibility = ["//:__subpackages__"], +) + filegroup( name = "testdata", srcs = glob(["testdata/**/*"]) + [ diff --git a/src/google/protobuf/json_options.proto b/src/google/protobuf/json_options.proto index 60b03e2d4c..db5c745dac 100644 --- a/src/google/protobuf/json_options.proto +++ b/src/google/protobuf/json_options.proto @@ -12,3 +12,5 @@ edition = "2024"; package pb; import public "google/protobuf/json_enumvalue_options.proto"; + +option java_package = "com.google.protobuf.util";