-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make it possible to link to custom libfuzzer in another dep
- Loading branch information
1 parent
df3ac96
commit 47620bc
Showing
2 changed files
with
36 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,42 @@ | ||
fn main() { | ||
println!("cargo:rerun-if-env-changed=CUSTOM_LIBFUZZER_PATH"); | ||
if let Ok(custom) = ::std::env::var("CUSTOM_LIBFUZZER_PATH") { | ||
println!("cargo:rerun-if-changed={custom}"); | ||
if cfg!(feature = "link") { | ||
println!("cargo:rerun-if-env-changed=CUSTOM_LIBFUZZER_PATH"); | ||
if let Ok(custom) = ::std::env::var("CUSTOM_LIBFUZZER_PATH") { | ||
println!("cargo:rerun-if-changed={custom}"); | ||
|
||
let custom_lib_path = ::std::path::PathBuf::from(&custom); | ||
let custom_lib_dir = custom_lib_path.parent().unwrap().to_string_lossy(); | ||
let custom_lib_path = ::std::path::PathBuf::from(&custom); | ||
let custom_lib_dir = custom_lib_path.parent().unwrap().to_string_lossy(); | ||
|
||
let custom_lib_name = custom_lib_path.file_stem().unwrap().to_string_lossy(); | ||
let custom_lib_name = custom_lib_name | ||
.strip_prefix("lib") | ||
.unwrap_or(custom_lib_name.as_ref()); | ||
let custom_lib_name = custom_lib_path.file_stem().unwrap().to_string_lossy(); | ||
let custom_lib_name = custom_lib_name | ||
.strip_prefix("lib") | ||
.unwrap_or(custom_lib_name.as_ref()); | ||
|
||
println!("cargo:rustc-link-search=native={}", custom_lib_dir); | ||
println!("cargo:rustc-link-lib=static={}", custom_lib_name); | ||
println!("cargo:rustc-link-search=native={}", custom_lib_dir); | ||
println!("cargo:rustc-link-lib=static={}", custom_lib_name); | ||
|
||
match std::env::var("CUSTOM_LIBFUZZER_STD_CXX") { | ||
// Default behavior for backwards compat. | ||
Err(_) => println!("cargo:rustc-link-lib=stdc++"), | ||
Ok(s) if s == "none" => (), | ||
Ok(s) => println!("cargo:rustc-link-lib={}", s), | ||
match std::env::var("CUSTOM_LIBFUZZER_STD_CXX") { | ||
// Default behavior for backwards compat. | ||
Err(_) => println!("cargo:rustc-link-lib=stdc++"), | ||
Ok(s) if s == "none" => (), | ||
Ok(s) => println!("cargo:rustc-link-lib={}", s), | ||
} | ||
} else { | ||
let mut build = cc::Build::new(); | ||
let sources = ::std::fs::read_dir("libfuzzer") | ||
.expect("listable source directory") | ||
.map(|de| de.expect("file in directory").path()) | ||
.filter(|p| p.extension().map(|ext| ext == "cpp") == Some(true)) | ||
.collect::<Vec<_>>(); | ||
for source in sources.iter() { | ||
println!("cargo:rerun-if-changed={}", source.display()); | ||
build.file(source.to_str().unwrap()); | ||
} | ||
build.flag("-std=c++17"); | ||
build.flag("-fno-omit-frame-pointer"); | ||
build.flag("-w"); | ||
build.cpp(true); | ||
build.compile("libfuzzer.a"); | ||
} | ||
} else { | ||
let mut build = cc::Build::new(); | ||
let sources = ::std::fs::read_dir("libfuzzer") | ||
.expect("listable source directory") | ||
.map(|de| de.expect("file in directory").path()) | ||
.filter(|p| p.extension().map(|ext| ext == "cpp") == Some(true)) | ||
.collect::<Vec<_>>(); | ||
for source in sources.iter() { | ||
println!("cargo:rerun-if-changed={}", source.display()); | ||
build.file(source.to_str().unwrap()); | ||
} | ||
build.flag("-std=c++17"); | ||
build.flag("-fno-omit-frame-pointer"); | ||
build.flag("-w"); | ||
build.cpp(true); | ||
build.compile("libfuzzer.a"); | ||
} | ||
} |