Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No targets specified in the manifest when creating a Cargo workspace

Using Rust 1.11 and Cargo 1.12 (nightly), I'm trying to create a [workspace] which contains a few libraries and a few executables.

In my root folder, I added my sub-crates with:

cargo new loader 
cargo new shell --bin

I then added the cargo.toml shown below to my root folder.

[package]
name = "rustenv"
version = "0.1.0"
authors = ["ME"]

[workspace]
members = [
    "loader"
    , "shell"
    ]

Running cargo build in my root folder yields:

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

I am a bit confused about how this [workspace] feature is supposed to work given that I am a Visual Studio user by nature and there, I can simply add projects to a workspace. It appears there is something else I have to do with Cargo to get the same effect.

like image 487
BitTickler Avatar asked Aug 26 '16 12:08

BitTickler


People also ask

What is a cargo workspace?

A workspace is a collection of one or more packages, called workspace members, that are managed together. The key points of workspaces are: Common commands can run across all workspace members, like cargo check --workspace . All packages share a common Cargo. lock file which resides in the workspace root.

What is a virtual manifest?

In workspace manifests, if the package table is present, the workspace root crate will be treated as a normal package, as well as a workspace. If the package table is not present in a workspace manifest, it is called a virtual manifest.

Where do you put cargo in toml?

Cargo. toml and Cargo. lock are stored in the root of your project (package root). Source code goes in the src directory.

What is a cargo toml file?

Cargo. toml is the manifest file for Rust's package manager, cargo . This file contains metadata such as name, version, and dependencies for packages, which are call "crates" in Rust.


1 Answers

If your root project does not produce any artifacts (it is not a library/binary) then in terms of the Cargo workspaces RFC it is "virtual", it should contain only the workspace section:

[workspace]
members = [
    "loader"
    , "shell"
    ]

If cargo build does not work for it, you should

cd loader
cargo build
cd ..
cd shell
cargo build 

what works in such configuration? You have shared output directory "target" and "Cargo.lock", so if you type "cargo build" in "loader" subdirectory you have compiled library in "../target/"

Shell session that demonstrates how it works:

/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)

If you worked/work with Visual Studio, have look at the Rust plugin for Jetbrains IDE

like image 177
fghj Avatar answered Sep 29 '22 07:09

fghj