cargo-fuzz icon indicating copy to clipboard operation
cargo-fuzz copied to clipboard

Could not compile: Can't find crate rust

Open fwsGonzo opened this issue 6 years ago • 6 comments

I've used libfuzzer a lot in C++, and decided to try it in Rust as my first project. This is probably a beginner issue, but I managed to switch to nightly, call cargo init fuzz, and when running the default fuzz_target_1 I get this:

 --> fuzz_targets/fuzz_target_1.rs:3:1
  |
3 | extern crate rust;
  | ^^^^^^^^^^^^^^^^^^ can't find crate

Clearly, some crate is missing, but why? And cargo install rust had no effect.

fwsGonzo avatar Feb 11 '19 21:02 fwsGonzo

Is your crate named rust? Usually the crate there is the crate you're running cargo-fuzz within

Manishearth avatar Feb 11 '19 21:02 Manishearth

My crate? I didn't consider that, and yes you are completely right. My project is in a folder called rust. I guess that makes it a crate in the world of Rust. What exactly is the error about?

fwsGonzo avatar Feb 11 '19 21:02 fwsGonzo

You have to run cargo fuzz init in the top-level directory of a rust crate

Manishearth avatar Feb 11 '19 21:02 Manishearth

Yes, I have done that, and it does show the targets when listed:

$ cargo fuzz list
fuzz_target_1

fwsGonzo avatar Feb 11 '19 21:02 fwsGonzo

I ran into the same issue. In my case the problem was that the parent project was a binary. It needs to be a library instead.

ruuda avatar Feb 17 '19 11:02 ruuda