rules_rust icon indicating copy to clipboard operation
rules_rust copied to clipboard

Splicing out-of-tree cargo workspaces fails

Open Synss opened this issue 5 months ago • 0 comments

Splicing Cargo.toml files always assumes in-tree workspaces and crashes on out-of-tree workspaces.

Reproduction

Copy examples/crate_universe/cargo_workspace to examples/crate_universe/cargo_workspace_oot and modify the second to implement an out-of-tree workspace. See, for example, https://github.com/Synss/rules_rust/tree/pr-oot/

Then run

$ cd examples/crate_universe
$ REPIN=1 bazel mod deps --lockfile=update

Splicing fails with

error: failed to load manifest for workspace member `/tmp/.tmp17zZ7O/../num_printer`
referenced by workspace at `/tmp/.tmp17zZ7O/Cargo.toml`

Caused by:
  failed to read `/tmp/num_printer/Cargo.toml`

Caused by:
  No such file or directory (os error 2)

Error: Failed to generate lockfile

Compare with cargo

$ cd examples/crate_universe/cargo_workspace_oot/workspace
$ cargo run --quiet printer --version
Number Printer 

Analysis

It seems splicing always triggers the discovery, which assumes either flat or in-tree workspaces.

Note

I'm already working on the feature as we need it where I work. I'm already working on a patch and I'll upstream when I'm done.

See also

Out-of-tree workspaces are documented at

  • https://github.com/nox/rust-rfcs/blob/master/text/1525-cargo-workspace.md
  • https://doc.rust-lang.org/cargo/reference/workspaces.html

where the RFC appears to provide a more precise specification of the feature.

Synss avatar May 23 '25 06:05 Synss