如何告诉 Cargo 使用 git 存储库作为间接依赖项而不是 crates.io 的源? [英] How to tell Cargo to use a git repository as source for an indirect dependency instead of crates.io?

查看:42
本文介绍了如何告诉 Cargo 使用 git 存储库作为间接依赖项而不是 crates.io 的源?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

几天前,通过 Emscripten 交叉编译到 JavaScript 终于每晚都出现了.我想以这种方式使用 glium 编译一个项目.但是,许多 crate 中仍然存在许多与 Emscripten 相关的错误.虽然维护人员通常会快速修复这些错误,但他们不一定会立即将这些错误修复发布到 crates.io.

A few days ago, cross-compiling to JavaScript via Emscripten has finally hit nightly. I wanted to compile a project using glium in that manner. However, there are still many Emscripten-related bugs in many crates. While maintainers usually fix those bugs quickly, they don't necessarily release those bug fixes to crates.io immediately.

就我而言,glium 依赖于 glutin.glutin 有一个错误,现在已修复,但仅限于 git 存储库,而不是 crates.io.注意:glutin 不是我项目的直接依赖;只是通过 glium 间接的一个!

In my case, glium depends on glutin. glutin had a bug which is fixed now, but only in the git repository, not on crates.io. Note: glutin is not a direct dependency of my project; only an indirect one through glium!

我如何告诉 Cargo 使用 glutin 存储库作为 glutin 而不是 crates.io 的来源?

How do I tell Cargo to use the glutin repository as source for glutin instead of crates.io?

推荐答案

您可以在项目的 Cargo.toml 中使用 [replace] 部分代码>.您可以在此处在 Cargo 文档中找到有关该功能的文档.

You can use the [replace] section in your project's Cargo.toml. You can find the documentation about that feature here in the Cargo documentation.

在您的情况下,glium 取决于 glutin 0.6.1.crates.io 上的 0.6.1 版本仍然包含该错误.所以只需将其添加到您的 Cargo.toml 中:

In your case, glium depends on glutin 0.6.1. The version 0.6.1 on crates.io still contains the bug. So just add this to your Cargo.toml:

[replace]
"glutin:0.6.1" = { git = 'https://github.com/tomaka/glutin' }

<小时>

但是请注意,


Note however,

[...] 被替换的 crate 不仅必须具有相同的名称,而且必须具有相同的版本.

[...] that the replaced crate must not only have the same name but also the same version.

但即使在版本不匹配的情况下(存储库已经包含更新的版本),如果 crate 的维护者为每个版本创建 git 标签(Rust 社区中的许多人都这样做),您仍然很幸运.在这种情况下,您只需指定标签:

But even in the case of a version-mismatch (the repository already contains a newer version), you could still be in luck if the crate's maintainer creates git tags for every version (many in the Rust community do). In that case you can just specify the tag:

[replace]
"glutin:0.6.1" = { 
    git = 'https://github.com/tomaka/glutin' 
    tag = 'v0.6.1'
}

遗憾的是,这不适用于 glutin,因为维护者没有为每个版本都创建标签.在这种情况下,您可以简单地找到版本被碰撞之前的最后一次提交并使用 rev = 'b4a3d0...' 指定它或使用 指定一个特定的分支>branch = '...' 键.

Sadly, this won't work with glutin, because the maintainer did not create tags for every version. In that case you can simply find the last commit before the version was bumped and specify it with rev = 'b4a3d0...' or specify a specific branch with the branch = '...' key.

这篇关于如何告诉 Cargo 使用 git 存储库作为间接依赖项而不是 crates.io 的源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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