From 4c1aed55cf888feee187e25347c1aad119b439cd Mon Sep 17 00:00:00 2001 From: Istvan Fodor Date: Tue, 1 Oct 2024 07:02:59 -0500 Subject: [PATCH] fox: fixed cargo doc build --- Cargo.toml | 18 +++++++++++++----- build.rs | 15 ++++++++++----- src/ros_mapper.rs | 2 ++ src/schema.rs | 4 ++++ 4 files changed, 29 insertions(+), 10 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ce65489..bc6c685 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "r2a" -version = "0.1.2" +version = "0.1.3" edition = "2021" description = "A Rust library that provides a typesafe way to convert ROS2 messages into Apache Arrow format" homepage = "https://github.com/istvan-fodor/r2a" @@ -9,14 +9,18 @@ license = "Apache-2.0" readme = "README.md" keywords = ["ROS", "ROS2", "Humble", "Jazzy", "Arrow"] +[features] +doc-only = [] +default = ["r2r", "r2r_common"] + + [dependencies] arrow-schema = ">=50" arrow-array = ">=50" -r2r = ">=0.9.0" +r2r = { version = ">=0.9.0", optional = true } anyhow = ">=1" log = ">=0.4" - [dev-dependencies] futures = "0.3" tokio = { version = "1.40.0", features = ["rt-multi-thread", "full"] } @@ -25,11 +29,15 @@ rand = "0.8" [build-dependencies] walkdir = "2" -r2r = ">=0.9.0" -r2r_common = ">=0.9.0" +r2r = { version = ">=0.9.0", optional = true } +r2r_common = { version = ">=0.9.0", optional = true } anyhow = "1" proc-macro2 = "1.0.78" quote = "1.0.35" syn = { version = "2", features = ["full", "visit"] } serde = { version = "1", features = ["derive"] } serde_json = "1" + +[package.metadata.docs.rs] +no-default-features = true +features = ["doc-only"] diff --git a/build.rs b/build.rs index bb023d0..057c222 100644 --- a/build.rs +++ b/build.rs @@ -1,6 +1,6 @@ use proc_macro2::TokenStream; use quote::quote; -use r2r_common::get_env_hash; + use anyhow::Result; use std::collections::BTreeMap; @@ -273,7 +273,6 @@ fn generate_imports() -> TokenStream { fn generate_arrow_imports() -> TokenStream { quote! { use arrow_schema::{DataType, Field, Fields, Schema}; - use std::sync::Arc; use r2r::{WrappedTypesupport}; } } @@ -1546,8 +1545,15 @@ fn generate_arrow_rowbuilders( gen_function } +#[cfg(feature = "doc-only")] +fn main() -> Result<()> { + Ok(()) +} + +#[cfg(not(feature = "doc-only"))] fn main() -> Result<()> { // Parse the source code as a syn file + use r2r_common::get_env_hash; let out_dir = env::var("OUT_DIR").unwrap(); let out_dir_path = Path::new(&out_dir); @@ -1572,16 +1578,15 @@ fn main() -> Result<()> { let (structs_by_schema, structs_by_type) = find_structs_by_schema_and_type(deps_dir, env_hash.as_str(), &implementing_structs); - //let map_function = generate_map_function(&structs_by_schema); + //let map_function = generate_map_function(&structs_by_schema);s generate_schema( out_dir_path, &structs_by_schema, - // &structs_by_type, + // &structs_by_type, &mut log_file, )?; generate_arrow_mappers(out_dir, structs_by_schema, structs_by_type, &mut log_file)?; - Ok(()) } diff --git a/src/ros_mapper.rs b/src/ros_mapper.rs index e2664dd..7f2c78f 100644 --- a/src/ros_mapper.rs +++ b/src/ros_mapper.rs @@ -1,6 +1,7 @@ use anyhow::Result; use arrow_array::builder::ArrayBuilder; use arrow_array::Array; +use std::sync::Arc; /// The `RowBuilder` trait is implemented for each ROS2 message type by a code generator. /// It serves as an accumulator that collects records and converts them into a collection @@ -152,6 +153,7 @@ pub trait ArrowSupport<'a> { fn arrow_schema() -> arrow_schema::Schema; } +#[cfg(feature = "default")] include!(concat!(env!("OUT_DIR"), "/generated_arrow_mappers.rs")); #[cfg(test)] diff --git a/src/schema.rs b/src/schema.rs index 3095cc3..51f0abb 100644 --- a/src/schema.rs +++ b/src/schema.rs @@ -1 +1,5 @@ +#[cfg(feature = "default")] include!(concat!(env!("OUT_DIR"), "/generated_schema.rs")); + +#[cfg(feature = "doc-only")] +pub static SUPPORTED_SCHEMAS: &'static [&'static str] = &[];