Skip to content

Commit bdfb98d

Browse files
Convert sas_core to a thin wrapper around sas_cpp (.deb) and sas_py (PyPI)
The C++ implementation (src/*.cpp), the pybind11 bindings and the pybind11 submodule no longer live in this package. Instead: - C++: depends on the libmarinholab-sas-core .deb (source: MarinhoLab/sas_cpp), which provides libmarinholab_sas_core, the headers and the CMake package config (find_package(marinholab_sas_core)). include/sas_core/*.hpp are now one-line compatibility shims that forward to include/marinholab/sas/core/*.hpp and re-alias the legacy namespace sas, and the ament target 'sas_core' forwards to marinholab::sas::core so downstream ament_target_dependencies(...) keeps working. - Python: sas_core/__init__.py is a pure-Python shim re-exporting Clock/Statistics/RobotDriver/ShutdownSignaler from the PyPI package marinholab-sas-core (MarinhoLab/sas_py), so 'from sas_core import Clock' keeps working. - docker/: the environment now installs marinholab-sas-core from PyPI and, until the .deb is published to an apt repository, builds the libmarinholab-sas-core .deb from MarinhoLab/sas_cpp (tag 26.09) inside the image and installs it. dqrobotics (C++ and Python) is already in the base image, so no PPA step is needed. - docker/compose.yml + docker/smoke_test.sh + scripts/sas_core_smoke_test.py verify the whole chain: colcon build, the Python shim, a CMake consumer probe (find_package + link + run) and a consumer of the legacy C++ include path/namespace. Verified end-to-end in the docker environment (arm64 base image).
1 parent 1507ac2 commit bdfb98d

36 files changed

Lines changed: 403 additions & 3101 deletions

‎.gitmodules‎

Lines changed: 0 additions & 4 deletions
This file was deleted.

‎CMakeLists.txt‎

Lines changed: 62 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,64 @@
1-
cmake_minimum_required(VERSION 3.11)
1+
cmake_minimum_required(VERSION 3.16)
22
project(sas_core)
33

4-
option(ROS2_BUILD "Enable ROS2/ament build (examples + ament integration)" ON)
5-
6-
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
7-
add_compile_options(-Wall -Wextra -Wpedantic)
8-
endif()
9-
10-
# ---- Core libraries (always built) ----
11-
include(cmake/cpplib.cmake)
12-
13-
if(ROS2_BUILD)
14-
find_package(ament_cmake REQUIRED)
15-
ament_python_install_package(${PROJECT_NAME})
16-
set(_SAS_PYTHON_INSTALL_DIR "${PYTHON_INSTALL_DIR}/${PROJECT_NAME}")
17-
endif()
18-
19-
include(cmake/pythonlib.cmake)
20-
21-
# ---- ROS2 / ament integration (conditional) ----
22-
if(ROS2_BUILD)
23-
# INTERFACE alias for downstream ROS packages
24-
add_library(sas_core INTERFACE)
25-
target_link_libraries(sas_core INTERFACE sas_core_pure)
26-
27-
ament_export_targets(export_${PROJECT_NAME} HAS_LIBRARY_TARGET)
28-
ament_export_dependencies(Eigen3)
29-
30-
install(DIRECTORY include/ DESTINATION include)
31-
32-
install(TARGETS sas_core sas_core_pure
33-
EXPORT export_${PROJECT_NAME}
34-
ARCHIVE DESTINATION lib
35-
INCLUDES DESTINATION include
36-
)
37-
38-
# Example executables
39-
foreach(_name IN ITEMS sas_core_example sas_clock_example
40-
sas_clock_sched_fifo_example)
41-
add_executable(${_name} src/examples/${_name}.cpp)
42-
target_link_libraries(${_name} sas_core_pure)
43-
if(_name STREQUAL "sas_core_example")
44-
target_link_libraries(${_name} -ldqrobotics)
45-
endif()
46-
install(TARGETS ${_name} DESTINATION lib/${PROJECT_NAME})
47-
endforeach()
48-
49-
add_executable(sas_robot_driver_example
50-
src/examples/sas_robot_driver_example_main.cpp)
51-
target_link_libraries(sas_robot_driver_example sas_core_pure)
52-
install(TARGETS sas_robot_driver_example DESTINATION lib/${PROJECT_NAME})
53-
54-
install(DIRECTORY
55-
scripts/
56-
FILE_PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ
57-
DESTINATION lib/${PROJECT_NAME}
58-
)
59-
60-
ament_package()
61-
endif()
4+
# =============================================================================
5+
# sas_core is a THIN WRAPPER around the SmartArmStack core:
6+
#
7+
# - C++ library: libmarinholab_sas_core, provided by the
8+
# libmarinholab-sas-core .deb (source: https://github.com/MarinhoLab/sas_cpp).
9+
# The .deb installs headers under include/marinholab/sas/core/, the shared
10+
# library, and the CMake package config (find_package(marinholab_sas_core)).
11+
# - Python bindings: the PyPI package marinholab-sas-core
12+
# (https://github.com/MarinhoLab/sas_py), imported as marinholab.sas.core.
13+
#
14+
# This package adds no implementation; it only:
15+
# 1. re-exports the ament target `sas_core` so downstream ROS packages keep
16+
# working with `ament_target_dependencies(<pkg> sas_core ...)`;
17+
# 2. installs compatibility headers include/sas_core/*.hpp that forward to
18+
# the .deb's include/marinholab/sas/core/*.hpp and re-alias `namespace sas`;
19+
# 3. installs the pure-Python `sas_core` shim (re-exporting
20+
# marinholab.sas.core) so `from sas_core import Clock` keeps working.
21+
# =============================================================================
22+
23+
find_package(marinholab_sas_core REQUIRED)
24+
find_package(ament_cmake REQUIRED)
25+
find_package(ament_cmake_python REQUIRED)
26+
27+
# Eigen3 is a PUBLIC dependency of the core (its headers include <Eigen/Dense>);
28+
# declare it so downstream ament packages can resolve it through this package.
29+
find_package(Eigen3 REQUIRED)
30+
31+
# ---- ament target ---------------------------------------------------------
32+
# INTERFACE alias forwarding downstream packages to the core target installed
33+
# by the libmarinholab-sas-core .deb.
34+
add_library(sas_core INTERFACE)
35+
target_link_libraries(sas_core INTERFACE marinholab::sas::core Eigen3::Eigen)
36+
37+
ament_export_targets(export_${PROJECT_NAME} HAS_LIBRARY_TARGET)
38+
# Eigen3 and marinholab_sas_core are consumed transitively by downstream
39+
# packages that link the `sas_core` target; propagate them so their
40+
# find_package() calls run in the consumer.
41+
ament_export_dependencies(Eigen3 marinholab_sas_core)
42+
43+
# ---- Compatibility headers ------------------------------------------------
44+
# include/sas_core/*.hpp are thin shims forwarding to the .deb's
45+
# include/marinholab/sas/core/*.hpp and re-aliasing `namespace sas`.
46+
install(DIRECTORY include/ DESTINATION include)
47+
48+
install(TARGETS sas_core
49+
EXPORT export_${PROJECT_NAME}
50+
)
51+
52+
# ---- Python compatibility shim ---------------------------------------------
53+
# Pure-Python module re-exporting marinholab.sas.core (installed from PyPI by
54+
# the docker environment / user). See sas_core/__init__.py.
55+
ament_python_install_package(${PROJECT_NAME})
56+
57+
# Example scripts (run against the PyPI-installed bindings).
58+
install(
59+
DIRECTORY scripts/
60+
FILE_PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ
61+
DESTINATION lib/${PROJECT_NAME}
62+
)
63+
64+
ament_package()

‎README.md‎

Lines changed: 58 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,81 @@
1-
# sas_core
1+
# sas_core (thin wrapper)
22

33
> [!TIP]
44
> Repository for this module: https://github.com/SmartArmStack/sas_core. <br/>
55
> More information about SmartArmStack is available in https://smartarmstack.github.io/.
66
7-
## Contents
8-
9-
- `include/sas_core/` — public C++ headers.
10-
- `src/` — implementation of the shared library and pybind11 bindings.
11-
- `scripts/` — example Python scripts.
12-
- `src/examples/` — C++ example programs and test nodes.
7+
`sas_core` is a **thin ROS 2 wrapper** around the SmartArmStack core. It
8+
contains no C++ implementation and no Python extension module of its own; it
9+
forwards to the two packages that provide the core:
1310

14-
## Using as a non-ROS2 dependency (CMake FetchContent)
11+
| Piece | Provided by | Installed as |
12+
|---|---|---|
13+
| C++ library (`libmarinholab_sas_core`) + headers + CMake config | [MarinhoLab/sas_cpp](https://github.com/MarinhoLab/sas_cpp) | `libmarinholab-sas-core` `.deb` (target namespace `marinholab::sas::core`) |
14+
| Python bindings | [MarinhoLab/sas_py](https://github.com/MarinhoLab/sas_py) | `marinholab-sas-core` on PyPI (import `marinholab.sas.core`) |
1515

16-
To include `sas_core_pure` in a plain CMake project (no ROS2/ament required):
16+
On Ubuntu the `.deb` links the dynamic `libdqrobotics` from the
17+
[dqrobotics PPA](https://launchpad.net/~dqrobotics-dev/+archive/ubuntu/development);
18+
in the provided docker environment both are already installed.
1719

18-
```cmake
19-
include(FetchContent)
20-
FetchContent_Declare(
21-
sas_core
22-
GIT_REPOSITORY https://github.com/SmartArmStack/sas_core.git
23-
GIT_TAG jazzy
24-
)
20+
## What this package provides
2521

26-
set(ROS2_BUILD OFF CACHE BOOL "" FORCE)
27-
FetchContent_MakeAvailable(sas_core)
28-
29-
target_link_libraries(your_target PRIVATE sas_core_pure)
30-
```
22+
- **C++**: the ament target `sas_core` (`ament_target_dependencies(<pkg> sas_core ...)`)
23+
forwarding to `marinholab::sas::core`, plus **compatibility headers**
24+
`include/sas_core/*.hpp` that keep the legacy include paths
25+
(`#include <sas_core/sas_clock.hpp>`) and the legacy `namespace sas` working
26+
via `#include <marinholab/sas/core/...>` + a namespace alias.
27+
- **Python**: a pure-Python `sas_core` shim that re-exports
28+
`Clock`, `Statistics`, `RobotDriver`, `ShutdownSignaler` from
29+
`marinholab.sas.core`, so `from sas_core import Clock` keeps working.
3130

32-
The library depends on **Eigen3** and **dqrobotics**; make sure both are
33-
available on your system.
31+
## Contents
3432

35-
## Examples
33+
- `include/sas_core/` — compatibility C++ headers (one-line forwards).
34+
- `sas_core/__init__.py` — Python compatibility shim.
35+
- `scripts/` — example Python scripts + `sas_core_smoke_test.py`.
36+
- `docker/` — build environment and integration smoke test.
3637

37-
Testing on a docker container.
38+
## Installation
3839

3940
```bash
40-
docker run --rm murilomarinho/sas:jazzy bash -c "ros2 run sas_core sas_clock_example"
41+
# C++ core (until the .deb is published to an apt repository, build it from source):
42+
sudo add-apt-repository ppa:dqrobotics-dev/development
43+
sudo apt-get update
44+
sudo apt-get install -y libdqrobotics
45+
# then build sas_cpp with dpkg-buildpackage and dpkg -i the result,
46+
# or simply: sudo apt-get install libmarinholab-sas-core (once published)
47+
48+
# Python bindings:
49+
python3 -m pip install marinholab-sas-core
50+
51+
# This wrapper (inside a ROS 2 workspace):
52+
colcon build
4153
```
4254

43-
```bash
44-
ros2 run sas_core sas_core_example
45-
ros2 run sas_core sas_clock_example
46-
ros2 run sas_core sas_clock_sched_fifo_example
47-
ros2 run sas_core sas_robot_driver_example
48-
```
55+
## Examples
56+
57+
The C++ example programs live with the C++ core
58+
([MarinhoLab/sas_cpp](https://github.com/MarinhoLab/sas_cpp), built with
59+
`-DMARINHO_LAB_SAS_CORE_BUILD_EXAMPLES=ON`). The Python examples in
60+
`scripts/` run against the PyPI-installed bindings:
4961

5062
```bash
5163
ros2 run sas_core sas_clock_example_py.py
52-
ros2 run sas_core sas_robot_driver_subclass_example_py.py
5364
ros2 run sas_core sas_clock_sched_fifo_example_py.py
65+
ros2 run sas_core sas_robot_driver_subclass_example_py.py
5466
```
5567

56-
The `scripts/sas_robot_driver_subclass_example_py.py` file demonstrates how to
57-
subclass `sas_core.RobotDriver` in Python and contains a minimal working
58-
example.
68+
`sas_robot_driver_subclass_example_py.py` demonstrates subclassing
69+
`sas_core.RobotDriver` in Python.
5970

71+
## Testing
72+
73+
The docker environment builds the wrapper with `colcon` and runs a smoke test
74+
covering both consumption paths (Python shim + C++ compatibility headers
75+
against the installed library):
76+
77+
```bash
78+
cd docker
79+
docker compose build
80+
docker compose up
81+
```

‎cmake/cpplib.cmake‎

Lines changed: 0 additions & 25 deletions
This file was deleted.

‎cmake/pythonlib.cmake‎

Lines changed: 0 additions & 27 deletions
This file was deleted.

‎docker/Dockerfile‎

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,31 @@ SHELL ["/bin/bash", "-c"]
44
ENV BASH_ENV="/etc/bash_env"
55

66
RUN sudo apt-get update && sudo apt-get upgrade -y
7-
RUN python3 -m pip install --upgrade dqrobotics --break-system-packages
8-
RUN sudo sudo apt-get remove -y ros-jazzy-sas-core
7+
8+
# Remove the legacy monolithic sas_core package shipped by the base image;
9+
# it would otherwise shadow this thin wrapper.
10+
RUN sudo apt-get remove -y ros-jazzy-sas-core
11+
12+
# Python bindings from PyPI (self-contained wheel, core statically linked).
13+
# dqrobotics (python) is already present in the base image.
14+
RUN python3 -m pip install --upgrade marinholab-sas-core --break-system-packages
15+
16+
# C++ core .deb -- TEMPORARY: built from source because the
17+
# libmarinholab-sas-core .deb is not yet published to an apt repository.
18+
# libdqrobotics (C++) is already present in the base image, so no PPA is
19+
# needed here. The build is architecture-agnostic (amd64 or arm64).
20+
#
21+
# Once the .deb is published to an apt repository, replace this block with:
22+
# RUN sudo apt-get update \
23+
# && sudo apt-get install -y libmarinholab-sas-core
24+
RUN sudo apt-get update \
25+
&& sudo apt-get install -y debhelper dpkg-dev \
26+
&& git clone --depth 1 --branch 26.09 https://github.com/MarinhoLab/sas_cpp.git /tmp/sas_cpp \
27+
&& cd /tmp/sas_cpp \
28+
&& dpkg-buildpackage -us -uc -b \
29+
&& cd /tmp \
30+
&& sudo dpkg -i ./libmarinholab-sas-core_*.deb \
31+
&& sudo rm -rf /tmp/sas_cpp /tmp/libmarinholab-sas-core_*.deb
32+
933
RUN mkdir -p /root/sas_core_devel/src/
10-
COPY . /root/sas_core_devel/src/sas_core
34+
COPY . /root/sas_core_devel/src/sas_core

‎docker/compose.yml‎

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,4 @@ services:
55
dockerfile: docker/Dockerfile
66
environment:
77
PYTHONUNBUFFERED: 1
8-
command: /bin/bash -c "
9-
cd /root/sas_core_devel/src/
10-
&& ls .
11-
&& colcon build
12-
&& source install/setup.bash
13-
&& ros2 run sas_core sas_clock_example
14-
&& ros2 run sas_core sas_clock_example_py.py
15-
&& ros2 run sas_core sas_robot_driver_example
16-
&& ros2 run sas_core sas_robot_driver_subclass_example_py.py
17-
&& ros2 run sas_core sas_clock_sched_fifo_example
18-
&& ros2 run sas_core sas_clock_sched_fifo_example_py.py
19-
"
8+
command: /bin/bash -c "bash /root/sas_core_devel/src/sas_core/docker/smoke_test.sh"

0 commit comments

Comments
 (0)