bazelbuild / bazelbuild/rules_rust

crate_universe fails with packages that have workspace = ".." declarations?

Open
#3,571 0 comments 0 reactions 0 assignees View on GitHub
crate-universe needs-triage
Dominant language
Starlark
Stars
843
Forks
651
Avg merge
2d 18h
Merged PRs (30d)
15

Description

Summary

When using crate.from_cargo() with bzlmod, the build fails for packages that contain workspace = ".." declarations, even when these packages are properly included in both the root workspace members list and the MODULE.bazel manifests.

Environment

• rules_rust version: 0.63.0
• Bazel version: 8.0.0
• Platform: macOS
• bzlmod: enabled

Error Message
```
Error: Failed to splice workspace crates

Caused by:
Found manifest at /path/to/workspace/package/Cargo.toml which is a member of the workspace at /path/to/workspace/package/.. which isn't included in the crates_universe
```
Minimal Reproduction Case

Project Structure
```
workspace-root/
├── Cargo.toml # Root workspace
├── MODULE.bazel
├── package-a/
│ └── Cargo.toml # Contains `workspace = ".."`
└── package-b/
└── Cargo.toml # Regular workspace member
```
Root Cargo.toml
```toml
[workspace]
members = [
"package-a",
"package-b"
]

[workspace.dependencies]
shared-dep = "1.0"
```
package-a/Cargo.toml (problematic)
```toml
[package]
name = "package-a"
version = "0.1.0"
workspace = ".." # This causes the issue
edition = "2021"

[dependencies]
shared-dep.workspace = true # Uses workspace dependency

[lints]
workspace = true # Uses workspace lints
```
MODULE.bazel
```python
bazel_dep(name = "rules_rust", version = "0.63.0")

rust = use_extension("@rules_rust//rust:extensions.bzl", "rust")
rust.toolchain(edition = "2021")

crate = use_extension("@rules_rust//crate_universe:extensions.bzl", "crate")
crate.from_cargo(
name = "crates",
cargo_lockfile = "//:Cargo.lock",
manifests = [
"//:Cargo.toml",
"//:package-a/Cargo.toml", # Explicitly included
],
)
use_repo(crate, "crates")
```
Expected Behavior

The build should succeed, treating package-a as a workspace member that inherits workspace configurations while being properly recognized by crate_universe.

Actual Behavior

The build fails with the error message above, indicating that crate_universe cannot properly handle packages with workspace = ".." declarations.

Analysis

The issue appears to stem from:

1. Packages with workspace = ".." need to inherit workspace dependencies and configurations
2. crate_universe expects packages to be either:
• Pure workspace members (discovered automatically), OR
• Independent packages with their own complete dependency specifications
3. The mixed mode (workspace member + workspace = ".." declaration) creates confusion in the splicing logic

Workarounds Attempted

1. Including manifests explicitly: Added the problematic package to manifests = [] - still fails
2. Removing from workspace members: Causes dependency resolution issues since the package needs workspace context
3. Using only root manifest: crate_universe still discovers and attempts to process the workspace = ".." packages

Use Case

This pattern is common in large monorepos where:
• Some packages need explicit workspace inheritance (workspace = "..")
• These packages use workspace dependencies (dep.workspace = true)
• The same packages need to be buildable with Bazel via crate_universe

Request

If there is a solution, please tell me how to do it. If there is no crate_oniverse to properly handle packages with workspace=".." declaration? This will involve:

1. Recognizing that such packages are intentionally inheriting from the parent workspace
2. Processing them in the context of their parent workspace rather than treating them as independent
3. Ensuring workspace dependency resolution works correctly for these packages

This would greatly improve bzlmod compatibility with existing Rust monorepo structures.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.