How to Fix ClickHouse Rust Client Dependency Conflicts with Cargo Links
This article explains why using both clickhouse-rs (TCP) and clickhouse.rs (HTTP) in a single Rust project causes a Cargo links conflict, demonstrates failed workspace isolation attempts, and shows how renaming the links field in the native library resolves the issue.
Problem Description
ClickHouse has two well‑maintained native Rust clients: clickhouse-rs (TCP) and clickhouse.rs (HTTP). Each works fine alone, but adding both to the same Cargo project triggers a build error.
Dependencies
<code># clickhouse http
clickhouse = { git = "https://github.com/loyd/clickhouse.rs", features = ["test-util"] }
# clickhouse tcp
clickhouse-rs = { git = "https://github.com/suharev7/clickhouse-rs", features = ["default"] }
</code>Error Message
<code>Blocking waiting for file lock on package cache
Updating git repository `https://github.com/suharev7/clickhouse-rs`
Updating crates.io index
error: failed to select a version for `clickhouse-rs-cityhash-sys`.
... required by package `clickhouse-rs v1.0.0-alpha.1`
... which satisfies git dependency `clickhouse-rs`
versions that meet the requirements `^0.1.2` are: 0.1.2
the package `clickhouse-rs-cityhash-sys` links to the native library `clickhouse-rs`, but it conflicts with a previous package which links to `clickhouse-rs` as well:
Only one package in the dependency graph may specify the same links value.
Try to adjust your dependencies so that only one package uses the links = 'clickhouse-rs-cityhash-sys' value.
</code>Root Cause
The conflict originates from the
clickhouse-rs-cityhash-syscrate, which is referenced differently by the two clients.
clickhouse.rspulls it from
crates.iousing a normal version entry, while
clickhouse-rsincludes it as a local path dependency.
<code># clickhouse.rs (crates.io)
clickhouse-rs-cityhash-sys = { version = "0.1.2", optional = true }
</code> <code># clickhouse-rs (local)
[dependencies.clickhouse-rs-cityhash-sys]
path = "clickhouse-rs-cityhash-sys"
version = "0.1.2"
</code>Attempted Workspace Isolation
Creating a Cargo workspace with separate libraries (
ck_httpand
ck_tcp) and moving each client into its own crate did not eliminate the conflict, because the
linksfield is still duplicated in the dependency graph.
Solution
Inspecting
clickhouse-rs-cityhash-sys/Cargo.tomlreveals a
links = "clickhouse-rs"entry. Changing this value to a unique name (e.g.,
links = "ck-rs-cityhash-sys") removes the duplication and the project builds successfully.
Understanding the links Field
The
linksfield specifies the name of the native library that Cargo will link to. Only one package in the entire dependency graph may declare the same
linksname, ensuring a single copy of a native library in the final binary.
Conclusion
Renaming the
linksidentifier in the conflicting native crate resolves the Cargo dependency conflict when using both ClickHouse Rust clients together. The full sample repository is available at https://github.com/jiashiwen/ck_dependency_conflict_sample for further experimentation.
JD Cloud Developers
JD Cloud Developers (Developer of JD Technology) is a JD Technology Group platform offering technical sharing and communication for AI, cloud computing, IoT and related developers. It publishes JD product technical information, industry content, and tech event news. Embrace technology and partner with developers to envision the future.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.