Skip to content

Commit 0213732

Browse files
authored
Merge branch 'main' into RSDK-10680-support-commented-code-samples
2 parents 85f2763 + d164762 commit 0213732

File tree

94 files changed

+15550
-3969
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+15550
-3969
lines changed

.github/workflows/conan.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,3 +213,34 @@ jobs:
213213
--tool-requires=b2/5.3.1 --build=b2/5.3.1 -s compiler.cppstd=14 -s:a compiler.cppstd=14
214214
215215
conan create . --build=missing -s compiler.cppstd=14 -s:a compiler.cppstd=14
216+
217+
build_windows:
218+
if: github.repository_owner == 'viamrobotics'
219+
needs: [prepare]
220+
runs-on: windows-latest
221+
strategy:
222+
fail-fast: false
223+
matrix:
224+
include:
225+
- target: x86_64-windows
226+
platform: windows_x86_64
227+
steps:
228+
- name: Checkout Code
229+
uses: actions/checkout@v4
230+
with:
231+
ref: ${{ needs.prepare.outputs.sha }}
232+
233+
- name: Install dependencies
234+
run: choco install -y conan git
235+
236+
- name: Create package
237+
shell: powershell
238+
run: |
239+
Import-Module $env:ChocolateyInstall\helpers\chocolateyProfile.psm1
240+
refreshenv
241+
conan profile detect
242+
conan create . --build=missing -o "&:shared=False"
243+
env:
244+
CONAN_USER_HOME: c:/cache
245+
CONAN_USER_HOME_SHORT: c:/cache/conan_shortpaths
246+

.github/workflows/release.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,53 @@ jobs:
3636
uses: andymckay/[email protected]
3737
if: steps.release_exists.outputs.id != ''
3838

39+
build_windows:
40+
if: github.repository_owner == 'viamrobotics'
41+
needs: [prepare]
42+
runs-on: windows-latest
43+
strategy:
44+
fail-fast: false
45+
matrix:
46+
include:
47+
- target: x86_64-windows
48+
platform: windows_x86_64
49+
steps:
50+
- name: Checkout Code
51+
uses: actions/checkout@v4
52+
with:
53+
ref: ${{ needs.prepare.outputs.sha }}
54+
55+
- name: Install dependencies
56+
run: choco install -y conan git
57+
58+
- name: Create package
59+
shell: powershell
60+
# TODO (RSDK-10666) Use conan invocations rather than cmake invocations here
61+
run: |
62+
Import-Module $env:ChocolateyInstall\helpers\chocolateyProfile.psm1
63+
refreshenv
64+
conan profile detect
65+
conan install . --output-folder=build-conan --build=missing -o "&:shared=False"
66+
cmake . --preset conan-default
67+
cmake --build --preset=conan-release --target ALL_BUILD install -j 8
68+
env:
69+
CONAN_USER_HOME: c:/cache
70+
CONAN_USER_HOME_SHORT: c:/cache/conan_shortpaths
71+
72+
- name: Copy
73+
run: |
74+
cmake --install build-conan/build --prefix builds/viam-cpp-sdk-${{ matrix.platform }}
75+
76+
- name: Create tar
77+
run: |
78+
tar -czvf builds/viam-cpp-sdk-${{ matrix.platform }}.tar.gz builds/viam-cpp-sdk-${{ matrix.platform }}
79+
80+
- name: Upload artifacts
81+
uses: actions/upload-artifact@v4
82+
with:
83+
name: viam-cpp-sdk-${{ matrix.platform }}.tar.gz
84+
path: builds/viam-cpp-sdk-${{ matrix.platform }}.tar.gz
85+
3986
build_macos:
4087
if: github.repository_owner == 'viamrobotics'
4188
needs: [prepare]

.github/workflows/test.yml

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,17 @@ name: Test
22

33
on:
44
pull_request:
5+
paths-ignore:
6+
- conanfile.py
7+
- '**.md'
58
workflow_dispatch:
69
inputs:
710
no-tidy:
811
type: boolean
912
description: set to true to build without clang-tidy (2x faster)
1013

