Compile a Rust binary from a test crate directory. Each feature set gets its own target dir, otherwise parallel test cases race to overwrite one binary.
(
crate_dir: &Path,
name: &str,
features: &[&str],
)
| 145 | /// Compile a Rust binary from a test crate directory. Each feature set gets its |
| 146 | /// own target dir, otherwise parallel test cases race to overwrite one binary. |
| 147 | pub fn compile_rust_binary( |
| 148 | crate_dir: &Path, |
| 149 | name: &str, |
| 150 | features: &[&str], |
| 151 | ) -> anyhow::Result<std::path::PathBuf> { |
| 152 | let target_dir = match features { |
| 153 | [] => "target/default".to_string(), |
| 154 | _ => format!("target/{}", features.join("-")), |
| 155 | }; |
| 156 | |
| 157 | let mut cmd = Command::new("cargo"); |
| 158 | cmd.current_dir(crate_dir).args([ |
| 159 | "build", |
| 160 | "--release", |
| 161 | "--bin", |
| 162 | name, |
| 163 | "--target-dir", |
| 164 | &target_dir, |
| 165 | ]); |
| 166 | |
| 167 | if !features.is_empty() { |
| 168 | cmd.arg("--features").arg(features.join(",")); |
| 169 | } |
| 170 | |
| 171 | let output = cmd.output()?; |
| 172 | if !output.status.success() { |
| 173 | eprintln!("cargo stderr: {}", String::from_utf8_lossy(&output.stderr)); |
| 174 | eprintln!("cargo stdout: {}", String::from_utf8_lossy(&output.stdout)); |
| 175 | return Err(anyhow::anyhow!("Failed to compile Rust crate")); |
| 176 | } |
| 177 | |
| 178 | Ok(crate_dir.join(format!("{target_dir}/release/{name}"))) |
| 179 | } |
| 180 | |
| 181 | /// Track a binary, collecting all memory events. |
| 182 | pub fn track_binary(binary: &Path) -> TrackResult { |
no test coverage detected