Compile a Rust binary from a test crate directory.
(
crate_dir: &Path,
name: &str,
features: &[&str],
)
| 102 | |
| 103 | /// Compile a Rust binary from a test crate directory. |
| 104 | pub fn compile_rust_binary( |
| 105 | crate_dir: &Path, |
| 106 | name: &str, |
| 107 | features: &[&str], |
| 108 | ) -> anyhow::Result<std::path::PathBuf> { |
| 109 | let mut cmd = Command::new("cargo"); |
| 110 | cmd.current_dir(crate_dir) |
| 111 | .args(["build", "--release", "--bin", name]); |
| 112 | |
| 113 | if !features.is_empty() { |
| 114 | cmd.arg("--features").arg(features.join(",")); |
| 115 | } |
| 116 | |
| 117 | let output = cmd.output()?; |
| 118 | if !output.status.success() { |
| 119 | eprintln!("cargo stderr: {}", String::from_utf8_lossy(&output.stderr)); |
| 120 | eprintln!("cargo stdout: {}", String::from_utf8_lossy(&output.stdout)); |
| 121 | return Err(anyhow::anyhow!("Failed to compile Rust crate")); |
| 122 | } |
| 123 | |
| 124 | Ok(crate_dir.join(format!("target/release/{name}"))) |
| 125 | } |
| 126 | |
| 127 | /// Track a spawned command, collecting all memory events. |
| 128 | /// |
no test coverage detected