Skip to content

Commit 37cb90c

Browse files
committed
fix: remove use_ros_shim. Let user pass compiler flag to specify the ROS distro
Signed-off-by: Esteve Fernandez <[email protected]>
1 parent 5696315 commit 37cb90c

File tree

3 files changed

+33
-37
lines changed

3 files changed

+33
-37
lines changed

rclrs/Cargo.toml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,13 @@ tempfile = "3.3.0"
4343
tokio = { version = "1", features = ["rt", "time", "macros"] }
4444

4545
[build-dependencies]
46-
# Needed for FFI
47-
bindgen = "0.70"
4846
# Needed for uploading documentation to docs.rs
49-
cfg-if = "1.0.0"
47+
rustflags = "0.1"
5048

5149
[features]
5250
default = []
5351
dyn_msg = ["ament_rs", "libloading"]
5452
serde = ["dep:serde", "dep:serde-big-array", "rosidl_runtime_rs/serde"]
55-
# This feature is solely for the purpose of being able to generate documetation without a ROS installation
56-
# The only intended usage of this feature is for docs.rs builders to work, and is not intended to be used by end users
57-
use_ros_shim = ["rosidl_runtime_rs/use_ros_shim"]
5853

5954
[package.metadata.docs.rs]
60-
features = ["use_ros_shim"]
55+
rustc-args = ["--cfg", "ros_distro=humble"]

rclrs/build.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
use std::{
22
env,
3-
fs::read_dir,
4-
path::{Path, PathBuf},
3+
path::Path,
54
};
5+
use rustflags::Flag;
66

77
const AMENT_PREFIX_PATH: &str = "AMENT_PREFIX_PATH";
88
const ROS_DISTRO: &str = "ROS_DISTRO";
9-
const BINDGEN_WRAPPER: &str = "src/rcl_wrapper.h";
109

1110
fn get_env_var_or_abort(env_var: &'static str) -> String {
1211
if let Ok(value) = env::var(env_var) {
@@ -23,16 +22,20 @@ fn main() {
2322
let ros_distro = if let Ok(value) = env::var(ROS_DISTRO) {
2423
value
2524
} else {
26-
let error_msg =
27-
"ROS_DISTRO environment variable not set - please source ROS 2 installation first.";
28-
cfg_if::cfg_if! {
29-
if #[cfg(feature="use_ros_shim")] {
30-
println!("{}", error_msg);
31-
return;
32-
} else {
33-
panic!("{}", error_msg);
25+
// Look for --cfg ros_distro=<ros_distro>
26+
for flag in rustflags::from_env() {
27+
if matches!(flag, Flag::Cfg { ref name, value : _ } if name == "ros_distro") {
28+
if let Flag::Cfg {name:_, value: flag_value} = flag {
29+
println!("cargo:rustc-cfg=ros_distro={}", flag_value.unwrap());
30+
return;
31+
} else {
32+
continue;
33+
}
3434
}
3535
}
36+
let error_msg =
37+
"ROS_DISTRO environment variable not set - please source ROS 2 installation first.";
38+
panic!("{}", error_msg);
3639
};
3740

3841
println!("cargo:rustc-check-cfg=cfg(ros_distro, values(\"humble\", \"jazzy\", \"rolling\"))");

rclrs/src/rcl_bindings.rs

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,26 @@
1212
#![allow(missing_docs)]
1313

1414
cfg_if::cfg_if! {
15-
if #[cfg(feature="use_ros_shim")] {
16-
include!(
17-
concat!(
18-
env!("CARGO_MANIFEST_DIR"),
19-
"/src/rcl_bindings_generated_",
20-
"rolling", // rolling will always be a valid ROS distro
21-
".rs",
22-
)
23-
);
24-
15+
let ros_distro = if #[cfg(ros_distro="humble")] {
16+
"humble"
17+
} else if #[cfg(ros_distro="jazzy")] {
18+
"jazzy"
19+
} else if #[cfg(ros_distro="kilted")] {
20+
"kilted"
21+
} else if #[cfg(ros_distro="rolling")] {
22+
"rolling"
2523
} else {
26-
include!(
27-
concat!(
28-
env!("CARGO_MANIFEST_DIR"),
29-
"/src/rcl_bindings_generated_",
30-
env!("ROS_DISTRO"),
31-
".rs",
24+
panic!("Unsupported ROS distribution");
25+
}
26+
include!(
27+
concat!(
28+
env!("CARGO_MANIFEST_DIR"),
29+
"/src/rcl_bindings_generated_",
30+
ros_distro,
31+
".rs",
3232
)
3333
);
34-
35-
pub const RMW_GID_STORAGE_SIZE: usize = rmw_gid_storage_size_constant;
36-
}
34+
pub const RMW_GID_STORAGE_SIZE: usize = rmw_gid_storage_size_constant;
3735
}
3836

3937
/// Wrapper around [`std::slice::from_raw_parts`] that accommodates the rcl

0 commit comments

Comments
 (0)