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

Function compile_cpp_project

crates/memtrack/tests/cpp_tests.rs:9–44  ·  view source on GitHub ↗
(project_dir: &Path, target: &str)

Source from the content-addressed store, hash-verified

7use std::process::Command;
8
9fn compile_cpp_project(project_dir: &Path, target: &str) -> anyhow::Result<std::path::PathBuf> {
10 let build_exists = project_dir.join("build").exists();
11 if !build_exists {
12 // Configure with cmake -B build
13 let config = Command::new("cmake")
14 .current_dir(project_dir)
15 .args(["-B", "build", "-DCMAKE_BUILD_TYPE=Release"])
16 .output()?;
17
18 if !config.status.success() {
19 eprintln!(
20 "cmake configure failed: {}",
21 String::from_utf8_lossy(&config.stderr)
22 );
23 return Err(anyhow::anyhow!("Failed to configure C++ project"));
24 }
25 }
26
27 // Build specific target
28 let build = Command::new("cmake")
29 .current_dir(project_dir)
30 .args(["--build", "build", "--target", target, "-j"])
31 .output()?;
32
33 if !build.status.success() {
34 eprintln!(
35 "cmake build failed: {}",
36 String::from_utf8_lossy(&build.stderr)
37 );
38 eprintln!("cmake stdout: {}", String::from_utf8_lossy(&build.stdout));
39 return Err(anyhow::anyhow!("Failed to build target: {target}"));
40 }
41
42 let binary_path = project_dir.join(format!("build/{target}"));
43 Ok(binary_path)
44}
45
46#[test_with::env(GITHUB_ACTIONS)]
47#[rstest]

Callers 1

test_cpp_alloc_trackingFunction · 0.85

Calls 2

argsMethod · 0.80
current_dirMethod · 0.80

Tested by

no test coverage detected