Cargo "cyclic package dependency" in CI
Cargo detected a dependency cycle: crate A depends on B which depends back on A. Normal dependencies cannot form a cycle, so cargo aborts resolution -- usually a dev-dependency edge closing a loop.
What this error means
cargo fails with error: cyclic package dependency: package A depends on itself and prints the cycle path. It is deterministic for the manifest set.
cargo
error: cyclic package dependency: package `core v0.1.0` depends on itself. Cycle:
package `core v0.1.0`
... which satisfies dependency `utils` of package `core v0.1.0`
package `utils v0.1.0`
... which satisfies dependency `core` of package `utils v0.1.0`Common causes
Mutually dependent crates
Two workspace members list each other as dependencies, forming a cycle cargo cannot order.
Dev-dependency closing the loop
A [dev-dependencies] edge from a lower crate back up to a higher one creates a cycle, even if the normal deps are acyclic.
How to fix it
Break the cycle by extracting shared code
- Identify the two crates in the printed cycle.
- Move the shared types/functions into a third, lower-level crate both can depend on.
- Remove the back-edge so the graph is a DAG again.
Cargo.toml
# crates/core -> depends on crates/shared
# crates/utils -> depends on crates/shared
# (neither depends on the other)How to prevent it
- Keep workspace crates layered; avoid back-edges.
- Factor shared code into a low-level crate instead of cross-depending.
- Watch dev-dependencies -- they count toward cycles.
Related guides
Cargo "failed to load manifest for workspace member" in CIFix cargo "failed to load manifest for workspace member" / "package ... is not a member of workspace" in CI -…
Cargo "multiple packages with the same name" in CIFix cargo "error: two packages named X in this workspace" / "found multiple packages" in CI -- two workspace…
Cargo "cyclic package dependency" in a Workspace in CIFix cargo "error: cyclic package dependency" in CI -- two workspace crates depend on each other in a build cy…