Skip to content

Commit f71506c

Browse files
committed
[RSDK-10385] Windows build system improvements and rust_utils workarounds
1 parent 62d40eb commit f71506c

File tree

8 files changed

+99
-24
lines changed

8 files changed

+99
-24
lines changed

CMakeLists.txt

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,10 @@ if (NOT CMAKE_CXX_STANDARD)
173173
set(CMAKE_CXX_STANDARD 14)
174174
endif()
175175
set(CMAKE_CXX_STANDARD_REQUIRED True)
176+
if(MSVC)
177+
# https://discourse.cmake.org/t/set-cmake-cxx-standard-should-set-zc-cplusplus-for-msvc/1876
178+
string(APPEND CMAKE_CXX_FLAGS " /Zc:__cplusplus")
179+
endif()
176180
set(CMAKE_CXX_EXTENSIONS OFF)
177181

178182

@@ -255,7 +259,7 @@ if (viam_rust_utils_files)
255259
${viam_rust_utils_file}
256260
ONLY_IF_DIFFERENT
257261
)
258-
else()
262+
elseif(NOT WIN32) # TODO(RSDK-10366): Currently, rust_utils is not published for windows, so don't even try downloading
259263
set(lvru_system_name ${CMAKE_SYSTEM_NAME})
260264
if (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
261265
set(lvru_system_name "macosx")
@@ -275,21 +279,23 @@ else()
275279

276280
endif()
277281

278-
add_library(viam_rust_utils SHARED IMPORTED)
282+
# TODO(RSDK-10366): Currently, rust_utils is not published for windows, so don't even declare the library
283+
if (NOT WIN32)
284+
add_library(viam_rust_utils SHARED IMPORTED)
279285

280-
target_link_directories(viam_rust_utils
281-
INTERFACE
286+
target_link_directories(viam_rust_utils
287+
INTERFACE
282288
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>"
283289
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_LIBDIR}>"
284-
)
285-
286-
set_property(TARGET viam_rust_utils PROPERTY IMPORTED_LOCATION ${viam_rust_utils_file})
290+
)
287291

288-
install(
289-
IMPORTED_RUNTIME_ARTIFACTS viam_rust_utils
290-
LIBRARY COMPONENT viam-cpp-sdk_runtime
291-
)
292+
set_property(TARGET viam_rust_utils PROPERTY IMPORTED_LOCATION ${viam_rust_utils_file})
292293

294+
install(
295+
IMPORTED_RUNTIME_ARTIFACTS viam_rust_utils
296+
LIBRARY COMPONENT viam-cpp-sdk_runtime
297+
)
298+
endif()
293299

294300
# Install the license file
295301
install(FILES

conanfile.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,11 @@ def package(self):
8282
CMake(self).install()
8383

8484
def package_info(self):
85-
self.cpp_info.components["viam_rust_utils"].libs = ["viam_rust_utils"]
85+
86+
# TODO(RSDK-10366): Currently, rust_utils is not published for windows
87+
# and the C++ SDK just doesn't include it as a dependency on that platform
88+
if not self.settings.os == "Windows":
89+
self.cpp_info.components["viam_rust_utils"].libs = ["viam_rust_utils"]
8690

8791
self.cpp_info.components["viamsdk"].libs = ["viamsdk"]
8892

@@ -103,10 +107,16 @@ def package_info(self):
103107
else:
104108
lib_folder = os.path.join(self.package_folder, "lib")
105109
lib_fullpath = os.path.join(lib_folder, "libviamapi.a")
110+
if self.settings.os == "Windows":
111+
lib_fullpath = os.path.join(lib_folder, "viamapi.lib")
112+
106113
if is_apple_os(self):
107114
whole_archive = f"-Wl,-force_load,{lib_fullpath}"
115+
elif self.settings.os == "Windows":
116+
whole_archive = f"/WHOLEARCHIVE:{lib_fullpath}"
108117
else:
109118
whole_archive = f"-Wl,--push-state,--whole-archive,{lib_fullpath},--pop-state"
119+
110120
self.cpp_info.components["viamapi"].exelinkflags.append(whole_archive)
111121
self.cpp_info.components["viamapi"].sharedlinkflags.append(whole_archive)
112122

@@ -118,7 +128,13 @@ def package_info(self):
118128
"xtensor::xtensor",
119129

120130
"viamapi",
121-
"viam_rust_utils"
122131
])
123132

