[build][cpp] Add cmake option to skip HTTP downloads (#34587)

Fixes #30385 for C++/cmake.

Add a `gRPC_DOWNLOAD_ARCHIVES` switch that is on by default but can be disabled for environments building without Internet connectivity.

Passes build tests:

```
$ python tools/run_tests/run_tests.py -l c++ --build_only
PASSED: tools/run_tests/helper_scripts/build_cxx.sh [time=7116.3sec, retries=0:0SUCCESS: All tests passed

=== run_tests.py DEBUG INFO ===
command: "tools/run_tests/run_tests.py -l c++ --build_only"
===============================
$
```

And tested in a Docker container with `eth0` down to ensure we can now build when `-DgRPC_DOWNLOAD_ARCHIVES="OFF"` is passed to cmake.

Closes #34587

COPYBARA_INTEGRATE_REVIEW=https://github.com/grpc/grpc/pull/34587 from matthewjmiller1:no-download-option 9c07bdce87
PiperOrigin-RevId: 599954208
pull/35530/head
Matt Miller 1 year ago committed by Copybara-Service
parent 8144346e2c
commit d4f1f8543e
  1. 17
      CMakeLists.txt
  2. 3
      templates/CMakeLists.txt.template

17
CMakeLists.txt generated

@ -49,6 +49,7 @@ set(gRPC_BUILD_MSVC_MP_COUNT 0 CACHE STRING "The maximum number of processes for
# Options
option(gRPC_BUILD_TESTS "Build tests" OFF)
option(gRPC_BUILD_CODEGEN "Build codegen" ON)
option(gRPC_DOWNLOAD_ARCHIVES "Download archives for empty 3rd party directories" ON)
set(gRPC_INSTALL_default ON)
if(NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
@ -344,7 +345,7 @@ if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_POSIX)
endif()
# Setup external proto library at third_party/envoy-api with 2 download URLs
if (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/third_party/envoy-api)
if (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/third_party/envoy-api AND gRPC_DOWNLOAD_ARCHIVES)
# Download the archive via HTTP, validate the checksum, and extract to third_party/envoy-api.
download_archive(
${CMAKE_CURRENT_SOURCE_DIR}/third_party/envoy-api
@ -353,7 +354,7 @@ if (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/third_party/envoy-api)
data-plane-api-9d6ffa70677c4dbf23f6ed569676206c4e2edff4
)
endif()
if (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/third_party/envoy-api)
if (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/third_party/envoy-api AND gRPC_DOWNLOAD_ARCHIVES)
# Download the archive via HTTP, validate the checksum, and extract to third_party/envoy-api.
download_archive(
${CMAKE_CURRENT_SOURCE_DIR}/third_party/envoy-api
@ -363,7 +364,7 @@ if (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/third_party/envoy-api)
)
endif()
# Setup external proto library at third_party/googleapis with 2 download URLs
if (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/third_party/googleapis)
if (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/third_party/googleapis AND gRPC_DOWNLOAD_ARCHIVES)
# Download the archive via HTTP, validate the checksum, and extract to third_party/googleapis.
download_archive(
${CMAKE_CURRENT_SOURCE_DIR}/third_party/googleapis
@ -372,7 +373,7 @@ if (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/third_party/googleapis)
googleapis-2f9af297c84c55c8b871ba4495e01ade42476c92
)
endif()
if (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/third_party/googleapis)
if (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/third_party/googleapis AND gRPC_DOWNLOAD_ARCHIVES)
# Download the archive via HTTP, validate the checksum, and extract to third_party/googleapis.
download_archive(
${CMAKE_CURRENT_SOURCE_DIR}/third_party/googleapis
@ -382,7 +383,7 @@ if (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/third_party/googleapis)
)
endif()
# Setup external proto library at third_party/opencensus-proto/src with 2 download URLs
if (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/third_party/opencensus-proto/src)
if (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/third_party/opencensus-proto/src AND gRPC_DOWNLOAD_ARCHIVES)
# Download the archive via HTTP, validate the checksum, and extract to third_party/opencensus-proto/src.
download_archive(
${CMAKE_CURRENT_SOURCE_DIR}/third_party/opencensus-proto/src
@ -391,7 +392,7 @@ if (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/third_party/opencensus-proto/src)
opencensus-proto-0.3.0/src
)
endif()
if (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/third_party/opencensus-proto/src)
if (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/third_party/opencensus-proto/src AND gRPC_DOWNLOAD_ARCHIVES)
# Download the archive via HTTP, validate the checksum, and extract to third_party/opencensus-proto/src.
download_archive(
${CMAKE_CURRENT_SOURCE_DIR}/third_party/opencensus-proto/src
@ -401,7 +402,7 @@ if (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/third_party/opencensus-proto/src)
)
endif()
# Setup external proto library at third_party/xds with 2 download URLs
if (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/third_party/xds)
if (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/third_party/xds AND gRPC_DOWNLOAD_ARCHIVES)
# Download the archive via HTTP, validate the checksum, and extract to third_party/xds.
download_archive(
${CMAKE_CURRENT_SOURCE_DIR}/third_party/xds
@ -410,7 +411,7 @@ if (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/third_party/xds)
xds-e9ce68804cb4e64cab5a52e3c8baf840d4ff87b7
)
endif()
if (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/third_party/xds)
if (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/third_party/xds AND gRPC_DOWNLOAD_ARCHIVES)
# Download the archive via HTTP, validate the checksum, and extract to third_party/xds.
download_archive(
${CMAKE_CURRENT_SOURCE_DIR}/third_party/xds

@ -312,6 +312,7 @@
# Options
option(gRPC_BUILD_TESTS "Build tests" OFF)
option(gRPC_BUILD_CODEGEN "Build codegen" ON)
option(gRPC_DOWNLOAD_ARCHIVES "Download archives for empty 3rd party directories" ON)
set(gRPC_INSTALL_default ON)
if(NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
@ -505,7 +506,7 @@
# Setup external proto library at ${external_proto_library.destination} if it doesn't exist
% endif
% for download_url in external_proto_library.urls:
if (NOT EXISTS <%text>${CMAKE_CURRENT_SOURCE_DIR}</%text>/${external_proto_library.destination})
if (NOT EXISTS <%text>${CMAKE_CURRENT_SOURCE_DIR}</%text>/${external_proto_library.destination} AND gRPC_DOWNLOAD_ARCHIVES)
# Download the archive via HTTP, validate the checksum, and extract to ${external_proto_library.destination}.
download_archive(
<%text>${CMAKE_CURRENT_SOURCE_DIR}</%text>/${external_proto_library.destination}

Loading…
Cancel
Save