Skip to content

Commit 9b52a03

Browse files
author
carter
committed
Example package using macro (again proving dependency hygiene
1 parent 1998e2a commit 9b52a03

File tree

6 files changed

+46
-0
lines changed

6 files changed

+46
-0
lines changed

Cargo.lock

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
members = [
44
"example_package",
5+
"example_package_macro",
56
"roslibrust",
67
"roslibrust_codegen",
78
"roslibrust_codegen_macro",

example_package/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Example RosLibRust Package
2+
23
The point of this package is provide a good example of how to integrate roslibrust into a package using a build.rs file.
34

45
This package also serves as a testbed for maintainers of roslibrust to refine build.rs integration.

example_package_macro/Cargo.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[package]
2+
name = "example_package_macro"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[dependencies]
7+
# The code generated by roslibrust_codegen has dependendencies
8+
# We need to depend on the crate at build time so that the generate code has access to these dependencies
9+
roslibrust_codegen = { path = "../roslibrust_codegen" }
10+
# This crate contains the actual macro we will invoke
11+
roslibrust_codegen_macro = { path = "../roslibrust_codegen_macro" }

example_package_macro/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Example RosLibRust Package
2+
3+
The point of this package is provide a good example of how to integrate roslibrust into a package using the proc macro.
4+
5+
This package also serves as a testbed for maintainers of roslibrust to refine proc macro integration.

example_package_macro/src/main.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
roslibrust_codegen_macro::find_and_generate_ros_messages!(
2+
"assets/ros1_test_msgs",
3+
"assets/ros1_common_interfaces"
4+
);
5+
6+
// Example of 'use' pointing to code created by the include! macro
7+
mod submodule {
8+
#[allow(unused_imports)]
9+
use crate::std_msgs::Header;
10+
}
11+
12+
// Our actual "main" here doesn't do much, just shows the generate types
13+
// are here and real.
14+
fn main() {
15+
// Note: within our assets there is a folder named ros1_test_msgs which contains a ros package
16+
// The ros package in its package.xml refers to the name of that package as test_msgs
17+
// The module that is generated will use the name in package.xml and not the directory
18+
let data = test_msgs::Constants::TEST_STR;
19+
println!("Hello World! {data}");
20+
}

0 commit comments

Comments
 (0)