dampen_cli/commands/
build.rs1#![allow(clippy::print_stderr, clippy::print_stdout)]
2
3use std::path::Path;
6
7#[derive(clap::Args)]
9pub struct BuildArgs {
10 #[arg(short, long, default_value = "ui")]
12 input: String,
13
14 #[arg(short, long, default_value = "src/ui_generated.rs")]
16 output: String,
17
18 #[arg(long, default_value = "Model")]
20 model: String,
21
22 #[arg(long, default_value = "Message")]
24 message: String,
25
26 #[arg(short, long)]
28 verbose: bool,
29
30 #[arg(short, long)]
32 package: Option<String>,
33
34 #[arg(long, value_delimiter = ',')]
36 features: Vec<String>,
37}
38
39pub fn execute(args: &BuildArgs) -> Result<(), String> {
63 execute_production_build(args)
65}
66
67fn execute_production_build(args: &BuildArgs) -> Result<(), String> {
69 use std::process::Command;
70
71 if args.verbose {
72 eprintln!("Running debug build with codegen...");
73 }
74
75 if !Path::new("build.rs").exists() {
77 return Err(
78 "build.rs not found. This project may not be configured for codegen builds."
79 .to_string(),
80 );
81 }
82
83 if !Path::new("Cargo.toml").exists() {
85 return Err("Cargo.toml not found. Are you in a Rust project directory?".to_string());
86 }
87
88 let mut cmd = Command::new("cargo");
90 cmd.arg("build");
91
92 if let Some(ref package) = args.package {
94 cmd.arg("-p").arg(package);
95 }
96
97 if args.verbose {
98 cmd.arg("--verbose");
99 }
100
101 let mut all_features = vec!["codegen".to_string()];
103 all_features.extend(args.features.clone());
104
105 cmd.arg("--features").arg(all_features.join(","));
107
108 if args.verbose {
110 let features_str = all_features.join(",");
111 eprintln!("Executing: cargo build --features {}", features_str);
112 }
113
114 let status = cmd
115 .status()
116 .map_err(|e| format!("Failed to execute cargo: {}", e))?;
117
118 if !status.success() {
119 return Err("Build failed".to_string());
120 }
121
122 if args.verbose {
123 eprintln!("Build successful! Binary is in target/debug/");
124 }
125
126 eprintln!("Debug build completed successfully!");
127 eprintln!("Use 'dampen release' for optimized production builds.");
128 Ok(())
129}