Skip to content

Commit

Permalink
Add ROSEnv example (#164)
Browse files Browse the repository at this point in the history
* rosenv example

* missing files

* changes

* add to readme

* add docker ci for the example

* fix

* fix

* Update examples/tools/ros/rosenv/workspace/consumer/CMakeLists.txt

Co-authored-by: Carlos Zoido <[email protected]>

* update example

* Update examples/tools/ros/rosenv/workspace/consumer/CMakeLists.txt

* test in github actions

* use bash

* fix cd

* wip

* Update examples/tools/README.md

Co-authored-by: Carlos Zoido <[email protected]>

* Update .github/workflows/ros-tests.yml

* add develop2 testing

* wip

* wip

* minor changes

* wip

---------

Co-authored-by: Carlos Zoido <[email protected]>
  • Loading branch information
danimtb and czoido authored Nov 14, 2024
1 parent b09d9cb commit be895a1
Show file tree
Hide file tree
Showing 13 changed files with 207 additions and 1 deletion.
52 changes: 52 additions & 0 deletions .github/workflows/ros-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: ROS and Conan Integration Test

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
test_conan_release:
runs-on: ubuntu-latest
container:
image: osrf/ros:humble-desktop

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Configure environment and install Conan release
run: |
apt-get update && apt-get install -y python3 python3-pip
python3 -m pip install conan
chmod +x ./examples/tools/ros/rosenv/workspace/test_ros.sh
- name: Run example with latest Conan release
shell: bash
run: |
cd examples/tools/ros/rosenv/workspace
./test_ros.sh
test_conan_develop2:
runs-on: ubuntu-latest
container:
image: osrf/ros:humble-desktop

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Configure environment and install Conan from develop2 branch
run: |
apt-get update && apt-get install -y python3 python3-pip
python3 -m pip install git+https://github.com/conan-io/conan.git
chmod +x ./examples/tools/ros/rosenv/workspace/test_ros.sh
- name: Run example with Conan from repo
shell: bash
run: |
cd examples/tools/ros/rosenv/workspace
./test_ros.sh
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,6 @@ examples/tools/google/bazeltoolchain/7_x/string_formatter/MODULE.bazel.lock
examples/libraries/libcurl/ascii_art_color/conan/*
examples/libraries/libcurl/ascii_art_color/asciiartgen/x64/*
examples/libraries/libcurl/ascii_art_color/x64/Release/*

examples/tools/ros/rosenv/workspace/install/
examples/tools/ros/rosenv/workspace/log/
4 changes: 4 additions & 0 deletions examples/tools/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,7 @@

- Build a [Bazel 6.x compatible project](bazel/bazeltoolchain/6_x/string_formatter/) using Conan and [fmt](https://fmt.dev/). [Docs](https://docs.conan.io/2/examples/tools/google/bazeltoolchain/build_simple_bazel_project.rst)
- Build a [Bazel >= 7.1 compatible project](bazel/bazeltoolchain/7_x/string_formatter/) using Conan and [fmt](https://fmt.dev/). [Docs](https://docs.conan.io/2/examples/tools/google/bazeltoolchain/build_simple_bazel_7x_project.rst)

### [tools.ros](ros)

- Build [ROS packages inside their workspace](ros/rosenv/workspace/) using dependencies from Conan Center and consuming them also as transitive dependencies.
24 changes: 24 additions & 0 deletions examples/tools/ros/rosenv/workspace/consumer/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
cmake_minimum_required(VERSION 3.8)
project(consumer)

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
endif()

# find dependencies
find_package(ament_cmake REQUIRED)
find_package(str_printer REQUIRED)

add_executable(main src/main.cpp)

target_include_directories(main PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/consumer>
$<INSTALL_INTERFACE:include>)

target_compile_features(main PUBLIC c_std_99 cxx_std_17) # Require C99 and C++17
ament_target_dependencies(main str_printer)

install(TARGETS main
DESTINATION lib/${PROJECT_NAME})

ament_package()
20 changes: 20 additions & 0 deletions examples/tools/ros/rosenv/workspace/consumer/package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>consumer</name>
<version>0.0.0</version>
<description>Consumer application that prints a fancy string</description>
<maintainer email="[email protected]">danimtb</maintainer>
<license>MIT</license>

<buildtool_depend>ament_cmake</buildtool_depend>

<test_depend>ament_lint_auto</test_depend>
<test_depend>ament_lint_common</test_depend>

<depend>str_printer</depend>

<export>
<build_type>ament_cmake</build_type>
</export>
</package>
10 changes: 10 additions & 0 deletions examples/tools/ros/rosenv/workspace/consumer/src/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include "str_printer/str_printer.h"

int main(int argc, char ** argv)
{
(void) argc;
(void) argv;

str_printer("Hi there! I am using fmt library fetched with Conan C/C++ Package Manager");
return 0;
}
38 changes: 38 additions & 0 deletions examples/tools/ros/rosenv/workspace/str_printer/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
cmake_minimum_required(VERSION 3.8)
project(str_printer)

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
endif()

# find dependencies
find_package(ament_cmake REQUIRED)
find_package(fmt REQUIRED) # Retrieved with Conan C/C++ Package Manager

add_library(str_printer src/str_printer.cpp)

target_include_directories(str_printer PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/str_printer>
$<INSTALL_INTERFACE:include>)

target_compile_features(str_printer PUBLIC c_std_99 cxx_std_17) # Require C99 and C++17
ament_target_dependencies(str_printer fmt)

ament_export_targets(str_printerTargets HAS_LIBRARY_TARGET)
ament_export_dependencies(fmt)

install(
DIRECTORY include/
DESTINATION include
)

install(
TARGETS str_printer
EXPORT str_printerTargets
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
RUNTIME DESTINATION bin
INCLUDES DESTINATION include
)

ament_package()
7 changes: 7 additions & 0 deletions examples/tools/ros/rosenv/workspace/str_printer/conanfile.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[requires]
fmt/11.0.2

[generators]
CMakeDeps
CMakeToolchain
ROSEnv
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once

#include <string>

#ifdef WIN32
#define FN_EXPORT __declspec(dllexport)
#else
#define FN_EXPORT
#endif

FN_EXPORT void str_printer(std::string);
18 changes: 18 additions & 0 deletions examples/tools/ros/rosenv/workspace/str_printer/package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>str_printer</name>
<version>0.0.0</version>
<description>Library that provides a function to print a fancy string using the fmt library fetched by Conan C/C++ Package Manager</description>
<maintainer email="[email protected]">danimtb</maintainer>
<license>MIT</license>

<buildtool_depend>ament_cmake</buildtool_depend>

<test_depend>ament_lint_auto</test_depend>
<test_depend>ament_lint_common</test_depend>

<export>
<build_type>ament_cmake</build_type>
</export>
</package>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include <iostream>
#include <string>

#include "fmt/core.h"
#include "fmt/color.h"

#include "str_printer.h"

void str_printer(std::string str) {
fmt::print(fmt::fg(fmt::color::gold) | fmt::emphasis::bold, "{}\n", str);
}
8 changes: 8 additions & 0 deletions examples/tools/ros/rosenv/workspace/test_ros.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
source /opt/ros/humble/setup.bash
conan profile detect --force
conan install str_printer/conanfile.txt --build=missing --output-folder install/conan
source install/conan/conanrosenv.sh
colcon build --packages-select str_printer
colcon build --packages-select consumer
source install/setup.bash
ros2 run consumer main
2 changes: 1 addition & 1 deletion test/examples_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def run(cmd, error=False):
print("Running: {}".format(cmd))
start_time = time.time()

process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True, text=True)
process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True, text=True, encoding='utf-8')

output = ''

Expand Down

0 comments on commit be895a1

Please sign in to comment.