Skip to content

RSDK-10366 - rust utils for windows #416

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 95 commits into from
May 16, 2025
Merged
Show file tree
Hide file tree
Changes from 87 commits
Commits
Show all changes
95 commits
Select commit Hold shift + click to select a range
e9d3ea1
only prepend unix when using uds
stuqdog Apr 18, 2025
0e3b8af
untested download and install rust-utils for windows
stuqdog Apr 18, 2025
b968803
cr comments
stuqdog Apr 18, 2025
5d5bb2d
const correctness
stuqdog Apr 18, 2025
d9827e5
try windows build
stuqdog Apr 21, 2025
adff932
test it
stuqdog Apr 21, 2025
59fd83c
try getting all dependencies installed
stuqdog Apr 21, 2025
a8e1751
no setting buf_config_dir
stuqdog Apr 21, 2025
ff01f42
try earlier cmake
stuqdog Apr 21, 2025
96652c8
goldilocks cmake
stuqdog Apr 21, 2025
46dad50
set boost root
stuqdog Apr 21, 2025
1d1ad1e
set boost includedir, try to find librarydir
stuqdog Apr 21, 2025
3268789
try list better
stuqdog Apr 21, 2025
57e6d5d
set librarydir
stuqdog Apr 21, 2025
cb01ea7
set boost compiler
stuqdog Apr 21, 2025
5cf9590
12 not 13
stuqdog Apr 21, 2025
ff5a2bf
had boost compiler backwards
stuqdog Apr 21, 2025
bc83e5b
github action for grpc
stuqdog Apr 21, 2025
674e729
specify grpc version
stuqdog Apr 21, 2025
952c305
install grpc with vcpkg
stuqdog Apr 21, 2025
7e38e1b
powershell
stuqdog Apr 21, 2025
9eab8c5
typo
stuqdog Apr 21, 2025
d590eff
try conan instead
stuqdog Apr 22, 2025
2d7df41
build too
stuqdog Apr 22, 2025
f299251
py -m conan
stuqdog Apr 22, 2025
9e36c2f
fixup
stuqdog Apr 22, 2025
02660a3
refreshenv
stuqdog Apr 22, 2025
6728c57
more installs, set envvars, etc
stuqdog Apr 22, 2025
38667a8
format fix
stuqdog Apr 22, 2025
ae64216
specify cmake version
stuqdog Apr 22, 2025
1dd810f
syntax change
stuqdog Apr 22, 2025
15abea3
cleanup release a bit, print more info
stuqdog Apr 22, 2025
d6982be
get correct arch
stuqdog Apr 23, 2025
11e56e9
one more arch fix
stuqdog Apr 23, 2025
b1e8526
fix unix://, another arch fix
stuqdog Apr 23, 2025
e21ba06
hardcode lib prefix
stuqdog Apr 23, 2025
c7490e2
print system name
stuqdog Apr 23, 2025
758bacf
Merge branch 'main' into RSDK-10366-rust-utils-for-windows
stuqdog Apr 23, 2025
7e0953c
case sensitive
stuqdog Apr 26, 2025
c98af91
Merge branch 'RSDK-10366-rust-utils-for-windows' of ssh://github.com/…
stuqdog Apr 26, 2025
72004be
restart tests
stuqdog Apr 26, 2025
412cbb9
set shared library prefix earlier
stuqdog Apr 28, 2025
73c5410
cleaner
stuqdog Apr 28, 2025
b4c4b84
just hardcode lib
stuqdog Apr 28, 2025
de30df1
fixups from windows testing
stuqdog May 2, 2025
0b2512b
fix token
stuqdog May 2, 2025
4c29471
some cleanup
stuqdog May 2, 2025
add6916
remove comments to self
stuqdog May 2, 2025
d4cb253
a couple more comment cleanups
stuqdog May 2, 2025
89df7fb
add instructions for building on windows
stuqdog May 2, 2025
ba316a3
Merge branch 'main' of ssh://github.com/viamrobotics/viam-cpp-sdk int…
stuqdog May 2, 2025
f1ba0d3
try keeping shared for unix
stuqdog May 2, 2025
07470b2
try keeping shared for unix pt2
stuqdog May 2, 2025
3ee79d5
typo
stuqdog May 2, 2025
6e77560
static for windows only, import chrono
stuqdog May 2, 2025
59ed94e
nominmax for windows
stuqdog May 6, 2025
0f5812a
specify type
stuqdog May 6, 2025
c66a2e0
prepare for working rust-utils
stuqdog May 7, 2025
51de5d8
try stuff from CR comments
stuqdog May 7, 2025
a9b2337
dont install when static building
stuqdog May 7, 2025
7afa451
shared again
stuqdog May 7, 2025
1bd47b2
test from convo with drew
stuqdog May 7, 2025
d43865b
fix ordering of link libraries for rust-utils
stuqdog May 7, 2025
b3a339a
rust-utils always static
stuqdog May 7, 2025
4b68fda
invert check for installing rust-utils
stuqdog May 7, 2025
952702b
revert to linking to viamsdk, not rust-utils
stuqdog May 7, 2025
f1c1e4f
shift to install FILES
stuqdog May 7, 2025
ec59387
did I get conan stuff wrong
stuqdog May 8, 2025
5e15a93
always install
stuqdog May 8, 2025
e5a3a5a
typo
stuqdog May 8, 2025
b843938
workflow cleanup, print out info for to find where to copy from with …
stuqdog May 8, 2025
861a35c
remove commented out stuff
stuqdog May 8, 2025
6306025
cleanup
stuqdog May 8, 2025
9de2913
fixup ls
stuqdog May 8, 2025
2779b50
Merge branch 'main' of ssh://github.com/viamrobotics/viam-cpp-sdk int…
stuqdog May 8, 2025
1e042cf
try cmake invocation for windows
stuqdog May 8, 2025
c6382e1
conanfile always include rust-utils info
stuqdog May 8, 2025
c4143af
include .lib
stuqdog May 8, 2025
165ca0c
interface not private
stuqdog May 8, 2025
d292417
try cmake invocation again
stuqdog May 8, 2025
9095b79
typos
stuqdog May 8, 2025
84b1874
actually install
stuqdog May 8, 2025
bfc6faf
no install
stuqdog May 8, 2025
4ba53d5
no all
stuqdog May 8, 2025
7cb2dd7
all-build
stuqdog May 9, 2025
3186390
more comprehensive listing
stuqdog May 9, 2025
3d56ccc
fix release, comment out windows conan build for now
stuqdog May 9, 2025
b710c7a
remove unused code
stuqdog May 9, 2025
47aca71
Merge branch 'main' into RSDK-10366-rust-utils-for-windows
stuqdog May 9, 2025
b56ab5c
cr comments
stuqdog May 16, 2025
3693c60
Merge branch 'RSDK-10366-rust-utils-for-windows' of ssh://github.com/…
stuqdog May 16, 2025
9459e17
Merge branch 'main' into RSDK-10366-rust-utils-for-windows
stuqdog May 16, 2025
230b29d
cr comments, test direct choco invocation
abe-winter May 16, 2025
cd7690b
get primetime ready
stuqdog May 16, 2025
fa063e4
improve comment
stuqdog May 16, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions .github/workflows/conan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,39 @@ jobs:
github.event_name == 'schedule' &&
steps.git_info.outputs.current_commit == steps.last_successful_commit.outputs.commit-hash

