How to generate Cargo.lock based on last month's crates.io?

为君一笑 提交于 2019-12-06 22:16:37

问题


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.)

I tried this to no avail:

  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"
    

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

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


回答1:


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.

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.

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 in the root of the Crates repo has the URLs for downloading packages, which are officially considered unstable, but works right now.

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.

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.



来源:https://stackoverflow.com/questions/42979096/how-to-generate-cargo-lock-based-on-last-months-crates-io

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!