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

Function compile_c_source

crates/memtrack/tests/c_tests.rs:11–32  ·  view source on GitHub ↗

Compiles C source code and returns the binary path

(
    source_code: &str,
    name: &str,
    output_dir: &Path,
)

Source from the content-addressed store, hash-verified

9
10/// Compiles C source code and returns the binary path
11fn compile_c_source(
12 source_code: &str,
13 name: &str,
14 output_dir: &Path,
15) -> Result<std::path::PathBuf, Box<dyn std::error::Error>> {
16 let source_path = output_dir.join(format!("{name}.c"));
17 let binary_path = output_dir.join(name);
18
19 fs::write(&source_path, source_code)?;
20
21 let output = Command::new("gcc")
22 .args(["-o", binary_path.to_str().unwrap()])
23 .arg(&source_path)
24 .output()?;
25
26 if !output.status.success() {
27 eprintln!("gcc stderr: {}", String::from_utf8_lossy(&output.stderr));
28 return Err("Failed to compile C fixture".into());
29 }
30
31 Ok(binary_path)
32}
33
34struct AllocationTestCase {
35 name: &'static str,

Callers 1

test_allocation_trackingFunction · 0.85

Calls 2

argMethod · 0.80
argsMethod · 0.80

Tested by

no test coverage detected