(project_dir: &Path, target: &str)
| 7 | use std::process::Command; |
| 8 | |
| 9 | fn compile_cpp_project(project_dir: &Path, target: &str) -> anyhow::Result<std::path::PathBuf> { |
| 10 | let build_exists = project_dir.join("build").exists(); |
| 11 | if !build_exists { |
| 12 | // Configure with cmake -B build |
| 13 | let config = Command::new("cmake") |
| 14 | .current_dir(project_dir) |
| 15 | .args(["-B", "build", "-DCMAKE_BUILD_TYPE=Release"]) |
| 16 | .output()?; |
| 17 | |
| 18 | if !config.status.success() { |
| 19 | eprintln!( |
| 20 | "cmake configure failed: {}", |
| 21 | String::from_utf8_lossy(&config.stderr) |
| 22 | ); |
| 23 | return Err(anyhow::anyhow!("Failed to configure C++ project")); |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | // Build specific target |
| 28 | let build = Command::new("cmake") |
| 29 | .current_dir(project_dir) |
| 30 | .args(["--build", "build", "--target", target, "-j"]) |
| 31 | .output()?; |
| 32 | |
| 33 | if !build.status.success() { |
| 34 | eprintln!( |
| 35 | "cmake build failed: {}", |
| 36 | String::from_utf8_lossy(&build.stderr) |
| 37 | ); |
| 38 | eprintln!("cmake stdout: {}", String::from_utf8_lossy(&build.stdout)); |
| 39 | return Err(anyhow::anyhow!("Failed to build target: {target}")); |
| 40 | } |
| 41 | |
| 42 | let binary_path = project_dir.join(format!("build/{target}")); |
| 43 | Ok(binary_path) |
| 44 | } |
| 45 | |
| 46 | #[test_with::env(GITHUB_ACTIONS)] |
| 47 | #[rstest] |
no test coverage detected