在 Cargo.toml 或 Cargo.lock 中设置项目依赖的特定版本的依赖 [英] Set specific version of the dependency of a project's dependency in Cargo.toml or Cargo.lock

查看:131
本文介绍了在 Cargo.toml 或 Cargo.lock 中设置项目依赖的特定版本的依赖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我的项目 A 依赖于依赖于库 C 的库 B.

库 B 将依赖版本设置为*"(任意),以便 Cargo 下载 C 的最新版本.

如何指示cargo 使用特定版本的库C 来构建库B?

<小时>

目前我正在尝试构建 iron.

当前构建失败,但我可以在 https://travis-ci.org/iron/iron/builds/45254195,包括rust版本和cargo包版本.

所以我下载了构建中每晚使用的特定 Rust,并通过编辑 Cargo.toml 将铁的直接依赖项设置为该构建中使用的依赖项:

(...)[依赖项]超级=0.0.18"类型映射 = "0.0.5"网址 = "0.2.9"(……)

但是 rust-serialized,它是url"和time"包的一个依赖项,它是在最新版本中下载的,它不能与我的特定 rust 版本一起编译.

如果我使用上面 Travis 构建中使用的版本,我相信它会成功编译.

解决方案

自从提供了 anwser,Cargo 已将 [patch] 部分添加到清单中,允许您执行此用例.

覆盖依赖

Let's say my project A depends on library B that depends on library C.

Library B sets the dependency version to "*" (any) so cargo will download the latest version of C.

How can I instruct cargo to build library B to using a specific version of library C?


Currently I'm trying to build iron.

The current build is failing, but I can see the last successful build in https://travis-ci.org/iron/iron/builds/45254195, including rust version and cargo package versions.

So I downloaded the specific rust nightly used in the build, and I've set the the direct dependencies of iron to the ones used in that build, by editing Cargo.toml:

(...)
[dependencies]
hyper = "0.0.18"
typemap = "0.0.5"
url = "0.2.9"
(...)

But rust-serialized, which is a dependency of the "url" and "time" packages is downloaded in the latest version which doesn't compile with my specific rust version.

If I used the version used in the Travis build above I'm sure it will compile successfully.

解决方案

Since the anwser provided, Cargo has added the [patch] section to the manifest which allows you to do this use case.

overriding-dependencies

这篇关于在 Cargo.toml 或 Cargo.lock 中设置项目依赖的特定版本的依赖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