Skip to content

Commit 62d40eb

Browse files
authored
[RSDK-10385] Basic windows and macos build compatibility improvements (#401)
1 parent 1fd2b1d commit 62d40eb

File tree

13 files changed

+42
-23
lines changed

13 files changed

+42
-23
lines changed

CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,10 @@ if (VIAMCPPSDK_ENFORCE_COMPILER_MINIMA)
150150
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 10.0)
151151
message(FATAL_ERROR "Insufficient Apple clang version: XCode 10.0+ required")
152152
endif()
153+
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
154+
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19.34)
155+
message(FATAL_ERROR "Insufficient MSVC version: Visual Studio 2022 17.4 (MSVC 19.34) or later is required")
156+
endif()
153157
else()
154158
message(FATAL_ERROR "Unknown / untested compiler ${CMAKE_CXX_COMPILER_ID}")
155159
endif()

src/viam/examples/camera/example_camera.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#include <fstream>
22
#include <string>
3-
#include <unistd.h>
43
#include <vector>
54

65
#include <viam/sdk/common/instance.hpp>

src/viam/examples/dial/example_dial.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#include <memory>
55
#include <ostream>
66
#include <string>
7-
#include <unistd.h>
87
#include <vector>
98

109
#include <boost/optional.hpp>

src/viam/examples/dial_api_key/example_dial_api_key.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#include <memory>
55
#include <ostream>
66
#include <string>
7-
#include <unistd.h>
87
#include <vector>
98

109
#include <boost/optional.hpp>

src/viam/examples/modules/complex/client.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#include <memory>
44
#include <ostream>
55
#include <string>
6-
#include <unistd.h>
76
#include <vector>
87

98
#include <grpcpp/channel.h>

src/viam/examples/motor/example_motor.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#include <unistd.h>
2-
31
#include <chrono>
42
#include <fstream>
53
#include <iostream>

src/viam/sdk/CMakeLists.txt

+11-1
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,18 @@ configure_file(common/grpc_fwd.hpp.in common/grpc_fwd.hpp)
3434

3535
# Set compile and link options based on arguments
3636
if (VIAMCPPSDK_USE_WALL_WERROR)
37-
target_compile_options(viamsdk PRIVATE -Wall -Werror)
37+
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
38+
target_compile_options(viamsdk PRIVATE -Wall -Werror)
39+
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
40+
target_compile_options(viamsdk PRIVATE -Wall -Werror)
41+
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
42+
# Note: Currently, the generated protos throw W4244 and W4267, so turn that back to a warning.
43+
target_compile_options(viamsdk PRIVATE /W4 /WX /wd4244 /wd4267)
44+
else()
45+
message(ERROR "VIAMCPPSDK_USE_WALL_ERROR is set, but not known how to enable for compiler ID ${CMAKE_CXX_COMPILER_ID}")
46+
endif()
3847
endif()
48+
3949
if (VIAMCPPSDK_SANITIZED_BUILD)
4050
target_link_options(viamsdk PRIVATE -fsanitize=undefined -fno-omit-frame-pointer -fno-sanitize-recover)
4151
target_compile_options(viamsdk PRIVATE -fsanitize=undefined -fno-omit-frame-pointer -fno-sanitize-recover)

src/viam/sdk/components/camera.hpp

+5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@
99
#include <vector>
1010

1111
#include <boost/endian/conversion.hpp>
12+
13+
#if defined(__has_include) && (__has_include(<xtensor/containers/xarray.hpp>))
14+
#include <xtensor/containers/xarray.hpp>
15+
#else
1216
#include <xtensor/xarray.hpp>
17+
#endif
1318

1419
#include <viam/sdk/common/proto_value.hpp>
1520
#include <viam/sdk/common/utils.hpp>

src/viam/sdk/module/service.cpp

+3-10
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
#include <memory>
55
#include <sstream>
66
#include <string>
7-
#include <sys/socket.h>
8-
#include <sys/stat.h>
97

