(content: &str)
| 33 | } |
| 34 | |
| 35 | fn 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 | |
| 58 | fn execute_rust_program(obj: &str) -> anyhow::Result<String> { |
| 59 | let result = std::process::Command::new(&obj) |
no test coverage detected