从GitHub构建一个依赖的箱子时找不到`Cargo.toml`

时间:2015-07-22 18:23:22

标签: rust rust-cargo

我试图使用rust-mosquitto library。我目前的Cargo.toml是:

[package]
name = "HomeDaemon"
version = "0.1.0"
authors = ["RTR <k.teza1@gmail.com>"]

[dependencies.mosquitto]
git = "https://github.com/kteza1/rust-mosquitto"

当我运行cargo build时,会报告以下错误:

Could not find `Cargo.toml` in `/Users/ravitejareddy/.cargo/git/checkouts/rust-mosquitto-8203e77dcf072bf7/rust-mosquitto`

~/.cargo/git/checkouts/rust-mosquitto-8203e77dcf072bf7/master中的实际下载显示Cargo.toml存在。

上面的路径中有一个额外的rust-mosquitto,这是一个问题吗?

2 个答案:

答案 0 :(得分:5)

问题来自您的Cargo.toml in examples/ticktock

[dependencies.mosquitto]
version = "*"
path = "../../../rust-mosquitto" 

从git下载项目时,将扫描所有子目录以查找更多Cargo.toml个文件。如果您运行RUST_LOG=trace cargo build -v,就会看到发生了什么:

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然后尝试确保嵌套的Cargo.toml可以满足所有依赖项。

答案 1 :(得分:4)

这并没有具体回答@tez提出的问题,但是我遇到了相同的错误,但根源稍有不同。我在vim中编写一些简单的代码,所以我创建了一个简单的main.rs文件。当我cargo run出现时,它会吐出相同的错误:

错误:在Cargo.toml或任何父目录中找不到/Users/yvonmanzi/Documents/Rust

毫无疑问,令人惊讶的是,rustc main.rs正在按预期创建二进制可执行文件,而cargo run不是。事实证明,到目前为止,我已经使用cargo new project-name --bin创建了所有锈包(又名Project),如图here所示,因此默认情况下包括Cargo.lockCargo.toml和{ {1}}文件夹。希望到现在为止,我的情况显然已经是一个简单的菜鸟错误。从字面上看,我只是简单地在项目文件夹中没有src。因此,亲爱的新秀联盟Rustacean,如果遇到相同的错误,请使用Cargo.toml命令创建项目。