|
| 1 | +# conan_workspace |
| 2 | + |
| 3 | +Same layout as [`consumer_colcon`](../consumer_colcon/readme.md) — two packages under |
| 4 | +`src/` — but orchestrated with a [Conan workspace](https://docs.conan.io/2/tutorial/developing_packages/workspaces.html) |
| 5 | +instead of `colcon`. There is no `package.xml`, no `ament_cmake`, and no `colcon`: |
| 6 | +each package is a plain CMake project with its own `conanfile.py`. Workspace packages |
| 7 | +are resolved as [editables](https://docs.conan.io/2/tutorial/developing_packages/editable_packages.html) |
| 8 | +and built in dependency order. |
| 9 | + |
| 10 | +- `dummy_lib` — a static library with no ROS dependencies, used to demonstrate |
| 11 | + cross-package linking inside the workspace. |
| 12 | +- `consumer_node` — depends on `dummy_lib` and `ros-kilted` (`rclcpp`), prints a |
| 13 | + message and starts a short-lived node. |
| 14 | + |
| 15 | +[← back to main README](../../README.md) |
| 16 | + |
| 17 | +## Layout |
| 18 | + |
| 19 | +```text |
| 20 | +conan_workspace/ |
| 21 | +├── conanws.yml # workspace root + package inventory |
| 22 | +└── src/ |
| 23 | + ├── dummy_lib/ |
| 24 | + │ ├── conanfile.py # replaces package.xml |
| 25 | + │ ├── CMakeLists.txt |
| 26 | + │ ├── include/ |
| 27 | + │ └── src/ |
| 28 | + └── consumer_node/ |
| 29 | + ├── conanfile.py |
| 30 | + ├── CMakeLists.txt |
| 31 | + └── src/ |
| 32 | +``` |
| 33 | + |
| 34 | +Conan walks up from the current directory until it finds `conanws.yml` and/or |
| 35 | +`conanws.py`; that folder is the workspace root. Paths in `conanws.yml` are |
| 36 | +relative to it. |
| 37 | + |
| 38 | +This example only needs `conanws.yml`. A `conanws.py` is optional Python |
| 39 | +customization (`root_conanfile()` for a monolithic super-build, custom |
| 40 | +`add`/`clean`/`build_order`, or `get_ref()` when name/version come from |
| 41 | +`python_requires`). Orchestrated `conan workspace build` does not use any of |
| 42 | +that. |
| 43 | + |
| 44 | +This example uses the **orchestrated** workspace flow (`conan workspace build`), |
| 45 | +which is the closest analogue to `colcon build`: each package is configured and |
| 46 | +built on its own, in topological order, with workspace members consumed as |
| 47 | +editables. |
| 48 | + |
| 49 | +Conan workspaces are experimental and subject to breaking changes — see the |
| 50 | +[Conan stability notes](https://docs.conan.io/2/introduction.html#stability). |
| 51 | + |
| 52 | +## How it is wired |
| 53 | + |
| 54 | +| Piece | Role | |
| 55 | +| ----- | ---- | |
| 56 | +| [`conanws.yml`](conanws.yml) | Lists `src/dummy_lib` and `src/consumer_node` as workspace packages. | |
| 57 | +| [`src/dummy_lib/conanfile.py`](src/dummy_lib/conanfile.py) | CMake library recipe: `CMakeToolchain` + `CMakeDeps`, `cmake_layout()`. | |
| 58 | +| [`src/consumer_node/conanfile.py`](src/consumer_node/conanfile.py) | Requires `dummy_lib/0.1` (editable, from this workspace) and `ros-kilted/2026.06.17`. | |
| 59 | +| CMake | Plain `find_package(dummy_lib)` / `find_package(rclcpp)` — configs come from Conan, not from sourcing a ROS `setup` script. | |
| 60 | + |
| 61 | +`conan workspace build` is `conan build` for every workspace package, in the |
| 62 | +right order. External dependencies (`ros-kilted` and its graph) are installed |
| 63 | +from the cache/remotes; `dummy_lib` is never looked up as a binary because it |
| 64 | +is in the workspace. |
| 65 | + |
| 66 | +## Prerequisites |
| 67 | + |
| 68 | +- A C++17 compiler. |
| 69 | +- CMake ≥ 3.22 (the [profile](../../profiles/ros) tool-requires `cmake/3.29.3`). |
| 70 | +- Conan 2.31+ (For `conan workspace build`, as the feature has received recent improvements). |
| 71 | +- A Conan remote that exposes `ros-kilted` — see the |
| 72 | + [main README](../../README.md#quick-start). |
| 73 | + |
| 74 | +## Build & run |
| 75 | + |
| 76 | +From this directory: |
| 77 | + |
| 78 | +```bash |
| 79 | +conan workspace build --profile ../../profiles/ros --build=missing |
| 80 | +``` |
| 81 | + |
| 82 | +Then activate the consumer's Conan run environment and execute the node: |
| 83 | + |
| 84 | +**Windows (cmd):** |
| 85 | + |
| 86 | +```bat |
| 87 | +call src\consumer_node\build\generators\conanrun.bat |
| 88 | +src\consumer_node\build\Release\consumer_node.exe |
| 89 | +``` |
| 90 | + |
| 91 | +**macOS / Linux (bash/zsh):** |
| 92 | + |
| 93 | +```bash |
| 94 | +. ./src/consumer_node/build/Release/generators/conanrun.sh |
| 95 | +./src/consumer_node/build/Release/consumer_node |
| 96 | +``` |
| 97 | + |
| 98 | +Expected output (truncated): |
| 99 | + |
| 100 | +```text |
| 101 | +[dummy_lib] hello from library |
| 102 | +[INFO] [...] [workspace_consumer_node]: Conan workspace consumer_node: rclcpp linked and node started. |
| 103 | +``` |
| 104 | + |
| 105 | +The exact CI invocation lives in [`ci_test_example.py`](ci_test_example.py). |
0 commit comments