MCPcopy Create free account
hub / github.com/SeaQL/FireDBG.for.Rust / compile_rust_program

Function compile_rust_program

debugger/src/debugger/probe.rs:35–56  ·  view source on GitHub ↗
(content: &str)

Source from the content-addressed store, hash-verified

33}
34
35fn compile_rust_program(content: &str) -> anyhow::Result<String> {
36 let timestamp = SystemTime::now().duration_since(UNIX_EPOCH)?.as_nanos();
37 let path = format!("/tmp/{}", timestamp);
38 let src = format!("{path}.rs");
39 let obj = format!("{path}.o");
40 let mut file = File::create(&src).with_context(|| format!("Fail to create file: `{src}`"))?;
41 file.write_all(content.as_bytes())
42 .context("Fail to write")?;
43 let result = std::process::Command::new("rustc")
44 .arg("--cap-lints=allow")
45 .arg("--edition=2021")
46 .arg("-g")
47 .arg(&src)
48 .arg("-o")
49 .arg(&obj)
50 .spawn()?
51 .wait_with_output()?;
52 if result.status.code().context("compile")? != 0 {
53 anyhow::bail!("Failed to compile {src}");
54 }
55 Ok(obj)
56}
57
58fn execute_rust_program(obj: &str) -> anyhow::Result<String> {
59 let result = std::process::Command::new(&obj)

Callers 1

probe_layout_ofFunction · 0.85

Calls 1

as_bytesMethod · 0.80

Tested by

no test coverage detected