-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.rs
More file actions
104 lines (96 loc) · 4.68 KB
/
build.rs
File metadata and controls
104 lines (96 loc) · 4.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
use std::env;
use std::path::PathBuf;
fn main() {
// Generate Rust FFI bindings for the ROS2-generated C message structs.
//
// This does not generate full message support; we use it as the low-level
// rmw struct definitions which we can then pair with typesupport symbols.
let ament_prefix =
env::var("AMENT_PREFIX_PATH").unwrap_or_else(|_| "/opt/ros/jazzy".to_string());
let include_root = PathBuf::from(ament_prefix).join("include");
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
let bindings_path = out_dir.join("ros_tf_msgs_bindings.rs");
let mut builder = bindgen::Builder::default()
.clang_arg(format!("-I{}", include_root.display()))
// Some packages include headers as <pkg/msg/...> which live under include/<pkg>.
.clang_arg(format!(
"-I{}",
include_root.join("builtin_interfaces").display()
))
.clang_arg(format!("-I{}", include_root.join("std_msgs").display()))
.clang_arg(format!(
"-I{}",
include_root.join("geometry_msgs").display()
))
.clang_arg(format!("-I{}", include_root.join("tf2_msgs").display()))
// ROS2 installs some headers under include/<pkg>/<pkg>/... but also expects
// includes like <rosidl_runtime_c/...>, which live under include/rosidl_runtime_c/rosidl_runtime_c.
.clang_arg(format!(
"-I{}",
include_root.join("rosidl_runtime_c").display()
))
.clang_arg(format!("-I{}", include_root.join("rcutils").display()))
.clang_arg(format!(
"-I{}",
include_root.join("rosidl_typesupport_interface").display()
))
.clang_arg("-std=c11")
// Keep bindgen output stable and minimal.
.allowlist_type("builtin_interfaces__msg__Time")
.allowlist_type("std_msgs__msg__Header")
.allowlist_type("geometry_msgs__msg__Vector3")
.allowlist_type("geometry_msgs__msg__Quaternion")
.allowlist_type("geometry_msgs__msg__Transform")
.allowlist_type("geometry_msgs__msg__TransformStamped")
.allowlist_type("tf2_msgs__msg__TFMessage")
// Sequences used by TFMessage.
.allowlist_type("geometry_msgs__msg__TransformStamped__Sequence")
// Functions for init/fini.
.allowlist_function("builtin_interfaces__msg__Time__.*")
.allowlist_function("std_msgs__msg__Header__.*")
.allowlist_function("geometry_msgs__msg__Vector3__.*")
.allowlist_function("geometry_msgs__msg__Quaternion__.*")
.allowlist_function("geometry_msgs__msg__Transform__.*")
.allowlist_function("geometry_msgs__msg__TransformStamped__.*")
.allowlist_function("tf2_msgs__msg__TFMessage__.*")
// Needed basic C types.
.allowlist_type("rosidl_runtime_c__String")
.allowlist_type("rosidl_runtime_c__String__Sequence")
.allowlist_function("rosidl_runtime_c__String__.*")
.allowlist_function("rosidl_runtime_c__String__Sequence__.*")
// Avoid pulling in platform-specific stuff.
.blocklist_type("max_align_t")
.derive_default(true)
.generate_comments(false);
// The headers we need.
let headers = [
"builtin_interfaces/builtin_interfaces/msg/detail/time__struct.h",
"builtin_interfaces/builtin_interfaces/msg/detail/time__functions.h",
"std_msgs/std_msgs/msg/detail/header__struct.h",
"std_msgs/std_msgs/msg/detail/header__functions.h",
"geometry_msgs/geometry_msgs/msg/detail/vector3__struct.h",
"geometry_msgs/geometry_msgs/msg/detail/vector3__functions.h",
"geometry_msgs/geometry_msgs/msg/detail/quaternion__struct.h",
"geometry_msgs/geometry_msgs/msg/detail/quaternion__functions.h",
"geometry_msgs/geometry_msgs/msg/detail/transform__struct.h",
"geometry_msgs/geometry_msgs/msg/detail/transform__functions.h",
"geometry_msgs/geometry_msgs/msg/detail/transform_stamped__struct.h",
"geometry_msgs/geometry_msgs/msg/detail/transform_stamped__functions.h",
"tf2_msgs/tf2_msgs/msg/detail/tf_message__struct.h",
"tf2_msgs/tf2_msgs/msg/detail/tf_message__functions.h",
"rosidl_runtime_c/rosidl_runtime_c/string.h",
];
for h in headers {
builder = builder.header(include_root.join(h).to_string_lossy());
}
let bindings = builder
.generate()
.expect("Unable to generate ROS TF message bindings");
bindings
.write_to_file(&bindings_path)
.expect("Couldn't write bindings");
println!("cargo:rerun-if-env-changed=AMENT_PREFIX_PATH");
for h in headers {
println!("cargo:rerun-if-changed={}", include_root.join(h).display());
}
}