Skip to content
Latchkey

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

  1. Identify the two crates in the printed cycle.
  2. Move the shared types/functions into a third, lower-level crate both can depend on.
  3. 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

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →