Skip to content

Commit 0570fc0

Browse files
estevecarter
andcommitted
Allow rustdoc to run without a ROS distribution (#347)
* Allow rustdoc to run without a ROS distribution * Extensions to get working * Fail if generate_docs feature is not enabled and ROS_DISTRO is not set * Fix formatting * Fix formatting * Make clippy slightly less unhappy * Do not run clippy for all features if checking rclrs * Clean up rcl_bindings.rs * Fix comparison * Avoid warnings for rosidl_runtime_rs * Avoid running cargo test with all features for rclrs * Ignore rosidl_runtime_rs for cargo test * rosidl_runtime_rs does not have a dyn_msg feature * Add comment about the generate_docs feature --------- Co-authored-by: carter <[email protected]>
1 parent e5fc50e commit 0570fc0

File tree

2 files changed

+35
-15
lines changed

2 files changed

+35
-15
lines changed

rosidl_runtime_rs/Cargo.toml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,21 @@ path = "src/lib.rs"
1717
# formats such as JSON, YAML, Pickle, etc.
1818
serde = { version = "1", optional = true }
1919

20+
[features]
21+
default = []
22+
# This feature is solely for the purpose of being able to generate documetation without a ROS installation
23+
# The only intended usage of this feature is for docs.rs builders to work, and is not intended to be used by end users
24+
generate_docs = []
25+
2026
[dev-dependencies]
2127
# Needed for writing property tests
2228
quickcheck = "1"
2329
# Needed for testing serde support
2430
serde_json = "1"
31+
32+
[build-dependencies]
33+
# Needed for uploading documentation to docs.rs
34+
cfg-if = "1.0.0"
35+
36+
[package.metadata.docs.rs]
37+
features = ["generate_docs"]

rosidl_runtime_rs/build.rs

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,31 @@
1-
use std::env;
2-
use std::path::Path;
1+
cfg_if::cfg_if! {
2+
if #[cfg(not(feature="generate_docs"))] {
3+
use std::env;
4+
use std::path::Path;
35

4-
const AMENT_PREFIX_PATH: &str = "AMENT_PREFIX_PATH";
6+
const AMENT_PREFIX_PATH: &str = "AMENT_PREFIX_PATH";
57

6-
fn get_env_var_or_abort(env_var: &'static str) -> String {
7-
if let Ok(value) = env::var(env_var) {
8-
value
9-
} else {
10-
panic!(
11-
"{} environment variable not set - please source ROS 2 installation first.",
12-
env_var
13-
);
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+
}
1418
}
1519
}
1620

1721
fn main() {
18-
let ament_prefix_path_list = get_env_var_or_abort(AMENT_PREFIX_PATH);
19-
for ament_prefix_path in ament_prefix_path_list.split(':') {
20-
let library_path = Path::new(ament_prefix_path).join("lib");
21-
println!("cargo:rustc-link-search=native={}", library_path.display());
22+
#[cfg(not(feature = "generate_docs"))]
23+
{
24+
let ament_prefix_path_list = get_env_var_or_abort(AMENT_PREFIX_PATH);
25+
for ament_prefix_path in ament_prefix_path_list.split(':') {
26+
let library_path = Path::new(ament_prefix_path).join("lib");
27+
println!("cargo:rustc-link-search=native={}", library_path.display());
28+
}
2229
}
2330

2431
// Invalidate the built crate whenever this script changes

0 commit comments

Comments
 (0)