Skip to content

Commit 743699d

Browse files
committed
Merge branch 'main' of github.com:viamrobotics/viam-cpp-sdk into logger
2 parents 6018b94 + 83c031b commit 743699d

Some content is hidden

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

51 files changed

+6709
-2256
lines changed

.github/workflows/conan.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ on:
1111
paths:
1212
- conanfile.py
1313
- test_package/conanfile.py
14+
- .github/workflows/conan.yml
1415

1516
jobs:
1617
prepare:
@@ -100,6 +101,8 @@ jobs:
100101
apt-get update
101102
apt-get -y dist-upgrade
102103
DEBIAN_FRONTEND=noninteractive apt-get -y --no-install-recommends install \
104+
autoconf \
105+
automake \
103106
build-essential \
104107
ca-certificates \
105108
curl \
@@ -120,15 +123,15 @@ jobs:
120123
sudo echo 'deb [signed-by=/usr/share/keyrings/kitware-archive-keyring.gpg] https://apt.kitware.com/ubuntu/ jammy main' | sudo tee /etc/apt/sources.list.d/kitware.list >/dev/null
121124
122125
apt-get update
123-
apt-get -y install cmake
126+
apt-get -y install cmake=3.25.2-0kitware1ubuntu22.04.1 cmake-data=3.25.2-0kitware1ubuntu22.04.1
124127
125128
pip install conan
126129
127130
- name: Create package
128131
shell: bash
129132
run: |
130133
conan profile detect
131-
conan create . --build=missing -s compiler.cppstd=14
134+
conan create . --build=missing -s compiler.cppstd=14 -s:a compiler.cppstd=14
132135
133136
build_linux_debian:
134137
if: github.repository_owner == 'viamrobotics'
@@ -166,6 +169,7 @@ jobs:
166169
apt-get update
167170
apt-get -y dist-upgrade
168171
DEBIAN_FRONTEND=noninteractive apt-get -y --no-install-recommends install \
172+
autoconf \
169173
build-essential \
170174
ca-certificates \
171175
cmake \
@@ -204,4 +208,4 @@ jobs:
204208
205209
pip install conan
206210
conan profile detect
207-
conan create . --build=missing -s compiler.cppstd=14
211+
conan create . --build=missing -s compiler.cppstd=14 -s:a compiler.cppstd=14

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,6 @@
1212

1313
# ignore doxygen output
1414
/etc/docs/api/*
15+
16+
# Conan user presets should be ignored
17+
CMakeUserPresets.json

CMakeLists.txt

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
# TODO: Better clang-format integration (versions, dependencies, only changed, etc.)
2222
# TODO: Version from git describe?
2323
# TODO: Export macros and visibilty annotations
24-
# TODO: CPack? CTest? Conan?
24+
# TODO: CPack? CTest?
2525

2626

2727
# This is a tricky decision. If we set this too old, we lose access to
@@ -32,9 +32,16 @@
3232
# most uses of this product, it is expected to be cross-compiling for
3333
# the target platform on a development system, meaning that we are not
3434
# constrained by the version of CMake available on target systems.
35-
cmake_minimum_required(VERSION 3.25 FATAL_ERROR)
3635

37-
set(CMAKE_PROJECT_VERSION 0.6.0)
36+
if (WIN32)
37+
# Use a newer version of CMake on Windows, so we are NEW for
38+
# https://cmake.org/cmake/help/latest/policy/CMP0149.html
39+
cmake_minimum_required(VERSION 3.27 FATAL_ERROR)
40+
else()
41+
cmake_minimum_required(VERSION 3.25 FATAL_ERROR)
42+
endif()
43+
44+
set(CMAKE_PROJECT_VERSION 0.9.0)
3845

3946
# Identify the project.
4047
project(viam-cpp-sdk
@@ -150,6 +157,10 @@ if (VIAMCPPSDK_ENFORCE_COMPILER_MINIMA)
150157
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 10.0)
151158
message(FATAL_ERROR "Insufficient Apple clang version: XCode 10.0+ required")
152159
endif()
160+
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
161+
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19.34)
162+
message(FATAL_ERROR "Insufficient MSVC version: Visual Studio 2022 17.4 (MSVC 19.34) or later is required")
163+
endif()
153164
else()
154165
message(FATAL_ERROR "Unknown / untested compiler ${CMAKE_CXX_COMPILER_ID}")
155166
endif()
@@ -169,6 +180,10 @@ if (NOT CMAKE_CXX_STANDARD)
169180
set(CMAKE_CXX_STANDARD 14)
170181
endif()
171182
set(CMAKE_CXX_STANDARD_REQUIRED True)
183+
if(MSVC)
184+
# https://discourse.cmake.org/t/set-cmake-cxx-standard-should-set-zc-cplusplus-for-msvc/1876
185+
string(APPEND CMAKE_CXX_FLAGS " /Zc:__cplusplus")
186+
endif()
172187
set(CMAKE_CXX_EXTENSIONS OFF)
173188

174189

@@ -251,7 +266,7 @@ if (viam_rust_utils_files)
251266
${viam_rust_utils_file}
252267
ONLY_IF_DIFFERENT
253268
)
254-
else()
269+
elseif(NOT WIN32) # TODO(RSDK-10366): Currently, rust_utils is not published for windows, so don't even try downloading
255270
set(lvru_system_name ${CMAKE_SYSTEM_NAME})
256271
if (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
257272
set(lvru_system_name "macosx")
@@ -271,21 +286,23 @@ else()
271286

272287
endif()
273288

274-
add_library(viam_rust_utils SHARED IMPORTED)
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)
275292

276-
target_link_directories(viam_rust_utils
277-
INTERFACE
293+
target_link_directories(viam_rust_utils
294+
INTERFACE
278295
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>"
279296
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_LIBDIR}>"
280-
)
281-
282-
set_property(TARGET viam_rust_utils PROPERTY IMPORTED_LOCATION ${viam_rust_utils_file})
297+
)
283298

284-
install(
285-
IMPORTED_RUNTIME_ARTIFACTS viam_rust_utils
286-
LIBRARY COMPONENT viam-cpp-sdk_runtime
287-
)
299+
set_property(TARGET viam_rust_utils PROPERTY IMPORTED_LOCATION ${viam_rust_utils_file})
288300

301+
install(
302+
IMPORTED_RUNTIME_ARTIFACTS viam_rust_utils
303+
LIBRARY COMPONENT viam-cpp-sdk_runtime
304+
)
305+
endif()
289306

290307
# Install the license file
291308
install(FILES

conanfile.py

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def configure(self):
3939
# From some experiments it seems that the shared-ness of these packages
4040
# should match that of the SDK recipe. Failure to do so can cause linker
4141
# errors while compiling, or static initialization errors at runtime for modules.
42-
for lib in ["grpc", "protobuf"]:
42+
for lib in ["grpc", "protobuf", "abseil"]:
4343
self.options[lib].shared = True
4444

4545
def requirements(self):
@@ -49,8 +49,7 @@ def requirements(self):
4949
# maintained conan packages.
5050
self.requires('grpc/[>=1.48.4]')
5151
self.requires('protobuf/[>=3.17.1]')
52-
53-
self.requires('xtensor/[>=0.24.3]')
52+
self.requires('xtensor/[>=0.24.3]', transitive_headers=True)
5453

5554
def build_requirements(self):
5655
if self.options.offline_proto_generation:
@@ -66,6 +65,15 @@ def generate(self):
6665
tc.cache_variables["VIAMCPPSDK_OFFLINE_PROTO_GENERATION"] = self.options.offline_proto_generation
6766
tc.cache_variables["VIAMCPPSDK_USE_DYNAMIC_PROTOS"] = True
6867

68+
# We don't want to constrain these for conan builds because we
69+
# don't know the context where we might be being built. We
70+
# should permit the build if it works. Also, even the C++ SDK
71+
# is warnings clean on the modern compilers we use in CI, it,
72+
# or headers from its dependencies, might throw warnings with
73+
# older compilers, and we should still allow a build there.
74+
tc.cache_variables["VIAMCPPSDK_ENFORCE_COMPILER_MINIMA"] = False
75+
tc.cache_variables["VIAMCPPSDK_USE_WALL_WERROR"] = False
76+
6977
tc.cache_variables["VIAMCPPSDK_BUILD_TESTS"] = False
7078
tc.cache_variables["VIAMCPPSDK_BUILD_EXAMPLES"] = False
7179

@@ -82,7 +90,11 @@ def package(self):
8290
CMake(self).install()
8391

8492
def package_info(self):
85-
self.cpp_info.components["viam_rust_utils"].libs = ["viam_rust_utils"]
93+
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"]
8698

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

@@ -103,10 +115,16 @@ def package_info(self):
103115
else:
104116
lib_folder = os.path.join(self.package_folder, "lib")
105117
lib_fullpath = os.path.join(lib_folder, "libviamapi.a")
118+
if self.settings.os == "Windows":
119+
lib_fullpath = os.path.join(lib_folder, "viamapi.lib")
120+
106121
if is_apple_os(self):
107122
whole_archive = f"-Wl,-force_load,{lib_fullpath}"
123+
elif self.settings.os == "Windows":
124+
whole_archive = f"/WHOLEARCHIVE:{lib_fullpath}"
108125
else:
109126
whole_archive = f"-Wl,--push-state,--whole-archive,{lib_fullpath},--pop-state"
127+
110128
self.cpp_info.components["viamapi"].exelinkflags.append(whole_archive)
111129
self.cpp_info.components["viamapi"].sharedlinkflags.append(whole_archive)
112130

@@ -116,9 +134,14 @@ def package_info(self):
116134
"grpc::grpc++_reflection",
117135
"protobuf::libprotobuf",
118136
"xtensor::xtensor",
119-
120137
"viamapi",
121-
"viam_rust_utils"
122138
])
123139

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+
])
146+
124147
self.cpp_info.components["viamsdk"].frameworks = ["Security"]

src/viam/api/CMakeLists.txt

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,20 +63,34 @@ if (VIAMCPPSDK_USE_DYNAMIC_PROTOS)
6363
#
6464
find_program(BUF_COMMAND buf)
6565
if (NOT BUF_COMMAND)
66+
67+
set(HOST_SYSTEM_PROCESSOR_FOR_BUF_DOWNLOAD ${CMAKE_HOST_SYSTEM_PROCESSOR})
68+
if (CMAKE_HOST_WIN32)
69+
if (HOST_SYSTEM_PROCESSOR_FOR_BUF_DOWNLOAD STREQUAL "AMD64")
70+
set(HOST_SYSTEM_PROCESSOR_FOR_BUF_DOWNLOAD x86_64)
71+
elseif (HOST_SYSTEM_PROCESSOR_FOR_BUF_DOWNLOAD STREQUAL "ARM64")
72+
set(HOST_SYSTEM_PROCESSOR_FOR_BUF_DOWNLOAD arm64)
73+
else()
74+
message(FATAL_ERROR "Unknown Windows platform to correct buf download URL: ${HOST_SYSTEM_PROCESSOR_FOR_BUF_DOWNLOAD}")
75+
endif()
76+
endif()
77+
78+
set(BUF_DOWNLOAD_URL https://github.com/bufbuild/buf/releases/latest/download/buf-${CMAKE_HOST_SYSTEM_NAME}-${HOST_SYSTEM_PROCESSOR_FOR_BUF_DOWNLOAD}${CMAKE_HOST_EXECUTABLE_SUFFIX})
79+
6680
file(
6781
DOWNLOAD
68-
https://github.com/bufbuild/buf/releases/latest/download/buf-${CMAKE_HOST_SYSTEM_NAME}-${CMAKE_HOST_SYSTEM_PROCESSOR}
69-
${CMAKE_CURRENT_BINARY_DIR}/buf_latest
82+
${BUF_DOWNLOAD_URL}
83+
${CMAKE_CURRENT_BINARY_DIR}/buf_latest${CMAKE_HOST_EXECUTABLE_SUFFIX}
7084
STATUS buf_status
7185
)
7286
list(GET buf_status 0 buf_status_code)
7387
list(GET buf_status 1 buf_status_string)
7488

7589
if(NOT buf_status_code EQUAL 0)
76-
message(FATAL_ERROR "No local `buf` program found (try setting PATH?) and failed to download: ${buf_status_string}")
90+
message(FATAL_ERROR "No local `buf` program found (try setting PATH?) and failed to download: ${buf_status_string} for ${BUF_DOWNLOAD_URL}")
7791
endif()
7892

79-
set(BUF_COMMAND ${CMAKE_CURRENT_BINARY_DIR}/buf_latest)
93+
set(BUF_COMMAND ${CMAKE_CURRENT_BINARY_DIR}/buf_latest${CMAKE_HOST_EXECUTABLE_SUFFIX})
8094
file(CHMOD ${BUF_COMMAND} PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE)
8195
endif()
8296

@@ -113,6 +127,16 @@ if (VIAMCPPSDK_USE_DYNAMIC_PROTOS)
113127
)
114128
endif()
115129

130+
# List of names of non-compilable generated code
131+
# The Switch component generates protobuf which uses `switch` as a namespace.
132+
# This needs to be processed below.
133+
set(VIAMCPPSDK_SWITCH_REPLACE_PATHS
134+
${PROTO_GEN_DIR}/component/switch/v1/switch.grpc.pb.cc
135+
${PROTO_GEN_DIR}/component/switch/v1/switch.grpc.pb.h
136+
${PROTO_GEN_DIR}/component/switch/v1/switch.pb.cc
137+
${PROTO_GEN_DIR}/component/switch/v1/switch.pb.h
138+
)
139+
116140
add_custom_command(
117141
OUTPUT
118142
# Unfortunately, there isn't a good way to know in advance what
@@ -201,6 +225,10 @@ if (VIAMCPPSDK_USE_DYNAMIC_PROTOS)
201225
${PROTO_GEN_DIR}/component/servo/v1/servo.grpc.pb.h
202226
${PROTO_GEN_DIR}/component/servo/v1/servo.pb.cc
203227
${PROTO_GEN_DIR}/component/servo/v1/servo.pb.h
228+
${PROTO_GEN_DIR}/component/switch/v1/switch.grpc.pb.cc
229+
${PROTO_GEN_DIR}/component/switch/v1/switch.grpc.pb.h
230+
${PROTO_GEN_DIR}/component/switch/v1/switch.pb.cc
231+
${PROTO_GEN_DIR}/component/switch/v1/switch.pb.h
204232
${PROTO_GEN_DIR}/google/api/annotations.pb.cc
205233
${PROTO_GEN_DIR}/google/api/annotations.pb.h
206234
${PROTO_GEN_DIR}/google/api/httpbody.pb.cc
@@ -245,6 +273,9 @@ if (VIAMCPPSDK_USE_DYNAMIC_PROTOS)
245273
COMMAND ${BUF_COMMAND} generate ${BUF_GOOGLE_API_SOURCE} --template buf.gen.yaml --path google/rpc --path google/api
246274
COMMAND ${BUF_COMMAND} generate ${BUF_VIAM_GOUTILS_SOURCE} --template buf.gen.yaml
247275
COMMAND ${BUF_COMMAND} generate ${BUF_VIAM_API_SOURCE} --template buf.gen.yaml --path ${BUF_PROTO_COMPONENTS_JOINED}
276+
277+
# After generating the protos, include a step to invoke a search-and-replace for switch -> switch_ in the Switch component files
278+
COMMAND ${CMAKE_COMMAND} "-DSWITCH_REPLACE_PATHS=\"${VIAMCPPSDK_SWITCH_REPLACE_PATHS}\"" -P ${CMAKE_CURRENT_SOURCE_DIR}/viamcppsdk_replace_switch.cmake
248279
MAIN_DEPENDENCY buf.gen.yaml
249280
)
250281

@@ -328,6 +359,8 @@ target_sources(viamapi
328359
${PROTO_GEN_DIR}/component/sensor/v1/sensor.pb.cc
329360
${PROTO_GEN_DIR}/component/servo/v1/servo.grpc.pb.cc
330361
${PROTO_GEN_DIR}/component/servo/v1/servo.pb.cc
362+
${PROTO_GEN_DIR}/component/switch/v1/switch.grpc.pb.cc
363+
${PROTO_GEN_DIR}/component/switch/v1/switch.pb.cc
331364
${PROTO_GEN_DIR}/google/api/annotations.pb.cc
332365
${PROTO_GEN_DIR}/google/api/http.pb.cc
333366
${PROTO_GEN_DIR}/google/api/httpbody.pb.cc
@@ -390,6 +423,8 @@ target_sources(viamapi
390423
${PROTO_GEN_DIR}/../../viam/api/component/sensor/v1/sensor.pb.h
391424
${PROTO_GEN_DIR}/../../viam/api/component/servo/v1/servo.grpc.pb.h
392425
${PROTO_GEN_DIR}/../../viam/api/component/servo/v1/servo.pb.h
426+
${PROTO_GEN_DIR}/../../viam/api/component/switch/v1/switch.grpc.pb.h
427+
${PROTO_GEN_DIR}/../../viam/api/component/switch/v1/switch.pb.h
393428
${PROTO_GEN_DIR}/../../viam/api/google/api/annotations.pb.h
394429
${PROTO_GEN_DIR}/../../viam/api/google/api/http.pb.h
395430
${PROTO_GEN_DIR}/../../viam/api/google/api/httpbody.pb.h

src/viam/api/api_proto_tag.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v0.1.417
1+
v0.1.429

0 commit comments

Comments
 (0)