diff --git a/rclrs/Cargo.toml b/rclrs/Cargo.toml index 81ec8a539..0e0250584 100644 --- a/rclrs/Cargo.toml +++ b/rclrs/Cargo.toml @@ -16,7 +16,9 @@ path = "src/lib.rs" [dependencies] # Needed for dynamically finding type support libraries ament_rs = { version = "0.2", optional = true } +# Needed for uploading documentation to docs.rs cfg-if = "1.0.0" + # Needed for clients futures = "0.3" # Needed for dynamic messages @@ -31,6 +33,8 @@ tempfile = "3.3.0" [build-dependencies] # Needed for FFI bindgen = "0.66.1" +# Needed for uploading documentation to docs.rs +cfg-if = "1.0.0" [features] dyn_msg = ["ament_rs", "libloading"] diff --git a/rclrs/build.rs b/rclrs/build.rs index 753345974..e6aa8ee05 100644 --- a/rclrs/build.rs +++ b/rclrs/build.rs @@ -21,11 +21,16 @@ fn main() { 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; + let error_msg = + "ROS_DISTRO environment variable not set - please source ROS 2 installation first."; + cfg_if::cfg_if! { + if #[cfg(feature="generate_docs")] { + println!(error_msg); + return; + } else { + panic!(error_msg); + } + } }; println!("cargo:rustc-cfg=ros_distro=\"{ros_distro}\"");