#![allow(clippy::module_name_repetitions)]
pub const SYMCC_REPO_URL: &str = "https://github.com/AFLplusplus/symcc.git";
pub const SYMCC_REPO_COMMIT: &str = "6010402596f02da6de1c2dc88794f339d7c4dfe7";
#[cfg(feature = "clone")]
mod clone {
use std::{
io::{stdout, Write},
path::Path,
process::Command,
};
use which::which;
use crate::{SYMCC_REPO_COMMIT, SYMCC_REPO_URL};
pub fn clone_symcc_at_version(path: &Path, url: &str, commit: &str) {
assert!(
which("git").is_ok(),
"ERROR: unable to find git. Git is required to download SymCC."
);
let mut cmd = Command::new("git");
cmd.arg("clone").arg(url).arg(path);
let output = cmd.output().expect("failed to execute git clone");
if output.status.success() {
let mut cmd = Command::new("git");
cmd.arg("checkout").arg(commit).current_dir(path);
let output = cmd.output().expect("failed to execute git checkout");
if !output.status.success() {
eprintln!("failed to checkout symcc git repository commit:");
let mut stdout = stdout();
stdout
.write_all(&output.stderr)
.expect("failed to write git error message to stdout");
panic!();
}
} else {
eprintln!("failed to clone symcc git repository:");
let mut stdout = stdout();
stdout
.write_all(&output.stderr)
.expect("failed to write git error message to stdout");
panic!();
}
}
pub fn clone_symcc(path: &Path) {
clone_symcc_at_version(path, SYMCC_REPO_URL, SYMCC_REPO_COMMIT);
}
}
#[cfg(feature = "clone")]
pub use clone::clone_symcc;
#[cfg(feature = "build")]
mod build {
use std::path::{Path, PathBuf};
#[must_use]
pub fn build_symcc(path: &Path) -> PathBuf {
use cmake::Config;
Config::new(path)
.define("Z3_TRUST_SYSTEM_VERSION", "ON")
.no_build_target(true)
.build()
.join("build")
}
}
#[cfg(feature = "build")]
pub use build::build_symcc;