Allow QEMU location and version to be specified in environment (#3226)
* Allow QEMU location and version to be specified in environment * Rename things * Change remote to url
This commit is contained in:
parent
626812a7ce
commit
b5ab6bad1c
@ -9,9 +9,9 @@ use which::which;
|
|||||||
|
|
||||||
use crate::cargo_add_rpath;
|
use crate::cargo_add_rpath;
|
||||||
|
|
||||||
pub const QEMU_URL: &str = "https://github.com/AFLplusplus/qemu-libafl-bridge";
|
pub const LIBAFL_QEMU_GIT_URL: &str = "https://github.com/AFLplusplus/qemu-libafl-bridge";
|
||||||
pub const QEMU_DIRNAME: &str = "qemu-libafl-bridge";
|
pub const LIBAFL_QEMU_DIRNAME: &str = "qemu-libafl-bridge";
|
||||||
pub const QEMU_REVISION: &str = "0bea78a122b249cbffafdb130af04cc7331c9aee";
|
pub const LIBAFL_QEMU_GIT_REV: &str = "0bea78a122b249cbffafdb130af04cc7331c9aee";
|
||||||
|
|
||||||
pub struct BuildResult {
|
pub struct BuildResult {
|
||||||
pub qemu_path: PathBuf,
|
pub qemu_path: PathBuf,
|
||||||
@ -278,12 +278,18 @@ pub fn build(
|
|||||||
env::var_os("LIBAFL_QEMU_CLONE_DIR").map(|x| x.to_string_lossy().to_string());
|
env::var_os("LIBAFL_QEMU_CLONE_DIR").map(|x| x.to_string_lossy().to_string());
|
||||||
let libafl_qemu_force_configure = env::var("LIBAFL_QEMU_FORCE_CONFIGURE").is_ok();
|
let libafl_qemu_force_configure = env::var("LIBAFL_QEMU_FORCE_CONFIGURE").is_ok();
|
||||||
let libafl_qemu_no_build = env::var("LIBAFL_QEMU_NO_BUILD").is_ok();
|
let libafl_qemu_no_build = env::var("LIBAFL_QEMU_NO_BUILD").is_ok();
|
||||||
|
let libafl_qemu_git_url =
|
||||||
|
env::var_os("LIBAFL_QEMU_GIT_URL").map(|x| x.to_string_lossy().to_string());
|
||||||
|
let libafl_qemu_git_rev =
|
||||||
|
env::var_os("LIBAFL_QEMU_GIT_REV").map(|x| x.to_string_lossy().to_string());
|
||||||
|
|
||||||
println!("cargo:rerun-if-env-changed=LIBAFL_QEMU_DIR");
|
println!("cargo:rerun-if-env-changed=LIBAFL_QEMU_DIR");
|
||||||
println!("cargo:rerun-if-env-changed=LIBAFL_QEMU_CLONE_DIR");
|
println!("cargo:rerun-if-env-changed=LIBAFL_QEMU_CLONE_DIR");
|
||||||
println!("cargo:rerun-if-env-changed=LIBAFL_QEMU_FORCE_BUILD");
|
println!("cargo:rerun-if-env-changed=LIBAFL_QEMU_FORCE_BUILD");
|
||||||
println!("cargo:rerun-if-env-changed=LIBAFL_QEMU_FORCE_CONFIGURE");
|
println!("cargo:rerun-if-env-changed=LIBAFL_QEMU_FORCE_CONFIGURE");
|
||||||
println!("cargo:rerun-if-env-changed=LIBAFL_QEMU_NO_BUILD");
|
println!("cargo:rerun-if-env-changed=LIBAFL_QEMU_NO_BUILD");
|
||||||
|
println!("cargo:rerun-if-env-changed=LIBAFL_QEMU_GIT_URL");
|
||||||
|
println!("cargo:rerun-if-env-changed=LIBAFL_QEMU_GIT_REV");
|
||||||
|
|
||||||
let out_dir = env::var_os("OUT_DIR").unwrap();
|
let out_dir = env::var_os("OUT_DIR").unwrap();
|
||||||
let out_dir = out_dir.to_string_lossy().to_string();
|
let out_dir = out_dir.to_string_lossy().to_string();
|
||||||
@ -299,29 +305,45 @@ pub fn build(
|
|||||||
let cpp_compiler = cc::Build::new().cpp(true).get_compiler();
|
let cpp_compiler = cc::Build::new().cpp(true).get_compiler();
|
||||||
|
|
||||||
let libafl_qemu_dir = if let Some(qemu_dir) = libafl_qemu_dir.as_ref() {
|
let libafl_qemu_dir = if let Some(qemu_dir) = libafl_qemu_dir.as_ref() {
|
||||||
if libafl_qemu_clone_dir.is_some() {
|
assert!(
|
||||||
println!(
|
libafl_qemu_clone_dir.is_none(),
|
||||||
"cargo:warning=LIBAFL_QEMU_DIR and LIBAFL_QEMU_CLONE_DIR are both set. LIBAFL_QEMU_DIR will be considered in priority"
|
"cargo:warning=LIBAFL_QEMU_DIR and LIBAFL_QEMU_CLONE_DIR are both set."
|
||||||
);
|
);
|
||||||
}
|
|
||||||
|
assert!(
|
||||||
|
libafl_qemu_git_url.is_none(),
|
||||||
|
"cargo:warning=LIBAFL_QEMU_DIR and LIBAFL_QEMU_GIT_URL are both set."
|
||||||
|
);
|
||||||
|
|
||||||
|
assert!(
|
||||||
|
libafl_qemu_git_rev.is_none(),
|
||||||
|
"cargo:warning=LIBAFL_QEMU_DIR and LIBAFL_QEMU_GIT_REV are both set."
|
||||||
|
);
|
||||||
|
|
||||||
Path::new(&qemu_dir).to_path_buf()
|
Path::new(&qemu_dir).to_path_buf()
|
||||||
} else {
|
} else {
|
||||||
let qemu_path = if let Some(clone_dir) = &libafl_qemu_clone_dir {
|
let qemu_path = if let Some(clone_dir) = &libafl_qemu_clone_dir {
|
||||||
PathBuf::from(clone_dir)
|
PathBuf::from(clone_dir)
|
||||||
} else {
|
} else {
|
||||||
target_dir.join(QEMU_DIRNAME)
|
target_dir.join(LIBAFL_QEMU_DIRNAME)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let qemu_git_url = libafl_qemu_git_url
|
||||||
|
.as_deref()
|
||||||
|
.unwrap_or(LIBAFL_QEMU_GIT_URL);
|
||||||
|
let qemu_git_rev = libafl_qemu_git_rev
|
||||||
|
.as_deref()
|
||||||
|
.unwrap_or(LIBAFL_QEMU_GIT_REV);
|
||||||
|
|
||||||
let qemu_rev = target_dir.join("QEMU_REVISION");
|
let qemu_rev = target_dir.join("QEMU_REVISION");
|
||||||
if qemu_rev.exists()
|
if qemu_rev.exists()
|
||||||
&& fs::read_to_string(&qemu_rev).expect("Failed to read QEMU_REVISION") != QEMU_REVISION
|
&& fs::read_to_string(&qemu_rev).expect("Failed to read QEMU_REVISION") != qemu_git_rev
|
||||||
{
|
{
|
||||||
drop(fs::remove_dir_all(&qemu_path));
|
drop(fs::remove_dir_all(&qemu_path));
|
||||||
}
|
}
|
||||||
|
|
||||||
if !qemu_path.is_dir() {
|
if !qemu_path.is_dir() {
|
||||||
println!("cargo:warning=Qemu not found, cloning with git ({QEMU_REVISION})...");
|
println!("cargo:warning=Qemu not found, cloning with git ({qemu_git_rev})...");
|
||||||
fs::create_dir_all(&qemu_path).unwrap();
|
fs::create_dir_all(&qemu_path).unwrap();
|
||||||
assert!(
|
assert!(
|
||||||
Command::new("git")
|
Command::new("git")
|
||||||
@ -337,7 +359,7 @@ pub fn build(
|
|||||||
.arg("remote")
|
.arg("remote")
|
||||||
.arg("add")
|
.arg("add")
|
||||||
.arg("origin")
|
.arg("origin")
|
||||||
.arg(QEMU_URL)
|
.arg(qemu_git_url)
|
||||||
.status()
|
.status()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.success()
|
.success()
|
||||||
@ -349,7 +371,7 @@ pub fn build(
|
|||||||
.arg("--depth")
|
.arg("--depth")
|
||||||
.arg("1")
|
.arg("1")
|
||||||
.arg("origin")
|
.arg("origin")
|
||||||
.arg(QEMU_REVISION)
|
.arg(qemu_git_rev)
|
||||||
.status()
|
.status()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.success()
|
.success()
|
||||||
@ -363,7 +385,7 @@ pub fn build(
|
|||||||
.unwrap()
|
.unwrap()
|
||||||
.success()
|
.success()
|
||||||
);
|
);
|
||||||
fs::write(&qemu_rev, QEMU_REVISION).unwrap();
|
fs::write(&qemu_rev, qemu_git_rev).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
qemu_path
|
qemu_path
|
||||||
|
@ -24,7 +24,7 @@ mod build;
|
|||||||
pub use build::build;
|
pub use build::build;
|
||||||
|
|
||||||
#[rustversion::nightly]
|
#[rustversion::nightly]
|
||||||
use crate::build::QEMU_REVISION;
|
use crate::build::LIBAFL_QEMU_GIT_REV;
|
||||||
|
|
||||||
const LLVM_VERSION_MAX: i32 = 33;
|
const LLVM_VERSION_MAX: i32 = 33;
|
||||||
|
|
||||||
@ -421,7 +421,7 @@ pub fn maybe_generate_stub_bindings(
|
|||||||
None,
|
None,
|
||||||
vec![
|
vec![
|
||||||
header.as_str(),
|
header.as_str(),
|
||||||
format!("/* qemu git hash: {QEMU_REVISION} */").as_str(),
|
format!("/* qemu git hash: {LIBAFL_QEMU_GIT_REV} */").as_str(),
|
||||||
],
|
],
|
||||||
false,
|
false,
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user