首页 > 其他分享 >文盘Rust -- 本地库引发的依赖冲突

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

时间:2023-02-20 10:23:53浏览次数:61  
标签:links rs -- package cityhash 文盘 sys Rust clickhouse

作者:京东科技 贾世闻

问题描述

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

下期见。

标签:links,rs,--,package,cityhash,文盘,sys,Rust,clickhouse
From: https://www.cnblogs.com/Jcloud/p/17136427.html

相关文章

  • Mysql主从复制
    达到效果主数据库数据变更,从库对应同步变更(包含表、字段)前提条件两台数据库的数据要一致配置my.cnf主数据库配置#数据库服务器id,这个id用来在主从服务器中标记唯一......
  • Carbon真的会替代C++吗
    个人认为Carbon并不是一个编程语言,而是一个已经被苹果公司弃用的macOS开发框架,曾经用于编写ClassicMacOS和早期版本的macOS应用程序。因此,Carbon并不能替代C++......
  • springboot实现文件上传下载
    1.用IDEA创建名叫springboot-file的SpringBoot项目,并将Packagename改为com.example.springboot,导入SpringWeb和thymeleaf依赖。(如果创建过程中遇到了问题,可以看我写的文......
  • 说透中台 ---- 系列文章
    【005】说透中台 说透中台(答疑篇)--学习笔记说透中台(落地篇三)--学习笔记说透中台(落地篇二)--学习笔记说透中台(落地篇一)--学习笔记说透中台(概念篇)--学......
  • 对于多方安全计算,你是否也有这样的疑惑?
    学习&转载文章:对于多方安全计算,你是否也有这样的疑惑?问题假设多方安全计算中有两个参与方\(P_0\)和\(P_1\),其中\(P_0\)拥有\(x\),\(P_1\)拥有\(y\),双方想要在不暴露自己......
  • 嵌入式开发之优化---代码优化
    1.牢记Ahmdal定律funccost表示是函数func的运行时间百分比,funcspeedup是你优化后函数的运行系数;所以,如果函数TriangleIntersect......
  • vue——使用$router.push跳转无效
    我的情况:登录组件A,点击登录后,跳转首页无效,在全局路由守卫router.beforeEach中打印,也没有跳转信息。原因:登录组件A中,有个beforeRouteLeave生命周期函数,没有写next()回调......
  • LabWindows/CVI数据采集-DAQ相关函数介绍
    1.如果函数状态出现错误,就用goto语句跳转到错误Error函数块去执行。Error需要自己定义#defineDAQmxErrChk(functionCall)if(DAQmxFailed(error=(functionCall)))goto......
  • Windows下用wget批量下载文件
    本记录主要是为了应付下载大量CMIP6数据所写,配合新版数据下载网站ESGFMetaGrid(llnl.gov)和下面的方法,数据下载变得较为容易。1、下载wgetWindowsbinariesofGNUWget......
  • Python正则替换请求头格式代码
    有时候请求网站的时候需要携带请求头,从浏览器扒下来的请求头手动操作很不方便,代码类似如下:Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,......