Skip to content

basic windows and macos build compatibility improvements #401

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 4, 2025

Conversation

acmorrow
Copy link
Member

@acmorrow acmorrow commented Apr 3, 2025

Small fixes needed for building the C++ SDK on Windows. This is far from complete - this is just the stuff that seems reasonable to land as is. I'll leave some comments to explain a few things.

@acmorrow acmorrow requested a review from a team as a code owner April 3, 2025 21:50
@@ -150,6 +150,10 @@ if (VIAMCPPSDK_ENFORCE_COMPILER_MINIMA)
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 10.0)
message(FATAL_ERROR "Insufficient Apple clang version: XCode 10.0+ required")
endif()
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This establishes a compiler minimum for Windows. Since there is no history here, the newest Visual Studio seems like fair game. We can always try to downgrade it later if we find a need.

@@ -1,6 +1,5 @@
#include <fstream>
#include <string>
#include <unistd.h>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know why all these files included <unistd.h> and at least on my mac they appear to compile without it. We will see what CI says.

@@ -34,8 +34,18 @@ configure_file(common/grpc_fwd.hpp.in common/grpc_fwd.hpp)

# Set compile and link options based on arguments
if (VIAMCPPSDK_USE_WALL_WERROR)
target_compile_options(viamsdk PRIVATE -Wall -Werror)
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This enables warnings as errors flags for MSVC, and makes it an error if you ask for it and we can't do it on the current toolchain (or the toolchain is unknown).

@@ -4,8 +4,6 @@
#include <memory>
#include <sstream>
#include <string>
#include <sys/socket.h>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these were only needed for the creation of the socket below, which we are no longer doing.

@@ -115,8 +113,8 @@ struct ModuleService::ServiceImpl : viam::module::v1::ModuleService::Service {
Registry::get().lookup_model(cfg.name());
if (reg) {
try {
const std::shared_ptr<Resource> res = reg->construct_resource(deps, cfg);
manager->replace_one(cfg.resource_name(), res);
const std::shared_ptr<Resource> resource = reg->construct_resource(deps, cfg);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Windows throws a shadowing warning here which gets promoted to an error because we have res above.

server_->register_service(impl_.get());
const std::string address = "unix://" + module_->addr();
const std::string address = "unix:" + module_->addr();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is actually the most important change. Please see https://grpc.github.io/grpc/cpp/md_doc_naming.html regarding unix:// vs unix:. The former, which is what we were using before, requires an absolute path, and I was entirely unable to get it to work with Windows paths. However, the latter can handle both absolute and relative, and it seems to work just fine on windows.

@@ -216,7 +215,7 @@ void RobotClient::refresh_every() {
std::this_thread::sleep_for(std::chrono::seconds(refresh_interval_));
refresh();

} catch (std::exception& exc) {
} catch (std::exception&) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Windows warning that this was unused.

@@ -150,6 +150,11 @@ MLModelService::tensor_views make_sdk_tensor_from_api_tensor_t(const T* data,
shape_accum = next_shape_accum;
}

#ifdef _MSC_VER
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A nuisance. Windows concludes that for one instantiation of the template that the conditional on 164 is tautologically true, which it is. But the point is to handle it for the instantiations where it is not a tautology. I opted to just to suppress the warning at the site.

@@ -55,7 +55,7 @@ void NavigationClient::set_mode(const Navigation::Mode mode, const ProtoStruct&
request.set_mode(viam::service::navigation::v1::Mode(mode));
*request.mutable_extra() = to_proto(extra);
})
.invoke([](auto& response) {});
.invoke([](auto&) {});
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused var name warnings on windows, here and below.

@@ -252,13 +250,8 @@ ModuleService::~ModuleService() {
}

void ModuleService::serve() {
const mode_t old_mask = umask(0077);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forgot to mention this in my batch of comments. This code, which has been here forever, has always done nothing. It sure looked like it was making the socket that we were going to use for communication with RDK, but look carefully and you can see that we never actually bind the socket anywhere, or invoke it in any way. The actual socket gets made by gRPC.

Copy link
Collaborator

@lia-viam lia-viam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks good overall, __has_include comment would be nice to address but non-blocking

@acmorrow acmorrow merged commit 62d40eb into viamrobotics:main Apr 4, 2025
4 checks passed
@acmorrow acmorrow deleted the windows branch April 4, 2025 19:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants