Problem
Using cargo publish or cargo package on a binary crate inside a workspace ignores the Cargo.lock in the workspace directory, whereas cargo build considers it. However, when moving Cargo.lock inside the binary crate root, all commands consider it.
I believe that this means that crates published from workspaces, even when installed with cargo install --locked, do not respect the workspace's Cargo.lock. This seems to contradict the Cargo book:
The key points of workspaces are:
- All packages share a common
Cargo.lock file which resides in the workspace root.
- [...]
Steps
To set up the environment:
mkdir foo # our workspace
cd foo
echo -e '[workspace]\nmembers = ["bar"]' > Cargo.toml
cargo new bar # our binary
cd bar
cargo add beef@=0.5.0
cargo check # generate Cargo.lock with beef locked to 0.5.0
cargo add [email protected] # relax bounds
cd ..
Now run:
cargo build # uses beef 0.5.0 ✅
cargo publish --dry-run --allow-dirty -p bar # uses beef 0.5.2 (0.5.0 expected) ❌
cp Cargo.lock bar/
cargo publish --dry-run --allow-dirty -p bar # uses beef 0.5.0 ✅
(Using cargo publish with --locked does not change anything.)
Possible Solution(s)
No response
Notes
I tried to gather some advice whether this is indeed a bug, but did not obtain any response so far.
Version
cargo 1.62.0 (a748cf5a3 2022-06-08)
release: 1.62.0
commit-hash: a748cf5a3e666bc2dcdf54f37adef8ef22196452
commit-date: 2022-06-08
host: x86_64-unknown-linux-gnu
libgit2: 1.4.2 (sys:0.14.2 vendored)
libcurl: 7.80.0-DEV (sys:0.4.51+curl-7.80.0 vendored ssl:OpenSSL/1.1.1n)
os: Ubuntu 22.04 (jammy) [64-bit]
Problem
Using
cargo publishorcargo packageon a binary crate inside a workspace ignores theCargo.lockin the workspace directory, whereascargo buildconsiders it. However, when movingCargo.lockinside the binary crate root, all commands consider it.I believe that this means that crates published from workspaces, even when installed with
cargo install --locked, do not respect the workspace'sCargo.lock. This seems to contradict the Cargo book:Steps
To set up the environment:
Now run:
(Using
cargo publishwith--lockeddoes not change anything.)Possible Solution(s)
No response
Notes
I tried to gather some advice whether this is indeed a bug, but did not obtain any response so far.
Version