ustulation
ustulation

Reputation: 3760

Workspace giving two different behaviors in Rust

I am learning about Cargo workspaces and have set up the following structure:

Top-level:

[package]
name = "workspacer"
version = "0.1.0"
authors = ["ustulation <[email protected]>"]

[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 <[email protected]>"]
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 <[email protected]>"]

[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 <[email protected]>"]

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

Upvotes: 2

Views: 102

Answers (1)

ustulation
ustulation

Reputation: 3760

After confirming it on latest stable:

~$ rustc --version && cargo --version
rustc 1.13.0 (2c6933acc 2016-11-07)
cargo 0.13.0-nightly (eca9e15 2016-11-01)

It seems to be a bug:

All members of workspace should share the same target directory no matter what!

A bug report was submitted, and it is solved now.

Upvotes: 1

Related Questions