Patching multiple versions of a package in a workspace

⚓ Rust    📅 2025-08-15    👤 surdeus    👁️ 5      

surdeus

I am struggling to understand how to best handle this situation:

I have a monorepo that pulls in multiple different SQL libraries through transitive dependencies.

  • One of the projects depends on sqlx, which pulls in libsqlite3-sys@^0.35.0.
  • Another depends on sea-orm, which depends on libsqlite3-sys@^0.30.1
  • the repo links cargo as a library, which indirectly depends on libsqlite-sys@^0.31.0 via rusqlite

These are all carat dependencies but since these are 0.x dependencies, they're incompatible.

When the repo only has 2 conflicting versions, I am able to work around this with the semver trick mentioned here, where you declare an alias for the crate at a version that forwards all exported symbols at the crate level (pub use libsqlite3_sys::*) in my case.

I don't see a way to set multiple overrides for different versions of a package in my workspace's [patch] section, though.

[patch.crates-io]
libsqlite3-sys = { path = "crates/semver-trick/libsqlite3-sys@0.30.1", version = "0.30.1" }
# this isn't legal toml, right?
libsqlite3-sys = { path = "crates/semver-trick/libsqlite3-sys@0.31.0", version = "0.31.0" }

From the rust book It seems like the proposed solution is to rename the dependency. But when I don't directly control those packages, I'm not able to redirect them to the new package.

The only workaround I can think of is vendoring and updating sqlx/sea-orm/rusqlite directly. Which seems like a huge maintenance pain. Is there a more elegant solution? Or is this just a edge case pain point in large rust workspaces that hasn't been addressed?

1 post - 1 participant

Read full topic

🏷️ Rust_feed