Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make it possible to link to custom runtime in another dep #106

Merged
merged 4 commits into from May 11, 2023

Conversation

addisoncrump
Copy link
Contributor

We are implementing AFLplusplus/LibAFL#981, but don't want to make too much impact on the downstream users of libfuzzer-sys. As a compromise, this PR adds a default feature, link, which, when enabled, links to the libfuzzer runtime or the CUSTOM_LIBFUZZER_RUNTIME. When not enabled, it does not link to the fuzzer runtime.

This allows us to link to a custom runtime in our own dependency while reusing the infrastructure already provided by libfuzzer-sys (namely, fuzz_target and custom_mutator). See an example of this use case here:
https://github.com/AFLplusplus/LibAFL/blob/libfuzzer/libafl_libfuzzer/build.rs
https://github.com/AFLplusplus/LibAFL/blob/libfuzzer/libafl_libfuzzer/Cargo.toml#L17

@addisoncrump addisoncrump changed the title Make it possible to link to custom libfuzzer in another dep Make it possible to link to custom runtime in another dep May 9, 2023
Copy link
Member

@fitzgen fitzgen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but I think we should name the feature link_libfuzzer just in case we ever get the ability to link any other libfuzzer-compatible engines.

Can you also add a new subsection to the README about the new feature? Thanks!

build.rs Outdated
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") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move all the linking code out to a new function that is also cfg(feature = "link") so that it is easier to read this giant if with no else?

@addisoncrump
Copy link
Contributor Author

I also added details in the README about CUSTOM_LIBFUZZER_PATH as it seemed relevant.

Copy link
Member

@fitzgen fitzgen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lovely, thank you!

@fitzgen fitzgen merged commit 1221c35 into rust-fuzz:main May 11, 2023
1 check passed
@addisoncrump
Copy link
Contributor Author

Can a release be cut for this? We would like to publish a downstream crate that depends on this but cannot depend on the git revision.

@fitzgen
Copy link
Member

fitzgen commented Aug 10, 2023

Published 0.4.7

@addisoncrump
Copy link
Contributor Author

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants