@@ -3,8 +3,23 @@ use std::fs::read_dir;
3
3
use std:: path:: { Path , PathBuf } ;
4
4
5
5
const AMENT_PREFIX_PATH : & str = "AMENT_PREFIX_PATH" ;
6
+ const ROS_DISTRO : & str = "ROS_DISTRO" ;
7
+
8
+ fn get_env_var_or_abort ( env_var : & ' static str ) -> String {
9
+ if let Ok ( value) = env:: var ( env_var) {
10
+ value
11
+ } else {
12
+ panic ! (
13
+ "{} environment variable not set - please source ROS 2 installation first." ,
14
+ env_var
15
+ ) ;
16
+ }
17
+ }
6
18
7
19
fn main ( ) {
20
+ let distro = get_env_var_or_abort ( ROS_DISTRO ) ;
21
+ println ! ( "cargo:rustc-cfg=distro=\" {distro}\" " ) ;
22
+
8
23
let mut builder = bindgen:: Builder :: default ( )
9
24
. header ( "src/rcl_wrapper.h" )
10
25
. derive_copy ( false )
@@ -39,47 +54,41 @@ fn main() {
39
54
//
40
55
// See REP 122 for more details: https://www.ros.org/reps/rep-0122.html#filesystem-layout
41
56
42
- if let Ok ( ament_prefix_paths) = env :: var ( AMENT_PREFIX_PATH ) {
43
- for ament_prefix_path in ament_prefix_paths. split ( ':' ) . map ( Path :: new) {
44
- // Locate the ament index
45
- let ament_index = ament_prefix_path. join ( "share/ament_index/resource_index/packages" ) ;
46
- if !ament_index. is_dir ( ) {
47
- continue ;
48
- }
57
+ let ament_prefix_paths = get_env_var_or_abort ( AMENT_PREFIX_PATH ) ;
58
+ for ament_prefix_path in ament_prefix_paths. split ( ':' ) . map ( Path :: new) {
59
+ // Locate the ament index
60
+ let ament_index = ament_prefix_path. join ( "share/ament_index/resource_index/packages" ) ;
61
+ if !ament_index. is_dir ( ) {
62
+ continue ;
63
+ }
49
64
50
- // Old-style include directory
51
- let include_dir = ament_prefix_path. join ( "include" ) ;
65
+ // Old-style include directory
66
+ let include_dir = ament_prefix_path. join ( "include" ) ;
52
67
53
- // Including the old-style packages
54
- builder = builder. clang_arg ( format ! ( "-isystem{}" , include_dir. display( ) ) ) ;
68
+ // Including the old-style packages
69
+ builder = builder. clang_arg ( format ! ( "-isystem{}" , include_dir. display( ) ) ) ;
55
70
56
- // Search for and include new-style-converted package paths
57
- for dir_entry in read_dir ( & ament_index) . unwrap ( ) . filter_map ( |p| p. ok ( ) ) {
58
- let package = dir_entry. file_name ( ) ;
59
- let package_include_dir = include_dir. join ( & package) ;
71
+ // Search for and include new-style-converted package paths
72
+ for dir_entry in read_dir ( & ament_index) . unwrap ( ) . filter_map ( |p| p. ok ( ) ) {
73
+ let package = dir_entry. file_name ( ) ;
74
+ let package_include_dir = include_dir. join ( & package) ;
60
75
61
- if package_include_dir. is_dir ( ) {
62
- let new_style_include_dir = package_include_dir. join ( & package) ;
76
+ if package_include_dir. is_dir ( ) {
77
+ let new_style_include_dir = package_include_dir. join ( & package) ;
63
78
64
- // CycloneDDS is a special case - it needs to be included as if it were a new-style path, but
65
- // doesn't actually have a secondary folder within it called "CycloneDDS"
66
- // TODO(jhdcs): if this changes in future, remove this check
67
- if package == "CycloneDDS" || new_style_include_dir. is_dir ( ) {
68
- builder =
69
- builder. clang_arg ( format ! ( "-isystem{}" , package_include_dir. display( ) ) ) ;
70
- }
79
+ // CycloneDDS is a special case - it needs to be included as if it were a new-style path, but
80
+ // doesn't actually have a secondary folder within it called "CycloneDDS"
81
+ // TODO(jhdcs): if this changes in future, remove this check
82
+ if package == "CycloneDDS" || new_style_include_dir. is_dir ( ) {
83
+ builder =
84
+ builder. clang_arg ( format ! ( "-isystem{}" , package_include_dir. display( ) ) ) ;
71
85
}
72
86
}
73
-
74
- // Link the native libraries
75
- let library_path = ament_prefix_path. join ( "lib" ) ;
76
- println ! ( "cargo:rustc-link-search=native={}" , library_path. display( ) ) ;
77
87
}
78
- } else {
79
- panic ! (
80
- "{} environment variable not set - please source ROS 2 installation first." ,
81
- AMENT_PREFIX_PATH
82
- ) ;
88
+
89
+ // Link the native libraries
90
+ let library_path = ament_prefix_path. join ( "lib" ) ;
91
+ println ! ( "cargo:rustc-link-search=native={}" , library_path. display( ) ) ;
83
92
}
84
93
85
94
println ! ( "cargo:rustc-link-lib=dylib=rcl" ) ;
0 commit comments