Skip to content

Commit

Permalink
Merge branch 'main' into workflow/update-protos
Browse files Browse the repository at this point in the history
  • Loading branch information
lia-viam authored Nov 20, 2024
2 parents 3b03426 + e331f2c commit d672f39
Show file tree
Hide file tree
Showing 100 changed files with 1,906 additions and 1,142 deletions.
67 changes: 67 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
on:
workflow_dispatch:
inputs:
image-prefix:
description: "gets suffixed with 'base' and 'sdk' to create actual image name"
default: ghcr.io/viamrobotics/cpp-
dockerfile:
default: Dockerfile.debian.bullseye
tag:
default: bullseye-amd64
build-base:
description: "whether to build the base image. the base images change less often and may not be necessary to rebuild."
type: boolean
default: false
build-sdk:
description: "whether to build the SDK image. if this is true and no corresponding base image exists, the job will fail."
type: boolean
default: false
push:
description: "whether to push the images after building them"
type: boolean
default: false

jobs:
build-container:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4

- uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

# build base (if inputs.build-base)
- uses: docker/metadata-action@v5
id: base-meta
if: inputs.build-base
with:
images: ${{ inputs.image-prefix }}base
- uses: docker/build-push-action@v5
if: inputs.build-base
with:
push: ${{ inputs.push }}
tags: "${{ inputs.image-prefix }}base:${{ inputs.tag }}"
file: etc/docker/base-images/${{ inputs.dockerfile }}
labels: ${{ steps.base-meta.output.labels }}

# build sdk (if inputs.build-sdk)
- uses: docker/metadata-action@v5
id: sdk-meta
if: inputs.build-sdk
with:
images: ${{ inputs.image-prefix }}sdk
- uses: docker/build-push-action@v5
if: inputs.build-sdk
with:
build-args: |
BASE_TAG=${{ inputs.image-prefix }}base:${{ inputs.tag }}
push: ${{ inputs.push }}
tags: "${{ inputs.image-prefix }}sdk:${{ inputs.tag }}"
file: etc/docker/Dockerfile.sdk-build
labels: ${{ steps.sdk-meta.output.labels }}
13 changes: 6 additions & 7 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
name: cpp-linter

on: pull_request
on:
pull_request:
workflow_dispatch:

jobs:
cpp-linter:
if: github.repository_owner == 'viamrobotics'
runs-on: ubuntu-latest
container:
image: ghcr.io/viamrobotics/canon:amd64
container: ghcr.io/viamrobotics/cpp-base:bullseye-amd64
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: install clang-format
run: sudo apt install -y clang-format
- name: verify no uncommitted changes
run: |
chown $(whoami) .
git init
git add .
chown -R testbot .
sudo -u testbot bash -lc 'sh ./bin/run-clang-format.sh'
./bin/run-clang-format.sh
GEN_DIFF=$(git status -s)
if [ -n "$GEN_DIFF" ]; then
Expand Down
40 changes: 22 additions & 18 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,38 @@ name: Test
on:
pull_request:
workflow_dispatch:
inputs:
no-tidy:
type: boolean
description: set to true to build without clang-tidy (2x faster)

jobs:
run-tests:
if: github.repository_owner == 'viamrobotics'
runs-on: ubuntu-latest
container:
image: ghcr.io/viamrobotics/canon:amd64
container: ghcr.io/viamrobotics/cpp-base:bullseye-amd64
strategy:
matrix:
include:
- BUILD_SHARED: ON
- BUILD_SHARED: OFF
steps:
- uses: actions/checkout@v4
###########################################
# necessary installs for building #
###########################################
- name: build-docker-test
- name: cmake
run: |
docker build -t cpp . -f etc/docker/base-images/Dockerfile.debian.bullseye
docker build -t cpp-test . -f etc/docker/Dockerfile.sdk-build \
--build-arg BASE_TAG=cpp \
--build-arg REPO_SETUP=copy \
--build-arg BUILD_SHARED=${{ matrix.BUILD_SHARED }} \
--build-arg BUILD_TESTS=ON \
--build-arg BUILD_EXAMPLES=ON \
--build-arg "EXTRA_CMAKE_ARGS=\
-DVIAMCPPSDK_CLANG_TIDY=ON \
-DVIAMCPPSDK_SANITIZED_BUILD=${{ matrix.BUILD_SHARED }}"
docker run -w /viam-cpp-sdk/build -t --entrypoint /viam-cpp-sdk/etc/docker/tests/run_test.sh cpp-test /bin/bash
mkdir build
cd build
cmake .. -G Ninja \
-DBUILD_SHARED_LIBS=${{ matrix.BUILD_SHARED }} \
-DVIAMCPPSDK_OFFLINE_PROTO_GENERATION=ON \
-DVIAMCPPSDK_BUILD_TESTS=ON \
-DVIAMCPPSDK_BUILD_EXAMPLES=ON \
-DVIAMCPPSDK_CLANG_TIDY=${{ inputs.no-tidy && 'OFF' || 'ON' }} \
-DVIAMCPPSDK_SANITIZED_BUILD=${{ matrix.BUILD_SHARED }}
- name: build
run: |
cmake --build build --target install
cmake --install build
- name: test
working-directory: build
run: ../etc/docker/tests/run_test.sh
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
# constrained by the version of CMake available on target systems.
cmake_minimum_required(VERSION 3.25 FATAL_ERROR)

set(CMAKE_PROJECT_VERSION 0.0.15)
set(CMAKE_PROJECT_VERSION 0.0.16)

# Identify the project.
project(viam-cpp-sdk
Expand Down
3 changes: 2 additions & 1 deletion etc/docker/base-images/Dockerfile.debian.bookworm
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,5 @@ RUN apt-get update

RUN apt-get -y --no-install-recommends install -t llvm-toolchain-bookworm-15 \
clang-15 \
clang-tidy-15
clang-tidy-15 \
clang-format
5 changes: 3 additions & 2 deletions etc/docker/base-images/Dockerfile.debian.bullseye
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM debian:bullseye

ENV HOME /root
ENV HOME=/root
ARG DEBIAN_FRONTEND=noninteractive

RUN apt-get update
Expand Down Expand Up @@ -39,7 +39,8 @@ RUN apt-get update

RUN apt-get -y --no-install-recommends install -t llvm-toolchain-bullseye-15 \
clang-15 \
clang-tidy-15
clang-tidy-15 \
clang-format

RUN apt-get -y --no-install-recommends install -t bullseye-backports \
cmake
3 changes: 2 additions & 1 deletion etc/docker/base-images/Dockerfile.debian.sid
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,5 @@ RUN apt-get update

RUN apt-get -y --no-install-recommends install -t llvm-toolchain-15 \
clang-15 \
clang-tidy-15
clang-tidy-15 \
clang-format
3 changes: 2 additions & 1 deletion etc/docker/base-images/Dockerfile.ubuntu.focal
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ RUN apt-get update

RUN apt-get -y --no-install-recommends install -t llvm-toolchain-focal-15 \
clang-15 \
clang-tidy-15
clang-tidy-15 \
clang-format

RUN apt-get -y install cmake

Expand Down
3 changes: 2 additions & 1 deletion etc/docker/base-images/Dockerfile.ubuntu.jammy
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ RUN apt-get update

RUN apt-get -y --no-install-recommends install -t llvm-toolchain-jammy-15 \
clang-15 \
clang-tidy-15
clang-tidy-15 \
clang-format

RUN apt-get -y install cmake
8 changes: 8 additions & 0 deletions src/viam/api/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,10 @@ if (VIAMCPPSDK_USE_DYNAMIC_PROTOS)
${PROTO_GEN_DIR}/service/motion/v1/motion.grpc.pb.h
${PROTO_GEN_DIR}/service/motion/v1/motion.pb.cc
${PROTO_GEN_DIR}/service/motion/v1/motion.pb.h
${PROTO_GEN_DIR}/service/navigation/v1/navigation.grpc.pb.cc
${PROTO_GEN_DIR}/service/navigation/v1/navigation.grpc.pb.h
${PROTO_GEN_DIR}/service/navigation/v1/navigation.pb.cc
${PROTO_GEN_DIR}/service/navigation/v1/navigation.pb.h
${PROTO_GEN_DIR}/tagger/v1/tagger.grpc.pb.cc
${PROTO_GEN_DIR}/tagger/v1/tagger.grpc.pb.h
${PROTO_GEN_DIR}/tagger/v1/tagger.pb.cc
Expand Down Expand Up @@ -328,6 +332,8 @@ target_sources(viamapi
${PROTO_GEN_DIR}/service/mlmodel/v1/mlmodel.pb.cc
${PROTO_GEN_DIR}/service/motion/v1/motion.grpc.pb.cc
${PROTO_GEN_DIR}/service/motion/v1/motion.pb.cc
${PROTO_GEN_DIR}/service/navigation/v1/navigation.grpc.pb.cc
${PROTO_GEN_DIR}/service/navigation/v1/navigation.pb.cc
${PROTO_GEN_DIR}/tagger/v1/tagger.grpc.pb.cc
${PROTO_GEN_DIR}/tagger/v1/tagger.pb.cc
PUBLIC FILE_SET viamapi_includes TYPE HEADERS
Expand Down Expand Up @@ -385,6 +391,8 @@ target_sources(viamapi
${PROTO_GEN_DIR}/../../viam/api/service/mlmodel/v1/mlmodel.pb.h
${PROTO_GEN_DIR}/../../viam/api/service/motion/v1/motion.grpc.pb.h
${PROTO_GEN_DIR}/../../viam/api/service/motion/v1/motion.pb.h
${PROTO_GEN_DIR}/../../viam/api/service/navigation/v1/navigation.grpc.pb.h
${PROTO_GEN_DIR}/../../viam/api/service/navigation/v1/navigation.pb.h
${PROTO_GEN_DIR}/../../viam/api/tagger/v1/tagger.pb.h
)

Expand Down
4 changes: 2 additions & 2 deletions src/viam/examples/modules/complex/proto/buf.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ deps:
- remote: buf.build
owner: googleapis
repository: googleapis
commit: e7f8d366f5264595bcc4cd4139af9973
digest: shake256:e5e5f1c12f82e028ea696faa43b4f9dc6258a6d1226282962a8c8b282e10946281d815884f574bd279ebd9cd7588629beb3db17b892af6c33b56f92f8f67f509
commit: c0913f24652a4cfc95f77d97443a5005
digest: shake256:0ef3248c6235d420fe61f373154adcde6b94e3297f82472b1d8d8c3747240b61b4a10405e2a6f8ac1c98816ac6e690ea7871024aa5ae0e035cd540214667ceed
5 changes: 5 additions & 0 deletions src/viam/sdk/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ target_sources(viamsdk
components/private/board_server.cpp
components/private/camera_client.cpp
components/private/camera_server.cpp
components/private/encoder.cpp
components/private/encoder_client.cpp
components/private/encoder_server.cpp
components/private/gantry_client.cpp
Expand Down Expand Up @@ -119,13 +120,16 @@ target_sources(viamsdk
services/generic.cpp
services/mlmodel.cpp
services/motion.cpp
services/navigation.cpp
services/private/generic_client.cpp
services/private/generic_server.cpp
services/private/mlmodel.cpp
services/private/mlmodel_client.cpp
services/private/mlmodel_server.cpp
services/private/motion_client.cpp
services/private/motion_server.cpp
services/private/navigation_client.cpp
services/private/navigation_server.cpp
services/service.cpp
spatialmath/geometry.cpp
spatialmath/orientation.cpp
Expand Down Expand Up @@ -179,6 +183,7 @@ target_sources(viamsdk
../../viam/sdk/services/generic.hpp
../../viam/sdk/services/mlmodel.hpp
../../viam/sdk/services/motion.hpp
../../viam/sdk/services/navigation.hpp
../../viam/sdk/services/service.hpp
../../viam/sdk/spatialmath/geometry.hpp
../../viam/sdk/spatialmath/orientation.hpp
Expand Down
63 changes: 63 additions & 0 deletions src/viam/sdk/common/private/proto_utils.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/// @file common/proto_utils.hpp
///
/// @brief Utils that require generated proto includes. These should be #included
/// in cpp implementation files, but not in wrapper headers consumed by third party code.
#pragma once

#include <viam/api/common/v1/common.pb.h>

namespace viam {
namespace sdk {
namespace impl {

/// @brief Copies elements from a protobuf repeated pointer array into a std::vector. Src type
/// must have a `to_proto` method.
template <typename Src, typename Dst>
void vecToRepeatedPtr(const std::vector<Src>& vec, google::protobuf::RepeatedPtrField<Dst>& dest) {
dest.Clear();
dest.Reserve(vec.size());
for (auto& x : vec) {
*dest.Add() = x.to_proto();
}
}

/// @brief Non-member to_proto() version. (necessary for moving generated types out of wrapper
/// headers). Takes explicit `to_proto`.
template <typename Src, typename Dst>
void vecToRepeatedPtr(const std::vector<Src>& vec,
google::protobuf::RepeatedPtrField<Dst>& dest,
Dst to_proto(const Src&)) {
dest.Clear();
dest.Reserve(vec.size());
for (auto& x : vec) {
*dest.Add() = to_proto(x);
}
}

/// @brief Copies elements from a std::vector into a protobuf repeated pointer array. Dst type
/// must have a `from_proto` static method.
template <typename Src, typename Dst>
void repeatedPtrToVec(const google::protobuf::RepeatedPtrField<Src>& src, std::vector<Dst>& vec) {
vec.clear();
vec.reserve(src.size());
for (auto& x : src) {
vec.push_back(Dst::from_proto(x));
}
}

/// @brief Non-member from_proto() version. (necessary for moving generated types out of wrapper
/// headers). Takes explicit `from_proto`.
template <typename Src, typename Dst>
void repeatedPtrToVec(const google::protobuf::RepeatedPtrField<Src>& src,
std::vector<Dst>& vec,
Dst from_proto(const Src&)) {
vec.clear();
vec.reserve(src.size());
for (auto& x : src) {
vec.push_back(from_proto(x));
}
}

} // namespace impl
} // namespace sdk
} // namespace viam
21 changes: 21 additions & 0 deletions src/viam/sdk/common/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <unordered_map>
#include <vector>

#include <boost/algorithm/string.hpp>
#include <boost/blank.hpp>
#include <boost/log/core.hpp>
#include <boost/log/expressions.hpp>
Expand Down Expand Up @@ -183,6 +184,26 @@ bool from_dm_from_extra(const ProtoStruct& extra) {
}
return false;
}
std::pair<std::string, std::string> long_name_to_remote_and_short(const std::string& long_name) {
std::vector<std::string> name_parts;
// boost::split causes a clang-tidy false positive, see
// https://bugs.llvm.org/show_bug.cgi?id=41141
//
// NOLINTNEXTLINE
boost::split(name_parts, long_name, boost::is_any_of(":"));
auto name = name_parts.back();
name_parts.pop_back();
auto remote_name = name_parts.empty()
? ""
: std::accumulate(std::next(name_parts.begin()),
name_parts.end(),
*name_parts.begin(),
[](const std::string& a, const std::string& b) {
return a + ":" + b;
});

return {std::move(remote_name), std::move(name)};
}

} // namespace sdk
} // namespace viam
4 changes: 4 additions & 0 deletions src/viam/sdk/common/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ class ClientContext {
grpc::ClientContext wrapped_context_;
};

/// @brief Given a fully qualified resource name, returns remote name (or "" if no remote name
/// exists) and short name
std::pair<std::string, std::string> long_name_to_remote_and_short(const std::string& long_name);

/// @brief Returns a new `ProtoStruct` with a random key for server-side debug logging
ProtoStruct debug_map();

Expand Down
Loading

0 comments on commit d672f39

Please sign in to comment.