From 8227a91311e3c40e9f3852c05c3f578e084fe20f Mon Sep 17 00:00:00 2001 From: "Andrew C. Morrow" Date: Tue, 19 Mar 2024 10:59:06 -0400 Subject: [PATCH] RSDK-2113 Align buf remote plugin proto version with local (#224) --- CMakeLists.txt | 11 ++++++++++- etc/docker/Dockerfile.ubuntu.focal | 2 +- src/viam/api/CMakeLists.txt | 2 +- src/viam/api/config/buf.gen.remote.plugin.yaml.in | 4 +--- src/viam/examples/modules/complex/CMakeLists.txt | 2 +- .../complex/config/buf.gen.remote.plugin.yaml.in | 2 +- 6 files changed, 15 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 841bede38..c8c46ec6d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -71,7 +71,7 @@ option(VIAMCPPSDK_ENFORCE_COMPILER_MINIMA "Control whether we validate the selec # Do not use buf.builds remote definitions or services and use the # local proto compiler plugins to do generation. # -option(VIAMCPPSDK_OFFLINE_PROTO_GENERATION "Use local tools for proto generation" ON) +option(VIAMCPPSDK_OFFLINE_PROTO_GENERATION "Use local tools for proto generation" OFF) # - `VIAMCPPSDK_USE_DYNAMIC_PROTOS` @@ -339,6 +339,8 @@ find_package(gRPC ${VIAMCPPSDK_GRPC_VERSION_MINIMUM} CONFIG) if (gRPC_FOUND) get_target_property(VIAMCPPSDK_GRPC_CPP_PLUGIN gRPC::grpc_cpp_plugin LOCATION) set(VIAMCPPSDK_PROTOBUF_VERSION ${Protobuf_VERSION}) + set(VIAMCPPSDK_PROTOBUF_VERSION_MAJOR ${Protobuf_VERSION_MAJOR}) + set(VIAMCPPSDK_PROTOBUF_VERSION_MINOR ${Protobuf_VERSION_MINOR}) # We need a good value for VIAMCPPSDK_PROTOBUF_VERSION in order to # interpolate it into our `pkgconfig` requirements. Make sure we @@ -366,6 +368,8 @@ else() pkg_check_modules(GRPCXX REQUIRED grpc++>=${VIAMCPPSDK_GRPC_VERSION_MINIMUM}) set(VIAMCPPSDK_PROTOBUF_VERSION ${PROTOBUF_VERSION}) + string(REGEX REPLACE "^([0-9]+)\.([0-9]+)\.([0-9]+)$" "\\1" VIAMCPPSDK_PROTOBUF_VERSION_MAJOR ${VIAMCPPSDK_PROTOBUF_VERSION}) + string(REGEX REPLACE "^([0-9]+)\.([0-9]+)\.([0-9]+)$" "\\2" VIAMCPPSDK_PROTOBUF_VERSION_MINOR ${VIAMCPPSDK_PROTOBUF_VERSION}) set(VIAMCPPSDK_PROTOBUF_INCLUDE_DIRS ${PROTOBUF_INCLUDE_DIRS}) set(VIAMCPPSDK_PROTOBUF_LIBRARY_DIRS ${PROTOBUF_LIBRARY_DIRS}) set(VIAMCPPSDK_PROTOBUF_LIBRARIES ${PROTOBUF_LIBRARIES}) @@ -394,6 +398,11 @@ else() list(PREPEND VIAMCPPSDK_GRPCXX_REFLECTION_LIBRARIES ${VIAMCPPSDK_GRPCXX_REFLECTION_LIB}) endif() +# These are the minimum versions of gRPC and protobuf for which remote plugins with buf are supported. +if ((VIAMCPPSDK_GRPCXX_VERSION VERSION_GREATER 1.51.1) AND (VIAMCPPSDK_PROTOBUF_VERSION VERSION_GREATER 21.7.0)) + set(VIAMCPPSDK_BUF_REMOTE_PLUGIN_SUPPORTED 1) +endif() + include(FetchContent) FetchContent_Declare( diff --git a/etc/docker/Dockerfile.ubuntu.focal b/etc/docker/Dockerfile.ubuntu.focal index 439241830..39362932b 100644 --- a/etc/docker/Dockerfile.ubuntu.focal +++ b/etc/docker/Dockerfile.ubuntu.focal @@ -49,7 +49,7 @@ RUN apt-get -y install cmake RUN mkdir -p ${HOME}/opt/src RUN cd ${HOME}/opt/src && \ - git clone --recurse-submodules -b v1.52.0 --depth 1 --shallow-submodules https://github.com/grpc/grpc && \ + git clone --recurse-submodules -b v1.62.1 --depth 1 --shallow-submodules https://github.com/grpc/grpc && \ cd grpc && \ mkdir -p build && \ cd build && \ diff --git a/src/viam/api/CMakeLists.txt b/src/viam/api/CMakeLists.txt index 3bdfbf61f..12efd2bc0 100644 --- a/src/viam/api/CMakeLists.txt +++ b/src/viam/api/CMakeLists.txt @@ -100,7 +100,7 @@ if (VIAMCPPSDK_USE_DYNAMIC_PROTOS) # TODO: Should we have an option to always do local generation so # offline development always works? # - if ((NOT VIAMCPPSDK_OFFLINE_PROTO_GENERATION) AND (VIAMCPPSDK_GRPCXX_VERSION VERSION_GREATER 1.51.1)) + if ((NOT VIAMCPPSDK_OFFLINE_PROTO_GENERATION) AND VIAMCPPSDK_BUF_REMOTE_PLUGIN_SUPPORTED) configure_file( config/buf.gen.remote.plugin.yaml.in buf.gen.yaml diff --git a/src/viam/api/config/buf.gen.remote.plugin.yaml.in b/src/viam/api/config/buf.gen.remote.plugin.yaml.in index 631ec56f5..5405f7579 100644 --- a/src/viam/api/config/buf.gen.remote.plugin.yaml.in +++ b/src/viam/api/config/buf.gen.remote.plugin.yaml.in @@ -12,13 +12,11 @@ # See the License for the specific language governing permissions and # limitations under the License. -# buf.gen.yaml version: v1 managed: enabled: true plugins: - plugin: buf.build/grpc/cpp:v@VIAMCPPSDK_GRPCXX_VERSION@ out: gen/viam/api - # dependencies - - plugin: buf.build/protocolbuffers/cpp + - plugin: buf.build/protocolbuffers/cpp:v@VIAMCPPSDK_PROTOBUF_VERSION_MAJOR@.@VIAMCPPSDK_PROTOBUF_VERSION_MINOR@ out: gen/viam/api diff --git a/src/viam/examples/modules/complex/CMakeLists.txt b/src/viam/examples/modules/complex/CMakeLists.txt index 92fb7c534..51f63c044 100644 --- a/src/viam/examples/modules/complex/CMakeLists.txt +++ b/src/viam/examples/modules/complex/CMakeLists.txt @@ -57,7 +57,7 @@ if (NOT BUF_COMMAND) file(CHMOD ${BUF_COMMAND} PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE) endif() -if ((NOT VIAMCPPSDK_OFFLINE_PROTO_GENERATION) AND (VIAMCPPSDK_GRPCXX_VERSION VERSION_GREATER 1.51.1)) +if ((NOT VIAMCPPSDK_OFFLINE_PROTO_GENERATION) AND VIAMCPPSDK_BUF_REMOTE_PLUGIN_SUPPORTED) configure_file( config/buf.gen.remote.plugin.yaml.in buf.gen.yaml diff --git a/src/viam/examples/modules/complex/config/buf.gen.remote.plugin.yaml.in b/src/viam/examples/modules/complex/config/buf.gen.remote.plugin.yaml.in index 78fcdf91f..f1fe1dd88 100644 --- a/src/viam/examples/modules/complex/config/buf.gen.remote.plugin.yaml.in +++ b/src/viam/examples/modules/complex/config/buf.gen.remote.plugin.yaml.in @@ -18,5 +18,5 @@ managed: plugins: - plugin: buf.build/grpc/cpp:v@VIAMCPPSDK_GRPCXX_VERSION@ out: gen - - plugin: buf.build/protocolbuffers/cpp + - plugin: buf.build/protocolbuffers/cpp:v@VIAMCPPSDK_PROTOBUF_VERSION_MAJOR@.@VIAMCPPSDK_PROTOBUF_VERSION_MINOR@ out: gen