Skip to content

Commit 0a7a214

Browse files
authored
feat: rcl unit test (#36)
1 parent 27f09d3 commit 0a7a214

67 files changed

Lines changed: 24040 additions & 415 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/ci.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@ jobs:
109109
if: env.ACT != 'true'
110110
uses: mozilla-actions/sccache-action@v0.0.9
111111

112+
- name: Clippy (all targets, all features)
113+
run: |
114+
nix develop '.#${{ matrix.distro }}-ci' -c \
115+
cargo clippy --all-targets --all-features --workspace -- -D warnings
116+
112117
- name: Check rcl-z
113118
run: |
114119
nix develop '.#${{ matrix.distro }}-ci' -c cargo check -p rcl-z

flake.nix

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,13 @@
7070
rosidl-default-generators
7171
rosidl-default-runtime
7272
rosidl-adapter
73+
rosidl-typesupport-fastrtps-c
74+
rosidl-typesupport-fastrtps-cpp
75+
];
76+
77+
# Test-only message packages
78+
testMessages = with pkgs.rosPackages.${rosDistro}; [
79+
test-msgs
7380
];
7481

7582
devExtras = with pkgs.rosPackages.${rosDistro}; [
@@ -92,18 +99,35 @@
9299
};
93100
in
94101
{
102+
# Development environment with all dependencies including test messages
95103
dev = pkgs.rosPackages.${rosDistro}.buildEnv {
96-
paths = rosDeps.rcl ++ rosDeps.messages ++ rosDeps.devExtras;
104+
paths = rosDeps.rcl ++ rosDeps.messages ++ rosDeps.testMessages ++ rosDeps.devExtras;
97105
};
106+
107+
# Core RCL only (for minimal builds)
98108
rcl = pkgs.rosPackages.${rosDistro}.buildEnv {
99109
paths = rosDeps.rcl;
100110
};
111+
112+
# Runtime messages only
101113
msgs = pkgs.rosPackages.${rosDistro}.buildEnv {
102114
paths = rosDeps.messages;
103115
};
116+
117+
# Build environment with runtime messages but NO test messages
104118
build = pkgs.rosPackages.${rosDistro}.buildEnv {
105119
paths = rosDeps.rcl ++ rosDeps.messages;
106120
};
121+
122+
# Test environment for core tests only (no test_msgs)
123+
testCore = pkgs.rosPackages.${rosDistro}.buildEnv {
124+
paths = rosDeps.rcl ++ rosDeps.messages;
125+
};
126+
127+
# Test environment with test messages (for all tests)
128+
testFull = pkgs.rosPackages.${rosDistro}.buildEnv {
129+
paths = rosDeps.rcl ++ rosDeps.messages ++ rosDeps.testMessages;
130+
};
107131
};
108132

109133
# Common build tools
@@ -135,10 +159,13 @@
135159
];
136160

