Skip to content

Commit 814534c

Browse files
authored
Merge branch 'main' into workflow/update-protos
2 parents 5c32ba3 + ade116c commit 814534c

File tree

14 files changed

+322
-101
lines changed

14 files changed

+322
-101
lines changed

.github/workflows/conan.yml

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ jobs:
4040
github.event_name == 'schedule' &&
4141
steps.git_info.outputs.current_commit == steps.last_successful_commit.outputs.commit-hash
4242
43-
# TODO (RSDK-10666) add windows build testing
44-
4543
build_macos:
4644
if: github.repository_owner == 'viamrobotics'
4745
needs: [prepare]
@@ -215,3 +213,34 @@ jobs:
215213
--tool-requires=b2/5.3.1 --build=b2/5.3.1 -s compiler.cppstd=14 -s:a compiler.cppstd=14
216214
217215
conan create . --build=missing -s compiler.cppstd=14 -s:a compiler.cppstd=14
216+
217+
build_windows:
218+
if: github.repository_owner == 'viamrobotics'
219+
needs: [prepare]
220+
runs-on: windows-latest
221+
strategy:
222+
fail-fast: false
223+
matrix:
224+
include:
225+
- target: x86_64-windows
226+
platform: windows_x86_64
227+
steps:
228+
- name: Checkout Code
229+
uses: actions/checkout@v4
230+
with:
231+
ref: ${{ needs.prepare.outputs.sha }}
232+
233+
- name: Install dependencies
234+
run: choco install -y conan git
235+
236+
- name: Create package
237+
shell: powershell
238+
run: |
239+
Import-Module $env:ChocolateyInstall\helpers\chocolateyProfile.psm1
240+
refreshenv
241+
conan profile detect
242+
conan create . --build=missing -o "&:shared=False"
243+
env:
244+
CONAN_USER_HOME: c:/cache
245+
CONAN_USER_HOME_SHORT: c:/cache/conan_shortpaths
246+

.github/workflows/test.yml

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ on:
1212
description: set to true to build without clang-tidy (2x faster)
1313

1414
jobs:
15-
run-tests:
15+
test_ubuntu:
1616
if: github.repository_owner == 'viamrobotics'
1717
runs-on: ubuntu-latest
1818
container: ghcr.io/viamrobotics/cpp-base:bullseye-amd64
@@ -42,3 +42,40 @@ jobs:
4242
- name: test
4343
working-directory: build
4444
run: ../etc/docker/tests/run_test.sh
45+
test_windows:
46+
if: github.repository_owner == 'viamrobotics'
47+
runs-on: windows-latest
48+
strategy:
49+
fail-fast: false
50+
matrix:
51+
include:
52+
- target: x86_64-windows
53+
platform: windows_x86_64
54+
steps:
55+
- name: Checkout Code
56+
uses: actions/checkout@v4
57+
with:
58+
ref: ${{ needs.prepare.outputs.sha }}
59+
60+
- name: Install dependencies
61+
run: choco install -y conan git
62+
63+
- name: Build SDK
64+
shell: powershell
65+
run: |
66+
Import-Module $env:ChocolateyInstall\helpers\chocolateyProfile.psm1
67+
refreshenv
68+
conan profile detect
69+
conan install . --build=missing -o "&:shared=False"
70+
cmake . --preset conan-default -DVIAMCPPSDK_BUILD_EXAMPLES=ON
71+
cmake --build --preset=conan-release --target ALL_BUILD install -j 8
72+
env:
73+
CONAN_USER_HOME: c:/cache
74+
CONAN_USER_HOME_SHORT: c:/cache/conan_shortpaths
75+
76+
- name: Test examples
77+
shell: powershell
78+
run: |
79+
Start-Job -Init ([ScriptBlock]::Create("Set-Location '$pwd/build/install/bin'")) -ScriptBlock { .\simple_module.exe asdf 2>&1 > output.txt} | Wait-Job -Timeout 2 | Receive-Job
80+
if (-not $(Select-String -Pattern "Module listening" -Path ./build/install/bin/output.txt)) { throw "Module did not start listening" }
81+

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ else()
4141
cmake_minimum_required(VERSION 3.25 FATAL_ERROR)
4242
endif()
4343

44-
set(CMAKE_PROJECT_VERSION 0.13.2)
44+
set(CMAKE_PROJECT_VERSION 0.14.0)
4545

4646
# Identify the project.
4747
project(viam-cpp-sdk

src/viam/api/CMakeLists.txt

Lines changed: 2 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -55,46 +55,9 @@ list(JOIN BUF_PROTO_COMPONENTS , BUF_PROTO_COMPONENTS_JOINED)
5555

5656
if (VIAMCPPSDK_USE_DYNAMIC_PROTOS)
5757

58-
# Look for the `buf` command in the usual places, and use it if
59-
# found. If we can't find it, try to download it and use that.
60-
#
61-
# TODO: File an upstream issue with `buf.build` to add
62-
# `find_package` support for it, then use it.
63-
#
64-
find_program(BUF_COMMAND buf)
65-
if (NOT BUF_COMMAND)
66-
67-
set(HOST_SYSTEM_PROCESSOR_FOR_BUF_DOWNLOAD ${CMAKE_HOST_SYSTEM_PROCESSOR})
68-
if (CMAKE_HOST_WIN32)
69-
if (HOST_SYSTEM_PROCESSOR_FOR_BUF_DOWNLOAD STREQUAL "AMD64")
70-
set(HOST_SYSTEM_PROCESSOR_FOR_BUF_DOWNLOAD x86_64)
71-
elseif (HOST_SYSTEM_PROCESSOR_FOR_BUF_DOWNLOAD STREQUAL "ARM64")
72-
set(HOST_SYSTEM_PROCESSOR_FOR_BUF_DOWNLOAD arm64)
73-
else()
74-
message(FATAL_ERROR "Unknown Windows platform to correct buf download URL: ${HOST_SYSTEM_PROCESSOR_FOR_BUF_DOWNLOAD}")
75-
endif()
76-
endif()
77-
78-
set(BUF_DOWNLOAD_URL https://github.com/bufbuild/buf/releases/latest/download/buf-${CMAKE_HOST_SYSTEM_NAME}-${HOST_SYSTEM_PROCESSOR_FOR_BUF_DOWNLOAD}${CMAKE_HOST_EXECUTABLE_SUFFIX})
79-
80-
file(
81-
DOWNLOAD
82-
${BUF_DOWNLOAD_URL}
83-
${CMAKE_CURRENT_BINARY_DIR}/buf_latest${CMAKE_HOST_EXECUTABLE_SUFFIX}
84-
STATUS buf_status
85-
)
86-
list(GET buf_status 0 buf_status_code)
87-
list(GET buf_status 1 buf_status_string)
88-
89-
if(NOT buf_status_code EQUAL 0)
90-
message(FATAL_ERROR "No local `buf` program found (try setting PATH?) and failed to download: ${buf_status_string} for ${BUF_DOWNLOAD_URL}")
91-
endif()
92-
93-
set(BUF_COMMAND ${CMAKE_CURRENT_BINARY_DIR}/buf_latest${CMAKE_HOST_EXECUTABLE_SUFFIX})
94-
file(CHMOD ${BUF_COMMAND} PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE)
95-
endif()
58+
viamcppsdk_get_buf()
9659

97-
# TODO: IDeally we could just generate to `CMAKE_CURRENT_BINARY_DIR`
60+
# TODO: Ideally we could just generate to `CMAKE_CURRENT_BINARY_DIR`
9861
# and everything would work just fine. However, that directory also
9962
# has intermediate cmake state in it, so we can't use it as a source
10063
# for a directory copy to update the static protos, as we do

src/viam/cmake/viamcppsdk_utils.cmake

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,50 @@ function(viamcppsdk_link_viam_api TARGET_LIBRARY)
2525
target_link_libraries(${TARGET_LIBRARY} ${ARGV1} "$<LINK_LIBRARY:WHOLE_ARCHIVE,viam-cpp-sdk::viamapi>")
2626
endif()
2727
endfunction()
28+
29+
# Look for the `buf` command in the usual places, and use it if
30+
# found. If we can't find it, try to download it and use that.
31+
#
32+
# TODO: File an upstream issue with `buf.build` to add
33+
# `find_package` support for it, then use it.
34+
#
35+
function(viamcppsdk_get_buf)
36+
if (BUF_COMMAND)
37+
return()
38+
endif()
39+
40+
find_program(BUF_COMMAND buf)
41+
if (BUF_COMMAND)
42+
return()
43+
endif()
44+
45+
set(HOST_SYSTEM_PROCESSOR_FOR_BUF_DOWNLOAD ${CMAKE_HOST_SYSTEM_PROCESSOR})
46+
if (CMAKE_HOST_WIN32)
47+
if (HOST_SYSTEM_PROCESSOR_FOR_BUF_DOWNLOAD STREQUAL "AMD64")
48+
set(HOST_SYSTEM_PROCESSOR_FOR_BUF_DOWNLOAD x86_64)
49+
elseif (HOST_SYSTEM_PROCESSOR_FOR_BUF_DOWNLOAD STREQUAL "ARM64")
50+
set(HOST_SYSTEM_PROCESSOR_FOR_BUF_DOWNLOAD arm64)
51+
else()
52+
message(FATAL_ERROR "Unknown Windows platform to correct buf download URL: ${HOST_SYSTEM_PROCESSOR_FOR_BUF_DOWNLOAD}")
53+
endif()
54+
endif()
55+
56+
set(BUF_DOWNLOAD_URL https://github.com/bufbuild/buf/releases/latest/download/buf-${CMAKE_HOST_SYSTEM_NAME}-${HOST_SYSTEM_PROCESSOR_FOR_BUF_DOWNLOAD}${CMAKE_HOST_EXECUTABLE_SUFFIX})
57+
58+
file(
59+
DOWNLOAD
60+
${BUF_DOWNLOAD_URL}
61+
${CMAKE_CURRENT_BINARY_DIR}/buf_latest${CMAKE_HOST_EXECUTABLE_SUFFIX}
62+
STATUS buf_status
63+
)
64+
65+
list(GET buf_status 0 buf_status_code)
66+
list(GET buf_status 1 buf_status_string)
67+
68+
if(NOT buf_status_code EQUAL 0)
69+
message(FATAL_ERROR "No local `buf` program found (try setting PATH?) and failed to download: ${buf_status_string} for ${BUF_DOWNLOAD_URL}")
70+
endif()
71+
72+
set(BUF_COMMAND ${CMAKE_CURRENT_BINARY_DIR}/buf_latest${CMAKE_HOST_EXECUTABLE_SUFFIX} CACHE INTERNAL "buf command")
73+
file(CHMOD ${BUF_COMMAND} PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE)
74+
endfunction()

src/viam/examples/modules/complex/CMakeLists.txt

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -36,26 +36,9 @@ set(MODULE_PROTO_OUTPUT_FILES
3636
${MODULE_PROTO_GEN_DIR}/summation.pb.h
3737
)
3838

39-
# Look for the `buf` command in the usual places, and use it if found. If we
40-
# can't find it, try to download it and use that.
41-
find_program(BUF_COMMAND buf)
42-
if (NOT BUF_COMMAND)
43-
file(
44-
DOWNLOAD
45-
https://github.com/bufbuild/buf/releases/latest/download/buf-${CMAKE_HOST_SYSTEM_NAME}-${CMAKE_HOST_SYSTEM_PROCESSOR}
46-
${CMAKE_CURRENT_BINARY_DIR}/buf_latest
47-
STATUS buf_status
48-
)
49-
list(GET buf_status 0 buf_status_code)
50-
list(GET buf_status 1 buf_status_string)
51-
52-
if(NOT buf_status_code EQUAL 0)
53-
message(FATAL_ERROR "No local `buf` program found (try setting PATH?) and failed to download: ${buf_status_string}")
54-
endif()
55-
56-
set(BUF_COMMAND ${CMAKE_CURRENT_BINARY_DIR}/buf_latest)
57-
file(CHMOD ${BUF_COMMAND} PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE)
58-
endif()
39+
# Try to find buf in the path or get it online.
40+
# See the definition of this function for logic that can be adapted to other project files.
41+
viamcppsdk_get_buf()
5942

6043
if ((NOT VIAMCPPSDK_OFFLINE_PROTO_GENERATION) AND VIAMCPPSDK_BUF_REMOTE_PLUGIN_SUPPORTED)
6144
configure_file(

src/viam/sdk/log/logging.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,11 @@ void LogManager::set_global_log_level(log_level lvl) {
105105
}
106106

107107
void LogManager::set_global_log_level(int argc, char** argv) {
108-
if (argc >= 3 && strcmp(argv[2], "--log-level=debug") == 0) {
109-
set_global_log_level(log_level::debug);
108+
for (int i = 0; i < argc; ++i) {
109+
if (strcmp(argv[i], "--log-level=debug") == 0) {
110+
set_global_log_level(log_level::debug);
111+
return;
112+
}
110113
}
111114
}
112115

@@ -147,8 +150,8 @@ void LogManager::enable_console_logging() {
147150
void LogManager::disable_console_logging() {
148151
VIAM_SDK_LOG(debug) << "Disabling console logging";
149152

150-
// Set a filter which ignores all console logs unless they contain a console force flag which is
151-
// set to true.
153+
// Set a filter which ignores all console logs unless they contain a console force flag
154+
// which is set to true.
152155
console_sink_->set_filter(
153156
[filter = Filter{this}](const boost::log::attribute_value_set& attrs) {
154157
auto force = attrs[impl::attr_console_force_type{}];

src/viam/sdk/module/service.cpp

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,17 @@
4848
namespace viam {
4949
namespace sdk {
5050

51+
namespace {
52+
std::string get_protocol(int argc, char** argv) {
53+
for (int i = 0; i < argc; ++i) {
54+
if (strcmp(argv[i], "--tcp-mode") == 0) {
55+
return "dns:";
56+
}
57+
}
58+
return "unix:";
59+
}
60+
} // namespace
61+
5162
struct ModuleService::ServiceImpl : viam::module::v1::ModuleService::Service {
5263
ServiceImpl(ModuleService& p) : parent(p) {}
5364

@@ -191,7 +202,7 @@ struct ModuleService::ServiceImpl : viam::module::v1::ModuleService::Service {
191202
const std::lock_guard<std::mutex> lock(parent.lock_);
192203
const viam::module::v1::HandlerMap hm = to_proto(parent.module_->handles());
193204
*response->mutable_handlermap() = hm;
194-
auto new_parent_addr = request->parent_address();
205+
auto new_parent_addr = parent.grpc_conn_protocol_ + request->parent_address();
195206
if (parent.parent_addr_ != new_parent_addr) {
196207
parent.parent_addr_ = std::move(new_parent_addr);
197208
Options opts{0, boost::none};
@@ -233,21 +244,27 @@ std::shared_ptr<Resource> ModuleService::get_parent_resource_(const Name& name)
233244
return parent_->resource_by_name(name);
234245
}
235246

236-
ModuleService::ModuleService(std::string addr)
237-
: module_(std::make_unique<Module>(std::move(addr))), server_(std::make_unique<Server>()) {
247+
ModuleService::ModuleService(std::string addr) : ModuleService(std::move(addr), "unix:") {}
248+
249+
ModuleService::ModuleService(std::string addr, std::string grpc_conn_protocol)
250+
: module_(std::make_unique<Module>(std::move(addr))),
251+
grpc_conn_protocol_(std::move(grpc_conn_protocol)),
252+
server_(std::make_unique<Server>()) {
238253
impl_ = std::make_unique<ServiceImpl>(*this);
239254
}
240255

241256
ModuleService::ModuleService(int argc,
242257
char** argv,
243258
const std::vector<std::shared_ptr<ModelRegistration>>& registrations)
244-
: ModuleService([argc, argv] {
245-
if (argc < 2) {
246-
throw Exception(ErrorCondition::k_connection,
247-
"Need socket path as command line argument");
248-
}
249-
return argv[1];
250-
}()) {
259+
: ModuleService(
260+
[argc, argv] {
261+
if (argc < 2) {
262+
throw Exception(ErrorCondition::k_connection,
263+
"Need socket path as command line argument");
264+
}
265+
return (argv[1]);
266+
}(),
267+
get_protocol(argc, argv)) {
251268
LogManager::get().set_global_log_level(argc, argv);
252269

253270
for (auto&& mr : registrations) {
@@ -272,8 +289,7 @@ ModuleService::~ModuleService() {
272289

273290
void ModuleService::serve() {
274291
server_->register_service(impl_.get());
275-
const std::string address = "unix:" + module_->addr();
276-
server_->add_listening_port(address);
292+
server_->add_listening_port(grpc_conn_protocol_ + module_->addr());
277293

278294
module_->set_ready();
279295
server_->start();

src/viam/sdk/module/service.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ class ModuleService {
3333
/// @param addr Address of socket to serve on.
3434
explicit ModuleService(std::string addr);
3535

36+
/// @brief Creates a new ModuleService that can serve on the provided socket.
37+
/// @param addr Address of socket to serve on.
38+
/// @param grpc_conn_protocol The protocol to connect with (UDS or TCP)
39+
explicit ModuleService(std::string addr, std::string grpc_conn_protocol);
40+
3641
/// @brief Creates a new ModuleService. Socket path and log level will be
3742
/// inferred from passed in command line arguments, and passed in model
3843
/// registrations will be registered and added to module.
@@ -70,6 +75,7 @@ class ModuleService {
7075

7176
std::shared_ptr<RobotClient> parent_;
7277
std::string parent_addr_;
78+
std::string grpc_conn_protocol_;
7379

7480
std::unique_ptr<Server> server_;
7581

src/viam/sdk/robot/client.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,9 +363,9 @@ std::shared_ptr<RobotClient> RobotClient::at_address(const std::string& address,
363363

364364
std::shared_ptr<RobotClient> RobotClient::at_local_socket(const std::string& address,
365365
const Options& options) {
366-
const std::string addr = "unix:" + address;
366+
// TODO (RSDK-10720) - refactor/replace `at_local_socket`
367367
auto robot = RobotClient::with_channel(
368-
ViamChannel(sdk::impl::create_viam_channel(addr, grpc::InsecureChannelCredentials())),
368+
ViamChannel(sdk::impl::create_viam_channel(address, grpc::InsecureChannelCredentials())),
369369
options);
370370

371371
return robot;

0 commit comments

Comments
 (0)