diff --git a/src/cpgen/gen.rs b/src/cpgen/gen.rs index 75060ad..8280a44 100644 --- a/src/cpgen/gen.rs +++ b/src/cpgen/gen.rs @@ -73,7 +73,7 @@ fn generate(dir_path: &str, lang: &Language) -> anyhow::Result<()> { ]; InnerGenerator::new(cpp_files) } - Language::Rust => { + Language::Rs => { let rust_files = vec![crate::r#static::MAIN_RS]; InnerGenerator::new(rust_files) } diff --git a/src/lang.rs b/src/lang.rs index d7009d8..c70e1f6 100644 --- a/src/lang.rs +++ b/src/lang.rs @@ -4,7 +4,7 @@ use clap::ValueEnum; pub enum Language { #[default] Cpp, - Rust, + Rs, } impl Language { diff --git a/src/runner.rs b/src/runner.rs index 718dcd8..d9a9f38 100644 --- a/src/runner.rs +++ b/src/runner.rs @@ -27,6 +27,9 @@ impl Runner { .split("/") .last() .ok_or(anyhow::anyhow!("No file name"))?; + let file_path = (std::env::current_dir() + .map_err(|_| anyhow::anyhow!("Cannot get current directory"))?) + .join(&self.file_path); match lang { Language::Cpp => { @@ -35,17 +38,32 @@ impl Runner { .arg("-o") .arg("main") .arg("-DLOCAL") - .arg(&self.file_path) + .arg(file_path) .output()?; } - Language::Rust => { - Command::new("rustc") - .arg(file_name) - .arg("--cfg") - .arg(r#"'feature="local"'"#) + Language::Rs => { + if !file_path.is_file() { + return Err(anyhow::anyhow!("File not found: {}", file_path.display())); + } + + let output = Command::new("rustc") + .arg( + file_path + .to_str() + .ok_or(anyhow::anyhow!("Invalid file name"))?, + ) .arg("-o") .arg("main") + .arg("--cfg") + .arg("feature=\"local\"") .output()?; + if !output.stderr.is_empty() { + return Err(anyhow::anyhow!( + "Compilation failed: {}", + String::from_utf8(output.stderr)? + )); + } + println!("{}", String::from_utf8(output.stdout)?); } };