mirror of https://git.sr.ht/~garritfra/sabre
Garrit Franke
3 years ago
6 changed files with 169 additions and 7 deletions
@ -0,0 +1,56 @@ |
|||||||
|
use crate::command::build; |
||||||
|
use std::io::Write; |
||||||
|
use std::path::PathBuf; |
||||||
|
use std::process::Command; |
||||||
|
use std::process::Stdio; |
||||||
|
use tempfile::tempdir; |
||||||
|
|
||||||
|
pub fn run(in_file: PathBuf) -> Result<(), String> { |
||||||
|
let out_dir = tempdir() |
||||||
|
.expect("Could not create temporary file") |
||||||
|
.into_path(); |
||||||
|
|
||||||
|
let intermediate_out_file_path = out_dir.join("intermediate.c"); |
||||||
|
build::build(&in_file, &intermediate_out_file_path)?; |
||||||
|
let out_file = out_dir.join("out"); |
||||||
|
if cfg!(feature = "backend_c") { |
||||||
|
let comp = Command::new("/usr/bin/cc") |
||||||
|
.arg(&intermediate_out_file_path) |
||||||
|
.arg("-o") |
||||||
|
.arg(&out_file) |
||||||
|
.stdout(Stdio::piped()) |
||||||
|
.stderr(Stdio::piped()) |
||||||
|
.output() |
||||||
|
.expect("Could not spawn compilation process"); |
||||||
|
|
||||||
|
let out = Command::new(out_file) |
||||||
|
.stdout(Stdio::piped()) |
||||||
|
.stderr(Stdio::piped()) |
||||||
|
.output() |
||||||
|
.expect("Could not spawn run process"); |
||||||
|
|
||||||
|
std::io::stdout() |
||||||
|
.write_all(&out.stdout) |
||||||
|
.expect("Could not write to stdout"); |
||||||
|
|
||||||
|
std::io::stderr() |
||||||
|
.write_all(&out.stderr) |
||||||
|
.expect("Could not write to stderr"); |
||||||
|
} else if cfg!(feature = "backend_node") { |
||||||
|
let out = Command::new("node") |
||||||
|
.arg(&intermediate_out_file_path) |
||||||
|
.stdout(Stdio::piped()) |
||||||
|
.stderr(Stdio::piped()) |
||||||
|
.output() |
||||||
|
.expect("Could not spawn run process"); |
||||||
|
|
||||||
|
std::io::stdout() |
||||||
|
.write_all(&out.stdout) |
||||||
|
.expect("Could not write to stdout"); |
||||||
|
|
||||||
|
std::io::stderr() |
||||||
|
.write_all(&out.stderr) |
||||||
|
.expect("Could not write to stderr"); |
||||||
|
} |
||||||
|
Ok(()) |
||||||
|
} |
Loading…
Reference in new issue