如何在 Cargo.toml 中的依赖项中指定某个提交? [英] How to specify a certain commit in dependencies in Cargo.toml?

查看:81
本文介绍了如何在 Cargo.toml 中的依赖项中指定某个提交?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 GitHub 中的外部依赖项配置我的 Rust 项目.不幸的是,最近的一些提交对接口进行了一些更改,因此我无法使用最新版本.开发人员也不关心不同版本的标签和单独的分支,所以我认为唯一正确的方法是在界面适合我使用的地方以某种方式指定某个提交.

I am trying to configure my Rust project with an external dependency in GitHub. Unfortunately, some last commits made some changes in interfaces so I am unable to use the latest version. The developers also do not care of tags and separate branches for different versions, so I think the only correct way is to specify a certain commit somehow where the interface fits what I worked with.

我现在在 Cargo.toml 中有:

[dependencies]
...
thelib = { git = 'https://github.com/someguys/thelib' }

我看到可以像这样指定一个分支:

I saw it is possible to specify a branch like this:

thelib = { git = 'https://github.com/someguys/thelib', branch = 'branch1' }

但我还没有看到一个提交的工作示例.有人可以在这里提供吗?

But I have not seen a working example with a commit. Could anybody provide one here?

推荐答案

正如 Cargo.toml vs Cargo.lock 部分 Cargo 指南,您可以使用 rev 属性来指定提交哈希:

As hinted in the Cargo.toml vs Cargo.lock section of the Cargo guide, you can use the rev property to specify a commit hash:

[...] 如果你今天构建这个包,然后你给我发送一份副本,我明天构建这个包,可能会发生一些不好的事情.与此同时,可能会有更多的 rand 提交,我的构建将包含新的提交,而你的则不会.因此,我们会得到不同的构建.这会很糟糕,因为我们想要可重现的构建.

[...] If you build this package today, and then you send a copy to me, and I build this package tomorrow, something bad could happen. There could be more commits to rand in the meantime, and my build would include new commits while yours would not. Therefore, we would get different builds. This would be bad because we want reproducible builds.

我们可以通过在 Cargo.toml 中添加一个 rev 行来解决这个问题:

We could fix this problem by putting a rev line in our Cargo.toml:

[dependencies]
rand = { git = "https://github.com/rust-lang-nursery/rand.git", rev = "9f35b8e" }

指定依赖项,虽然没有给出示例(强调我的):

It is also mentioned in Specifying dependencies, although no example is given (emphasis mine):

由于我们没有指定任何其他信息,Cargo 假设我们打算使用 master 分支上的最新提交来构建我们的包.您可以将 git 键与 revtagbranch 组合以指定其他内容.[...]

Since we haven’t specified any other information, Cargo assumes that we intend to use the latest commit on the master branch to build our package. You can combine the git key with the rev, tag, or branch keys to specify something else. [...]

这篇关于如何在 Cargo.toml 中的依赖项中指定某个提交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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