1114
jobs:
12-
run-tests:
15+
test_ubuntu:
1316
if: github.repository_owner == 'viamrobotics'
1417
runs-on: ubuntu-latest
1518
container: ghcr.io/viamrobotics/cpp-base:bullseye-amd64
@@ -39,3 +42,40 @@ jobs:
3942
- name: test
4043
working-directory: build
4144
run: ../etc/docker/tests/run_test.sh
45+
test_windows:
46+
if: github.repository_owner == 'viamrobotics'
47+
runs-on: windows-latest
48+
strategy:
49+
fail-fast: false
50+
matrix:
51+
include:
52+
- target: x86_64-windows
53+
platform: windows_x86_64
54+
steps:
55+
- name: Checkout Code
56+
uses: actions/checkout@v4
57+
with:
58+
ref: ${{ needs.prepare.outputs.sha }}
59+
60+
- name: Install dependencies
61+
run: choco install -y conan git
62+
63+
- name: Build SDK
64+
shell: powershell
65+
run: |
66+
Import-Module $env:ChocolateyInstall\helpers\chocolateyProfile.psm1
67+
refreshenv
68+
conan profile detect
69+
conan install . --build=missing -o "&:shared=False"
70+
cmake . --preset conan-default -DVIAMCPPSDK_BUILD_EXAMPLES=ON
71+
cmake --build --preset=conan-release --target ALL_BUILD install -j 8
72+
env:
73+
CONAN_USER_HOME: c:/cache
74+
CONAN_USER_HOME_SHORT: c:/cache/conan_shortpaths
75+
76+
- name: Test examples
77+
shell: powershell
78+
run: |
79+
Start-Job -Init ([ScriptBlock]::Create("Set-Location '$pwd/build/install/bin'")) -ScriptBlock { .\simple_module.exe asdf 2>&1 > output.txt} | Wait-Job -Timeout 2 | Receive-Job
80+
if (-not $(Select-String -Pattern "Module listening" -Path ./build/install/bin/output.txt)) { throw "Module did not start listening" }
81+

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
/build/*
66

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

1012
# Ignore clang cache.
1113
/.cache/

BUILDING.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,23 @@ have a different version of `protoc` available in your `PATH`, it will
260260
silently fail and later cause compilation failures due to protobuf
261261
version mismatches.
262262

263+
## Building for ARM Windows
264+
265+
The C++ SDK works well on windows for both client and module code
266+
provided there is internet connectivity. However, some manual work is
267+
required to build for client code on ARM64 architecture.
268+
269+
1. (client code only) clone [rust-utils](https://github.com/viamrobotics/rust-utils) >= v0.3.0 and
270+
build locally with `cargo build --release`. Copy `target\release\viam_rust_utils.lib`
271+
to the root of the C++ SDK directory.
272+
2. Ensure `conan` is installed (see `Building with Conan` above).
273+
3. Run the following:
274+
```
275+
conan profile detect
276+
cmake . --preset conan-default <cmake args>
277+
cmake --build --preset=conan-release -j
278+
```
279+
263280
## Options to Configure or Customize the Build
264281

265282
### Options for Package Search

CMakeLists.txt

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ else()
4141
cmake_minimum_required(VERSION 3.25 FATAL_ERROR)
4242
endif()
4343

44-
set(CMAKE_PROJECT_VERSION 0.11.0)
44+
set(CMAKE_PROJECT_VERSION 0.15.0)
4545

4646
# Identify the project.
4747
project(viam-cpp-sdk
@@ -266,14 +266,20 @@ if (viam_rust_utils_files)
266266
${viam_rust_utils_file}
267267
ONLY_IF_DIFFERENT
268268
)
269-
elseif(NOT WIN32) # TODO(RSDK-10366): Currently, rust_utils is not published for windows, so don't even try downloading
269+
elseif(NOT WIN32 OR ${CMAKE_SYSTEM_PROCESSOR} STREQUAL "AMD64")
270270
set(lvru_system_name ${CMAKE_SYSTEM_NAME})
271271
if (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
272272
set(lvru_system_name "macosx")
273273
endif()
274+
275+
set(lvru_system_processor ${CMAKE_SYSTEM_PROCESSOR})
276+
if(WIN32)
277+
set(lvru_system_processor "x86_64")
278+
endif()
279+
274280
file(
275281
DOWNLOAD
276-
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}
282+
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}
277283
${viam_rust_utils_file}
278284
STATUS lvru_status
279285
)
@@ -283,24 +289,21 @@ elseif(NOT WIN32) # TODO(RSDK-10366): Currently, rust_utils is not published for
283289
if(NOT lvru_status_code EQUAL 0)
284290
message(FATAL_ERROR "No local viam_rust_utils found and failed to download: ${lvru_status_string}")
285291
endif()
286-
292+
else()
293+
message(WARNING "Currently running on Windows with no rust-utils file. Module code should work as expected, but client code may fail unexpectedly.")
287294
endif()
288295

289-
# TODO(RSDK-10366): Currently, rust_utils is not published for windows, so don't even declare the library
290-
if (NOT WIN32)
291-
add_library(viam_rust_utils SHARED IMPORTED)
292-
296+
if (NOT WIN32 OR ${CMAKE_SYSTEM_PROCESSOR} STREQUAL "AMD64")
297+
add_library(viam_rust_utils STATIC IMPORTED)
293298
target_link_directories(viam_rust_utils
294299
INTERFACE
295300
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>"
296301
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_LIBDIR}>"
297302
)
298-
299303
set_property(TARGET viam_rust_utils PROPERTY IMPORTED_LOCATION ${viam_rust_utils_file})
300304

301305
install(
302-
IMPORTED_RUNTIME_ARTIFACTS viam_rust_utils
303-
LIBRARY COMPONENT viam-cpp-sdk_runtime
306+
FILES ${viam_rust_utils_file} DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT viam-cpp-sdk_runtime
304307
)
305308
endif()
306309

README.md

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ docker build --build-arg BASE_TAG=base/bullseye --build-arg GIT_TAG=[...] -f etc
3737
```
3838

3939
This will use `base/bullseye` as a base to build the SDK version provided in `GIT_TAG`,
40-
which should be a tagged release version. The SDK will be cloned from
40+
which should be a tagged release version. The SDK will be cloned from
4141
https://github.com/viamrobotics/viam-cpp-sdk/. This is the recommended approach for
4242
C++ module development, which should generally be done against a tagged release.
4343

@@ -47,22 +47,22 @@ docker build --build-arg BASE_TAG=base/bullseye --build-arg REPO_SETUP=copy -f e
4747
```
4848

4949
Note the use of the build argument `REPO_SETUP=copy`, which adds a Docker instruction
50-
to copy the SDK repo from the current working directory, rather than cloning from
50+
to copy the SDK repo from the current working directory, rather than cloning from
5151
GitHub. This approach may make more sense for developing on the SDK itself, or if
5252
your C++ SDK development relies on a localversion of the SDK.
5353

5454
The examples above illustrated the use of several `--build-arg` arguments, namely
55-
`BASE_TAG`, `GIT_TAG`, and `REPO_SETUP`. Please see
55+
`BASE_TAG`, `GIT_TAG`, and `REPO_SETUP`. Please see
5656
[Dockerfile.sdk-build](etc/docker/Dockerfile.sdk-build) for a complete account of
5757
all build arguments and their defaults.
5858

5959
## Building Documentation Locally for Testing
6060
The C++ sdk uses [Doxygen](https://www.doxygen.nl/) to generate documentation.
6161
An automated workflow will generate and update our documentation on each merge,
62-
and publish it to [cpp.viam.dev](https://cpp.viam.dev).
62+
and publish it to [cpp.viam.dev](https://cpp.viam.dev).
6363

6464
Generating documentation locally to observe changes while developing with the
65-
C++ SDK is simple.
65+
C++ SDK is simple.
6666
First, make sure doxygen is installed, e.g.,
6767
```
6868
(on mac) brew install doxygen
@@ -91,12 +91,26 @@ quickly as possible.
9191
## A note on logging
9292

9393
Users should only interact with logging via the macros, classes, and functions in
94-
[`viam/sdk/log/logging.hpp`](src/viam/sdk/log/logging.hpp). Logging is
94+
[`viam/sdk/log/logging.hpp`](src/viam/sdk/log/logging.hpp). Logging is
9595
implemented using Boost.Log, but this is an implementation detail subject
9696
to change without warning. In particular, using Boost.Log macros such as
97-
`BOOST_LOG_TRIVIAL` or `BOOST_LOG_SEV` is undefined behavior which will likely
97+
`BOOST_LOG_TRIVIAL` or `BOOST_LOG_SEV` is undefined behavior which will likely
9898
fail to output log messages.
9999

100+
## Running Tests
101+
Tests for the SDK are located in `src/viam/sdk/tests`. The CMakeLists.txt file in that directory defines how to build them. When the SDK is built, the test executables are placed in the test folder within your specified build directory (e.g., `build`, if you followed the instructions in [`BUILDING.md`](https://github.com/viamrobotics/viam-cpp-sdk/blob/main/BUILDING.md)). The test executable files can be run individually. To run the entire test suite at once, navigate to the `tests` folder in your build directory and run:
102+
```
103+
ctest
104+
```
105+
Or to avoid navigating all the way to the folder you can specify the test directory, for example:
106+
```
107+
ctest --test-dir build/src/viam/sdk/tests/
108+
```
109+
Additionally, for more useful ctest options explore:
110+
```
111+
ctest --help
112+
```
113+
100114
## License
101115
Copyright 2022 Viam Inc.
102116

conanfile.py

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from conan import ConanFile
22
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
3+
from conan.tools.build import valid_max_cppstd
34
from conan.tools.files import load
45
from conan.tools.apple import is_apple_os
56
import os
@@ -42,19 +43,36 @@ def configure(self):
4243
for lib in ["grpc", "protobuf", "abseil"]:
4344
self.options[lib].shared = True
4445

46+
def _xtensor_requires(self):
47+
if valid_max_cppstd(self, 14, False):
48+
return 'xtensor/[>=0.24.3 <0.26.0]'
49+
50+
return 'xtensor/[>=0.24.3]'
51+
52+
def _grpc_requires(self):
53+
if valid_max_cppstd(self, 14, False):
54+
return 'grpc/[>=1.48.4 <1.70.0]'
55+
56+
return 'grpc/[>=1.48.4]'
57+
4558
def requirements(self):
46-
self.requires('boost/[>=1.74.0]', transitive_headers=True)
59+
if self.settings.os == "Windows":
60+
# This is temporary pending the resolution of a windows compilation
61+
# issue on boost 1.88.0
62+
self.requires('boost/[>=1.74.0 <1.88.0]', transitive_headers=True)
63+
else:
64+
self.requires('boost/[>=1.74.0]', transitive_headers=True)
4765

4866
# The SDK supports older grpc and protobuf, but these are the oldest
4967
# maintained conan packages.
50-
self.requires('grpc/[>=1.48.4]')
51-
self.requires('protobuf/[>=3.17.1]')
52-
self.requires('xtensor/[>=0.24.3]', transitive_headers=True)
68+
self.requires(self._grpc_requires())
69+
self.requires('protobuf/[>=3.17.1 <6.30.0]')
70+
self.requires(self._xtensor_requires(), transitive_headers=True)
5371

5472
def build_requirements(self):
5573
if self.options.offline_proto_generation:
56-
self.tool_requires('grpc/[>=1.48.4]')
57-
self.tool_requires('protobuf/[>=3.17.1]')
74+
self.tool_requires(self._grpc_requires())
75+
self.tool_requires('protobuf/[>=3.17.1 <6.30.0]')
5876

5977
def layout(self):
6078
cmake_layout(self)
@@ -91,10 +109,7 @@ def package(self):
91109

92110
def package_info(self):
93111

94-
# TODO(RSDK-10366): Currently, rust_utils is not published for windows
95-
# and the C++ SDK just doesn't include it as a dependency on that platform
96-
if not self.settings.os == "Windows":
97-
self.cpp_info.components["viam_rust_utils"].libs = ["viam_rust_utils"]
112+
self.cpp_info.components["viam_rust_utils"].libs = ["viam_rust_utils"]
98113

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

@@ -107,6 +122,8 @@ def package_info(self):
107122

108123
if self.settings.os in ["Linux", "FreeBSD"]:
109124
self.cpp_info.components["viamsdk"].system_libs.extend(["dl", "rt"])
125+
elif self.settings.os == "Windows":
126+
self.cpp_info.components["viamsdk"].system_libs.extend(["ncrypt", "secur32", "ntdll", "userenv"])
110127

111128
self.cpp_info.components["viamapi"].includedirs.append("include/viam/api")
112129

@@ -137,11 +154,8 @@ def package_info(self):
137154
"viamapi",
138155
])
139156

140-
# TODO(RSDK-10366): Currently, rust_utils is not published for windows
141-
# and the C++ SDK just doesn't include it as a dependency on that platform
142-
if self.settings.os != "Windows":
143-
self.cpp_info.components["viamsdk"].requires.extend([
144-
"viam_rust_utils"
145-
])
157+
self.cpp_info.components["viamsdk"].requires.extend([
158+
"viam_rust_utils"
159+
])
146160

147161
self.cpp_info.components["viamsdk"].frameworks = ["Security"]

0 commit comments

Comments
 (0)