-
Notifications
You must be signed in to change notification settings - Fork 13
/
build.rs
132 lines (124 loc) · 6.23 KB
/
build.rs
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#[cfg(target_os = "windows")]
// for windows find and add all ros2 libraries to avoid link issues
fn print_all_libs(path: std::path::PathBuf) {
if path.exists() {
if let Ok(entries) = std::fs::read_dir(&path) {
for pp in entries
.into_iter()
.filter(|e| e.is_ok())
.map(|e| e.unwrap().path())
.filter(|p| p.is_file() && p.extension().is_some())
{
if let Some(p) = pp.to_str() {
if p.ends_with("_c.lib") {
println!(
"cargo:rustc-link-lib={}",
pp.file_stem().unwrap().to_str().unwrap()
);
}
}
}
}
if let Some(pp) = path.to_str() {
println!("cargo:rustc-link-search={}", pp);
}
}
}
#[cfg(not(target_os = "windows"))]
fn print_all_libs(_path: std::path::PathBuf) {}
fn main() {
println!("cargo:rustc-link-lib=rcl");
println!("cargo:rustc-link-lib=rcl_action");
println!("cargo:rustc-link-lib=rcutils");
println!("cargo:rustc-link-lib=rmw");
println!("cargo:rustc-link-lib=rosidl_runtime_c");
if !cfg!(target_os = "windows") {
println!("cargo:rustc-link-lib=actionlib_msgs__rosidl_typesupport_c");
println!("cargo:rustc-link-lib=actionlib_msgs__rosidl_generator_c");
println!("cargo:rustc-link-lib=action_msgs__rosidl_typesupport_c");
println!("cargo:rustc-link-lib=action_msgs__rosidl_generator_c");
println!("cargo:rustc-link-lib=builtin_interfaces__rosidl_typesupport_c");
println!("cargo:rustc-link-lib=builtin_interfaces__rosidl_generator_c");
println!("cargo:rustc-link-lib=diagnostic_msgs__rosidl_typesupport_c");
println!("cargo:rustc-link-lib=diagnostic_msgs__rosidl_generator_c");
println!("cargo:rustc-link-lib=geometry_msgs__rosidl_typesupport_c");
println!("cargo:rustc-link-lib=geometry_msgs__rosidl_generator_c");
println!("cargo:rustc-link-lib=nav_msgs__rosidl_typesupport_c");
println!("cargo:rustc-link-lib=nav_msgs__rosidl_generator_c");
println!("cargo:rustc-link-lib=sensor_msgs__rosidl_typesupport_c");
println!("cargo:rustc-link-lib=sensor_msgs__rosidl_generator_c");
println!("cargo:rustc-link-lib=shape_msgs__rosidl_typesupport_c");
println!("cargo:rustc-link-lib=shape_msgs__rosidl_generator_c");
println!("cargo:rustc-link-lib=std_msgs__rosidl_typesupport_c");
println!("cargo:rustc-link-lib=std_msgs__rosidl_generator_c");
println!("cargo:rustc-link-lib=std_srvs__rosidl_typesupport_c");
println!("cargo:rustc-link-lib=std_srvs__rosidl_generator_c");
println!("cargo:rustc-link-lib=stereo_msgs__rosidl_typesupport_c");
println!("cargo:rustc-link-lib=stereo_msgs__rosidl_generator_c");
println!("cargo:rustc-link-lib=trajectory_msgs__rosidl_typesupport_c");
println!("cargo:rustc-link-lib=trajectory_msgs__rosidl_generator_c");
println!("cargo:rustc-link-lib=unique_identifier_msgs__rosidl_typesupport_c");
println!("cargo:rustc-link-lib=unique_identifier_msgs__rosidl_generator_c");
println!("cargo:rustc-link-lib=visualization_msgs__rosidl_typesupport_c");
println!("cargo:rustc-link-lib=visualization_msgs__rosidl_generator_c");
println!("cargo:rustc-link-lib=rcl_interfaces__rosidl_typesupport_c");
println!("cargo:rustc-link-lib=rcl_interfaces__rosidl_generator_c");
println!("cargo:rustc-link-lib=action_msgs__rosidl_typesupport_c");
println!("cargo:rustc-link-lib=action_msgs__rosidl_generator_c");
}
if std::env::var_os("SAFE_DRIVE_TEST").is_some() {
println!("cargo:rustc-link-lib=example_msg__rosidl_typesupport_c");
println!("cargo:rustc-link-lib=example_msg__rosidl_generator_c");
println!("cargo:rustc-link-search=supplements/ros2/install/example_msg/lib");
}
if let Some(e) = std::env::var_os("AMENT_PREFIX_PATH") {
let env = e.to_str().unwrap();
if cfg!(target_os = "windows") {
for path in env.split(';') {
print_all_libs(std::path::Path::new(path).join("Lib"));
}
} else {
for path in env.split(':') {
println!("cargo:rustc-link-search={path}/lib");
}
}
}
if cfg!(target_os = "windows") {
if let Some(e) = std::env::var_os("CMAKE_PREFIX_PATH") {
let env = e.to_str().unwrap();
for path in env.split(';') {
print_all_libs(std::path::Path::new(path).join("lib"));
}
}
}
println!("cargo:rerun-if-env-changed=ROS_DISTRO");
let distro_name = std::env::var_os("ROS_DISTRO");
match &*distro_name
.and_then(|v| v.into_string().ok())
.unwrap_or("".to_string())
{
"jazzy" => {
println!("cargo:rustc-link-lib=service_msgs__rosidl_typesupport_c");
println!("cargo:rustc-link-lib=service_msgs__rosidl_generator_c");
println!("cargo:rustc-link-lib=type_description_interfaces__rosidl_typesupport_c");
println!("cargo:rustc-link-lib=type_description_interfaces__rosidl_generator_c");
println!("cargo:rustc-cfg=feature=\"jazzy\"");
}
"iron" => {
println!("cargo:rustc-link-lib=service_msgs__rosidl_typesupport_c");
println!("cargo:rustc-link-lib=service_msgs__rosidl_generator_c");
println!("cargo:rustc-link-lib=type_description_interfaces__rosidl_typesupport_c");
println!("cargo:rustc-link-lib=type_description_interfaces__rosidl_generator_c");
println!("cargo:rustc-cfg=feature=\"iron\"");
}
"humble" => println!("cargo:rustc-cfg=feature=\"humble\""),
"galactic" => println!("cargo:rustc-cfg=feature=\"galactic\""),
_ => {
let default = "jazzy";
println!("cargo:warning='ROS_DISTRO is not set properly. Defaulting to {default}.'");
println!("cargo:rustc-link-lib=service_msgs__rosidl_typesupport_c");
println!("cargo:rustc-link-lib=service_msgs__rosidl_generator_c");
println!("cargo:rustc-cfg=feature=\"{default}\"");
}
}
}