文盘rust -凯发app官方网站

凯发app官方网站-凯发k8官网下载客户端中心 | | 凯发app官方网站-凯发k8官网下载客户端中心
  • 博客访问: 85417
  • 博文数量: 165
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 1655
  • 用 户 组: 普通用户
  • 注册时间: 2022-09-26 14:37
文章分类

全部博文(165)

文章存档

2024年(2)

2023年(95)

2022年(68)

我的朋友
相关博文
  • ·
  • ·
  • ·
  • ·
  • ·
  • ·
  • ·
  • ·
  • ·
  • ·

分类: 云计算

2023-02-20 10:23:06

作者:京东科技 贾世闻

问题描述

clickhouse 的原生 rust 客户端目前比较好的有两个  和  。clickhouse-rs 是 tcp 连接; 是 http 连接。两个库在单独使用时没有任何问题,但是,在同一工程同时引用时会报错。

  • cargo.toml

    # clickhouse http clickhouse = {git = "", features =      ["test-util"]} # clickhouse tcp clickhouse-rs = { git = "",     features = ["default"]} 
  • 报错如下

     blocking waiting for file lock on package cache updating git repository `` 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 (  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.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: 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 (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 reference/resolver.html#links. failed to select a version for `clickhouse-rs-cityhash-sys` which could   resolve this conflict 

错误描述还是很清楚的,clickhouse-rs-cityhash-sys 这个库冲突了。仔细看了一下两个库的源码,引用 clickhouse-rs-cityhash-sys 库的方式是不一样的。 是在其 cargo.toml 文件中使用{banned}最佳普遍的方式引用的

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

clickhouse-rs 是通过本地方式引用的

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

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

一开始是有个直观的想法,如果在一个工程中通过 workspace 进行隔离,是不是会解决冲突问题呢? 于是,工程的目录结构从这样

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

改成了这样

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

新建了两个 lib

cargo new ck_http --lib cargo new ck_tcp --lib 

在 workspace 中分别应用 clickhouse-rs 和  , 删除根下 cargo.toml 文件中的依赖关系。 很可惜,workspace 没有解决问题,报错没有一点儿差别。

又仔细看了看报错,里面有这样一段

 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 这个名字冲突了? 直接把 clickhouse-rs 源码拉下来作为本地库来试试呢? 于是把 clickhouse-rs clone 到本地,稍稍修改一下 ck_tcp workspace 的 cargo.toml

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

编译后冲突依旧存在。 翻翻 clickhouse-rs/clickhouse-rs-cityhash-sys/cargo.toml,里面的一个配置很可疑

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

把 links 随便改个名字比如:links = "ck-rs-cityhash-sys",编译就通过了。

错误提示中这句话很重要

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

看了一下 links 字段的含义

the links field the 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 ,有兴趣的同学可以亲自试一试

下期见。


阅读(282) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~
")); function link(t){ var href= $(t).attr('href'); href ="?url=" encodeuricomponent(location.href); $(t).attr('href',href); //setcookie("returnouturl", location.href, 60, "/"); }
网站地图