Rust crates 国内镜像源加速配置

最近发现拉取 crates.io 仓库代码尤其慢,很多次超时导致引用库没法编译。

这里可以切到国内镜像,配置如下:

  • 找到当前用户目录下 /Users/baoyachi/.cargo/.cargo 文件夹
  • 进入.cargo 当前目录,在当前目下创建 config 文件
  • 见下图,打开 config 文件,编写以下内容:
[source.crates-io]
registry = "https://github.com/rust-lang/crates.io-index"
replace-with = 'ustc'
[source.ustc]
registry = "git://mirrors.ustc.edu.cn/crates.io-index"

  • 关于Rust 下载安装加速指南,请点击查看

包牙齿:Rust 下载安装加速指南12 赞同 · 0 评论文章

  • 关于Rust错误处理,请点击查看

包牙齿:细说Rust错误处理125 赞同 · 12 评论文章

---------分割线----------

2020-04-11更新

ustc的镜像出了问题,建议换到TUNA的

建议config如下:

[source.crates-io]
registry = "https://github.com/rust-lang/crates.io-index"

replace-with = 'tuna'
[source.tuna]
registry = "https://mirrors.tuna.tsinghua.edu.cn/git/crates.io-index.git"

#replace-with = 'ustc'
#[source.ustc]
#registry = "git://mirrors.ustc.edu.cn/crates.io-index"

[net]
git-fetch-with-cli = true

Sparse registry 可能是更好的选择, 不用把整个index clone下来: https://blog.rust-lang.org/2022/06/22/sparse-registry-testing.html
https://www.zhihu.com/people/708b31abbb7d3c846d05c288ae02fdd0)

目前清华的源还可以。科大的确实慢

这样配置法,如果用了lazy-static包,在cargo publish的时候会报错

一般我发布到公开库http://crates.io前,会将替代源关掉

publish前换成官方源就行
转自:https://zhuanlan.zhihu.com/p/126204128

posted @ 2023-03-17 22:51  MasonLee  阅读(493)  评论(0编辑  收藏  举报