133+
# TODO(RSDK-10366): Currently, rust_utils is not published for windows
134+
# and the C++ SDK just doesn't include it as a dependency on that platform
135+
if self.settings.os != "Windows":
136+
self.cpp_info.components["viamsdk"].requires.extend([
137+
"viam_rust_utils"
138+
])
139+
124140
self.cpp_info.components["viamsdk"].frameworks = ["Security"]

src/viam/sdk/CMakeLists.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ target_sources(viamsdk
132132
rpc/dial.cpp
133133
rpc/server.cpp
134134
rpc/private/viam_grpc_channel.cpp
135+
rpc/private/viam_rust_utils_stubs.cpp
135136
services/discovery.cpp
136137
services/generic.cpp
137138
services/mlmodel.cpp
@@ -263,10 +264,15 @@ target_link_libraries(viamsdk
263264
PRIVATE ${VIAMCPPSDK_GRPCXX_LIBRARIES}
264265
PRIVATE ${VIAMCPPSDK_GRPC_LIBRARIES}
265266
PRIVATE ${VIAMCPPSDK_PROTOBUF_LIBRARIES}
266-
PRIVATE viam_rust_utils
267267
PRIVATE Threads::Threads
268268
)
269269

270+
# TODO(RSDK-10366): Currently, rust_utils is not published for windows, so don't link to it.
271+
if (NOT WIN32)
272+
target_link_libraries(viamsdk
273+
PRIVATE viam_rust_utils
274+
)
275+
endif()
270276

271277
if (APPLE)
272278
target_link_libraries(viamsdk PUBLIC "-framework Security")

src/viam/sdk/common/private/service_helper.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,14 @@ class ServiceHelper : public ServiceHelperBase {
5555
}
5656

5757
private:
58+
59+
#if __cplusplus >= 201703L
60+
template <typename Callable, typename... Args>
61+
using is_void_result = std::is_void<std::invoke_result_t<Callable, Args...>>;
62+
#else
5863
template <typename Callable, typename... Args>
5964
using is_void_result = std::is_void<std::result_of_t<Callable(Args...)>>;
65+
#endif
6066

6167
// Implementation of `invoke_` for a Callable returning non-void,
6268
// presumably an error return, which we return as a

src/viam/sdk/module/service.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
#ifdef _WIN32
2+
#define NOMINMAX
3+
#include <winsock2.h>
4+
#include <windows.h>
5+
#endif
6+
17
#include <viam/sdk/module/service.hpp>
28

39
#include <exception>

src/viam/sdk/rpc/dial.cpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,8 @@
1313
#include <viam/api/robot/v1/robot.pb.h>
1414
#include <viam/sdk/common/exception.hpp>
1515
#include <viam/sdk/rpc/private/viam_grpc_channel.hpp>
16+
#include <viam/sdk/rpc/private/viam_rust_utils.h>
1617

17-
extern "C" void* init_rust_runtime();
18-
extern "C" int free_rust_runtime(void* ptr);
19-
extern "C" void free_string(const char* s);
20-
extern "C" char* dial(const char* uri,
21-
const char* entity,
22-
const char* type,
23-
const char* payload,
24-
bool allow_insecure,
25-
float timeout,
26-
void* ptr);
2718
namespace viam {
2819
namespace sdk {
2920

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#if defined(__cplusplus)
2+
extern "C" {
3+
#endif
4+
5+
// Prototypes for the entrypoints from viam_rust_utils
6+
// that we use in the SDK.
7+
8+
void* init_rust_runtime();
9+
int free_rust_runtime(void* ptr);
10+
void free_string(const char* s);
11+
char* dial(const char* uri,
12+
const char* entity,
13+
const char* type,
14+
const char* payload,
15+
bool allow_insecure,
16+
float timeout,
17+
void* ptr);
18+
19+
#if defined(__cplusplus)
20+
} // extern "C"
21+
#endif
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include <viam/sdk/rpc/private/viam_rust_utils.h>
2+
3+
#include <cstdlib>
4+
5+
// TODO(RSDK-10366): Currently, rust_utils is not published for windows
6+
// so we just implement the associated entry points as `abort`.
7+
#ifdef _WIN32
8+
void* init_rust_runtime() {
9+
abort();
10+
}
11+
12+
int free_rust_runtime(void*) {
13+
abort();
14+
}
15+
16+
void free_string(const char*) {
17+
abort();
18+
}
19+
20+
char* dial(const char*, const char*, const char*, const char*, bool, float, void*) {
21+
abort();
22+
}
23+
#endif

0 commit comments

Comments
 (0)