I am learning about Cargo workspaces and have set up the following structure:
Top-level:
[package]
name = "workspacer"
version = "0.1.0"
authors = ["ustulation <zzzzzz@gmail.com>"]
[workspace]
members = ["safe_core", "safe_authenticator", "safe_app"]
# If this is removed then each of the sub-projects will have thier own Cargo.lock file
# will build binaries/objects in their own target/ directories. With this present, it's
# always the parent-projects Cargo.lock and target/ directory used. Need to check if this
# is standard behaviour or some bug about to be fixed.
[lib]
crate_type = ["rlib", "cdylib", "staticlib"]
A lib called safe_core which only needs to produce a .rlib
[package]
authors = ["ustulation <zzzzzz@gmail.com>"]
name = "safe_core"
version = "0.1.0"
[dependencies]
maidsafe_utilities = "~0.10.0"
A lib called safe_app which depends on safe_core and needs to produce all 3 .rlib, .a and .so:
[package]
name = "safe_app"
version = "0.1.0"
authors = ["ustulation <zzzzzz@gmail.com>"]
[dependencies]
maidsafe_utilities = "~0.10.0"
safe_core = { path = "../safe_core" }
[lib]
crate_type = ["rlib", "cdylib", "staticlib"]
A lib called safe_authenticator which depends on safe_core and needs to produce all 3 .rlib, .a and .so:
[package]
name = "safe_authenticator"
version = "0.1.0"
authors = ["ustulation <zzzzzz@gmail.com>"]
[dependencies]
safe_core = { path = "../safe_core" }
[lib]
crate_type = ["rlib", "cdylib", "staticlib"]
The tree looks like:
workspacer
āāā Cargo.toml
āāā safe_app
ā āāā Cargo.toml
ā āāā src
ā āāā lib.rs
āāā safe_authenticator
ā āāā Cargo.toml
ā āāā src
ā āāā lib.rs
āāā safe_core
āāā Cargo.toml
āāā src
āāā lib.rs
If I go to safe_core and build, it creates a target/ folder and Cargo.lock files inside the top level workspacer/, which is good.
If I go to safe_authenticator folder and build that it too uses the same target/ and Cargo.lock files and hence does not recompile safe_core which is what I want too. Same with safe_app.
However if I remove the [lib] section from the top-level workspacer/Cargo.toml, each of the sub-projects start creating their own Cargo.lock files and their own /target directories inside their respective sub-directories. I have mentioned this in the inline comment in the Cargo.toml of workspacer above (the 1st snippet above).
Is this an expected behavior or a bug or am I doing something wrong ?
~$ rustc --version && cargo --version
rustc 1.15.0-nightly (ba872f270 2016-11-17)
cargo 0.15.0-nightly (1877f59 2016-11-16)