From d29027511af5dcd09e0fc32aebe45ff78eddc768 Mon Sep 17 00:00:00 2001 From: Esun Kim Date: Fri, 22 Nov 2024 14:19:00 -0800 Subject: [PATCH] [CI] Added a gRPC_BUILD_TESTS guard to third_party protos (#38179) When not having submodules under the `third_party` directory, CMake throws an error in building gRPC because it couldn't find proto files in those directories even though those files are only used for tests. ``` CMake Error at CMakeLists.txt:611 (file): file COPY cannot find "/root/grpc/third_party/googleapis/google/api/annotations.proto": No such file or directory. Call Stack (most recent call first): CMakeLists.txt:1184 (protobuf_generate_grpc_cpp_with_import_path_correction) ``` There's a interesting quirk in the CMake build process: - Empty `third_party/googleapis` directory: Build fails. - No `third_party/googleapis` directory: Build succeeds. This inconsistency went undetected by our distrib-test because it completely removes the third_party/googleapis directory. However, Cloud C++ encountered this issue because it downloads a tarball that creates an empty third_party/googleapis directory. This fix hides those proto targets when `gRPC_BUILD_TESTS` is not turned on to not run ino this problem. Closes #38179 COPYBARA_INTEGRATE_REVIEW=https://github.com/grpc/grpc/pull/38179 from veblush:cmake-proto b8c9ca965d59d42251aaa5b0cc8a3e4ca191c2f2 PiperOrigin-RevId: 699286689 --- CMakeLists.txt | 5 +++++ templates/CMakeLists.txt.template | 14 ++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index b8b3fdd676a632..02b9ed45cea1ac 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -776,6 +776,10 @@ protobuf_generate_grpc_cpp_with_import_path_correction( protobuf_generate_grpc_cpp_with_import_path_correction( test/core/tsi/alts/fake_handshaker/transport_security_common.proto test/core/tsi/alts/fake_handshaker/transport_security_common.proto ) + +# This enables CMake to build the project without requiring submodules +# in the third_party directory as long as test builds are disabled. +if (gRPC_BUILD_TESTS) protobuf_generate_grpc_cpp_with_import_path_correction( third_party/envoy-api/envoy/admin/v3/certs.proto envoy/admin/v3/certs.proto ) @@ -1235,6 +1239,7 @@ protobuf_generate_grpc_cpp_with_import_path_correction( protobuf_generate_grpc_cpp_with_import_path_correction( third_party/xds/xds/type/v3/typed_struct.proto xds/type/v3/typed_struct.proto ) +endif() if(gRPC_BUILD_TESTS) add_custom_target(buildtests_c) diff --git a/templates/CMakeLists.txt.template b/templates/CMakeLists.txt.template index f5b7480d639b67..27c0d87d6728f5 100644 --- a/templates/CMakeLists.txt.template +++ b/templates/CMakeLists.txt.template @@ -713,11 +713,25 @@ DEPENDS tools_c tools_cxx) % for src in sorted(protobuf_gen_files): + % if not src.startswith('third_party/'): protobuf_generate_grpc_cpp_with_import_path_correction( ${src} ${third_party_proto_import_path(src)} ) + % endif % endfor + # This enables CMake to build the project without requiring submodules + # in the third_party directory as long as test builds are disabled. + if (gRPC_BUILD_TESTS) + % for src in sorted(protobuf_gen_files): + % if src.startswith('third_party/'): + protobuf_generate_grpc_cpp_with_import_path_correction( + ${src} ${third_party_proto_import_path(src)} + ) + % endif + % endfor + endif() + if(gRPC_BUILD_TESTS) add_custom_target(buildtests_c) % for tgt in targets: