Skip to content

Commit

Permalink
Allow rustdoc to run without a ROS distribution
Browse files Browse the repository at this point in the history
  • Loading branch information
esteve committed Nov 7, 2023
1 parent 9fb29f2 commit 61e2b4f
Show file tree
Hide file tree
Showing 3 changed files with 164 additions and 17 deletions.
6 changes: 6 additions & 0 deletions rclrs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ path = "src/lib.rs"
[dependencies]
# Needed for dynamically finding type support libraries
ament_rs = { version = "0.2", optional = true }
cfg-if = "1.0.0"
# Needed for clients
futures = "0.3"
# Needed for dynamic messages
Expand All @@ -33,3 +34,8 @@ bindgen = "0.66.1"

[features]
dyn_msg = ["ament_rs", "libloading"]
generate_docs = []

[package.metadata.docs.rs]

features = ["generate_docs"]
11 changes: 10 additions & 1 deletion rclrs/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,16 @@ fn get_env_var_or_abort(env_var: &'static str) -> String {
}

fn main() {
let ros_distro = get_env_var_or_abort(ROS_DISTRO);
let ros_distro = if let Ok(value) = env::var(ROS_DISTRO) {
value
} else {
println!(
"{} environment variable not set - please source ROS 2 installation first.",
ROS_DISTRO
);
return;
};

println!("cargo:rustc-cfg=ros_distro=\"{ros_distro}\"");

let mut builder = bindgen::Builder::default()
Expand Down
164 changes: 148 additions & 16 deletions rclrs/src/rcl_bindings.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,148 @@
#![allow(dead_code)]
#![allow(deref_nullptr)]
#![allow(non_upper_case_globals)]
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]
// Added to avoid clippy complaining about u128 types not being FFI safe
// Caused by https://github.com/ros2/ros2/issues/1374 in iron and newer
// See https://github.com/ros2-rust/ros2_rust/issues/320
#![allow(improper_ctypes)]
#![allow(improper_ctypes_definitions)]
#![allow(clippy::all)]
#![allow(missing_docs)]

include!(concat!(env!("OUT_DIR"), "/rcl_bindings_generated.rs"));

pub const RMW_GID_STORAGE_SIZE: usize = rmw_gid_storage_size_constant;
cfg_if::cfg_if! {
if #[cfg(feature="generate_docs")] {
#[repr(C)]
#[derive(Debug)]
pub struct rcl_wait_set_t;
#[repr(C)]
#[derive(Debug)]
pub struct rcl_clock_t;

#[repr(C)]
#[derive(Debug)]
pub struct rcl_node_t;

#[repr(C)]
#[derive(Debug)]
pub struct rcl_context_t;

#[repr(C)]
#[derive(Debug)]
pub struct rcl_guard_condition_t;

#[repr(C)]
#[derive(Debug)]
pub struct rcl_subscription_t;

#[repr(C)]
#[derive(Debug)]
pub struct rmw_request_id_t;

#[repr(C)]
#[derive(Debug)]
pub struct rcl_service_t;

#[repr(C)]
#[derive(Debug)]
pub struct rcl_client_t;

#[repr(C)]
#[derive(Debug)]
pub struct rcl_publisher_t;

#[repr(C)]
#[derive(Debug)]
pub struct rmw_time_t;

#[repr(C)]
#[derive(Debug)]
pub struct rcl_arguments_t;

#[repr(C)]
#[derive(Debug)]
pub struct rcl_allocator_t;

#[repr(C)]
#[derive(Debug)]
pub struct rcl_ret_t;

#[repr(C)]
#[derive(Debug)]
pub struct rcl_clock_type_t;

#[repr(C)]
#[derive(Debug)]
pub struct rcl_node_options_t;

#[repr(C)]
#[derive(Debug)]
pub struct rmw_names_and_types_t;

#[repr(C)]
#[derive(Debug)]
pub struct rmw_topic_endpoint_info_array_t;

#[repr(C)]
#[derive(Debug)]
pub struct rcutils_string_array_t;

#[repr(C)]
#[derive(Debug)]
pub struct rcl_names_and_types_t;

#[repr(C)]
#[derive(Debug)]
pub struct rcl_topic_endpoint_info_array_t;

#[repr(C)]
#[derive(Debug)]
pub struct rcl_node_params_t;

#[repr(C)]
#[derive(Debug)]
pub struct rcl_variant_t;

#[repr(C)]
#[derive(Debug)]
pub struct rcl_params_t;

#[repr(C)]
#[derive(Debug)]
pub struct rmw_message_info_t;

#[repr(C)]
#[derive(Debug)]
pub struct rmw_qos_durability_policy_t;

#[repr(C)]
#[derive(Debug)]
pub struct rmw_qos_history_policy_t;

#[repr(C)]
#[derive(Debug)]
pub struct rmw_qos_liveliness_policy_t;

#[repr(C)]
#[derive(Debug)]
pub struct rmw_qos_profile_t;

#[repr(C)]
#[derive(Debug)]
pub struct rmw_qos_reliability_policy_t;

#[repr(C)]
#[derive(Debug)]
pub struct rosidl_message_type_support_t;

pub const RMW_GID_STORAGE_SIZE: usize = 16;

extern "C" {
pub fn rcl_context_is_valid(context: *const rcl_context_t) -> bool;
}
} else {
#![allow(dead_code)]
#![allow(deref_nullptr)]
#![allow(non_upper_case_globals)]
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]
// Added to avoid clippy complaining about u128 types not being FFI safe
// Caused by https://github.com/ros2/ros2/issues/1374 in iron and newer
// See https://github.com/ros2-rust/ros2_rust/issues/320
#![allow(improper_ctypes)]
#![allow(improper_ctypes_definitions)]
#![allow(clippy::all)]
#![allow(missing_docs)]
include!(concat!(env!("OUT_DIR"), "/rcl_bindings_generated.rs"));

pub const RMW_GID_STORAGE_SIZE: usize = rmw_gid_storage_size_constant;
}
}

0 comments on commit 61e2b4f

Please sign in to comment.