Reputation: 1052
I am using a Rust script called build.rs
for code generation (it's not a Cargo build script). The script contains this at the top:
extern crate reqwest;
This is my Cargo.toml
file:
[package]
name = "my-script"
version = "0.1.0"
edition = "2018"
[[bin]]
path = "build.rs"
name = "builder"
[dependencies]
reqwest = { version = "0.10", features = ["blocking", "json"] }
When I do cargo run
, it gives me this error:
error[E0463]: can't find crate for `reqwest`
--> build.rs:1:1
|
1 | extern crate reqwest;
| ^^^^^^^^^^^^^^^^^^^^^ can't find crate
How do I make it able to find the reqwest
crate?
Upvotes: 3
Views: 2536
Reputation: 26609
build.rs
is the default name for a Cargo build script, which is ran at build time to generate code, link in C libraries, etc.
Since cargo sees that you have a build.rs
in your project directory, it assumes its a build script and tries to build it. However build scripts don't use the normal dependencies and instead use dependencies from the [build-dependencies]
section of Cargo.toml
. Since you don't have one, the reqwest
crate isn't available to the build script.
Renaming the file is an obvious fix. However the convention is to put executables into the bin/
directory of your project (cargo will even automatically find files in there for you).
Upvotes: 4
Reputation: 1052
The build.rs
script needs a different name. Rename build.rs
to builder.rs
and update Cargo.toml
:
path = "builder.rs"
You can also remove extern crate reqwest
statement because it's inferred by Cargo.
Upvotes: 0