use clap::CommandFactory; use clap_mangen::Man; use std::fs; use std::path::PathBuf; include!("src/cli.rs"); fn main() { // Vendored protoc for reproducible builds let protoc = protoc_bin_vendored::protoc_bin_path().expect("protoc"); println!("cargo:rerun-if-changed=proto/processes.proto"); println!("cargo:rerun-if-changed=src/cli.rs"); // Compile protobuf definitions for processes let mut cfg = prost_build::Config::new(); cfg.out_dir(std::env::var("OUT_DIR").unwrap()); cfg.protoc_executable(protoc); // Use the vendored protoc directly // Use local path (ensures file is inside published crate tarball) cfg.compile_protos(&["proto/processes.proto"], &["proto"]) // relative to CARGO_MANIFEST_DIR .expect("compile protos"); // Generate man page generate_man_page().expect("man page generation failed"); } fn generate_man_page() -> std::io::Result<()> { let out_dir = PathBuf::from(std::env::var("OUT_DIR").unwrap()); let man_dir = out_dir.join("man"); fs::create_dir_all(&man_dir)?; // Generate man page for socktop_agent let cmd = Cli::command(); let man = Man::new(cmd); let mut buffer = Vec::new(); man.render(&mut buffer)?; fs::write(man_dir.join("socktop_agent.1"), buffer)?; println!( "cargo:warning=Man page generated at {:?}", man_dir.join("socktop_agent.1") ); Ok(()) }