Skip to content

Commit 355bc59

Browse files
deweerdtnagisa
authored andcommitted
Optionally use a custom libFuzzer.a archive
Tweak build.rs so that it's possible to use a custom libFuzzer.a archive. This is necessary when using OSS-Fuzz (https://github.com/google/oss-fuzz): the build system has to link with the libFuzzer provided by the `LIB_FUZZING_ENGINE` environment variable (see https://github.com/google/oss-fuzz/blob/master/docs/new_project_guide.md)
1 parent bcaa8e1 commit 355bc59

File tree

1 file changed

+25
-12
lines changed

1 file changed

+25
-12
lines changed

build.rs

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,30 @@
11
extern crate gcc;
22

33
fn main() {
4-
let sources = ::std::fs::read_dir("llvm/lib/Fuzzer")
5-
.expect("listable source directory")
6-
.map(|de| de.expect("file in directory").path())
7-
.filter(|p| p.extension().map(|ext| ext == "cpp") == Some(true))
8-
.collect::<Vec<_>>();
9-
let mut config = gcc::Config::new();
10-
for source in sources.iter() {
11-
config.file(source.to_str().unwrap());
4+
if let Ok(custom) = ::std::env::var("CUSTOM_LIBFUZZER_PATH") {
5+
let custom_lib_dir = ::std::path::PathBuf::from(&custom);
6+
let custom_lib_dir = custom_lib_dir.parent().unwrap().to_string_lossy();
7+
8+
let custom_lib_name = ::std::path::PathBuf::from(&custom);
9+
let custom_lib_name = custom_lib_name.file_stem().unwrap().to_string_lossy();
10+
let custom_lib_name = &custom_lib_name[3..];
11+
12+
println!("cargo:rustc-link-search=native={}", custom_lib_dir);
13+
println!("cargo:rustc-link-lib=static={}", custom_lib_name);
14+
println!("cargo:rustc-link-lib=stdc++");
15+
} else {
16+
let mut config = gcc::Config::new();
17+
let sources = ::std::fs::read_dir("llvm/lib/Fuzzer")
18+
.expect("listable source directory")
19+
.map(|de| de.expect("file in directory").path())
20+
.filter(|p| p.extension().map(|ext| ext == "cpp") == Some(true))
21+
.collect::<Vec<_>>();
22+
for source in sources.iter() {
23+
config.file(source.to_str().unwrap());
24+
}
25+
config.flag("-std=c++11");
26+
config.flag("-fno-omit-frame-pointer");
27+
config.cpp(true);
28+
config.compile("libfuzzer.a");
1229
}
13-
config.flag("-std=c++11");
14-
config.flag("-fno-omit-frame-pointer");
15-
config.cpp(true);
16-
config.compile("libfuzzer.a");
1730
}

0 commit comments

Comments
 (0)