From fd955605120566b583a4f70829cffdda0dda3972 Mon Sep 17 00:00:00 2001 From: David CARLIER Date: Fri, 17 Mar 2023 15:00:54 +0000 Subject: [PATCH] Check for the presence of clang frontends. (#1158) * checks the presence of clang frontends. close GH-1149. * fix clippy complaints --- libafl_cc/build.rs | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/libafl_cc/build.rs b/libafl_cc/build.rs index ef5ede4ba1..8d44951936 100644 --- a/libafl_cc/build.rs +++ b/libafl_cc/build.rs @@ -205,6 +205,22 @@ pub const LIBAFL_CC_LLVM_VERSION: Option = None; 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 mut cxxflags: Vec = cxxflags.split_whitespace().map(String::from).collect(); @@ -226,32 +242,24 @@ pub const LIBAFL_CC_LLVM_VERSION: Option = None; } } - let llvm_bindir = exec_llvm_config(&["--bindir"]); - let bindir_path = Path::new(&llvm_bindir); - write!( clang_constants_file, "// These constants are autogenerated by build.rs /// The path to the `clang` executable - pub const CLANG_PATH: &str = {:?}; + pub const CLANG_PATH: &str = {clang:?}; /// The path to the `clang++` executable - pub const CLANGXX_PATH: &str = {:?}; + pub const CLANGXX_PATH: &str = {clangcpp:?}; /// 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 - pub const ACCOUNTING_MAP_SIZE: usize = {}; + pub const ACCOUNTING_MAP_SIZE: usize = {acc_map_size}; /// The llvm version used to build llvm passes - pub const LIBAFL_CC_LLVM_VERSION: Option = {:?}; + pub const LIBAFL_CC_LLVM_VERSION: Option = {llvm_version:?}; ", - bindir_path.join("clang"), - bindir_path.join("clang++"), - edges_map_size, - acc_map_size, - llvm_version, ) .expect("Could not write file");