Skip to content

Commit

Permalink
RSDK-2113 Align buf remote plugin proto version with local (viamrobot…
Browse files Browse the repository at this point in the history
  • Loading branch information
acmorrow authored Mar 19, 2024
1 parent 89519f7 commit 8227a91
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 8 deletions.
11 changes: 10 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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})
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion etc/docker/Dockerfile.ubuntu.focal
Original file line number Diff line number Diff line change
Expand Up @@ -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 && \
Expand Down
2 changes: 1 addition & 1 deletion src/viam/api/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions src/viam/api/config/buf.gen.remote.plugin.yaml.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion src/viam/examples/modules/complex/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 8227a91

Please sign in to comment.