Skip to content

Commit

Permalink
RSDK-7440: Build example projects in CI (#276)
Browse files Browse the repository at this point in the history
  • Loading branch information
lia-viam authored Aug 12, 2024
1 parent 5c72e22 commit fef2b46
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 10 deletions.
17 changes: 17 additions & 0 deletions etc/docker/tests/run_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion src/viam/api/config/viam-cpp-sdk-libviamapi.pc.in
Original file line number Diff line number Diff line change
Expand Up @@ -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}

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: 2bbd25900cb34c79bae97d85c948d3cf
digest: shake256:a6446e23f4408160217c22738a0c8c370ff3ff966f601d678960b803829cf53b5cf5998d20fcb3f9c9be944b24337843e7beb6e681ddbf9d036fb6491c0e47e7
commit: 8bc2c51e08c447cd8886cdea48a73e14
digest: shake256:a969155953a5cedc5b2df5b42c368f2bc66ff8ce1804bc96e0f14ff2ee8a893687963058909df844d1643cdbc98ff099d2daa6bc9f9f5b8886c49afdc60e19af
8 changes: 6 additions & 2 deletions src/viam/examples/modules/simple/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <viam/api/robot/v1/robot.pb.h>
#include <viam/api/service/generic/v1/generic.grpc.pb.h>

#include <viam/sdk/common/exception.hpp>
#include <viam/sdk/config/resource.hpp>
#include <viam/sdk/module/module.hpp>
#include <viam/sdk/module/service.hpp>
Expand Down Expand Up @@ -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<GenericService>();
Model m("viam", "generic", "printer");

Expand All @@ -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;
}
7 changes: 4 additions & 3 deletions src/viam/examples/project/pkg-config/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,22 @@ 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

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
2 changes: 1 addition & 1 deletion src/viam/sdk/config/viam-cpp-sdk-libviamsdk.pc.in
Original file line number Diff line number Diff line change
Expand Up @@ -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@
2 changes: 1 addition & 1 deletion src/viam/sdk/module/service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ ModuleService::ModuleService(int argc,
char** argv,
const std::vector<std::shared_ptr<ModelRegistration>>& 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<Module>(argv[1]);
server_ = std::make_unique<Server>();
Expand Down

0 comments on commit fef2b46

Please sign in to comment.