-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Description
Problem
In a workspace, after doing git mv foo bar to rename a sub-crate, cargo build and cargo clean fails to find renamed sub-crate.
what currently happens:
$ cargo build
error: failed to read `/Users/me/work/foo/Cargo.toml`
Caused by:
No such file or directory (os error 2)
$ cargo clean
error: failed to read `/Users/me/work/foo/Cargo.toml`
Caused by:
No such file or directory (os error 2)
what you expected to happen:
cargo build, especially cargo clean can find foo was renamed to bar, and continue to work.
Steps
- create a Cargo workspace, including at least 2 crates, say
appandfoo. The rootCargo.tomllooks like:
[workspace]
members = [
"app",
"foo"
]
app is an application (executable), while foo is a library. The structure looks like this:
├── Cargo.toml
├── app
│ ├── Cargo.toml
│ ├── src
│ │ ├── main.rs
├── foo
│ ├── Cargo.toml
│ ├── src
│ │ ├── lib.rs
- In the sub-crate
foo, itsCargo.tomllooks like this:
[package]
name = "foo"
version = "0.1.0"
authors = ["[email protected]"]
edition = "2018"
-
build the project using
cargo build. It should succeed. -
rename
footobar:git mv foo bar. -
modify root
Cargo.tomlto replacefoowithbar. -
modify sub-crate
Cargo.tomlunderbar/, to replacefoowithbar. -
Now run
cargo buildagain, orcargo clean. Will see the errors.
Possible Solution(s)
Not a real fix: remove the project and use git to re-pull the project.
Notes
Tried to remove target/ and remove Cargo.lock, did not fix the issue.
Output of cargo version:
cargo 1.51.0 (43b129a 2021-03-16)