108
#include <boost/log/trivial.hpp>
119
#include <boost/none.hpp>
@@ -115,8 +113,8 @@ struct ModuleService::ServiceImpl : viam::module::v1::ModuleService::Service {
115113
Registry::get().lookup_model(cfg.name());
116114
if (reg) {
117115
try {
118-
const std::shared_ptr<Resource> res = reg->construct_resource(deps, cfg);
119-
manager->replace_one(cfg.resource_name(), res);
116+
const std::shared_ptr<Resource> resource = reg->construct_resource(deps, cfg);
117+
manager->replace_one(cfg.resource_name(), resource);
120118
} catch (const std::exception& exc) {
121119
return grpc::Status(::grpc::INTERNAL, exc.what());
122120
}
@@ -252,13 +250,8 @@ ModuleService::~ModuleService() {
252250
}
253251

254252
void ModuleService::serve() {
255-
const mode_t old_mask = umask(0077);
256-
const int sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
257-
listen(sockfd, 10);
258-
umask(old_mask);
259-
260253
server_->register_service(impl_.get());
261-
const std::string address = "unix://" + module_->addr();
254+
const std::string address = "unix:" + module_->addr();
262255
server_->add_listening_port(address);
263256

264257
module_->set_ready();

src/viam/sdk/robot/client.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#include <mutex>
77
#include <string>
88
#include <thread>
9-
#include <unistd.h>
109
#include <vector>
1110

1211
#include <boost/log/trivial.hpp>
@@ -216,7 +215,7 @@ void RobotClient::refresh_every() {
216215
std::this_thread::sleep_for(std::chrono::seconds(refresh_interval_));
217216
refresh();
218217

219-
} catch (std::exception& exc) {
218+
} catch (std::exception&) {
220219
break;
221220
}
222221
}

src/viam/sdk/services/mlmodel.hpp

+5
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,12 @@
1818
#include <boost/mpl/list.hpp>
1919
#include <boost/mpl/transform_view.hpp>
2020
#include <boost/variant/variant.hpp>
21+
22+
#if defined(__has_include) && (__has_include(<xtensor/containers/xadapt.hpp>))
23+
#include <xtensor/containers/xadapt.hpp>
24+
#else
2125
#include <xtensor/xadapt.hpp>
26+
#endif
2227

2328
#include <viam/sdk/common/utils.hpp>
2429
#include <viam/sdk/services/service.hpp>

src/viam/sdk/services/private/mlmodel.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,11 @@ MLModelService::tensor_views make_sdk_tensor_from_api_tensor_t(const T* data,
150150
shape_accum = next_shape_accum;
151151
}
152152

153+
#ifdef _MSC_VER
154+
#pragma warning(push)
155+
#pragma warning(disable : 4127)
156+
#endif
157+
153158
// We need to handle the special case of an odd number of 16-bit
154159
// elements because that will arrive appearing to have one more
155160
// element than the shape would indicate, and we don't want to
@@ -160,6 +165,10 @@ MLModelService::tensor_views make_sdk_tensor_from_api_tensor_t(const T* data,
160165
size -= 1;
161166
}
162167

168+
#ifdef _MSC_VER
169+
#pragma warning(pop)
170+
#endif
171+
163172
if (size != shape_accum) {
164173
std::ostringstream message;
165174
// TODO: Provide the shape and details

src/viam/sdk/services/private/navigation_client.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ void NavigationClient::set_mode(const Navigation::Mode mode, const ProtoStruct&
5555
request.set_mode(viam::service::navigation::v1::Mode(mode));
5656
*request.mutable_extra() = to_proto(extra);
5757
})
58-
.invoke([](auto& response) {});
58+
.invoke([](auto&) {});
5959
}
6060

6161
Navigation::LocationResponse NavigationClient::get_location(const ProtoStruct& extra) {
@@ -81,7 +81,7 @@ void NavigationClient::add_waypoint(const geo_point& location, const ProtoStruct
8181
*request.mutable_location() = to_proto(location);
8282
*request.mutable_extra() = to_proto(extra);
8383
})
84-
.invoke([](auto& response) {});
84+
.invoke([](auto&) {});
8585
}
8686

8787
void NavigationClient::remove_waypoint(const std::string id, const ProtoStruct& extra) {
@@ -90,7 +90,7 @@ void NavigationClient::remove_waypoint(const std::string id, const ProtoStruct&
9090
*request.mutable_id() = id;
9191
*request.mutable_extra() = to_proto(extra);
9292
})
93-
.invoke([](auto& response) {});
93+
.invoke([](auto&) {});
9494
}
9595

9696
std::vector<geo_geometry> NavigationClient::get_obstacles(const ProtoStruct& extra) {
@@ -107,7 +107,7 @@ std::vector<NavigationClient::Path> NavigationClient::get_paths(const ProtoStruc
107107

108108
NavigationClient::Properties NavigationClient::get_properties() {
109109
return make_client_helper(this, *stub_, &StubType::GetProperties)
110-
.with([&](auto& request) {})
110+
.with([&](auto&) {})
111111
.invoke([](auto& response) { return Properties{MapType(response.map_type())}; });
112112
}
113113

0 commit comments

Comments
 (0)