Check for the presence of clang frontends. (#1158)

* checks the presence of clang frontends.

close GH-1149.

* fix clippy complaints
This commit is contained in:
David CARLIER 2023-03-17 15:00:54 +00:00 committed by GitHub
parent d6ee2dbe12
commit fd95560512
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -205,6 +205,22 @@ pub const LIBAFL_CC_LLVM_VERSION: Option<usize> = None;
return; return;
} }
let llvm_bindir = exec_llvm_config(&["--bindir"]);
let bindir_path = Path::new(&llvm_bindir);
let clang = bindir_path.join("clang");
let clangcpp = bindir_path.join("clang++");
if !clang.exists() {
println!("cargo:warning=Failed to find clang frontend.");
return;
}
if !clangcpp.exists() {
println!("cargo:warning=Failed to find clang++ frontend.");
return;
}
let cxxflags = exec_llvm_config(&["--cxxflags"]); let cxxflags = exec_llvm_config(&["--cxxflags"]);
let mut cxxflags: Vec<String> = cxxflags.split_whitespace().map(String::from).collect(); let mut cxxflags: Vec<String> = cxxflags.split_whitespace().map(String::from).collect();
@ -226,32 +242,24 @@ pub const LIBAFL_CC_LLVM_VERSION: Option<usize> = None;
} }
} }
let llvm_bindir = exec_llvm_config(&["--bindir"]);
let bindir_path = Path::new(&llvm_bindir);
write!( write!(
clang_constants_file, clang_constants_file,
"// These constants are autogenerated by build.rs "// These constants are autogenerated by build.rs
/// The path to the `clang` executable /// The path to the `clang` executable
pub const CLANG_PATH: &str = {:?}; pub const CLANG_PATH: &str = {clang:?};
/// The path to the `clang++` executable /// The path to the `clang++` executable
pub const CLANGXX_PATH: &str = {:?}; pub const CLANGXX_PATH: &str = {clangcpp:?};
/// The size of the edges map /// The size of the edges map
pub const EDGES_MAP_SIZE: usize = {}; pub const EDGES_MAP_SIZE: usize = {edges_map_size};
/// The size of the accounting maps /// The size of the accounting maps
pub const ACCOUNTING_MAP_SIZE: usize = {}; pub const ACCOUNTING_MAP_SIZE: usize = {acc_map_size};
/// The llvm version used to build llvm passes /// The llvm version used to build llvm passes
pub const LIBAFL_CC_LLVM_VERSION: Option<usize> = {:?}; pub const LIBAFL_CC_LLVM_VERSION: Option<usize> = {llvm_version:?};
", ",
bindir_path.join("clang"),
bindir_path.join("clang++"),
edges_map_size,
acc_map_size,
llvm_version,
) )
.expect("Could not write file"); .expect("Could not write file");