国产精品夜色视频一级区_hh99m福利毛片_国产一区二区成人久久免费影院_伊人久久大香线蕉综合影院75_国产精品久久果冻传媒

您的位置:首頁(yè) >聚焦 >

【快播報(bào)】文盤Rust -- 本地庫(kù)引發(fā)的依賴沖突

2023-02-18 05:38:15    來(lái)源:程序員客棧

問(wèn)題描述

clickhouse 的原生 rust 客戶端目前比較好的有兩個(gè)clickhouse-rs (https://github.com/suharev7/clickhouse-rs)和 clickhouse.rs(https://github.com/loyd/clickhouse.rs) 。clickhouse-rs 是 tcp 連接;clickhouse.rs 是 http 連接。兩個(gè)庫(kù)在單獨(dú)使用時(shí)沒(méi)有任何問(wèn)題,但是,在同一工程同時(shí)引用時(shí)會(huì)報(bào)錯(cuò)。

Cargo.toml

# clickhouse httpclickhouse = {git = "https://github.com/loyd/clickhouse.rs", features =      ["test-util"]}# clickhouse tcpclickhouse-rs={git="https://github.com/suharev7/clickhouse-rs",features=["default"]}報(bào)錯(cuò)如下


(資料圖片僅供參考)

報(bào)錯(cuò)如下:

Blocking waiting for file lock on package cacheUpdating git repository `https://github.com/suharev7/clickhouse-rs`Updating crates.io indexerror: failed to select a version for `clickhouse-rs-cityhash-sys`.... required by package `clickhouse-rs v1.0.0-alpha.1 (https://github.  com/suharev7/clickhouse-rs#ecf28f46)`... which satisfies git dependency `clickhouse-rs` of package   `conflict v0.1.0 (/Users/jiashiwen/rustproject/conflict)`versions that meet the requirements `^0.1.2` are: 0.1.2the 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:package `clickhouse-rs-cityhash-sys v0.1.2`... which satisfies dependency `clickhouse-rs-cityhash-sys = "^0.1.2"`   (locked to 0.1.2) of package `clickhouse v0.11.2 (https://github.com/  loyd/clickhouse.rs#4ba31e65)`... which satisfies git dependency `clickhouse` (locked to 0.11.2) of   package `conflict v0.1.0 (/Users/jiashiwen/rustproject/conflict)`Only one package in the dependency graph may specify the same links value.   This helps ensure that only one copy of a native library is linked in the   final binary. Try to adjust your dependencies so that only one package   uses the links ="clickhouse-rs-cityhash-sys" value. For more information,   see https://doc.rust-lang.org/cargo/reference/resolver.html#links.failed to select a version for `clickhouse-rs-cityhash-sys` which could   resolve this conflict

錯(cuò)誤描述還是很清楚的,clickhouse-rs-cityhash-sys 這個(gè)庫(kù)沖突了。仔細(xì)看了一下兩個(gè)庫(kù)的源碼,引用 clickhouse-rs-cityhash-sys 庫(kù)的方式是不一樣的。clickhouse.rs 是在其 Cargo.toml 文件中使用最普遍的方式引用的:

clickhouse-rs-cityhash-sys = { version = "0.1.2", optional = true }

clickhouse-rs 是通過(guò)本地方式引用的:

[dependencies.clickhouse-rs-cityhash-sys]path = "clickhouse-rs-cityhash-sys"version = "0.1.2"

clickhouse-rs-cityhash-sys 的源碼直接放在 clickhouse-rs 工程目錄下面。

一開始是有個(gè)直觀的想法,如果在一個(gè)工程中通過(guò)workspace 進(jìn)行隔離,是不是會(huì)解決沖突問(wèn)題呢?于是,工程的目錄結(jié)構(gòu)從這樣:

.├── Cargo.lock├── Cargo.toml└── src└── main.rs

改成了這樣

.├── Cargo.lock├── Cargo.toml├── ck_http│   ├── Cargo.toml│   └── src├── ck_tcp│   ├── Cargo.toml│   └── src└── src└── main.rs

新建了兩個(gè)lib

cargo new ck_http --libcargo new ck_tcp --lib

在 workspace 中分別應(yīng)用 clickhouse-rs 和 clickhouse.rs ,刪除根下 Cargo.toml 文件中的依賴關(guān)系。很可惜,workspace 沒(méi)有解決問(wèn)題,報(bào)錯(cuò)沒(méi)有一點(diǎn)兒差別。

又仔細(xì)看了看報(bào)錯(cuò),里面有這樣一段:

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`

難道是 clickhouse-rs 這個(gè)名字沖突了?直接把clickhouse-rs源碼拉下來(lái)作為本地庫(kù)來(lái)試試呢?于是把 clickhouse-rs clone 到本地,稍稍修改一下ck_tcp workspace 的 Cargo.toml

clickhouse-rs = { path = "../../clickhouse-rs", features = ["default"]}

編譯后沖突依舊存在。翻翻clickhouse-rs/clickhouse-rs-cityhash-sys/Cargo.toml,里面的一個(gè)配置很可疑:

[package]......links = "clickhouse-rs"

把 links 隨便改個(gè)名字比如:links = "ck-rs-cityhash-sys",編譯就通過(guò)了。

錯(cuò)誤提示中這句話很重要:

Only one package in the dependency graph may specify the same links value.

看了一下 links 字段的含義

The links fieldThe links field specifies the name of a native library that is being linked to. More information can be found in the links section of the build script guide.

links 指定了本地包被鏈接的名字,在這里引起了沖突,改掉本地包中的名字自然解決了沖突,在依賴圖中保證唯一性很重要。

本文涉及代碼github倉(cāng)庫(kù)(https://github.com/jiashiwen/ck_dependency_conflict_sample),有興趣的同學(xué)可以親自試一試。

下期見。

-end-

關(guān)鍵詞: 這個(gè)名字 問(wèn)題描述 解決問(wèn)題

相關(guān)閱讀