From fef2b46b3b9de3b2b8d403fe99a8969afbf02c32 Mon Sep 17 00:00:00 2001 From: lia <167905060+lia-viam@users.noreply.github.com> Date: Mon, 12 Aug 2024 13:28:22 -0400 Subject: [PATCH] RSDK-7440: Build example projects in CI (#276) --- etc/docker/tests/run_test.sh | 17 +++++++++++++++++ .../api/config/viam-cpp-sdk-libviamapi.pc.in | 2 +- .../examples/modules/complex/proto/buf.lock | 4 ++-- src/viam/examples/modules/simple/main.cpp | 8 ++++++-- src/viam/examples/project/pkg-config/Makefile | 7 ++++--- .../sdk/config/viam-cpp-sdk-libviamsdk.pc.in | 2 +- src/viam/sdk/module/service.cpp | 2 +- 7 files changed, 32 insertions(+), 10 deletions(-) diff --git a/etc/docker/tests/run_test.sh b/etc/docker/tests/run_test.sh index 48066e512..83fbc51a6 100755 --- a/etc/docker/tests/run_test.sh +++ b/etc/docker/tests/run_test.sh @@ -9,9 +9,26 @@ cmake .. -G Ninja -DVIAMCPPSDK_USE_DYNAMIC_PROTOS=ON \ -DVIAMCPPSDK_CLANG_TIDY=ON ninja all ninja install +INSTALL_DIR="$(pwd)/install" + pushd src/viam/sdk/tests UBSAN_OPTIONS="print_stacktrace=1" ctest --output-on-failure popd pushd src/viam/examples/modules/complex UBSAN_OPTIONS="print_stacktrace=1" ctest --output-on-failure popd + +# Test that example_module builds and runs with the SDK install from above. +# Check with both CMake and make/pkg-config that we can build the example +# and have it exit with the expected error message. + +cd ../src/viam/examples/project +pushd cmake +cmake . -G Ninja # Just do an in-source build to save path fiddling +ninja all +[ $(./example_module 2>&1 | grep 'main failed with exception:' -c) = 1 ] +popd +pushd pkg-config +PKG_CONFIG_PATH=${INSTALL_DIR}/lib/pkgconfig make all +[ $(./example_module 2>&1 | grep 'main failed with exception:' -c) = 1 ] +popd diff --git a/src/viam/api/config/viam-cpp-sdk-libviamapi.pc.in b/src/viam/api/config/viam-cpp-sdk-libviamapi.pc.in index e21ab9382..a55612130 100644 --- a/src/viam/api/config/viam-cpp-sdk-libviamapi.pc.in +++ b/src/viam/api/config/viam-cpp-sdk-libviamapi.pc.in @@ -7,7 +7,7 @@ Name: @PROJECT_NAME@-libapi Description: @PROJECT_DESCRIPTION@ URL: @PROJECT_HOMEPAGE_URL@ Version: @PROJECT_VERSION@ -Requires: gRPC++ >= @VIAMCPPSDK_GRPCXX_VERSION@ protobuf >= @VIAMCPPSDK_PROTOBUF_VERSION@ +Requires: grpc++ >= @VIAMCPPSDK_GRPCXX_VERSION@ protobuf >= @VIAMCPPSDK_PROTOBUF_VERSION@ Libs: -Wl,-rpath,${libdir} -L${libdir} -L@Boost_LIBRARY_DIRS@ -lviamapi Cflags: -I${base_includedir} -I${deep_includedir} diff --git a/src/viam/examples/modules/complex/proto/buf.lock b/src/viam/examples/modules/complex/proto/buf.lock index 225fe4689..2b3f954ff 100644 --- a/src/viam/examples/modules/complex/proto/buf.lock +++ b/src/viam/examples/modules/complex/proto/buf.lock @@ -4,5 +4,5 @@ deps: - remote: buf.build owner: googleapis repository: googleapis - commit: 2bbd25900cb34c79bae97d85c948d3cf - digest: shake256:a6446e23f4408160217c22738a0c8c370ff3ff966f601d678960b803829cf53b5cf5998d20fcb3f9c9be944b24337843e7beb6e681ddbf9d036fb6491c0e47e7 + commit: 8bc2c51e08c447cd8886cdea48a73e14 + digest: shake256:a969155953a5cedc5b2df5b42c368f2bc66ff8ce1804bc96e0f14ff2ee8a893687963058909df844d1643cdbc98ff099d2daa6bc9f9f5b8886c49afdc60e19af diff --git a/src/viam/examples/modules/simple/main.cpp b/src/viam/examples/modules/simple/main.cpp index 8e0ef8dd4..de214e42a 100644 --- a/src/viam/examples/modules/simple/main.cpp +++ b/src/viam/examples/modules/simple/main.cpp @@ -10,6 +10,7 @@ #include #include +#include #include #include #include @@ -72,7 +73,7 @@ class Printer : public GenericService, public Reconfigurable { std::string to_print_; }; -int main(int argc, char** argv) { +int main(int argc, char** argv) try { API generic = API::get(); Model m("viam", "generic", "printer"); @@ -96,4 +97,7 @@ int main(int argc, char** argv) { my_mod->serve(); return EXIT_SUCCESS; -}; +} catch (const viam::sdk::Exception& ex) { + std::cerr << "main failed with exception: " << ex.what() << "\n"; + return EXIT_FAILURE; +} diff --git a/src/viam/examples/project/pkg-config/Makefile b/src/viam/examples/project/pkg-config/Makefile index b3e31afa9..40f649a59 100644 --- a/src/viam/examples/project/pkg-config/Makefile +++ b/src/viam/examples/project/pkg-config/Makefile @@ -7,7 +7,8 @@ CXX_STANDARD ?= c++17 CXXFLAGS += -std=$(CXX_STANDARD) CXXFLAGS += `pkg-config --cflags viam-cpp-sdk-libviamsdk` -LDFLAGS += `pkg-config --libs viam-cpp-sdk-libviamsdk` +LDLIBS += `pkg-config --libs-only-l viam-cpp-sdk-libviamsdk` +LDFLAGS += `pkg-config --libs-only-L --libs-only-other viam-cpp-sdk-libviamsdk` all: example_dial example_module @@ -15,13 +16,13 @@ example_dial.o: ../../dial/example_dial.cpp $(CXX) $(CXXFLAGS) -c -o $@ $^ example_dial: example_dial.o - $(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $^ + $(CXX) $(CXXFLAGS) -o $@ $^ $(LDFLAGS) $(LDLIBS) example_module.o: ../../modules/simple/main.cpp $(CXX) $(CXXFLAGS) -c -o $@ $^ example_module: example_module.o - $(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $^ + $(CXX) $(CXXFLAGS) -o $@ $^ $(LDFLAGS) $(LDLIBS) clean: rm -f *.o example_dial example_module diff --git a/src/viam/sdk/config/viam-cpp-sdk-libviamsdk.pc.in b/src/viam/sdk/config/viam-cpp-sdk-libviamsdk.pc.in index 98061c1bd..005af602e 100644 --- a/src/viam/sdk/config/viam-cpp-sdk-libviamsdk.pc.in +++ b/src/viam/sdk/config/viam-cpp-sdk-libviamsdk.pc.in @@ -6,7 +6,7 @@ Name: @PROJECT_NAME@-libviamsdk Description: @PROJECT_DESCRIPTION@ URL: @PROJECT_HOMEPAGE_URL@ Version: @PROJECT_VERSION@ -Requires: gRPC++ >= @VIAMCPPSDK_GRPCXX_VERSION@ protobuf >= @VIAMCPPSDK_PROTOBUF_VERSION@ @PROJECT_NAME@-libviamapi >= @PROJECT_VERSION@ +Requires: grpc++ >= @VIAMCPPSDK_GRPCXX_VERSION@ protobuf >= @VIAMCPPSDK_PROTOBUF_VERSION@ @PROJECT_NAME@-libviamapi >= @PROJECT_VERSION@ Libs: -L${libdir} -L@Boost_LIBRARY_DIRS@ -lviamsdk -lviam_rust_utils Libs.private: -lboost_log-mt Cflags: -I${includedir} -I@Boost_INCLUDE_DIR@ diff --git a/src/viam/sdk/module/service.cpp b/src/viam/sdk/module/service.cpp index 843d16664..b1bad21ac 100644 --- a/src/viam/sdk/module/service.cpp +++ b/src/viam/sdk/module/service.cpp @@ -216,7 +216,7 @@ ModuleService::ModuleService(int argc, char** argv, const std::vector>& registrations) { if (argc < 2) { - throw Exception("Need socket path as command line argument"); + throw Exception(ErrorCondition::k_connection, "Need socket path as command line argument"); } module_ = std::make_unique(argv[1]); server_ = std::make_unique();