use std::path::PathBuf; fn main() { let manifest_directory = PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").unwrap()); let definitions = manifest_directory.join("definitions"); let dialect = definitions.join("kaptan.xml"); println!("cargo::rerun-if-changed={}", definitions.display()); // The upstream generator conditionally emits derives for these optional // ecosystem crates. Kaptan deliberately does not expose those incomplete // features, so tell rustc the generated inactive cfgs are intentional. println!("cargo::rustc-check-cfg=cfg(feature, values(\"serde\", \"arbitrary\", \"ts-rs\"))"); let output_directory = std::env::var("OUT_DIR").unwrap(); mavlink_bindgen::generate( mavlink_bindgen::XmlDefinitions::Files(vec![dialect]), &output_directory, ) .unwrap(); // Bindgen's index feature-gates every dialect module. Kaptan has exactly // one unconditional dialect, so load its generated file as a normal Rust // module instead of exposing a redundant Cargo feature. std::fs::write( PathBuf::from(output_directory).join("kaptan_module.rs"), "#[allow(non_camel_case_types, non_snake_case)]\n\ #[allow(clippy::derive_partial_eq_without_eq, clippy::field_reassign_with_default)]\n\ #[allow(clippy::unnecessary_cast, clippy::bad_bit_mask)]\n\ #[allow(clippy::suspicious_else_formatting)]\n\ #[path = \"kaptan.rs\"]\npub mod kaptan;\n", ) .unwrap(); }