(project_dir: &Path, target: &str)
| 25 | } |
| 26 | |
| 27 | fn build_cpp_target(project_dir: &Path, target: &str) -> anyhow::Result<std::path::PathBuf> { |
| 28 | let build_exists = project_dir.join("build").exists(); |
| 29 | if !build_exists { |
| 30 | // Configure with cmake -B build |
| 31 | let config = Command::new("cmake") |
| 32 | .current_dir(project_dir) |
| 33 | .args(["-B", "build", "-DCMAKE_BUILD_TYPE=Release"]) |
| 34 | .output()?; |
| 35 | |
| 36 | if !config.status.success() { |
| 37 | eprintln!( |
| 38 | "cmake configure failed: {}", |
| 39 | String::from_utf8_lossy(&config.stderr) |
| 40 | ); |
| 41 | return Err(anyhow::anyhow!("Failed to configure C++ project")); |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | // Build specific target |
| 46 | let build = Command::new("cmake") |
| 47 | .current_dir(project_dir) |
| 48 | .args(["--build", "build", "--target", target, "-j"]) |
| 49 | .output()?; |
| 50 | |
| 51 | if !build.status.success() { |
| 52 | eprintln!( |
| 53 | "cmake build failed: {}", |
| 54 | String::from_utf8_lossy(&build.stderr) |
| 55 | ); |
| 56 | eprintln!("cmake stdout: {}", String::from_utf8_lossy(&build.stdout)); |
| 57 | return Err(anyhow::anyhow!("Failed to build target: {target}")); |
| 58 | } |
| 59 | |
| 60 | let binary_path = project_dir.join(format!("build/{target}")); |
| 61 | Ok(binary_path) |
| 62 | } |
| 63 | |
| 64 | #[test_with::env(GITHUB_ACTIONS)] |
| 65 | #[rstest] |
no test coverage detected