代码之家  ›  专栏  ›  技术社区  ›  user51

如何在rust中建立多工作空间货物项目

  •  0
  • user51  · 技术社区  · 6 年前

    common server 常见的 lib project and server是一个 bin 项目。

    项目在Github中的位置是 here.

    以下是项目结构。

    .
    ├── Cargo.toml
    ├── common
    │   ├── Cargo.toml
    │   └── src
    │       └── lib.rs
    ├── README.md
    └── server
        ├── Cargo.toml
        └── src
            └── main.rs
    
    4 directories, 6 files
    

    而./Cargo.toml文件的文件内容是

    [package]
    name = "multi_module_cargo_project"
    version = "0.1.0"
    authors = ["rajkumar"]
    
    [workspace]
    members = ["common", "server"]
    
    [dependencies]
    

    当我运行命令时 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
    

    Cargo.toml 但仍然无法建立项目。

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

    1 回复  |  直到 6 年前
        1
  •  4
  •   Sven Marnach    6 年前

    你包括一个 [package] 在你的主要部分 Cargo.toml 文件。本节指出除了工作区中的包之外,还需要构建主包。但是,您没有任何主包的源文件,因此Cargo会抱怨。

    [套餐] 节,并且仅包括 [workspace] . 这将配置 虚拟工作空间 仅作为成员包的容器,但不构建包本身的工作区。

    main Cargo.toml file of Rocket 对于虚拟工作区的真实示例,以及 Tokio