use std::{ffi::OsStr, process::Command};
use tempfile::TempPath;
use crate::{
helper::{make_empty_tempfile, get_criterion_env_var, make_spec_tempfile},
runner::{run_command, CommunicatingBenchmark}, BenchSpec,
};
const HARNESS: &str = include_str!("harness.go.in");
const SOURCE_EXTENSION: &str = ".go";
pub fn compile(spec: BenchSpec) -> TempPath {
let temp_go_code = make_spec_tempfile(self::SOURCE_EXTENSION, HARNESS, &spec);
let temp_executable = make_empty_tempfile(super::BIN_EXTENSION);
let go_path = get_criterion_env_var("GO", "go");
let mut compiler_command = Command::new(go_path);
compiler_command
.args(["build", "-o"])
.arg(&temp_executable)
.arg(&temp_go_code);
run_command("compiling Go", &mut compiler_command, Some(temp_go_code));
temp_executable
}
pub fn spawn(executable: impl AsRef<OsStr>) -> CommunicatingBenchmark {
let command = Command::new(executable.as_ref());
CommunicatingBenchmark::start("running Go", command, None)
}