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

Don't rebuild coverage target on each coverage run #327

Merged
merged 2 commits into from
Dec 15, 2022
Merged

Don't rebuild coverage target on each coverage run #327

merged 2 commits into from
Dec 15, 2022

Conversation

sharnoff
Copy link
Contributor

Aside from reducing the amount of output from repeated cargo run executions (particularly when there's warnings), this also reduced the total time to run cargo fuzz coverage in my project from ~15 to ~4 seconds.

The new behavior should still be safe from other code changes in the project being fuzzed while running (and other cargo fuzz invocations), because the coverage directory is kept separate.

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.

Thanks!

src/project.rs Outdated
Comment on lines 270 to 280
if build.coverage {
Ok(env::current_dir()?
.join("target")
.join(default_target())
.join("coverage"))
} else {
Ok(build
.target_dir
.as_ref()
.map(PathBuf::from)
.unwrap_or_else(|| self.project_dir.join("target")))
Copy link
Member

Choose a reason for hiding this comment

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

If the user explicitly passes in a --target-dir I think that should take priority over the default coverage target directory. So I think this should look something like:

if let Some(target_dir) = build.target_dir {
    // use user-provided target dir...
} else if build.coverage {
    // use coverage target dir...
} else {
    // use default target dir...
}

src/project.rs Outdated
Comment on lines 317 to 318
if build.target_dir.is_some() || build.coverage {
let target_dir = self.target_dir(&build)?;
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 make the target_dir method return an Option and do if let Some(target) = self.target_dir(&build) here? That way we are less likely to specify the --target-dir flag to cargo when we intend to use the default (and the default might have been configured to a non-default location by the user in .cargo/config.toml or via env vars so it is best to omit the --target-dir flag than to guess its location by appending <project>/target or something like that)

src/project.rs Outdated
.target_dir
.as_ref()
.map(PathBuf::from)
.unwrap_or_else(|| self.project_dir.join("target")))
Copy link
Member

Choose a reason for hiding this comment

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

self.project_dir.join("target") is going to be incorrect if the user using either the CARGO_TARGET_DIR=... environment variable or configuring it via .cargo/config.toml. In this case, we should return None.

@sharnoff
Copy link
Contributor Author

Thanks for the quick review! Let me know if this works :)

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.

Thanks!!

@fitzgen fitzgen merged commit bb2de3e into rust-fuzz:master Dec 15, 2022
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.

2 participants