简体   繁体   English

如何在铁锈中建造多工作空间货物项目

[英]How to build multi workspace cargo project in rust

I have multi-workspace Cargo project. 我有多工作区货物项目。 It has two workspaces, common and server . 它有两个工作区, commonserver common is a lib project and server is a bin project. common是一个lib项目,server是bin项目。

The location of the project in Github is here. 该项目在Github的位置在这里。

Below is the project structure. 以下是项目结构。

.
├── Cargo.toml
├── common
│   ├── Cargo.toml
│   └── src
│       └── lib.rs
├── README.md
└── server
    ├── Cargo.toml
    └── src
        └── main.rs

4 directories, 6 files

And the file contents of ./Cargo.toml file is 而./Cargo.toml文件的文件内容是

[package]
name = "multi_module_cargo_project"
version = "0.1.0"
authors = ["rajkumar"]

[workspace]
members = ["common", "server"]

[dependencies]

When I run the command cargo build --all : 当我运行命令cargo build --all

error: failed to parse manifest at `/home/rajkumar/Coding/Rust/ProgrammingRust/multi_module_cargo_project/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

So I added below in Cargo.toml but still couldn't build the project. 所以我在Cargo.toml添加了以下内容,但仍然无法构建项目。

[[bin]]
name = "server/src/main.rs"

How can I build the project. 我该如何构建项目。 What I'm missing? 我错过了什么?

You included a [package] section in your main Cargo.toml file. 您在主Cargo.toml文件中包含了[package]部分。 This section indicates that you want to build a main package in addition to the packages in the workspace. 此部分表示除了工作空间中的包之外,还要构建主包。 However, you don't have any source files for the main package, so Cargo complains. 但是,您没有主程序包的任何源文件,因此Cargo抱怨。

The solution is to simply omit the [package] section, and only include [workspace] . 解决方案是简单地省略[package]部分,并且仅包括[workspace] This configures a virtual workspace – a workspace that is only a container for member packages, but does not build a package itself. 这会配置一个虚拟工作空间 - 一个仅作为成员包容器的工作空间,但不会自行构建包。

See the main Cargo.toml file of Rocket for a real-world example of a virtual workspace, and Tokio for a real-world example of a workspace with a main package. 有关虚拟工作空间的真实示例,请参阅Rocket主要Cargo.toml文件;有关使用主程序Cargo.toml工作空间的实际示例,请参阅Tokio

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM