1 Star 13 Fork 0

wtklbm / crm

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
Apache-2.0

crm (Cargo registry manager)

crm 是一个在终端运行的镜像管理程序,能够对 Cargo 镜像源进行简单的添加、修改、删除操作,并能帮助您快速的切换不同的 Cargo 镜像源。crm 内置了多种国内 (中国) 镜像源,它们分别是:sjtu, tuna, ustc, rsproxybfsu, nju, hit

在使用 Rust 语言做开发时,使用 Rust 官方镜像源进行 cargo build 的速度非常的慢,可能会因为网络的原因导致依赖下载超时而无法完成编译。为了能够在最少的时间内完成打包操作,一般会使用国内镜像源来代替官方镜像。

通常,大家一般会手动修改 ~/.cargo/config 文件来完成镜像的切换,手动修改配置文件的工作是繁琐的,它需要手动打开文件所在的目录,还要记住每一个镜像源的地址和配置方式,在不知道哪个国内源的网速最快的时候,我们还需要对镜像的速度进行手动的测速,在使用国内镜像源的过程中,如果当前所使用的国内镜像源也挂了,我们还需要切换到另一个国内镜像源,这就显得非常的棘手。如果您手动配置了国内镜像源,并且还经常的通过 cargo publish 发包的话 ,那么在发包之前,还需要将国内镜像源再手动切换为官方镜像。在比如,每一个国内镜像源同步镜像的时间是不一样的,如果您刚发了一个包并且想第一时间应用到您的项目中,但是因为国内镜像源的没有及时的同步镜像,而导致包无法下载,这个时候您还需要切换到官方镜像源来下载最新发布的包。每一次手动切换镜像的操作都是繁琐且耗时的,而 crm 就是为了解决上述的问题。

安装

通过 cargo 安装

# 在终端中执行
# NOTE 最好使用官方镜像源来安装或升级

cargo install crm

Arch Linux 上安装

您可以从 Arch Linux 用户仓库 (AUR) 中安装它,感谢 taotieren 为此做出的努力。

# 在终端中执行

# `yay` 是一个 AUR 包管理器,可以使用您喜欢的任何包管理器来安装它,例如 `paru`
yay -S crm
# 在终端中执行

yay -S crm-git

NOTE:crmcrm-git 都是基于源代码来构建二进制文件的,如果不想通过下载源代码的方式来构建,则可以到 Github Release 中下载预构建的二进制版本。

手动下载预编译的二进制文件

可以直接从 Github Release 下载预编译的二进制版本,将其下载后,保存到任意目录,然后将该目录放到操作系统的 PATH 环境变量中:

  • 如果使用的是 Windows 11 系统,则可以在搜索框中搜索 "编辑系统环境变量",然后找到 "环境变量",找到用户变量中的 "Path",双击它,并添加自定义路径
  • 如果使用的是 macOS 或 Linux 系统,则可以将 export PATH="$PATH:自定义路径" 添加到 .zshrc.bashrc 文件中 (取决于使用的是哪种 Shell)

通过这种安装方式,可以更加自由的管理该软件,半年甚至一年不更新也可以正常使用,可以用 crm check-update 来查询新版本,并进行更新。若要将 crm 批量安装到多台操作系统的话,这样会更加方便快捷。

在下载二进制文件时,可能会遇到下载失败的情况,为此,可以使用 Github 镜像来加速下载。

# 在终端中执行

# 使用 `https://hub.gitmirror.com/` 镜像来加速下载
# 下载哪个版本,就将下面的 URL 部分进行相应的替换即可
curl -O https://hub.gitmirror.com/https://github.com/wtklbm/crm/releases/download/v0.2.1/crm_windows_amd64.tar.gz

使用

crm 的原则是使用最小依赖,并尽可能的简化终端操作。您只需要在终端键入 crm 即可获得命令帮助信息。

# 在终端执行
#
# NOTE:
#  - [args] 表示 args 是一个或多个可选参数
#  - <name> 表示 name 是一个必填参数
#
# 下面这些命令在执行时会自动切换为官方镜像,避免了手动切换镜像的麻烦:
#  - `crm install` 对应 `cargo install`
#  - `crm publish` 对应 `cargo publish`
#  - `crm update` 对应 `cargo update`
#
# `crm test` 命令一般用于进行全量测试,而 `crm best` 是切换到最优镜像的快速方式

$ crm

  crm best                    评估网络延迟并自动切换到最优的镜像
    crm best git              仅评估 git 镜像源
    crm best sparse           仅评估支持 sparse 协议的镜像源
    crm best git-download     仅评估能够快速下载软件包的 git 镜像源 (推荐使用)
    crm best sparse-download  仅评估能够快速下载软件包且支持 sparse 协议的镜像源 (推荐使用)
  crm default                 恢复为官方默认镜像
  crm install [args]          使用官方镜像执行 "cargo install"
  crm list                    从镜像配置文件中获取镜像列表
  crm publish [args]          使用官方镜像执行 "cargo publish"
  crm remove <name>           在镜像配置文件中删除镜像
  crm save <name> <addr> <dl> 在镜像配置文件中添加/更新镜像
  crm test [name]             下载测试包以评估网络延迟
  crm update [args]           使用官方镜像执行 "cargo update"
  crm use <name>              切换为要使用的镜像
  crm version                 查看当前版本
  crm check-update            检测版本更新
  • 根据 反馈,并不建议您使用 ustc 镜像源,它会限制并发
  • 以下镜像只能在更新 git 镜像仓库时获得加速效果,在下载包时无法获得加速效果:
    • tuna
    • bfsu
    • nju
    • hit

在项目中使用来自不同镜像源的依赖

crm 在配置镜像源时,会默认在 ~/.cargo/config 中多增加一个 registries 属性对象,通过增加该属性对象,您就可以在项目中应用来自于不同镜像源的依赖。比如您在使用官方镜像源时,可以通过在项目的 Cargo.toml 文件中指定依赖的 registry 属性来使用不同的国内镜像源。如果您已经在使用国内镜像源了,那么也可以通过修改 registry 属性的方式来切换到其他的国内镜像源。以下是一个示例。

# Cargo.toml

# 使用官方镜像源时,`registry` 属性可选的值为: `sjtu`, `tuna`, `ustc`, `rsproxy`, `bfsu`, `nju`, `hit`
# 如果您已经使用 `crm` 切换到了 `rsproxy` 镜像源,那么 `registry` 属性可选的值则为其他国内镜像:`sjtu`, `tuna`, `ustc`, `bfsu`, `nju`, `hit`
# 以此类推
# 值得注意的是,在使用国内镜像源时,您无法直接通过修改 `registry` 属性的方式使用官方镜像源
# 如果您想使用官方镜像源,那么请在终端执行 `crm default` 来切换到官方镜像

[dependencies]
# 使用 `ustc` 国内镜像来下载 `log` 依赖
log = {version = "0.4.12", registry = "ustc"}

# 使用 `sjtu` 国内镜像来下载 `lazy_static` 依赖
lazy_static = {version = "1.4.0", registry = "sjtu"}

NOTE:

  • 如果您刚安装 crm,那么请在终端执行一次:crm default,然后就可以在项目的 Cargo.toml 文件中配置 registry 属性了。
  • 从 Rust v1.39.0 版本开始,~/.cargo/config.toml 将被推荐使用,如果 ~/.cargo/config~/.cargo/config.toml 同时存在,则优先使用 ~/.cargo/config 配置。

使用 sparse 协议

v1.68.0 版本中,新增了一个 sparse 协议。以前我们更新注册表默认都是通过克隆 git 仓库来实现的,在克隆 git 仓库时会出现明显的延迟,sparse 协议的好处就是不用再克隆镜像源仓库了,而是仅通过 HTTPS 从网络上查询和下载您所需要的包。虽然该协议避免了 git 克隆的步骤,但是当镜像源的网络不稳定时较容易出错。

按照官方说法,使用该协议有两种方式:

  1. export CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse 加入到 .bashrc.zshrc 文件中
  2. 或者编辑 ~/.cargo/config 文件:
    [registries.crates-io]
    protocol = "sparse"

但是,当您使用 crm 时,crm 自带了一些支持 sparse 协议的镜像源,它们是开箱即用的。只须执行 crm best sparsecrm best sparse-download 即可轻松切换到支持 sparse 协议的镜像源。

如果您想了解更多的内容,请参考下面的链接:

注意事项

  1. v0.1.0 版本以下的 .crmrc 配置文件和最新版本的配置文件并不能相互兼容,如果您正在使用小于 v0.1.0 的版本,当您更新到最新版本时,请手动删除 ~/.crmrc 文件
  2. crm 会修改 ~/.cargo/config 文件来进行镜像源的切换,如果您使用的是小于 v0.1.3 的版本,那么当您使用 crm 切换镜像时,~/.cargo/config 文件中的文档注释会被删除并且永远无法恢复,如果您在 ~/.cargo/config 文件中保存了笔记或者文档,请尽快更新到最新版,在最新版中,对此进行了优化,不再自动删除文档注释 (除修改的字段外)
  3. crm 默认会在 ~/.cargo/config 文件中增加一个 env.git-fetch-with-cli 属性,值为 true,在使用 crm 时您无法删除该选项,如果您不想使用 Git 可执行文件进行 Git 操作,请手动修改 ~/.cargo/config 文件并将 git-fetch-with-cli 的值修改为 false

Others

rust-library-chinese

rust-library-chinese 是 Rust 核心库和标准库的源码级中文翻译,可以用作 IDE 工具的中文智能提示,也可以基于翻译好的内容生成 Rust 中文 API 文档。

LICENSE

MIT OR Apache-2.0

Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright 2020 wtklbm Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

简介

Cargo registry manager (Cargo 注册表管理器),用于方便的管理和更换 Rust 国内镜像源 展开 收起
Rust
Apache-2.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
Rust
1
https://gitee.com/wtklbm/crm.git
git@gitee.com:wtklbm/crm.git
wtklbm
crm
crm
main

搜索帮助