From 05e9d5acd50071655900bd02d0b70b8f0cd70f02 Mon Sep 17 00:00:00 2001 From: sunface Date: Wed, 23 Feb 2022 11:52:44 +0800 Subject: [PATCH] update cargo config --- contents/cargo/reference/configuration.md | 29 ++++++++++++++++------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/contents/cargo/reference/configuration.md b/contents/cargo/reference/configuration.md index 73343f72..5b96cfc8 100644 --- a/contents/cargo/reference/configuration.md +++ b/contents/cargo/reference/configuration.md @@ -105,18 +105,18 @@ rpath = false [profile..build-override] [profile..package.] -[registries.] # registries other than crates.io -index = "…" # URL of the registry index -token = "…" # authentication token for the registry +[registries.] # 设置其它的注册服务: https://course.rs/cargo/reference/specify-deps.html#从其它注册服务引入依赖包 +index = "…" # 注册服务索引列表的 URL +token = "…" # 连接注册服务所需的鉴权 token [registry] -default = "…" # name of the default registry -token = "…" # authentication token for crates.io +default = "…" # 默认的注册服务名称: crates.io +token = "…" -[source.] # source definition and replacement -replace-with = "…" # replace this source with the given named source +[source.] # 注册服务源和替换source definition and replacement +replace-with = "…" # 使用给定的 source 来替换当前的 source,例如使用科大源来替换crates.io源以提升国内的下载速度:[source.crates-io] replace-with = 'ustc' directory = "…" # path to a directory source -registry = "…" # URL to a registry source +registry = "…" # 注册源的 URL ,例如科大源: [source.ustc] registry = "git://mirrors.ustc.edu.cn/crates.io-index" local-registry = "…" # path to a local registry source git = "…" # URL of a git repository source branch = "…" # branch name for the git repository @@ -147,4 +147,15 @@ verbose = false # whether cargo provides verbose output color = 'auto' # whether cargo colorizes output progress.when = 'auto' # whether cargo shows progress bar progress.width = 80 # width of progress bar -``` \ No newline at end of file +``` + +## 环境变量 +除了 `config.toml` 配置文件,我们还可以使用环境变量的方式对 Cargo 进行配置。 + +配置文件的中的 key `foo.bar` 对应的环境变量形式为 `CARGO_FOO_BAR`,其中的`.`、`-` 被转换成 `_`,且字母都变成大写的。例如,`target.x86_64-unknown-linux-gnu.runner` key 转换成环境变量后变成 `CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_RUNNER`。 + +就优先级而言,环境变量是比配置文件更高的。除了上面的机制,Cargo 还支持一些[预定义的环境变量](https://doc.rust-lang.org/stable/cargo/reference/environment-variables.html)。 + + +> 官方 Cargo Book 中本文的内容还有[很多](https://doc.rust-lang.org/stable/cargo/reference/config.html#configuration-keys),但是剩余内容对于绝大多数用户都用不到,因此我们并没有涵盖其中。 +