文盘Rust -- 本地库引发的依赖冲突

京东云开发者
• 阅读 261

作者:京东科技 贾世闻

问题描述

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

下期见。

点赞
收藏
评论区
推荐文章
blmius blmius
2年前
MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1
文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s
皕杰报表之UUID
​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为
Wesley13 Wesley13
2年前
PPDB:今晚老齐直播
【今晚老齐直播】今晚(本周三晚)20:0021:00小白开始“用”飞桨(https://www.oschina.net/action/visit/ad?id1185)由PPDE(飞桨(https://www.oschina.net/action/visit/ad?id1185)开发者专家计划)成员老齐,为深度学习小白指点迷津。
Wesley13 Wesley13
2年前
VBox 启动虚拟机失败
在Vbox(5.0.8版本)启动Ubuntu的虚拟机时,遇到错误信息:NtCreateFile(\\Device\\VBoxDrvStub)failed:0xc000000034STATUS\_OBJECT\_NAME\_NOT\_FOUND(0retries) (rc101)Makesurethekern
Wesley13 Wesley13
2年前
FLV文件格式
1.        FLV文件对齐方式FLV文件以大端对齐方式存放多字节整型。如存放数字无符号16位的数字300(0x012C),那么在FLV文件中存放的顺序是:|0x01|0x2C|。如果是无符号32位数字300(0x0000012C),那么在FLV文件中的存放顺序是:|0x00|0x00|0x00|0x01|0x2C。2.  
Wesley13 Wesley13
2年前
mysql设置时区
mysql设置时区mysql\_query("SETtime\_zone'8:00'")ordie('时区设置失败,请联系管理员!');中国在东8区所以加8方法二:selectcount(user\_id)asdevice,CONVERT\_TZ(FROM\_UNIXTIME(reg\_time),'08:00','0
Wesley13 Wesley13
2年前
PHP创建多级树型结构
<!lang:php<?php$areaarray(array('id'1,'pid'0,'name''中国'),array('id'5,'pid'0,'name''美国'),array('id'2,'pid'1,'name''吉林'),array('id'4,'pid'2,'n
Wesley13 Wesley13
2年前
Java日期时间API系列36
  十二时辰,古代劳动人民把一昼夜划分成十二个时段,每一个时段叫一个时辰。二十四小时和十二时辰对照表:时辰时间24时制子时深夜11:00凌晨01:0023:0001:00丑时上午01:00上午03:0001:0003:00寅时上午03:00上午0
Stella981 Stella981
2年前
Jenkins 插件开发之旅:两天内从 idea 到发布(上篇)
本文首发于:Jenkins中文社区(https://www.oschina.net/action/GoToLink?urlhttp%3A%2F%2Fjenkinszh.cn)!huashan(https://oscimg.oschina.net/oscnet/f499d5b4f76f20cf0bce2a00af236d10265.jpg)
Wesley13 Wesley13
2年前
MySQL部分从库上面因为大量的临时表tmp_table造成慢查询
背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_