MCPcopy Create free account
hub / github.com/CodSpeedHQ/codspeed / compile_rust_binary

Function compile_rust_binary

crates/memtrack/tests/shared.rs:147–179  ·  view source on GitHub ↗

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],
)

Source from the content-addressed store, hash-verified

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.
147pub 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.
182pub fn track_binary(binary: &Path) -> TrackResult {

Callers 2

test_rust_alloc_trackingFunction · 0.85
compile_spawn_binaryFunction · 0.85

Calls 4

argsMethod · 0.80
current_dirMethod · 0.80
argMethod · 0.80
is_emptyMethod · 0.45

Tested by

no test coverage detected