# TODO (RSDK-10666) Uncomment and fix
#build_windows:
#if: github.repository_owner == 'viamrobotics'
#needs: [prepare]
#runs-on: windows-latest
#strategy:
#fail-fast: false
#matrix:
#include:
#- target: x86_64-windows
#platform: windows_x86_64
#steps:
#- name: Checkout Code
#uses: actions/checkout@v4

#- name: Install dependencies
#uses: crazy-max/ghaction-chocolatey@v3
#with:
#args: install -y conan git

#- name: Create package
#shell: powershell
#run: |
#Import-Module $env:ChocolateyInstall\helpers\chocolateyProfile.psm1
#refreshenv
#conan profile detect
#conan create . `
#--build=missing `
#-o "&:shared=False"
#env:
#CONAN_USER_HOME: c:/cache
#CONAN_USER_HOME_SHORT: c:/cache/conan_shortpaths
Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure when we'll get around to fixing this so I don't know that I feel quite as strongly about leaving this in for future reference. Happy to just remove if preferred.

We can definitely try and fix now, but unless someone has a very clear picture of what's wrong I think I'd prefer to do that in a separate PR so we can lock in the wins here now.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think maybe just leave in the TODO/ticket number but the commented code can be removed, we can always consult this diff to see what you had written I believe


