Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions rclrs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,13 @@ tempfile = "3.3.0"
tokio = { version = "1", features = ["rt", "time", "macros"] }

[build-dependencies]
# Needed for FFI
bindgen = "0.70"
# Needed for uploading documentation to docs.rs
cfg-if = "1.0.0"
rustflags = "0.1"

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

[package.metadata.docs.rs]
features = ["use_ros_shim"]
rustc-args = ["--cfg", "ros_distro=humble"]
25 changes: 14 additions & 11 deletions rclrs/build.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
use std::{
env,
fs::read_dir,
path::{Path, PathBuf},
path::Path,
};
use rustflags::Flag;

const AMENT_PREFIX_PATH: &str = "AMENT_PREFIX_PATH";
const ROS_DISTRO: &str = "ROS_DISTRO";
const BINDGEN_WRAPPER: &str = "src/rcl_wrapper.h";

fn get_env_var_or_abort(env_var: &'static str) -> String {
if let Ok(value) = env::var(env_var) {
Expand All @@ -23,16 +22,20 @@ fn main() {
let ros_distro = if let Ok(value) = env::var(ROS_DISTRO) {
value
} else {
let error_msg =
"ROS_DISTRO environment variable not set - please source ROS 2 installation first.";
cfg_if::cfg_if! {
if #[cfg(feature="use_ros_shim")] {
println!("{}", error_msg);
return;
} else {
panic!("{}", error_msg);
// Look for --cfg ros_distro=<ros_distro>
for flag in rustflags::from_env() {
if matches!(flag, Flag::Cfg { ref name, value : _ } if name == "ros_distro") {
if let Flag::Cfg {name:_, value: flag_value} = flag {
println!("cargo:rustc-cfg=ros_distro={}", flag_value.unwrap());
return;
} else {
continue;
}
}
}
let error_msg =
"ROS_DISTRO environment variable not set - please source ROS 2 installation first.";
panic!("{}", error_msg);
};

println!("cargo:rustc-check-cfg=cfg(ros_distro, values(\"humble\", \"jazzy\", \"rolling\"))");
Expand Down
36 changes: 17 additions & 19 deletions rclrs/src/rcl_bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,26 @@
#![allow(missing_docs)]

cfg_if::cfg_if! {
if #[cfg(feature="use_ros_shim")] {
include!(
concat!(
env!("CARGO_MANIFEST_DIR"),
"/src/rcl_bindings_generated_",
"rolling", // rolling will always be a valid ROS distro
".rs",
)
);

let ros_distro = if #[cfg(ros_distro="humble")] {
"humble"
} else if #[cfg(ros_distro="jazzy")] {
"jazzy"
} else if #[cfg(ros_distro="kilted")] {
"kilted"
} else if #[cfg(ros_distro="rolling")] {
"rolling"
} else {
include!(
concat!(
env!("CARGO_MANIFEST_DIR"),
"/src/rcl_bindings_generated_",
env!("ROS_DISTRO"),
".rs",
panic!("Unsupported ROS distribution");
}
include!(
concat!(
env!("CARGO_MANIFEST_DIR"),
"/src/rcl_bindings_generated_",
ros_distro,
".rs",
)
);

pub const RMW_GID_STORAGE_SIZE: usize = rmw_gid_storage_size_constant;
}
pub const RMW_GID_STORAGE_SIZE: usize = rmw_gid_storage_size_constant;
}

/// Wrapper around [`std::slice::from_raw_parts`] that accommodates the rcl
Expand Down
Loading