[英]No targets specified in the manifest when creating a Cargo workspace
使用Rust 1.11和Cargo 1.12(每晚),我正在嘗試創建一個包含一些庫和一些可執行文件的[workspace]
。
在我的根文件夾中,我添加了我的子包:
cargo new loader
cargo new shell --bin
然后我將cargo.toml
顯示的cargo.toml
添加到我的根文件夾中。
[package]
name = "rustenv"
version = "0.1.0"
authors = ["ME"]
[workspace]
members = [
"loader"
, "shell"
]
在我的根文件夾中運行cargo build
產生:
PS E:\\r\\rustenv> cargo build error: failed to parse manifest at `E:\\r\\rustenv\\Cargo.toml` Caused by: no targets specified in the manifest either src/lib.rs, src/main.rs, a [lib] section, or [[bin]] section must be present
鑒於我本質上是一個Visual Studio用戶,我對這個[workspace]
功能應該如何[workspace]
有點困惑,我可以簡單地將項目添加到工作區。 似乎我還有其他一些與Cargo有關的東西可以達到同樣的效果。
如果您的根項目沒有產生任何工件(它不是庫/二進制文件),那么就Cargo工作區RFC而言它是“虛擬”,它應該只包含workspace
部分:
[workspace]
members = [
"loader"
, "shell"
]
如果cargo build
不起作用,你應該
cd loader
cargo build
cd ..
cd shell
cargo build
這種配置有什么用? 你有共享輸出目錄“target”和“Cargo.lock”,所以如果你在“loader”子目錄中輸入“cargo build”,你在“../target/”中編譯了庫。
Shell會話,演示它是如何工作的:
/tmp $ mkdir test
/tmp $ cd test
/tmp/test $ cargo new loader && cargo new shell --bin
Created library `loader` project
Created binary (application) `shell` project
/tmp/test $ cat > Cargo.toml
[workspace]
members = ["loader", "shell"]
/tmp/test $ cat loader/Cargo.toml
[package]
name = "loader"
version = "0.1.0"
authors = ["me"]
workspace = ".."
[dependencies]
/tmp/test $ cat shell/Cargo.toml
[package]
name = "shell"
version = "0.1.0"
authors = ["me"]
workspace = ".."
[dependencies]
/tmp/test/shell $ cargo build
Compiling shell v0.1.0 (file:///tmp/test/shell)
Finished debug [unoptimized + debuginfo] target(s) in 0.57 secs
evgeniy@localhost /tmp/test/shell $ ls
Cargo.toml src
evgeniy@localhost /tmp/test/shell $ ls ../
Cargo.lock Cargo.toml loader shell target
/tmp/test $ cargo --version
cargo 0.13.0-nightly (cd8ad10 2016-08-15)
如果您使用Visual Studio工作/工作,請查看Jetbrains IDE的Rust插件
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.