blob: 21c57c15d95e460b9f1f7e9835e28bd32ff40b41 [file] [log] [blame]
Ivan Lozanod4c94da2020-11-16 10:56:18 -05001fn main() {
2 if let Ok(custom) = ::std::env::var("CUSTOM_LIBFUZZER_PATH") {
3 let custom_lib_path = ::std::path::PathBuf::from(&custom);
4 let custom_lib_dir = custom_lib_path.parent().unwrap().to_string_lossy();
5
6 let custom_lib_name = custom_lib_path.file_stem().unwrap().to_string_lossy();
7 let custom_lib_name = custom_lib_name.trim_start_matches("lib");
8
9 println!("cargo:rustc-link-search=native={}", custom_lib_dir);
10 println!("cargo:rustc-link-lib=static={}", custom_lib_name);
11
12 match std::env::var("CUSTOM_LIBFUZZER_STD_CXX") {
13 // Default behavior for backwards compat.
14 Err(_) => println!("cargo:rustc-link-lib=stdc++"),
15 Ok(s) if s == "none" => (),
16 Ok(s) => println!("cargo:rustc-link-lib={}", s),
17 }
18 } else {
19 let mut build = cc::Build::new();
20 let sources = ::std::fs::read_dir("libfuzzer")
21 .expect("listable source directory")
22 .map(|de| de.expect("file in directory").path())
23 .filter(|p| p.extension().map(|ext| ext == "cpp") == Some(true))
24 .collect::<Vec<_>>();
25 for source in sources.iter() {
26 println!("cargo:rerun-if-changed={}", source.display());
27 build.file(source.to_str().unwrap());
28 }
29 build.flag("-std=c++11");
30 build.flag("-fno-omit-frame-pointer");
31 build.flag("-w");
32 build.cpp(true);
33 build.compile("libfuzzer.a");
34 }
35}