Reputation: 11947
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.
Upvotes: 10
Views: 6272
Reputation: 9404
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
Upvotes: 8