如何根据上个月的 crates.io 生成 Cargo.lock? [英] How to generate Cargo.lock based on last month's crates.io?

查看:38
本文介绍了如何根据上个月的 crates.io 生成 Cargo.lock?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想根据 2017 年 2 月 22 日可用的内容在 Cargo.toml 的 Rust 项目中创建 Cargo.lock 文件.我需要使版本选择与那天发生的事情兼容.(不,不要在某处使用版本控制的 Cargo.lock.)

I want to create a Cargo.lock file in a Rust project from Cargo.toml based on what was available on 22 Feb 2017. I need to make version selection compatible to what would happen on that specific day. (No, don't have a version controlled Cargo.lock around somewhere.)

我试过没有用:

  1. 将 crates.io 索引克隆到本地目录并检查与所需日期匹配的旧提交.
  2. 在 .cargo/config 中使用以下几行:

  1. Clone the crates.io index into a local directory and check out an older commit that matches the desired date.
  2. Use the following lines in .cargo/config:

[source.mycrates]
registry = "file:///path/to/crates.io-index"  # contains old checkout

[source.crates-io]
replace-with = "mycrates"

然而,cargo 将 Cargo.toml 中的依赖项解析为可用的最新版本,而不是指定结帐中的最新版本.

Nevertheless, cargo resolves dependencies in Cargo.toml to the newest ones available, not to the newest ones in the specified checkout.

我怎样才能及时扭曲 Cargo 的版本选择?

How could I warp Cargo's version selection back in time?

推荐答案

既然你说你已经尝试过克隆索引,我假设你仍然有它.为了其他读者的利益,该存储库似乎是在 Git 中维护的,可在 https://github.com/rust-lang/crates.io-index.

Since you say you've already tried cloning the index, I'll assume you still have it lying around. For the benefit of other readers, the repository appears to be maintained in Git and is available at https://github.com/rust-lang/crates.io-index.

你需要告诉 cargo 使用 --frozen 运行,这样它就不会接触到网络,q.v.Cargo FAQ,如果它认为它需要.如果它已经下载了一些东西,你也需要cargo clean,否则就会破坏缓存.

You'll need to tell cargo to run with --frozen so that it doesn't touch the network, q.v. the Cargo FAQ, and it will blow up if it thinks it needs to. If it has already downloaded stuff, you'll need to cargo clean too, or otherwise nuke the cache.

如果您在结帐时还没有获得所需的所有软件包,您还需要下载您感兴趣的特定版本.Dissecting Crates.io: Bare minimum Mirror 有一个解释,我会在这里总结一下,以防链接失效.

If you don't already all of the packages you need in the checkout, you'll also need to download the specific versions you're interested in. Dissecting Crates.io: Bare Minimum Mirror has an explanation, which I'll summarize here in case the link blows up.

config.json 在 Crates 存储库的根目录中有下载包的 URL,官方认为这些包不稳定,但现在可以使用.

config.json in the root of the Crates repo has the URLs for downloading packages, which are officially considered unstable, but works right now.

gmjosack"使用的 libc 板条箱中的示例根据https://crates的dl键,显示/api/v1/crates/libc/0.1.10/download的下载路径config.json 中的 .io/api/v1/crates 和发布时可用的版本.

The example from the libc crate used by the "gmjosack" shows a path of /api/v1/crates/libc/0.1.10/download to download it, based upon the dl key of https://crates.io/api/v1/crates in config.json and the version available at the time of the post.

您可能需要编写下载脚本以构建镜像.另请参阅:使用网络浏览器下载 Rust crates on stackoverflow.

You'll probably need to script the downloads in order to build up your mirror. See also: Downloading Rust crates using a web browser on stackoverflow.

这篇关于如何根据上个月的 crates.io 生成 Cargo.lock?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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