Allow multiple source file in libafl_cc (#1296)

* add

* clp

* fi

* fmt
This commit is contained in:
Dongjia "toka" Zhang 2023-05-26 11:35:04 +02:00 committed by GitHub
parent 0336eae908
commit 8445ae54b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,6 +1,11 @@
#[cfg(target_vendor = "apple")]
use std::path::PathBuf;
use std::{env, fs::File, io::Write, path::Path, process::Command, str};
use std::{
env,
fs::File,
io::Write,
path::{Path, PathBuf},
process::Command,
str,
};
#[cfg(target_vendor = "apple")]
use glob::glob;
@ -125,6 +130,7 @@ fn find_llvm_version() -> Option<i32> {
None
}
#[allow(clippy::too_many_arguments)]
fn build_pass(
bindir_path: &Path,
out_dir: &Path,
@ -132,17 +138,25 @@ fn build_pass(
ldflags: &Vec<&str>,
src_dir: &Path,
src_file: &str,
additional_srcfiles: Option<&Vec<&str>>,
optional: bool,
) {
let dot_offset = src_file.rfind('.').unwrap();
let src_stub = &src_file[..dot_offset];
let additionals = if let Some(x) = additional_srcfiles {
x.iter().map(|f| src_dir.join(f)).collect::<Vec<PathBuf>>()
} else {
Vec::new()
};
println!("cargo:rerun-if-changed=src/{src_file}");
let r = if cfg!(unix) {
let r = Command::new(bindir_path.join("clang++"))
.arg("-v")
.args(cxxflags)
.arg(src_dir.join(src_file))
.args(additionals)
.args(ldflags)
.arg("-o")
.arg(out_dir.join(format!("{src_stub}.{}", dll_extension())))
@ -154,6 +168,7 @@ fn build_pass(
.arg("-v")
.args(cxxflags)
.arg(src_dir.join(src_file))
.args(additionals)
.arg("/link")
.args(ldflags)
.arg(format!(
@ -359,6 +374,7 @@ pub const LIBAFL_CC_LLVM_VERSION: Option<usize> = None;
&ldflags,
src_dir,
pass,
None,
false,
);
}
@ -372,6 +388,7 @@ pub const LIBAFL_CC_LLVM_VERSION: Option<usize> = None;
&ldflags,
src_dir,
pass,
None,
true,
);
}