137161
# Environment variables for Rust/C++ interop
138-
commonEnvVars = {
162+
commonEnvVars = rec {
139163
LIBCLANG_PATH = "${pkgs.llvmPackages.libclang.lib}/lib";
140164
CLANG_PATH = "${pkgs.llvmPackages.clang}/bin/clang";
141-
LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath [ pkgs.stdenv.cc.cc.lib ];
165+
LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath [
166+
pkgs.stdenv.cc.cc.lib
167+
# ROS libraries will be added by the ROS environment packages
168+
];
142169
RUST_BACKTRACE = "1";
143170
RMW_IMPLEMENTATION = "rmw_zenoh_cpp";
144171
RUSTC_WRAPPER = "${pkgs.sccache}/bin/sccache";
@@ -194,7 +221,7 @@
194221

195222
ci = mkDevShell {
196223
name = "ros-z-ci-${rosDistro}";
197-
packages = commonBuildInputs ++ [ rosEnv.build ];
224+
packages = commonBuildInputs ++ testTools ++ [ rosEnv.testFull ];
198225
};
199226
};
200227

rcl-z/Cargo.toml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,21 @@ strum = { workspace = true, features = ["derive"] }
2222

2323
[lib]
2424
name = "rcl_z"
25-
crate-type = ["cdylib"]
25+
crate-type = ["cdylib", "rlib"]
2626

2727
[build-dependencies]
2828
bindgen = { workspace = true }
2929
cxx-build = { workspace = true }
30+
31+
[features]
32+
# Tests that don't need any message packages
33+
test-core = []
34+
35+
# Tests that need test_msgs package
36+
test-msgs = []
37+
38+
# Run all tests
39+
test-all = ["test-core", "test-msgs"]
40+
41+
# Legacy compatibility
42+
test-rcl = ["test-all"]

rcl-z/build.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ const INCLUDE_PACKAGES: &[&str] = &[
1616
];
1717

1818
fn main() {
19+
// Declare custom cfg for auto-detection
20+
println!("cargo:rustc-check-cfg=cfg(has_test_msgs)");
21+
1922
// Get AMENT_PREFIX_PATH from the environment
2023
let ament_prefix = env::var("AMENT_PREFIX_PATH").expect("AMENT_PREFIX_PATH is missing!");
2124

@@ -39,11 +42,14 @@ fn main() {
3942
.clang_args(include_args)
4043
.allowlist_function("rcl_.*")
4144
.allowlist_function("rmw_get_gid_for_publisher")
45+
.allowlist_function("rmw_publisher_count_matched_subscriptions")
46+
.allowlist_function("rmw_subscription_count_matched_publishers")
4247
.allowlist_function("rosidl_typesupport_c__get_service_type_support_handle__type_description_interfaces__srv__GetTypeDescription")
4348
.allowlist_type("rcl_.*")
4449
.blocklist_type("rmw_qos_profile_s")
4550
.blocklist_type("rmw_qos_.*_policy_e")
4651
.allowlist_var("RCL_.*")
52+
.allowlist_var("RMW_.*")
4753
// .no_default("rmw_qos_profile_s")
4854
.default_enum_style(bindgen::EnumVariation::Rust {
4955
non_exhaustive: false,
@@ -128,11 +134,23 @@ fn main() {
128134

129135
println!("cargo:rustc-link-search=native=/usr/local/lib");
130136
println!("cargo:rustc-link-search=native={ament_prefix}/lib/");
137+
138+
println!("cargo:rustc-link-lib=dylib=rcl");
131139
println!("cargo:rustc-link-lib=dylib=rmw");
132140
println!("cargo:rustc-link-lib=dylib=rcutils");
133141
println!("cargo:rustc-link-lib=dylib=fastcdr");
134142
println!("cargo:rustc-link-lib=dylib=rosidl_runtime_c");
135143
println!("cargo:rustc-link-lib=dylib=rosidl_typesupport_fastrtps_c");
136144
println!("cargo:rustc-link-lib=dylib=rosidl_typesupport_fastrtps_cpp");
137145
println!("cargo:rustc-link-lib=dylib=type_description_interfaces__rosidl_typesupport_c");
146+
147+
// Link test_msgs for tests
148+
#[cfg(feature = "test-msgs")]
149+
{
150+
// Explicit feature: always link (fail if not available)
151+
println!("cargo:rustc-link-lib=dylib=test_msgs__rosidl_generator_c");
152+
println!("cargo:rustc-link-lib=dylib=test_msgs__rosidl_typesupport_c");
153+
println!("cargo:rustc-link-lib=dylib=test_msgs__rosidl_typesupport_fastrtps_c");
154+
println!("cargo:rustc-link-lib=dylib=test_msgs__rosidl_typesupport_fastrtps_cpp");
155+
}
138156
}

rcl-z/include/serde_bridge.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
#include <rosidl_typesupport_fastrtps_cpp/message_type_support.h>
44
#include <rosidl_typesupport_fastrtps_cpp/service_type_support.h>
5+
#include <rosidl_typesupport_fastrtps_c/identifier.h>
6+
#include <rosidl_typesupport_fastrtps_cpp/identifier.hpp>
57

68
#include "rust/cxx.h"
79

0 commit comments

Comments
 (0)