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

Function compile_rust_binary

crates/memtrack/tests/shared.rs:104–125  ·  view source on GitHub ↗

Compile a Rust binary from a test crate directory.

(
    crate_dir: &Path,
    name: &str,
    features: &[&str],
)

Source from the content-addressed store, hash-verified

102
103/// Compile a Rust binary from a test crate directory.
104pub 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///

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