Skip to content

Commit 91df7e5

Browse files
authored
Merge branch 'main' into local-protos
2 parents 2d856ea + 352f025 commit 91df7e5

File tree

4 files changed

+222
-190
lines changed

4 files changed

+222
-190
lines changed

README.md

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -11,50 +11,7 @@
1111

1212
## Getting Started
1313

14-
Please see [BUILDING.md](https://github.com/viamrobotics/viam-cpp-sdk/blob/main/BUILDING.md) for instructions on how to use CMake-based build system for this project.
15-
16-
NOTE: Windows is not supported. If you are using Windows, build the project in WSL.
17-
18-
## Using Docker for Development
19-
20-
Some Dockerfiles are provided for C++ SDK development, either for developing
21-
on the SDK itself, or for module development. The docker images are split up
22-
into base images, found in [etc/docker/base-images](etc/docker/base-images), and
23-
an [SDK build image](etc/docker/Dockerfile.sdk-build). The base images install
24-
apt packages required to build and develop the SDK, whereas the SDK build image
25-
is meant to be built on top of a base image using multi-stage Docker building.
26-
27-
From the root of this repository, run
28-
```shell
29-
docker build -t base/bullseye -f etc/docker/base-images/Dockerfile.debian.bullseye .
30-
```
31-
This will create a Debian Bullseye base image. Note the use of the `-t base/bullseye`
32-
arg to assign a tag to the image, which is important for the next step. You can then
33-
use `Dockerfile.sdk-build` in a couple different ways.
34-
35-
```shell
36-
docker build --build-arg BASE_TAG=base/bullseye --build-arg GIT_TAG=[...] -f etc/docker/Dockerfile.sdk-build .
37-
```
38-
39-
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
41-
https://github.com/viamrobotics/viam-cpp-sdk/. This is the recommended approach for
42-
C++ module development, which should generally be done against a tagged release.
43-
44-
You can also do
45-
```shell
46-
docker build --build-arg BASE_TAG=base/bullseye --build-arg REPO_SETUP=copy -f etc/docker/Dockerfile.sdk-build .
47-
```
48-
49-
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
51-
GitHub. This approach may make more sense for developing on the SDK itself, or if
52-
your C++ SDK development relies on a localversion of the SDK.
53-
54-
The examples above illustrated the use of several `--build-arg` arguments, namely
55-
`BASE_TAG`, `GIT_TAG`, and `REPO_SETUP`. Please see
56-
[Dockerfile.sdk-build](etc/docker/Dockerfile.sdk-build) for a complete account of
57-
all build arguments and their defaults.
14+
Please see [BUILDING.md](doc/BUILDING.md) for instructions on how to use CMake-based build system for this project.
5815

5916
## Building Documentation Locally for Testing
6017
The C++ sdk uses [Doxygen](https://www.doxygen.nl/) to generate documentation.

BUILDING.md renamed to doc/BUILDING.md

Lines changed: 30 additions & 146 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,29 @@
11
# Viam C++ SDK - Build Instructions
22
## Overview
33

4-
The `viam-cpp-sdk` has a newly introduced CMake build system to
5-
replace the existing Makefile infrastructure. This document explains
6-
how to use the new infrastructure.
4+
The Viam C++ SDK uses CMake for build system generation. Below,
5+
we walk through the use case of directly invoking CMake to develop on
6+
Linux or Mac, with the help of the system package manager.
7+
Some other approaches are possible, covered in separate documents. These include
8+
9+
- [Using the Conan package manager.](conan.md)
10+
This allows you to manage dependencies with Conan, or to
11+
create or consume a Viam C++ SDK package. This is supported on Windows, Linux, and Mac, but on
12+
Windows it is the only approach with first class support. This also provides a practical way to work
13+
with older Linux distributions where the system packages may not otherwise be usable.
14+
- [Using Docker for C++ SDK or Module development.](docker-dev.md)
15+
16+
Generally speaking, a developer may want to _build the SDK_ for the purpose of developing the SDK itself,
17+
or they may want to _build against the SDK_ for the purpose of writing a Viam C++ Module based on the
18+
Viam C++ SDK. In this document and the others linked above, we will distinguish between these use cases.
719

820
If you experience problems while following this guide, please see the
9-
`Limitations, Known Issues, and Troubleshooting` section at the bottom
10-
to see if your issue (and hopefully a workaround) is covered there.
21+
[Limitations, Known Issues, and Troubleshooting](#limitations-known-issues-and-troubleshooting)
22+
section at the bottom to see if your issue (and hopefully a workaround) is covered there.
1123

12-
PLEASE NOTE: It is very likely that you will need to rebuild the
13-
generated sources as part of building the SDK. Please see the
14-
documentation on `VIAMCPPSDK_USE_DYNAMIC_PROTOS` below, and the
15-
additional comments about mismatched protobufs in the troubleshooting
16-
guide, before continuing further.
24+
## Building the SDK
1725

18-
## Software Prerequisites
26+
### Software Prerequisites
1927

2028
The project depends on [CMake](https://cmake.org/) >= 3.25,
2129
[Boost](https://www.boost.org/) >= 1.74, [gRPC](https://grpc.io/) >=
@@ -25,22 +33,21 @@ and on the transitive dependencies of
2533
those projects.
2634

2735
You will need to install these required dependencies before building
28-
the Viam C++ SDK, preferably by way of your system package manager:
36+
the Viam C++ SDK, preferably using your system package manager:
2937

30-
- Debian: `apt-get install cmake build-essential libboost-all-dev libgrpc++-dev libprotobuf-dev libxtensor-dev`
38+
- Linux: `apt-get install cmake build-essential libboost-all-dev libgrpc++-dev libprotobuf-dev libxtensor-dev`
3139
- MacOS with Homebrew: `brew install cmake boost grpc protobuf xtensor`
3240

3341
There are also several optional or conditionally required dependencies:
3442

35-
- Debian: `apt-get install pkg-config ninja-build protobuf-compiler-grpc`
43+
- Linux: `apt-get install pkg-config ninja-build protobuf-compiler-grpc`
3644
- MacOS with Homebrew: `brew install pkg-config ninja buf`
3745

38-
The `pkg-config` dependency is needed if your local system does not
39-
provide CMake `find_package` support for one or more required
40-
dependencies like `gRPC`.
46+
The `pkg-config` dependency is needed for very old Ubuntu (Jammy) or Debian (Bullseye)
47+
for which the system `gRPC` package does not have CMake `find_package` support.
4148

4249
The `ninja[-build]` dependency is only required if you want to use
43-
Ninja as the target build system, so is entirely optional.
50+
Ninja as the target build system.
4451

4552
You will need `protobuf-compiler-grpc` if you intend to do local
4653
dynamic protobuf generation (see the relevant SDK options below) or if
@@ -67,12 +74,7 @@ manually rather than via your package manager, though this is likely
6774
to make it more difficult to correctly configure the build of the Viam
6875
C++ SDK.
6976

70-
## Obtaining the `viam-cpp-sdk` Source
71-
72-
Just clone https://github.com/viamrobotics/viam-cpp-sdk into a
73-
directory of your choice and checkout the branch or tag of interest.
74-
75-
## Invoking CMake to Generate a Build System
77+
### Invoking CMake to Generate a Build System
7678

7779
This document doesn't intend to provide a complete guide for how CMake
7880
is used, as that is a complex topic. Please consult the [CMake
@@ -89,7 +91,8 @@ under the root of the project. The `viam-cpp-sdk` top-level
8991
starting there:
9092

9193
``` shell
92-
git clone https://github.com/viamrobotics/viam-cpp-sdk
94+
git clone https://github.com/viamrobotics/viam-cpp-sdk.git
95+
# Optionally: git checkout branch-or-tag-of-interest
9396
cd viam-cpp-sdk
9497
mkdir build
9598
cd build
@@ -120,7 +123,7 @@ show this, since the `build` directory is ignored.
120123
If you wish to use a different generator than Ninja, change the
121124
argument to `-G` above to the build system you wish to generate for.
122125

123-
## Building and Installing the SDK
126+
### Building and Installing the SDK
124127

125128
To compile all targets in the SDK:
126129

@@ -141,128 +144,9 @@ an installation tree under `build/install`.
141144

142145
If the build did not succeed, please see the next section.
143146

144-
## Building with `conan`
145-
146-
The Viam C++ SDK provides first class support for the `conan` C++
147-
package manager. This section will go into more detail
148-
without assuming any familiarity with `conan`, but please consult the
149-
[`conan` docs](https://docs.conan.io/2/introduction.html) for more info.
150-
151-
To use `conan`, you'll need to have `python` and `pip` on your system if
152-
you don't already. For example,
153-
154-
- Debian: `apt-get install python3 python3-pip`
155-
- MacOS with Homebrew: `brew install python`
156-
157-
and then, optionally in a venv if you prefer,
158-
159-
```shell
160-
pip install conan
161-
conan profile detect
162-
```
163-
164-
The second line detects a default [`conan`
165-
profile](https://docs.conan.io/2/reference/config_files/profiles.html)
166-
encapsulating your build environment, which you can modify as needed.
167-
168-
Next note that there are two possible approaches here, which complement
169-
or supersede some of the other sections in this document. Namely, it is
170-
possible to
171-
172-
1. use `conan` to build and package the SDK; OR
173-
2. use `conan` to obtain the [software
174-
prerequisites](#software-prerequisites) for the SDK.
175-
176-
Option 1. makes more sense for [building against the
177-
SDK](#building-against-the-sdk) as you would in module development.
178-
There we use `conan` to get the SDK's dependencies, and then to build,
179-
install, and package the SDK, which can then be consumed by declaring it
180-
as a `conan` dependency.
181-
182-
Option 2. makes more sense for doing locally development *on* the SDK
183-
while using `conan` to get dependencies instead of your system package
184-
manager. Note that Option 1 implies a superset of Option 2.
185-
186-
In either case, `conan` will use the [`conanfile.py`](/conanfile.py).
187-
Note that we build with `offline_proto_generation=True` by default.
188-
189-
### Option 1. Creating and consuming the SDK `conan` package.
190-
191-
Here we use `conan` to package and install the SDK so that we can build
192-
against it by declaring it as a dependency in a
193-
`conanfile.txt` or a `conanfile.py`.
194-
195-
To do this, call `conan create .` from the project root. This will build
196-
and test the `viam-cpp-sdk` recipe, adding it into your local cache. See
197-
the [conan docs](https://docs.conan.io/2/reference/commands/create.html)
198-
for more info on `conan create`, as we will omit any details about using
199-
profiles, options, or settings to customize the build.
200-
201-
Once this is done, the `viam-cpp-sdk` package is ready to be consumed.
202-
The example projects show a [minimal
203-
`conanfile.txt`](src/viam/examples/project/cmake/conanfile.txt). With
204-
this `conanfile.txt` in the same directory as your project's
205-
`CMakeLists.txt`, you can then do, for example,
206-
207-
```shell
208-
conan install . --output-folder=build-conan --build=missing
209-
cmake . --preset=conan-release
210-
cmake --build --preset=conan-release -j 8
211-
```
212-
213-
Note that this can be done with the same `CMakeLists.txt` from the
214-
[example project](src/viam/examples/project/cmake/CMakeLists.txt): it is
215-
agnostic of the use of `conan` to package the SDK as opposed to the SDK
216-
having been built and installed manually.
217-
218-
It is also possible to build using a `conanfile.py` rather than a
219-
`conanfile.txt`, see again the [conan
220-
docs](https://docs.conan.io/2/tutorial/consuming_packages/the_flexibility_of_conanfile_py.html#consuming-packages-flexibility-of-conanfile-py),
221-
or look at the [`test_package/conanfile.py`](test_package/conanfile.py)
222-
which is the test package recipe.
223-
224-
### Option 2. Using `conan` to manage the SDK dependencies
225-
226-
Here we use `conan` to grab the SDK dependencies, setting ourselves up
227-
for local SDK development.
228-
229-
From the root of this repo, you can do
230-
``` shell
231-
conan install . --output-folder=build-conan --build=missing
232-
```
233-
to install dependencies with `conan`. And then
234-
``` shell
235-
cmake . --preset conan-release
236-
cmake --build --preset=conan-release -j
237-
```
238-
The `conan install` sets up some
239-
[cmake-presets](https://cmake.org/cmake/help/latest/manual/cmake-presets.7.html)
240-
which are used to resolve `--preset conan-release` above. Among other
241-
things, this tells CMake about the `conan_toolchain.cmake` generated by
242-
`conan`, and runs CMake with certain environment variables set.
243-
244-
If you do not want to use cmake-presets, you can do
245-
``` shell
246-
cd build-conan
247-
source conanbuild.sh
248-
cmake .. -G Ninja -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake
249-
```
250-
and later call `source deactivate_conanbuild.sh`. The `conanbuild.sh`
251-
script does the same environment variable setting as the cmake-presets,
252-
but it may be preferable if you would rather invoke your build system
253-
directly.
254-
255-
PLEASE NOTE: Whether by cmake-presets or `conanbuild.sh`, you MUST, one
256-
way or another, make the `PATH` entries set by `conan` available to
257-
CMake, because `buf` requires that `protoc` is available on `PATH`. If
258-
you do not do this then `buf generate` will fail outright, or, if you
259-
have a different version of `protoc` available in your `PATH`, it will
260-
silently fail and later cause compilation failures due to protobuf
261-
version mismatches.
262-
263147
## Building for ARM Windows
264148

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

0 commit comments

Comments
 (0)