diff --git a/CMakeLists.txt b/CMakeLists.txt index 133f2f255..6b3bc3729 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -173,6 +173,10 @@ if (NOT CMAKE_CXX_STANDARD) set(CMAKE_CXX_STANDARD 14) endif() set(CMAKE_CXX_STANDARD_REQUIRED True) +if(MSVC) + # https://discourse.cmake.org/t/set-cmake-cxx-standard-should-set-zc-cplusplus-for-msvc/1876 + string(APPEND CMAKE_CXX_FLAGS " /Zc:__cplusplus") +endif() set(CMAKE_CXX_EXTENSIONS OFF) @@ -255,7 +259,7 @@ if (viam_rust_utils_files) ${viam_rust_utils_file} ONLY_IF_DIFFERENT ) -else() +elseif(NOT WIN32) # TODO(RSDK-10366): Currently, rust_utils is not published for windows, so don't even try downloading set(lvru_system_name ${CMAKE_SYSTEM_NAME}) if (CMAKE_SYSTEM_NAME STREQUAL "Darwin") set(lvru_system_name "macosx") @@ -275,21 +279,23 @@ else() endif() -add_library(viam_rust_utils SHARED IMPORTED) +# TODO(RSDK-10366): Currently, rust_utils is not published for windows, so don't even declare the library +if (NOT WIN32) + add_library(viam_rust_utils SHARED IMPORTED) -target_link_directories(viam_rust_utils - INTERFACE + target_link_directories(viam_rust_utils + INTERFACE "$" "$" -) - -set_property(TARGET viam_rust_utils PROPERTY IMPORTED_LOCATION ${viam_rust_utils_file}) + ) -install( - IMPORTED_RUNTIME_ARTIFACTS viam_rust_utils - LIBRARY COMPONENT viam-cpp-sdk_runtime -) + set_property(TARGET viam_rust_utils PROPERTY IMPORTED_LOCATION ${viam_rust_utils_file}) + install( + IMPORTED_RUNTIME_ARTIFACTS viam_rust_utils + LIBRARY COMPONENT viam-cpp-sdk_runtime + ) +endif() # Install the license file install(FILES diff --git a/conanfile.py b/conanfile.py index b1c98ecea..f3e2fa923 100644 --- a/conanfile.py +++ b/conanfile.py @@ -82,7 +82,11 @@ def package(self): CMake(self).install() def package_info(self): - self.cpp_info.components["viam_rust_utils"].libs = ["viam_rust_utils"] + + # TODO(RSDK-10366): Currently, rust_utils is not published for windows + # and the C++ SDK just doesn't include it as a dependency on that platform + if not self.settings.os == "Windows": + self.cpp_info.components["viam_rust_utils"].libs = ["viam_rust_utils"] self.cpp_info.components["viamsdk"].libs = ["viamsdk"] @@ -103,10 +107,16 @@ def package_info(self): else: lib_folder = os.path.join(self.package_folder, "lib") lib_fullpath = os.path.join(lib_folder, "libviamapi.a") + if self.settings.os == "Windows": + lib_fullpath = os.path.join(lib_folder, "viamapi.lib") + if is_apple_os(self): whole_archive = f"-Wl,-force_load,{lib_fullpath}" + elif self.settings.os == "Windows": + whole_archive = f"/WHOLEARCHIVE:{lib_fullpath}" else: whole_archive = f"-Wl,--push-state,--whole-archive,{lib_fullpath},--pop-state" + self.cpp_info.components["viamapi"].exelinkflags.append(whole_archive) self.cpp_info.components["viamapi"].sharedlinkflags.append(whole_archive) @@ -118,7 +128,13 @@ def package_info(self): "xtensor::xtensor", "viamapi", - "viam_rust_utils" ]) + # TODO(RSDK-10366): Currently, rust_utils is not published for windows + # and the C++ SDK just doesn't include it as a dependency on that platform + if self.settings.os != "Windows": + self.cpp_info.components["viamsdk"].requires.extend([ + "viam_rust_utils" + ]) + self.cpp_info.components["viamsdk"].frameworks = ["Security"] diff --git a/src/viam/sdk/CMakeLists.txt b/src/viam/sdk/CMakeLists.txt index 94454f2ca..84616c39a 100644 --- a/src/viam/sdk/CMakeLists.txt +++ b/src/viam/sdk/CMakeLists.txt @@ -267,10 +267,19 @@ target_link_libraries(viamsdk PRIVATE ${VIAMCPPSDK_GRPCXX_LIBRARIES} PRIVATE ${VIAMCPPSDK_GRPC_LIBRARIES} PRIVATE ${VIAMCPPSDK_PROTOBUF_LIBRARIES} - PRIVATE viam_rust_utils PRIVATE Threads::Threads ) +# TODO(RSDK-10366): Currently, rust_utils is not published for +# windows, so don't link to it. Instead, link a stub implementation +# that just calls `abort`. +if (NOT WIN32) + target_link_libraries(viamsdk + PRIVATE viam_rust_utils + ) +else() + target_sources(viamsdk PRIVATE rpc/private/viam_rust_utils_stubs.cpp) +endif() if (APPLE) target_link_libraries(viamsdk PUBLIC "-framework Security") diff --git a/src/viam/sdk/common/private/service_helper.hpp b/src/viam/sdk/common/private/service_helper.hpp index 3212fe00f..0c8326b40 100644 --- a/src/viam/sdk/common/private/service_helper.hpp +++ b/src/viam/sdk/common/private/service_helper.hpp @@ -55,8 +55,13 @@ class ServiceHelper : public ServiceHelperBase { } private: +#if __cplusplus >= 201703L + template + using is_void_result = std::is_void>; +#else template using is_void_result = std::is_void>; +#endif // Implementation of `invoke_` for a Callable returning non-void, // presumably an error return, which we return as a diff --git a/src/viam/sdk/module/service.cpp b/src/viam/sdk/module/service.cpp index 7445e5057..bb1178b65 100644 --- a/src/viam/sdk/module/service.cpp +++ b/src/viam/sdk/module/service.cpp @@ -1,3 +1,13 @@ +#ifdef _WIN32 +#define NOMINMAX +// clang-format off +// Otherwise clang-format tries to alphabetize these headers, +// but `winsock2.h` should definitely precede `windows.h`. +#include +#include +// clang-format on +#endif + #include #include diff --git a/src/viam/sdk/rpc/dial.cpp b/src/viam/sdk/rpc/dial.cpp index d360acca2..35a990363 100644 --- a/src/viam/sdk/rpc/dial.cpp +++ b/src/viam/sdk/rpc/dial.cpp @@ -13,17 +13,8 @@ #include #include #include +#include -extern "C" void* init_rust_runtime(); -extern "C" int free_rust_runtime(void* ptr); -extern "C" void free_string(const char* s); -extern "C" char* dial(const char* uri, - const char* entity, - const char* type, - const char* payload, - bool allow_insecure, - float timeout, - void* ptr); namespace viam { namespace sdk { diff --git a/src/viam/sdk/rpc/private/viam_rust_utils.h b/src/viam/sdk/rpc/private/viam_rust_utils.h new file mode 100644 index 000000000..7542a51f4 --- /dev/null +++ b/src/viam/sdk/rpc/private/viam_rust_utils.h @@ -0,0 +1,21 @@ +#if defined(__cplusplus) +extern "C" { +#endif + +// Prototypes for the entrypoints from viam_rust_utils +// that we use in the SDK. + +void* init_rust_runtime(); +int free_rust_runtime(void* ptr); +void free_string(const char* s); +char* dial(const char* uri, + const char* entity, + const char* type, + const char* payload, + bool allow_insecure, + float timeout, + void* ptr); + +#if defined(__cplusplus) +} // extern "C" +#endif diff --git a/src/viam/sdk/rpc/private/viam_rust_utils_stubs.cpp b/src/viam/sdk/rpc/private/viam_rust_utils_stubs.cpp new file mode 100644 index 000000000..caa78aef2 --- /dev/null +++ b/src/viam/sdk/rpc/private/viam_rust_utils_stubs.cpp @@ -0,0 +1,19 @@ +#include + +#include + +void* init_rust_runtime() { + abort(); +} + +int free_rust_runtime(void*) { + abort(); +} + +void free_string(const char*) { + abort(); +} + +char* dial(const char*, const char*, const char*, const char*, bool, float, void*) { + abort(); +}