Could not find `Cargo.toml` when building a dependent crate from GitHub
Solution 1
The problem comes from your Cargo.toml
in examples/ticktock:
[dependencies.mosquitto]
version = "*"
path = "../../../rust-mosquitto"
When downloading your project from git, all the subdirectories are scanned for more Cargo.toml
files. If you run RUST_LOG=trace cargo build -v
, you see what's happening:
TRACE:cargo::ops::cargo_read_manifest: looking for root package: /Users/shep/.cargo/git/checkouts/rust-mosquitto-77eb7033f32b19c9/master, source_id=https://github.com/kteza1/rust-mosquitto#7e08a291
TRACE:cargo::ops::cargo_read_manifest: looking for child package: /Users/shep/.cargo/git/checkouts/rust-mosquitto-77eb7033f32b19c9/master
TRACE:cargo::ops::cargo_read_manifest: read_package; path=/Users/shep/.cargo/git/checkouts/rust-mosquitto-77eb7033f32b19c9/master/Cargo.toml; source-id=https://github.com/kteza1/rust-mosquitto#7e08a291
TRACE:cargo::ops::cargo_read_manifest: looking for child package: /Users/shep/.cargo/git/checkouts/rust-mosquitto-77eb7033f32b19c9/master/.git
TRACE:cargo::ops::cargo_read_manifest: not processing /Users/shep/.cargo/git/checkouts/rust-mosquitto-77eb7033f32b19c9/master/.git
TRACE:cargo::ops::cargo_read_manifest: looking for child package: /Users/shep/.cargo/git/checkouts/rust-mosquitto-77eb7033f32b19c9/master/examples
TRACE:cargo::ops::cargo_read_manifest: looking for child package: /Users/shep/.cargo/git/checkouts/rust-mosquitto-77eb7033f32b19c9/master/examples/c-mosquitto
TRACE:cargo::ops::cargo_read_manifest: looking for child package: /Users/shep/.cargo/git/checkouts/rust-mosquitto-77eb7033f32b19c9/master/examples/ticktock
TRACE:cargo::ops::cargo_read_manifest: read_package; path=/Users/shep/.cargo/git/checkouts/rust-mosquitto-77eb7033f32b19c9/master/examples/ticktock/Cargo.toml; source-id=https://github.com/kteza1/rust-mosquitto#7e08a291
DEBUG:cargo: handle_error; err=CliError { error: ChainedError { error: Unable to update https://github.com/kteza1/rust-mosquitto, cause: Could not find `Cargo.toml` in `/Users/shep/.cargo/git/checkouts/rust-mosquitto-77eb7033f32b19c9/rust-mosquitto` }, unknown: false, exit_code: 101 }
Cargo then tries to ensure that the nested Cargo.toml
can have all of the dependencies satisfied.
Solution 2
This does not specifically answer the question that @tez asked, but I encountered the same error with a slightly different root culprit. I was writing some simple code in vim, so I created a simple main.rs file. When I cargo run
it, it was spitting out the same error:
error: could not find
Cargo.toml
in/Users/yvonmanzi/Documents/Rust
or any parent directory
The surprising thing, without the hindsight, of course, was that rustc main.rs
was creating a binary executable as expected while cargo run
wasn't. It turns out I had created all my rust packages(aka projects) up to that point using cargo new project-name --bin
as shown here, thus by default including Cargo.lock
, Cargo.toml
, and src
folder. Hopefully, it is clear by now that mine was just a simple rookie mistake; I simply, quite literally, didn't have Cargo.toml
in my project folder. So, dear fellow rooky league Rustacean, if you get the same error, create your project with cargo new project-name --bin
command.
Related videos on Youtube
tez
Updated on September 15, 2022Comments
-
tez over 1 year
I'm trying to use the rust-mosquitto library. My current
Cargo.toml
is:[package] name = "HomeDaemon" version = "0.1.0" authors = ["RTR <[email protected]>"] [dependencies.mosquitto] git = "https://github.com/kteza1/rust-mosquitto"
When I run
cargo build
, following error is reported:Could not find `Cargo.toml` in `/Users/ravitejareddy/.cargo/git/checkouts/rust-mosquitto-8203e77dcf072bf7/rust-mosquitto`
The actual download in
~/.cargo/git/checkouts/rust-mosquitto-8203e77dcf072bf7/master
shows thatCargo.toml
is present.There is an extra
rust-mosquitto
in the path above, is that a problem? -
DK. almost 9 years@tez: Because you go up three directories, when there are only two in the repository. You're effectively requiring that your repository always be checked out with the name
rust-mosquitto
and nothing else. -
tez almost 9 yearsOk. The folder structure is different while downloading from git where Cargo.toml resides inside branch name. 'master' in this case.
-
Jason Aller almost 4 yearsIf this contains a separate question and answer you can post it as a separate question and then self answer it. If very relevant when you have enough reputation to post comments you could even leave a comment on this question referencing the related question.
-
George over 2 yearsI think a correction is needed; both your "mistake" and "recommendations" presently show to use,
cargo new project-name --bin
to create a project.