-
Notifications
You must be signed in to change notification settings - Fork 0
Add example with conan workspaces #33
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
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import platform | ||
|
|
||
| from test.examples_tools import VARIANT_ARGS, run | ||
|
|
||
| run( | ||
| f"conan workspace build --profile ../../profiles/ros {VARIANT_ARGS} --build=missing" | ||
| ) | ||
|
|
||
| if platform.system() == "Windows": | ||
| run( | ||
| r"call .\src\consumer_node\build\generators\conanrun.bat && " | ||
| r".\src\consumer_node\build\Release\consumer_node.exe" | ||
| ) | ||
| else: | ||
| run( | ||
| ". ./src/consumer_node/build/Release/generators/conanrun.sh && " | ||
| "./src/consumer_node/build/Release/consumer_node" | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| name: conan_workspace | ||
| packages: | ||
| - path: src/dummy_lib | ||
| ref: dummy_lib/0.1 | ||
| - path: src/consumer_node | ||
| ref: consumer_node/0.1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| # conan_workspace | ||
|
|
||
| Same layout as [`consumer_colcon`](../consumer_colcon/readme.md) — two packages under | ||
| `src/` — but orchestrated with a [Conan workspace](https://docs.conan.io/2/tutorial/developing_packages/workspaces.html) | ||
| instead of `colcon`. There is no `package.xml`, no `ament_cmake`, and no `colcon`: | ||
| each package is a plain CMake project with its own `conanfile.py`. Workspace packages | ||
| are resolved as [editables](https://docs.conan.io/2/tutorial/developing_packages/editable_packages.html) | ||
| and built in dependency order. | ||
|
|
||
| - `dummy_lib` — a static library with no ROS dependencies, used to demonstrate | ||
| cross-package linking inside the workspace. | ||
| - `consumer_node` — depends on `dummy_lib` and `ros-kilted` (`rclcpp`), prints a | ||
| message and starts a short-lived node. | ||
|
|
||
| [← back to main README](../../README.md) | ||
|
|
||
| ## Layout | ||
|
|
||
| ```text | ||
| conan_workspace/ | ||
| ├── conanws.yml # workspace root + package inventory | ||
| └── src/ | ||
| ├── dummy_lib/ | ||
| │ ├── conanfile.py # replaces package.xml | ||
| │ ├── CMakeLists.txt | ||
| │ ├── include/ | ||
| │ └── src/ | ||
| └── consumer_node/ | ||
| ├── conanfile.py | ||
| ├── CMakeLists.txt | ||
| └── src/ | ||
| ``` | ||
|
|
||
| Conan walks up from the current directory until it finds `conanws.yml` and/or | ||
| `conanws.py`; that folder is the workspace root. Paths in `conanws.yml` are | ||
| relative to it. | ||
|
|
||
| This example only needs `conanws.yml`. A `conanws.py` is optional Python | ||
| customization (`root_conanfile()` for a monolithic super-build, custom | ||
| `add`/`clean`/`build_order`, or `get_ref()` when name/version come from | ||
| `python_requires`). Orchestrated `conan workspace build` does not use any of | ||
| that. | ||
|
|
||
| This example uses the **orchestrated** workspace flow (`conan workspace build`), | ||
| which is the closest analogue to `colcon build`: each package is configured and | ||
| built on its own, in topological order, with workspace members consumed as | ||
| editables. | ||
|
|
||
| Conan workspaces are experimental and subject to breaking changes — see the | ||
| [Conan stability notes](https://docs.conan.io/2/introduction.html#stability). | ||
|
|
||
| ## How it is wired | ||
|
|
||
| | Piece | Role | | ||
| | ----- | ---- | | ||
| | [`conanws.yml`](conanws.yml) | Lists `src/dummy_lib` and `src/consumer_node` as workspace packages. | | ||
| | [`src/dummy_lib/conanfile.py`](src/dummy_lib/conanfile.py) | CMake library recipe: `CMakeToolchain` + `CMakeDeps`, `cmake_layout()`. | | ||
| | [`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`. | | ||
| | CMake | Plain `find_package(dummy_lib)` / `find_package(rclcpp)` — configs come from Conan, not from sourcing a ROS `setup` script. | | ||
|
|
||
| `conan workspace build` is `conan build` for every workspace package, in the | ||
| right order. External dependencies (`ros-kilted` and its graph) are installed | ||
| from the cache/remotes; `dummy_lib` is never looked up as a binary because it | ||
| is in the workspace. | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| - A C++17 compiler. | ||
| - CMake ≥ 3.22 (the [profile](../../profiles/ros) tool-requires `cmake/3.29.3`). | ||
| - Conan 2.31+ (For `conan workspace build`, as the feature has received recent improvements). | ||
| - A Conan remote that exposes `ros-kilted` — see the | ||
| [main README](../../README.md#quick-start). | ||
|
|
||
| ## Build & run | ||
|
|
||
| From this directory: | ||
|
|
||
| ```bash | ||
| conan workspace build --profile ../../profiles/ros --build=missing | ||
| ``` | ||
|
|
||
| Then activate the consumer's Conan run environment and execute the node: | ||
|
|
||
| **Windows (cmd):** | ||
|
|
||
| ```bat | ||
| call src\consumer_node\build\generators\conanrun.bat | ||
| src\consumer_node\build\Release\consumer_node.exe | ||
| ``` | ||
|
|
||
| **macOS / Linux (bash/zsh):** | ||
|
|
||
| ```bash | ||
| . ./src/consumer_node/build/Release/generators/conanrun.sh | ||
| ./src/consumer_node/build/Release/consumer_node | ||
| ``` | ||
|
|
||
| Expected output (truncated): | ||
|
|
||
| ```text | ||
| [dummy_lib] hello from library | ||
| [INFO] [...] [workspace_consumer_node]: Conan workspace consumer_node: rclcpp linked and node started. | ||
| ``` | ||
|
|
||
| The exact CI invocation lives in [`ci_test_example.py`](ci_test_example.py). | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| cmake_minimum_required(VERSION 3.22) | ||
| project(consumer_node CXX) | ||
|
|
||
| find_package(dummy_lib REQUIRED) | ||
| find_package(rclcpp REQUIRED) | ||
|
|
||
| add_executable(consumer_node src/main.cpp) | ||
| target_link_libraries(consumer_node PRIVATE dummy_lib::dummy_lib rclcpp::rclcpp) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| from conan import ConanFile | ||
| from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout | ||
|
|
||
|
|
||
| class ConsumerNodeConan(ConanFile): | ||
| name = "consumer_node" | ||
| version = "0.1" | ||
| package_type = "application" | ||
| settings = "os", "compiler", "build_type", "arch" | ||
| exports_sources = "CMakeLists.txt", "src/*" | ||
|
|
||
| def layout(self): | ||
| cmake_layout(self) | ||
|
|
||
| def requirements(self): | ||
| self.requires("dummy_lib/0.1") | ||
| self.requires("ros-kilted/2026.06.17") | ||
|
|
||
| def generate(self): | ||
| CMakeDeps(self).generate() | ||
| CMakeToolchain(self).generate() | ||
|
|
||
| def build(self): | ||
| cmake = CMake(self) | ||
| cmake.configure() | ||
| cmake.build() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| #include <memory> | ||
|
|
||
| #include <dummy_lib/print.hpp> | ||
| #include <rclcpp/rclcpp.hpp> | ||
|
|
||
| int main(int argc, char ** argv) | ||
| { | ||
| dummy_lib::print_hello(); | ||
|
|
||
| rclcpp::init(argc, argv); | ||
| auto node = std::make_shared<rclcpp::Node>("workspace_consumer_node"); | ||
| RCLCPP_INFO(node->get_logger(), "Conan workspace consumer_node: rclcpp linked and node started."); | ||
| rclcpp::shutdown(); | ||
| return 0; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| cmake_minimum_required(VERSION 3.22) | ||
| project(dummy_lib CXX) | ||
|
|
||
| add_library(dummy_lib STATIC src/print.cpp) | ||
| target_include_directories(dummy_lib PUBLIC | ||
| "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>" | ||
| "$<INSTALL_INTERFACE:include>") | ||
|
|
||
| install(TARGETS dummy_lib | ||
| ARCHIVE DESTINATION lib | ||
| LIBRARY DESTINATION lib | ||
| RUNTIME DESTINATION bin) | ||
| install(DIRECTORY include/ DESTINATION include) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| from conan import ConanFile | ||
| from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout | ||
|
|
||
|
|
||
| class DummyLibConan(ConanFile): | ||
| name = "dummy_lib" | ||
| version = "0.1" | ||
| package_type = "static-library" | ||
| settings = "os", "compiler", "build_type", "arch" | ||
| exports_sources = "CMakeLists.txt", "src/*", "include/*" | ||
|
|
||
| def layout(self): | ||
| cmake_layout(self) | ||
|
|
||
| def generate(self): | ||
| CMakeDeps(self).generate() | ||
| CMakeToolchain(self).generate() | ||
|
|
||
| def build(self): | ||
| cmake = CMake(self) | ||
| cmake.configure() | ||
| cmake.build() | ||
|
|
||
| def package(self): | ||
| cmake = CMake(self) | ||
| cmake.install() | ||
|
|
||
| def package_info(self): | ||
| self.cpp_info.libs = ["dummy_lib"] |
12 changes: 12 additions & 0 deletions
12
examples/conan_workspace/src/dummy_lib/include/dummy_lib/print.hpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| #ifndef DUMMY_LIB__PRINT_HPP_ | ||
| #define DUMMY_LIB__PRINT_HPP_ | ||
|
|
||
| namespace dummy_lib | ||
| { | ||
|
|
||
| /** Writes a fixed dummy message to stdout (example library API). */ | ||
| void print_hello(); | ||
|
|
||
| } // namespace dummy_lib | ||
|
|
||
| #endif // DUMMY_LIB__PRINT_HPP_ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| #include <cstdio> | ||
|
|
||
| #include "dummy_lib/print.hpp" | ||
|
|
||
| namespace dummy_lib | ||
| { | ||
|
|
||
| void print_hello() | ||
| { | ||
| std::puts("[dummy_lib] hello from library"); | ||
| } | ||
|
|
||
| } // namespace dummy_lib |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.