How to let cargo use the workspace version of a child dependency of a dependency specified by path pointing to crate inside another workspace?

I'm trying to use rolldown as a dependency of my project, this crate is not published on crates.io yet, so I need to clone it's repo and reference it from my project:

This is folder structure and parts of cargo.toml:

projects
├── my_project
│   └── cargo.toml // rolldown = { path = "../rolldown/crates/rolldown" }
└── rolldown
    ├── crates
    │   ├── rolldown
    │   │   └── cargo.toml // rolldown_resolver = { workspace = true }
    │   └── rolldown_resolver
    │       └── cargo.toml // oxc_resolver = { workspace = true }
    └── cargo.toml // oxc_resolver = { version = "1.11.0" }

I think the version of oxc_resolver in my_project should be looked up like this:

rolldown          -> rolldown_resolver (in its own workspace)
rolldown_resolver -> oxc_resolver      (version in workspace cargo.toml)
oxc_resolver (version "1.11.0")

But what I actually got is 1.12.0, which is the latest version in crates.io, which caused problem because a new variant in an enum.

What should I do to make crago follow the version of oxc_resolver in rolldown's workspace cargo.toml when I reference rolldown from my own project?

Thanks in advance!

I merged my codes into rolldown's codebase, it worked, though not pretty

The version requirement "1.11.0" is shorthand for "^1.11.0", which is shorthand for ">=1.11.0, <2.0.0". 1.12.0 is a perfectly valid version that meets the version requirements as specified in the rolldown workspace dependency of oxc_resolver. To make Cargo match exactly version "1.11.0", you should change the oxc_resolver version in rolldown/Cargo.toml to "=1.11.0". You can read more about how to specify the version of a dependency in the Cargo book.

1 Like

Thank you for your detailed explanation, I was thinking about this after posting this help. It seems that when cargo resolving dependencies in another workspace, it will use an "update" approach, which results in a newer version of oxc_resolver, but when resolving dependencies in current workspace, it will resolve exactly to the version written in cargo.toml. Anyway, I got to fork rolldown to fix this, thank you!

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.