build_macos:
if: github.repository_owner == 'viamrobotics'
needs: [prepare]
Expand Down
48 changes: 48 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,54 @@ jobs:
uses: andymckay/[email protected]
if: steps.release_exists.outputs.id != ''

build_windows:
if: github.repository_owner == 'viamrobotics'
needs: [prepare]
runs-on: windows-latest
strategy:
fail-fast: false
matrix:
include:
- target: x86_64-windows
platform: windows_x86_64
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
ref: ${{ needs.prepare.outputs.sha }}

- name: Install dependencies
uses: crazy-max/ghaction-chocolatey@v3
with:
args: install -y conan git
Copy link
Member

Choose a reason for hiding this comment

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

I'm still surprised you need this. Chocolatey is pre-installed on windows builders, from what I know. The tflite cpu build uses choco to install conan without doing anything special to install choco itself:

https://github.com/viam-modules/mlmodel-tflite/blob/main/bin/setup.ps1#L5

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah you're probably right that it's not necessary! I kept it in just because we needed to do a choco install some way or another, it seemed totally innocuous to include, and I didn't want to do another round of testing to confirm. If you think there's a good reason to switch to a choco install invocation instead, let me know!

Copy link
Member

Choose a reason for hiding this comment

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

Without knowing exactly what it does, it likely is innocuous until "crazy max"'s repo ends up being a vector for / victim of a supply chain attack.

At least when run on windows, all it actually seems to do is call choco with args:

https://github.com/crazy-max/ghaction-chocolatey/blob/master/src/main.ts#L22

So, from a risk / reward ratio it looks to me like it shouldn't stay. However, I'm fine with leaving it in for now since I know there has been a lot of back and forth on this and testing is slow. If you end up leaving it in, could you please file a ticket to remove it and add a TODO here before merging?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ahh that's a good point! this is reason enough to just make the change now imo, tested and it works.


- name: Create package
shell: powershell
run: |
Import-Module $env:ChocolateyInstall\helpers\chocolateyProfile.psm1
refreshenv
conan profile detect
conan install . --output-folder=build-conan --build=missing -o "&:shared=False"
cmake . --preset conan-default
cmake --build --preset=conan-release --target ALL_BUILD install -j 8
Comment on lines +66 to +67
Copy link
Member

Choose a reason for hiding this comment

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

Just curious: but why direct invocation of cmake here rather than conan build?

Copy link
Member Author

Choose a reason for hiding this comment

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

For reasons that weren't entirely clear, the conan build invocation resulted in a number of undefined symbols coming from the libraries that we were importing in the CMakeLists.txt. @lia-viam and I spent a short time trying to debug and then just determined that the cmake invocation was good enough to get releases built. Will fix in RSDK-10666.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm trying to remember if we were in fact using conan build or that was with conan create ?

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 recall having issues with both, but there was so much back and forth and problem solving that it's hard for me to speak to with total confidence. at any rate I think this seems like a reasonable thing to revisit in the above-linked ticket.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe throw a # TODO(RSDK-10666): ... on there.

Copy link
Member Author

Choose a reason for hiding this comment

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

done!

env:
CONAN_USER_HOME: c:/cache
CONAN_USER_HOME_SHORT: c:/cache/conan_shortpaths

- name: Copy
run: |
cmake --install build-conan/build --prefix builds/viam-cpp-sdk-${{ matrix.platform }}

- name: Create tar
run: |
tar -czvf builds/viam-cpp-sdk-${{ matrix.platform }}.tar.gz builds/viam-cpp-sdk-${{ matrix.platform }}

- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: viam-cpp-sdk-${{ matrix.platform }}.tar.gz
path: builds/viam-cpp-sdk-${{ matrix.platform }}.tar.gz

build_macos:
if: github.repository_owner == 'viamrobotics'
needs: [prepare]
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
/build/*

# For now, ignore any viam_rust_utils library in the root.
# The `lib` prefix is on unix-based systems only
/libviam_rust_utils*
/viam_rust_utils*

# Ignore clang cache.
/.cache/
Expand Down
17 changes: 17 additions & 0 deletions BUILDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,23 @@ have a different version of `protoc` available in your `PATH`, it will
silently fail and later cause compilation failures due to protobuf
version mismatches.

## Building for ARM Windows

The C++ SDK works well on windows for both client and module code
provided there is internet connectivity. However, some manual work is
required to build for client code on ARM64 architecture.

1. (client code only) clone [rust-utils](https://github.com/viamrobotics/rust-utils) >= v0.3.0 and
build locally with `cargo build --release`. Copy `target\release\viam_rust_utils.lib`
to the root of the C++ SDK directory.
2. Ensure `conan` is installed (see `Building with Conan` above).
3. Run the following:
```
conan profile detect
cmake . --preset conan-default <cmake args>
cmake --build --preset=conan-release -j
```

## Options to Configure or Customize the Build

### Options for Package Search
Expand Down
23 changes: 13 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -266,14 +266,20 @@ if (viam_rust_utils_files)
${viam_rust_utils_file}
ONLY_IF_DIFFERENT
)
elseif(NOT WIN32) # TODO(RSDK-10366): Currently, rust_utils is not published for windows, so don't even try downloading
elseif(NOT WIN32 OR ${CMAKE_SYSTEM_PROCESSOR} STREQUAL "AMD64")
set(lvru_system_name ${CMAKE_SYSTEM_NAME})
if (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
set(lvru_system_name "macosx")
endif()

set(lvru_system_processor ${CMAKE_SYSTEM_PROCESSOR})
if(WIN32)
set(lvru_system_processor "x86_64")
endif()

file(
DOWNLOAD
https://github.com/viamrobotics/rust-utils/releases/latest/download/${CMAKE_SHARED_LIBRARY_PREFIX}viam_rust_utils-${lvru_system_name}_${CMAKE_SYSTEM_PROCESSOR}${CMAKE_STATIC_LIBRARY_SUFFIX}
https://github.com/viamrobotics/rust-utils/releases/latest/download/${CMAKE_SHARED_LIBRARY_PREFIX}viam_rust_utils-${lvru_system_name}_${lvru_system_processor}${CMAKE_STATIC_LIBRARY_SUFFIX}
${viam_rust_utils_file}
STATUS lvru_status
)
Expand All @@ -283,24 +289,21 @@ elseif(NOT WIN32) # TODO(RSDK-10366): Currently, rust_utils is not published for
if(NOT lvru_status_code EQUAL 0)
message(FATAL_ERROR "No local viam_rust_utils found and failed to download: ${lvru_status_string}")
endif()

else()
message(WARNING "Currently running on Windows with no rust-utils file. Module code should work as expected, but client code may fail unexpectedly.")
endif()

# 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)

if (NOT WIN32 OR ${CMAKE_SYSTEM_PROCESSOR} STREQUAL "AMD64")
add_library(viam_rust_utils STATIC IMPORTED)
target_link_directories(viam_rust_utils
INTERFACE
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>"
Copy link
Member

Choose a reason for hiding this comment

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

Apologies: I've changed my mind here, I think you still do need INSTALL_INTERFACE here for the BUILD_SHARED_LIBS=OFF case.

"$<INSTALL_INTERFACE:${CMAKE_INSTALL_LIBDIR}>"
)

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
FILES ${viam_rust_utils_file} DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT viam-cpp-sdk_runtime
Copy link
Member Author

Choose a reason for hiding this comment

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

@acmorrow fwiw it appears that this install is necessary regardless of whether build_shared_libs is on (failure to include it results in test failure).

Copy link
Member

Choose a reason for hiding this comment

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

OK. I may try it out myself after this merges to understand better, because it doesn't align with my understanding of how this ought to be working.

)
endif()

Expand Down
14 changes: 4 additions & 10 deletions conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,7 @@ def package(self):

def package_info(self):

# 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":
Copy link
Member Author

Choose a reason for hiding this comment

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

@lia-viam can you help me understand what this is doing? Based on testing on the windows laptop, it doesn't seem to matter whether we run this always or not. Same below.

Copy link
Collaborator

Choose a reason for hiding this comment

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

See https://docs.conan.io/2/examples/conanfile/package_info/components.html for more info, but basically we are telling conan that the SDK depends on a library called viam_rust_utils, and the name of the library to be linked is also viam_rust_utils

self.cpp_info.components["viam_rust_utils"].libs = ["viam_rust_utils"]
self.cpp_info.components["viam_rust_utils"].libs = ["viam_rust_utils"]

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

Expand Down Expand Up @@ -137,11 +134,8 @@ def package_info(self):
"viamapi",
])

# 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"].requires.extend([
"viam_rust_utils"
])

self.cpp_info.components["viamsdk"].frameworks = ["Security"]
2 changes: 1 addition & 1 deletion src/viam/examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ char *path = dial("<your robot uri here>", "<your authentication type>", "<your
Then to obtain a robot client do :

``` c++
std::string address("unix://");
std::string address("unix:");
address += path;
RobotServiceClient client(grpc::CreateChannel(address, grpc::InsecureChannelCredentials()));
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ int main(int argc, char* argv[]) try {
});

// Print out the top 5 (or fewer) label/score pairs.
for (size_t i = 0; i != std::min(5UL, scored_labels.size()); ++i) {
for (size_t i = 0; i != std::min<std::size_t>(5UL, scored_labels.size()); ++i) {
Copy link
Member

Choose a reason for hiding this comment

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

Why the explicit std::size_t?

Copy link
Member Author

Choose a reason for hiding this comment

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

On windows specifically, it was necessary to specify the type. Otherwise, there was a no matching overloaded function found compilation error.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@acmorrow since the template wants both its arguments to be the same typename T, a call to std::min(5UL, std::size_t{}) was ambiguous...vexing but I think MSVC may have been right there since size_t is unsigned long long not unsigned long

Copy link
Member

Choose a reason for hiding this comment

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

Or just make the 5 a size_t? I'd expect std::min(size_t{5}, scored_labels.size()) to do the right thing.

// TODO: Avoid hardcoding the width here.
VIAM_SDK_LOG(info) << boost::format("%1%: %2% %|40t|%3%\n") % i %
*scored_labels[i].label % scored_labels[i].score;
Expand Down
6 changes: 4 additions & 2 deletions src/viam/examples/modules/complex/gizmo/api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@ class Gizmo : public Component {
explicit Gizmo(std::string name);
};

namespace viam::sdk {
namespace viam {
namespace sdk {
Comment on lines +33 to +34
Copy link
Member Author

Choose a reason for hiding this comment

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

Make compiles on C++14.

template <>
struct API::traits<Gizmo> {
static ::viam::sdk::API api();
};
} // namespace viam::sdk
} // namespace sdk
} // namespace viam

// `GizmoClient` is the gRPC client implementation of a `Gizmo` component.
class GizmoClient : public Gizmo {
Expand Down
6 changes: 4 additions & 2 deletions src/viam/examples/modules/complex/summation/api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@ class Summation : public Service {
explicit Summation(std::string name);
};

namespace viam::sdk {
namespace viam {
namespace sdk {
Comment on lines +32 to +33
Copy link
Member Author

Choose a reason for hiding this comment

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

make compile on C++14

template <>
struct API::traits<Summation> {
static API api();
};
} // namespace viam::sdk
} // namespace sdk
} // namespace viam

// `SummationClient` is the gRPC client implementation of a `Summation`
// service.
Expand Down
15 changes: 10 additions & 5 deletions src/viam/sdk/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -276,10 +276,10 @@ target_link_libraries(viamsdk
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)
# rust-utils doesn't build in CI on windows other than x86_64, so confirm that we're either not
# windows, or if we are windows that we're AMD64, or else that the user has provided their own
# build of rust_utils.
if (NOT WIN32 OR num_viam_rust_utils_files GREATER 0 OR ${CMAKE_SYSTEM_PROCESSOR} STREQUAL "AMD64")
Copy link
Member

Choose a reason for hiding this comment

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

Could this test just look only at num_viam_rust_utils_files now? I'd assume that if it is greater than zero then one was found and it should be used.

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 may be wrong, but is this a correct assumption? I thought num_viam_rust_utils_files was evaluated before we downloaded, in order to determine if we should download a rust_utils file. So the not WIN32 or AMD64 cases are important for the cases where the user hasn't provided a rust-utils file but we can download one for them.

Copy link
Member

Choose a reason for hiding this comment

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

Sorry, you are right, I got myself tangled up. I was reacting to having complex logic to decide whether to use rust utils or build the stub here. It just feels like it would be better if all of that tortured logic was isolated up in the top level CMakeLists.txt and this file had a way of making a simple yes/no decision about whether to use the library or build the stubs.

Actually, I wonder if if (TARGET... is what I'm after: https://cmake.org/cmake/help/latest/command/if.html#target

Again, I know you are eager to land this, but could you please add a TODO (doesn't need a ticket, leave it for someone to clean up later).

Copy link
Member Author

Choose a reason for hiding this comment

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

went ahead and switched to if (TARGET viam_rust_utils), confirmed that it builds correctly both with a user-provided rust-utils file and without one.

target_link_libraries(viamsdk
PRIVATE viam_rust_utils
)
Expand All @@ -289,9 +289,14 @@ endif()

if (APPLE)
target_link_libraries(viamsdk PUBLIC "-framework Security")
else()
elseif (NOT WIN32)
target_link_libraries(viamsdk PRIVATE dl)
target_link_libraries(viamsdk PRIVATE rt)
else()
target_link_libraries(viamsdk INTERFACE Ncrypt.lib)
target_link_libraries(viamsdk INTERFACE Secur32.lib)
target_link_libraries(viamsdk INTERFACE Ntdll.lib)
target_link_libraries(viamsdk INTERFACE Userenv.lib)
endif()


Expand Down
2 changes: 1 addition & 1 deletion src/viam/sdk/robot/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ std::shared_ptr<RobotClient> RobotClient::at_address(const std::string& address,

std::shared_ptr<RobotClient> RobotClient::at_local_socket(const std::string& address,
const Options& options) {
const std::string addr = "unix://" + address;
const std::string addr = "unix:" + address;
auto robot = RobotClient::with_channel(
ViamChannel(sdk::impl::create_viam_channel(addr, grpc::InsecureChannelCredentials())),
options);
Expand Down
2 changes: 1 addition & 1 deletion src/viam/sdk/robot/client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class RobotClient {
/// @brief Creates a robot client connected to the robot at the provided local socket.
/// @param address The local socket of the robot (a .sock file, etc.).
/// @param options Options for connecting and refreshing.
/// Creates a direct connection to the robot using the `unix://` scheme.
/// Creates a direct connection to the robot using the `unix:` scheme.
/// Only useful for connecting to robots across Unix sockets.
static std::shared_ptr<RobotClient> at_local_socket(const std::string& address,
const Options& options);
Expand Down
16 changes: 11 additions & 5 deletions src/viam/sdk/rpc/dial.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <viam/sdk/rpc/dial.hpp>

#include <algorithm>
#include <istream>
#include <string>

Expand Down Expand Up @@ -171,18 +172,23 @@ ViamChannel ViamChannel::dial(const char* uri, const boost::optional<DialOptions
if (opts.entity()) {
entity = opts.entity()->c_str();
}
char* socket_path = ::dial(
char* proxy_path = ::dial(
uri, entity, type, payload, opts.allows_insecure_downgrade(), float_timeout.count(), ptr);
if (socket_path == NULL) {
if (!proxy_path) {
free_rust_runtime(ptr);
throw Exception(ErrorCondition::k_connection, "Unable to establish connecting path");
}

std::string address("unix://");
address += socket_path;
const std::string localhost_prefix("127.0.0.1");
std::string address;
if (std::string(proxy_path).find(localhost_prefix) == std::string::npos) {
// proxy path is not a localhost address and is therefore a unix domain socket (UDS)
address += "unix:";
}
address += proxy_path;

return ViamChannel(sdk::impl::create_viam_channel(address, grpc::InsecureChannelCredentials()),
socket_path,
proxy_path,
ptr);
}

Expand Down
2 changes: 2 additions & 0 deletions src/viam/sdk/rpc/server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
/// @brief Defines the `Server` class.
#pragma once

#include <chrono>

#include <viam/sdk/common/grpc_fwd.hpp>
#include <viam/sdk/resource/resource.hpp>
#include <viam/sdk/resource/resource_api.hpp>
Expand Down
12 changes: 8 additions & 4 deletions src/viam/sdk/tests/mocks/mock_robot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,8 @@ ::grpc::Status MockRobotService::FrameSystemConfig(
const ::viam::robot::v1::FrameSystemConfigRequest*,
::viam::robot::v1::FrameSystemConfigResponse* response) {
auto client_md = context->client_metadata();
if (auto client_info = client_md.find("viam_client"); client_info == client_md.end()) {
auto client_info = client_md.find("viam_client");
if (client_info == client_md.end()) {
Comment on lines +302 to +303
Copy link
Member Author

Choose a reason for hiding this comment

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

make compile on C++14

return ::grpc::Status(::grpc::StatusCode::FAILED_PRECONDITION,
"viam_client info not properly set in metadata");
}
Expand All @@ -314,7 +315,8 @@ ::grpc::Status MockRobotService::TransformPose(::grpc::ServerContext* context,
const ::viam::robot::v1::TransformPoseRequest*,
::viam::robot::v1::TransformPoseResponse* response) {
auto client_md = context->client_metadata();
if (auto client_info = client_md.find("viam_client"); client_info == client_md.end()) {
auto client_info = client_md.find("viam_client");
if (client_info == client_md.end()) {
return ::grpc::Status(::grpc::StatusCode::FAILED_PRECONDITION,
"viam_client info not properly set in metadata");
}
Expand All @@ -327,7 +329,8 @@ ::grpc::Status MockRobotService::GetMachineStatus(
const ::viam::robot::v1::GetMachineStatusRequest*,
::viam::robot::v1::GetMachineStatusResponse* response) {
auto client_md = context->client_metadata();
if (auto client_info = client_md.find("viam_client"); client_info == client_md.end()) {
auto client_info = client_md.find("viam_client");
if (client_info == client_md.end()) {
return ::grpc::Status(::grpc::StatusCode::FAILED_PRECONDITION,
"viam_client info not properly set in metadata");
}
Expand All @@ -341,7 +344,8 @@ ::grpc::Status MockRobotService::GetOperations(::grpc::ServerContext* context,
const ::viam::robot::v1::GetOperationsRequest*,
::viam::robot::v1::GetOperationsResponse* response) {
auto client_md = context->client_metadata();
if (auto client_info = client_md.find("viam_client"); client_info == client_md.end()) {
auto client_info = client_md.find("viam_client");
if (client_info == client_md.end()) {
return ::grpc::Status(::grpc::StatusCode::FAILED_PRECONDITION,
"viam_client info not properly set in metadata");
}
Expand Down
Loading