Skip to content

Commit 74c7a52

Browse files
committed
init commit
1 parent 04dc333 commit 74c7a52

File tree

5 files changed

+37
-31
lines changed

5 files changed

+37
-31
lines changed

CMakeLists.txt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,32 @@ find_package(Threads REQUIRED)
253253
# `target_link_directories` call down in src/CMakeLists.txt, as it
254254
# will no longer be needed.
255255
set(viam_rust_utils_file ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_SHARED_LIBRARY_PREFIX}viam_rust_utils${CMAKE_STATIC_LIBRARY_SUFFIX})
256+
set(viam_rust_utils_header_file ${CMAKE_CURRENT_BINARY_DIR}/viam_rust_utils.h)
256257

257258
file(GLOB viam_rust_utils_files ${PROJECT_SOURCE_DIR}/${CMAKE_SHARED_LIBRARY_PREFIX}viam_rust_utils*${CMAKE_STATIC_LIBRARY_SUFFIX})
259+
file(GLOB existing_viam_rust_utils_header_file ${PROJECT_SOURCE_DIR}/viam_rust_utils.h)
260+
261+
if (NOT existing_viam_rust_utils_header_file)
262+
file(
263+
DOWNLOAD
264+
https://github.com/viamrobotics/rust-utils/releases/latest/download/viam_rust_utils.h
265+
${viam_rust_utils_header_file}
266+
STATUS lvruh_status
267+
)
268+
list(GET lvruh_status 0 lvruh_status_code)
269+
list(GET lvruh_status 1 lvruh_status_string)
270+
271+
if(NOT lvruh_status_code EQUAL 0)
272+
message(FATAL_ERROR "No local viam_rust_utils.h found and failed to download: ${lvruh_status_string}")
273+
endif()
274+
#configure_file(${CMAKE_CURRENT_BINARY_DIR}/viam_rust_utils.h src/viam/sdk/rpc/private/viam_rust_utils.h COPYONLY)
275+
else()
276+
FILE(COPY_FILE
277+
${existing_viam_rust_utils_header_file}
278+
${viam_rust_utils_header_file}
279+
ONLY_IF_DIFFERENT
280+
)
281+
endif()
258282

259283
if (viam_rust_utils_files)
260284
list(LENGTH viam_rust_utils_files num_viam_rust_utils_files)

src/viam/sdk/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ else()
2828
endif()
2929
message(WARNING "api proto label is ${VIAMCPPSDK_API_PROTO_LABEL}")
3030
configure_file(common/private/version_metadata.hpp.in common/private/version_metadata.hpp @ONLY)
31+
configure_file(${CMAKE_CURRENT_BINARY_DIR}/../../../viam_rust_utils.h rpc/private/viam_rust_utils.h COPYONLY)
3132

3233
# Configure the grpc client forward declarations file
3334
configure_file(common/grpc_fwd.hpp.in common/grpc_fwd.hpp)
@@ -314,7 +315,7 @@ endif()
314315
# TODO several of these dependencies should properly be attached to `viam_rust_utils`,
315316
# not `viamsdk`. However, we currently are unable to do so while maintaining compilation
316317
if (APPLE)
317-
target_link_libraries(viamsdk PUBLIC "-framework Security")
318+
target_link_libraries(viamsdk PUBLIC "-framework CoreFoundation" "-framework Security")
318319
elseif (NOT WIN32)
319320
target_link_libraries(viamsdk PRIVATE dl)
320321
target_link_libraries(viamsdk PRIVATE rt)

src/viam/sdk/rpc/dial.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ namespace viam {
2020
namespace sdk {
2121

2222
struct ViamChannel::impl {
23-
impl(const char* path, void* runtime) : path(path), rust_runtime(runtime) {}
23+
impl(const char* path, void* runtime)
24+
: path(path), rust_runtime(reinterpret_cast<viam_dial_ffi*>(runtime)) {}
2425

2526
impl(const impl&) = delete;
2627

@@ -38,12 +39,13 @@ struct ViamChannel::impl {
3839
}
3940

4041
~impl() {
41-
free_string(path);
42-
free_rust_runtime(rust_runtime);
42+
auto& p = const_cast<char*&>(path);
43+
viam_free_string(p);
44+
viam_free_rust_runtime(rust_runtime);
4345
}
4446

4547
const char* path;
46-
void* rust_runtime;
48+
viam_dial_ffi* rust_runtime;
4749
};
4850

4951
ViamChannel::ViamChannel(std::shared_ptr<grpc::Channel> channel, const char* path, void* runtime)
@@ -158,7 +160,7 @@ ViamChannel ViamChannel::dial_initial(const char* uri,
158160
}
159161

160162
ViamChannel ViamChannel::dial(const char* uri, const boost::optional<DialOptions>& options) {
161-
void* ptr = init_rust_runtime();
163+
viam_dial_ffi* ptr = init_rust_runtime();
162164
const DialOptions opts = options.get_value_or(DialOptions());
163165
const std::chrono::duration<float> float_timeout = opts.timeout();
164166
const char* type = nullptr;

src/viam/sdk/rpc/private/viam_rust_utils.h

Lines changed: 0 additions & 21 deletions
This file was deleted.

src/viam/sdk/rpc/private/viam_rust_utils_stubs.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22

33
#include <cstdlib>
44

5-
void* init_rust_runtime() {
5+
viam_dial_ffi* viam_init_rust_runtime() {
66
abort();
77
}
88

9-
int free_rust_runtime(void*) {
9+
int viam_free_rust_runtime(viam_dial_ffi*) {
1010
abort();
1111
}
1212

13-
void free_string(const char*) {
13+
void viam_free_string(char*) {
1414
abort();
1515
}
1616

17-
char* dial(const char*, const char*, const char*, const char*, bool, float, void*) {
17+
char* viam_dial(const char*, const char*, const char*, const char*, bool, float, viam_dial_ffi*) {
1818
abort();
1919
}

0 commit comments

Comments
 (0)