|
|
|
load(
|
|
|
|
"//bazel:upb_proto_library.bzl",
|
|
|
|
"upb_c_proto_library",
|
|
|
|
"upb_proto_reflection_library",
|
|
|
|
)
|
|
|
|
|
|
|
|
package(default_applicable_licenses = ["//:license"])
|
|
|
|
|
|
|
|
licenses(["notice"])
|
|
|
|
|
|
|
|
# Def to Proto
|
|
|
|
|
|
|
|
cc_library(
|
|
|
|
name = "def_to_proto",
|
|
|
|
srcs = ["def_to_proto.c"],
|
|
|
|
hdrs = ["def_to_proto.h"],
|
|
|
|
visibility = ["//visibility:public"],
|
|
|
|
deps = [
|
Fixed layering check violations once and for all in upb bootstrapping.
Our bootstrapping setup compiles multiple versions of the generated code for `descriptor.proto` and `plugin.proto`, one for each stage of the bootstrap. For source files (`.c`), we can always select the correct version of the file in the BUILD rules, but for header files we need to make sure the correct stage's file is always selected via `#include`.
Previously we used `cc_library(includes=[])` to make it appear as though our bootstrapped headers had the same names as the "real" headers. This allowed a lot of the code to be agnostic to whether a bootstrap header was being used, which simplified things because we did not have to change the code performing the `#include`.
Unfortunately, due to build system limitations, this sometimes led to the incorrect header getting included. This should not have been possible, because we had a clean BUILD graph that should have removed all ambiguity about which header should be available. But in non-sandboxed builds, the compiler was able to find headers that were not actually in `deps=[]`, and worse it preferred those headers over the headers that actually were in `deps=[]`. This led to unintended results and errors about layering check violations.
This CL fixes the problem by removing all use of `includes=[]`. We now spell a full pathname to all bootstrap headers, so this class of errors is no longer possible. Unfortunately this adds some complexity, as we have to hard-code these full paths in several places.
A nice improvement in this CL is that `bootstrap_upb_proto_library()` can now only be used for bootstrapping; it only exposes the `descriptor_bootstrap.h` / `plugin_bootstrap.h` files. Anyone wanting to use the normal `net/proto2/proto/descriptor.upb.h` file should depend on `//net/proto2/proto:descriptor_upb_c_proto` target instead.
PiperOrigin-RevId: 664953196
3 months ago
|
|
|
"//src/google/protobuf:descriptor_upb_c_proto",
|
|
|
|
"//upb:base",
|
|
|
|
"//upb:port",
|
|
|
|
"//upb:reflection",
|
|
|
|
"//upb/reflection:internal",
|
|
|
|
],
|
|
|
|
)
|
|
|
|
|
|
|
|
proto_library(
|
|
|
|
name = "def_to_proto_test_proto",
|
|
|
|
srcs = [
|
|
|
|
"def_to_proto_public_import_test.proto",
|
|
|
|
"def_to_proto_regular_import_test.proto",
|
|
|
|
"def_to_proto_test.proto",
|
|
|
|
],
|
|
|
|
)
|
|
|
|
|
|
|
|
upb_c_proto_library(
|
|
|
|
name = "def_to_proto_test_upb_proto",
|
|
|
|
deps = ["def_to_proto_test_proto"],
|
|
|
|
)
|
|
|
|
|
|
|
|
upb_proto_reflection_library(
|
|
|
|
name = "def_to_proto_test_upb_proto_reflection",
|
|
|
|
deps = ["def_to_proto_test_proto"],
|
|
|
|
)
|
|
|
|
|
|
|
|
cc_library(
|
|
|
|
name = "def_to_proto_test_lib",
|
|
|
|
testonly = 1,
|
|
|
|
hdrs = ["def_to_proto_test.h"],
|
|
|
|
deps = [
|
|
|
|
":def_to_proto",
|
|
|
|
"//:protobuf",
|
Fixed layering check violations once and for all in upb bootstrapping.
Our bootstrapping setup compiles multiple versions of the generated code for `descriptor.proto` and `plugin.proto`, one for each stage of the bootstrap. For source files (`.c`), we can always select the correct version of the file in the BUILD rules, but for header files we need to make sure the correct stage's file is always selected via `#include`.
Previously we used `cc_library(includes=[])` to make it appear as though our bootstrapped headers had the same names as the "real" headers. This allowed a lot of the code to be agnostic to whether a bootstrap header was being used, which simplified things because we did not have to change the code performing the `#include`.
Unfortunately, due to build system limitations, this sometimes led to the incorrect header getting included. This should not have been possible, because we had a clean BUILD graph that should have removed all ambiguity about which header should be available. But in non-sandboxed builds, the compiler was able to find headers that were not actually in `deps=[]`, and worse it preferred those headers over the headers that actually were in `deps=[]`. This led to unintended results and errors about layering check violations.
This CL fixes the problem by removing all use of `includes=[]`. We now spell a full pathname to all bootstrap headers, so this class of errors is no longer possible. Unfortunately this adds some complexity, as we have to hard-code these full paths in several places.
A nice improvement in this CL is that `bootstrap_upb_proto_library()` can now only be used for bootstrapping; it only exposes the `descriptor_bootstrap.h` / `plugin_bootstrap.h` files. Anyone wanting to use the normal `net/proto2/proto/descriptor.upb.h` file should depend on `//net/proto2/proto:descriptor_upb_c_proto` target instead.
PiperOrigin-RevId: 664953196
3 months ago
|
|
|
"//src/google/protobuf:descriptor_upb_c_proto",
|
Breaking change: make protobuf comply with the C++ layering check
This check enforces that each C++ build target has the correct dependencies for
all headers that it includes. We have many targets that were not correct with
respect to this check, so I fixed them up.
I also cleaned up the C++ targets related to the well-known types. I created a
cc_proto_library() target for each one and removed the :wkt_cc_protos target,
since this was necessary to satisfy the layering check. I deleted the
//src/google/protobuf:protobuf_nowkt target and deprecated :protobuf_nowkt,
because the distinction between the :protobuf and :protobuf_nowkt targets was
not really correct. Neither one exposed the headers for the well-known types in
a way that was valid with respect to the layering check, and the idea of
bundling all the well-known types together is not idiomatic in Bazel anyway.
This is a breaking change, because the //:protobuf target no longer bundles the
well-known types. From now on they should be accessed through the new
//:*_cc_proto aliases in our top-level package.
I renamed the :port_def target to :port, which simplifies things a bit by
matching our internal name.
The original motivation for this change was that to move utf8_range onto our CI
infrastructure, we needed to make its dependency rules_fuzzing compatible with
Bazel 6. The rules_fuzzing project builds with the layering check, and I found
that the process of upgrading it to Bazel 6 made it take a dependency on
protobuf, which caused it to break due to layering violations. I was able to
work around this, but it would still be nice to comply with the layering check
so that we don't have to worry about this kind of thing in the future.
PiperOrigin-RevId: 595516736
11 months ago
|
|
|
"//src/google/protobuf/util:differencer",
|
|
|
|
"//upb:base",
|
|
|
|
"//upb:mem",
|
|
|
|
"//upb/reflection:internal",
|
|
|
|
"@com_google_googletest//:gtest",
|
|
|
|
],
|
|
|
|
)
|
|
|
|
|
|
|
|
cc_test(
|
|
|
|
name = "def_to_proto_test",
|
|
|
|
srcs = ["def_to_proto_test.cc"],
|
|
|
|
deps = [
|
|
|
|
":def_to_proto",
|
|
|
|
":def_to_proto_editions_test_upb_proto",
|
|
|
|
":def_to_proto_editions_test_upb_proto_reflection",
|
|
|
|
":def_to_proto_test_lib",
|
|
|
|
":def_to_proto_test_upb_proto",
|
|
|
|
":def_to_proto_test_upb_proto_reflection",
|
|
|
|
"//:protobuf",
|
Fixed layering check violations once and for all in upb bootstrapping.
Our bootstrapping setup compiles multiple versions of the generated code for `descriptor.proto` and `plugin.proto`, one for each stage of the bootstrap. For source files (`.c`), we can always select the correct version of the file in the BUILD rules, but for header files we need to make sure the correct stage's file is always selected via `#include`.
Previously we used `cc_library(includes=[])` to make it appear as though our bootstrapped headers had the same names as the "real" headers. This allowed a lot of the code to be agnostic to whether a bootstrap header was being used, which simplified things because we did not have to change the code performing the `#include`.
Unfortunately, due to build system limitations, this sometimes led to the incorrect header getting included. This should not have been possible, because we had a clean BUILD graph that should have removed all ambiguity about which header should be available. But in non-sandboxed builds, the compiler was able to find headers that were not actually in `deps=[]`, and worse it preferred those headers over the headers that actually were in `deps=[]`. This led to unintended results and errors about layering check violations.
This CL fixes the problem by removing all use of `includes=[]`. We now spell a full pathname to all bootstrap headers, so this class of errors is no longer possible. Unfortunately this adds some complexity, as we have to hard-code these full paths in several places.
A nice improvement in this CL is that `bootstrap_upb_proto_library()` can now only be used for bootstrapping; it only exposes the `descriptor_bootstrap.h` / `plugin_bootstrap.h` files. Anyone wanting to use the normal `net/proto2/proto/descriptor.upb.h` file should depend on `//net/proto2/proto:descriptor_upb_c_proto` target instead.
PiperOrigin-RevId: 664953196
3 months ago
|
|
|
"//src/google/protobuf:descriptor_upb_c_proto",
|
|
|
|
"//src/google/protobuf:descriptor_upb_reflection_proto",
|
Breaking change: make protobuf comply with the C++ layering check
This check enforces that each C++ build target has the correct dependencies for
all headers that it includes. We have many targets that were not correct with
respect to this check, so I fixed them up.
I also cleaned up the C++ targets related to the well-known types. I created a
cc_proto_library() target for each one and removed the :wkt_cc_protos target,
since this was necessary to satisfy the layering check. I deleted the
//src/google/protobuf:protobuf_nowkt target and deprecated :protobuf_nowkt,
because the distinction between the :protobuf and :protobuf_nowkt targets was
not really correct. Neither one exposed the headers for the well-known types in
a way that was valid with respect to the layering check, and the idea of
bundling all the well-known types together is not idiomatic in Bazel anyway.
This is a breaking change, because the //:protobuf target no longer bundles the
well-known types. From now on they should be accessed through the new
//:*_cc_proto aliases in our top-level package.
I renamed the :port_def target to :port, which simplifies things a bit by
matching our internal name.
The original motivation for this change was that to move utf8_range onto our CI
infrastructure, we needed to make its dependency rules_fuzzing compatible with
Bazel 6. The rules_fuzzing project builds with the layering check, and I found
that the process of upgrading it to Bazel 6 made it take a dependency on
protobuf, which caused it to break due to layering violations. I was able to
work around this, but it would still be nice to comply with the layering check
so that we don't have to worry about this kind of thing in the future.
PiperOrigin-RevId: 595516736
11 months ago
|
|
|
"//src/google/protobuf/util:differencer",
|
|
|
|
"//upb:base",
|
|
|
|
"//upb:mem",
|
|
|
|
"//upb:reflection",
|
|
|
|
"//upb/test:parse_text_proto",
|
|
|
|
"@com_google_absl//absl/strings",
|
|
|
|
"@com_google_googletest//:gtest",
|
|
|
|
"@com_google_googletest//:gtest_main",
|
|
|
|
],
|
|
|
|
)
|
|
|
|
|
|
|
|
# Required fields
|
|
|
|
|
|
|
|
cc_library(
|
|
|
|
name = "required_fields",
|
|
|
|
srcs = ["required_fields.c"],
|
|
|
|
hdrs = ["required_fields.h"],
|
|
|
|
visibility = ["//visibility:public"],
|
|
|
|
deps = [
|
|
|
|
"//upb:base",
|
|
|
|
"//upb:mem",
|
|
|
|
"//upb:message",
|
|
|
|
"//upb:port",
|
|
|
|
"//upb:reflection",
|
|
|
|
],
|
|
|
|
)
|
|
|
|
|
|
|
|
proto_library(
|
|
|
|
name = "def_to_proto_editions_test_proto",
|
|
|
|
srcs = ["def_to_proto_editions_test.proto"],
|
|
|
|
)
|
|
|
|
|
|
|
|
upb_c_proto_library(
|
|
|
|
name = "def_to_proto_editions_test_upb_proto",
|
|
|
|
deps = ["def_to_proto_editions_test_proto"],
|
|
|
|
)
|
|
|
|
|
|
|
|
upb_proto_reflection_library(
|
|
|
|
name = "def_to_proto_editions_test_upb_proto_reflection",
|
|
|
|
deps = ["def_to_proto_editions_test_proto"],
|
|
|
|
)
|
|
|
|
|
|
|
|
proto_library(
|
|
|
|
name = "required_fields_test_proto",
|
|
|
|
srcs = [
|
|
|
|
"required_fields_editions_test.proto",
|
|
|
|
"required_fields_test.proto",
|
|
|
|
],
|
|
|
|
)
|
|
|
|
|
|
|
|
upb_c_proto_library(
|
|
|
|
name = "required_fields_test_upb_proto",
|
|
|
|
deps = ["required_fields_test_proto"],
|
|
|
|
)
|
|
|
|
|
|
|
|
upb_proto_reflection_library(
|
|
|
|
name = "required_fields_test_upb_proto_reflection",
|
|
|
|
deps = ["required_fields_test_proto"],
|
|
|
|
)
|
|
|
|
|
|
|
|
cc_test(
|
|
|
|
name = "required_fields_test",
|
|
|
|
srcs = ["required_fields_test.cc"],
|
|
|
|
deps = [
|
|
|
|
":required_fields",
|
|
|
|
":required_fields_test_upb_proto",
|
|
|
|
":required_fields_test_upb_proto_reflection",
|
|
|
|
"//upb:base",
|
|
|
|
"//upb:json",
|
|
|
|
"//upb:mem",
|
|
|
|
"//upb:reflection",
|
|
|
|
"//upb/reflection:internal",
|
|
|
|
"@com_google_absl//absl/strings",
|
|
|
|
"@com_google_googletest//:gtest",
|
|
|
|
"@com_google_googletest//:gtest_main",
|
|
|
|
],
|
|
|
|
)
|
|
|
|
|
|
|
|
filegroup(
|
|
|
|
name = "source_files",
|
|
|
|
srcs = [
|
|
|
|
"def_to_proto.c",
|
|
|
|
"def_to_proto.h",
|
|
|
|
"required_fields.c",
|
|
|
|
"required_fields.h",
|
|
|
|
],
|
|
|
|
visibility = ["//python/dist:__pkg__"],
|
|
|
|
)
|
|
|
|
|
|
|
|
filegroup(
|
|
|
|
name = "test_srcs",
|
|
|
|
srcs = glob(
|
|
|
|
[
|
|
|
|
"**/*test.cc",
|
|
|
|
],
|
|
|
|
exclude = ["def_to_proto_fuzz_test.cc"],
|
|
|
|
),
|
|
|
|
visibility = ["//upb:__pkg__"],
|
|
|
|
)
|
|
|
|
|
|
|
|
filegroup(
|
|
|
|
name = "test_util",
|
|
|
|
srcs = glob(
|
|
|
|
[
|
|
|
|
"**/*test.h",
|
|
|
|
],
|
|
|
|
),
|
|
|
|
visibility = ["//upb:__pkg__"],
|
|
|
|
)
|
|
|
|
|
|
|
|
filegroup(
|
|
|
|
name = "test_protos",
|
|
|
|
srcs = glob(
|
|
|
|
[
|
|
|
|
"**/*test.proto",
|
|
|
|
],
|
|
|
|
),
|
|
|
|
visibility = ["//upb:__pkg__"],
|
|
|
|
)
|