作者:京东科技 贾世闻

问题描述

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

  • Cargo.toml

    # 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"]}
  • 报错如下

        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 (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.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 (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

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

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 和 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仓库,有兴趣的同学可以亲自试一试

下期见。

文盘Rust -- 本地库引发的依赖冲突的更多相关文章

  1. 文盘Rust -- rust 连接云上数仓 starwift

    作者:京东云 贾世闻 最近想看看 rust 如何集成 clickhouse,又犯了好吃懒做的心理(不想自己建环境),刚好京东云发布了兼容ck 的云原生数仓 Starwfit,于是搞了个实例折腾一番. ...

  2. 文盘Rust -- struct 中的生命周期

    最近在用rust 写一个redis的数据校验工具.redis-rs中具备 redis::ConnectionLike trait,借助它可以较好的来抽象校验过程.在开发中,不免要定义struct 中的 ...

  3. 文盘Rust -- 把程序作为守护进程启动

    当我们写完一个服务端程序,需要上线部署的时候,或多或少都会和操作系统的守护进程打交道,毕竟谁也不希望shell关闭既停服.今天我们就来聊聊这个事儿. 最早大家部署应用的通常操作是 "nohu ...

  4. 文盘Rust -- 给程序加个日志

    作者:贾世闻 日志是应用程序的重要组成部分.无论是服务端程序还是客户端程序都需要日志做为错误输出或者业务记录.在这篇文章中,我们结合[log4rs](https://github.com/estk/l ...

  5. Maven的包依赖冲突可引发java.lang.IncompatibleClassChangeError错误

    新版API上线后,发现LOG文件没有正常输出.查看Tomcat的Log文件发现如下的错误信息 May , :: AM com.sun.xml.ws.server.sei.EndpointMethodH ...

  6. 【核心】project(idea文件)、module(iml文件)到SSM集成、热部署、Tomcat启动、MAVEN依赖冲突

    http://wiki.jikexueyuan.com/project/intellij-idea-tutorial/project-composition-introduce.html 在 Inte ...

  7. 如何快速的解决Maven依赖冲突

    为什么会出现依赖冲突 首先要说明Maven的依赖管理,具体的可以参考这边 Maven学习——依赖管理 这篇文章,maven在依赖冲管理中有一下几个原则. 依赖是使用Maven坐标来定位的,而Maven ...

  8. Maven间接依赖冲突解决办法

    如果项目中maven依赖太多,由于还有jar之间的间接依赖,所以可能会存在依赖冲突.依赖冲突大部分都是由于版本冲突引起的,查看maven的依赖关系,可以找到引起冲突的间接依赖 如上图,通过Depend ...

  9. Maven提高篇系列之(五)——处理依赖冲突

    这是一个Maven提高篇的系列,包含有以下文章: Maven提高篇系列之(一)——多模块 vs 继承 Maven提高篇系列之(二)——配置Plugin到某个Phase(以Selenium集成测试为例) ...

  10. maven 检查依赖冲突和版本冲突

    maven 检查依赖冲突和版本冲突   在项目发布的时候,一般都需要进行依赖冲突检查或者重复类的检查,这个时候我一般会使用下面的两个命令:   1 2 3 mvn -U clean package - ...

随机推荐

  1. toB应用私有化交付发展历程、技术对比和选型

    由于数据隐私和网络安全的考虑,大多数toB场景的客户需要私有化应用交付,也就是需要交付到客户的环境里,这样的客户有政府.金融.军工.公安.大型企业.特色行业等,这些私有化场景限制很多,如何提高私有化应 ...

  2. i春秋Fuzz

    点开只有三个单词plz fuzz parameter 大概意思就是让我们疯狂尝试参数... 我们通过url尝试传入参数 ?user=123 ?name=123 ?username=123 ?id=12 ...

  3. i春秋wanna to see your hat?

    打开题目网页发现是个选择帽子的网页,点击超链接进入一个网页让我们输入我们的name然后匹配帽子颜色(其实不管怎么填都是绿色的)这里也有个注册窗口 先查看源码没什么特别发现,再试试抓包吧 在这个界面抓包 ...

  4. 《浅谈亚 log 数据结构在 OI 中的应用》阅读随笔

    这篇又长长长了! \(8435\to 8375\to 9729\) 早就馋这篇了!终于学了( 压位 Trie 确实很好写啊 但是总感觉使用范围不是很广的样子 似乎是见的题少 原文里都在用 \(\log ...

  5. python3中的常见知识点3------reduce()函数

    python3中的常见知识点3--reduce()函数 python3导入reduce()函数 reduce()函数语法 reduce()举例 其他python3常用函数 参考链接 python3中不 ...

  6. intel Pin:动态二进制插桩的安装和使用,以及如何开发一个自己的Pintool

    先贴几个你可能用得上的链接 intel Pin的官方介绍Pin: Pin 3.21 User Guide (intel.com) intel Pin的API文档Pin: API Reference ( ...

  7. 如何使用 IdGen 生成 UID

    在分布式系统中,雪花 ID 是一种常用的唯一 ID 生成算法.它通过结合时间戳.机器码和自增序列来生成 64 位整数 ID,可以保证 ID 的唯一性和顺序性. 在.Net 项目中,我们可以使用 IdG ...

  8. Surp Suite入门

    BurpSuite代理工具是以拦截代理的方式,拦截所有通过代理的网络流量,如客户端的请求数据.服务器端的返回信息等.Burp Suite主要拦截HTTP和HTTPS 协议的流量,通过拦截,Burp S ...

  9. C#多线程(四)并行编程篇之结构化

    前言 在前三章中我们的案例大量使用到了Thread这个类,通过其原始API,对其进行创建.启动.中断.中断.终止.取消以及异常处理,这样的写法不仅不够优雅(对接下来这篇,我称其为.NET现代化并行编程 ...

  10. vulnhub靶场之GROTESQUE: 3.0.1

    准备: 攻击机:虚拟机kali.本机win10. 靶机:Grotesque: 3.0.1,下载地址:https://download.vulnhub.com/grotesque/grotesque3. ...