Cargo 的配置目录的位置如何被覆盖? [英] How can the location of Cargo's configuration directory be overridden?
问题描述
似乎 Cargo 在搜索其配置目录时的默认行为是查看当前用户的主目录(在我的系统上为 ~/.cargo
).如何修改这种行为,让 Cargo 在用户提供的目录中查找?
It seems that the default behavior of Cargo when searching for its configuration directory is to look in the current user's home directory (~/.cargo
on my system). How can this behavior be modified to make Cargo look in a user-supplied directory instead?
推荐答案
环境变量 Cargo 读取
你可以覆盖这些环境变量来改变 Cargo 的您系统上的行为:
Environment variables Cargo reads
You can override these environment variables to change Cargo's behavior on your system:
CARGO_HOME
— Cargo 维护注册表索引和 crate 的 git checkouts 的本地缓存.默认情况下,这些存储在$HOME/.cargo
,但是这个变量覆盖了这个的位置目录.一旦一个 crate 被缓存,它就不会被 clean 删除命令.CARGO_TARGET_DIR
— 放置所有生成的工件的位置,相对于当前工作目录.RUSTC
— Cargo 将执行这个指定的编译器,而不是运行rustc
.RUSTC_WRAPPER
— Cargo 不是简单地运行rustc
,而是执行这个指定的包装器,作为它的命令行传递参数 rustc 调用,第一个参数是 rustc.RUSTDOC
— Cargo 将执行此指定的rustdoc
实例,而不是运行rustdoc
.RUSTDOCFLAGS
— 以空格分隔的自定义标志列表,用于传递给 Cargo 执行的所有rustdoc
调用.与...相比cargo rustdoc
,这对于将标志传递给 all 很有用rustdoc
实例.RUSTFLAGS
— 以空格分隔的自定义标志列表,用于传递给 Cargo 执行的所有编译器调用.与cargo rustc
相比,这对于将标志传递给 all 编译器很有用实例.CARGO_INCREMENTAL
— 如果设置为 1,则 Cargo 将强制为当前编译启用增量编译,当设置为 0 时,它将强制禁用它.如果这个环境变量不是否则将使用货物的默认值.CARGO_CACHE_RUSTC_INFO
— 如果设置为 0,则 Cargo 不会尝试缓存编译器版本信息.
CARGO_HOME
— Cargo maintains a local cache of the registry index and of git checkouts of crates. By default these are stored under$HOME/.cargo
, but this variable overrides the location of this directory. Once a crate is cached it is not removed by the clean command.CARGO_TARGET_DIR
— Location of where to place all generated artifacts, relative to the current working directory.RUSTC
— Instead of runningrustc
, Cargo will execute this specified compiler instead.RUSTC_WRAPPER
— Instead of simply runningrustc
, Cargo will execute this specified wrapper instead, passing as its commandline arguments the rustc invocation, with the first argument being rustc.RUSTDOC
— Instead of runningrustdoc
, Cargo will execute this specifiedrustdoc
instance instead.RUSTDOCFLAGS
— A space-separated list of custom flags to pass to allrustdoc
invocations that Cargo performs. In contrast withcargo rustdoc
, this is useful for passing a flag to allrustdoc
instances.RUSTFLAGS
— A space-separated list of custom flags to pass to all compiler invocations that Cargo performs. In contrast withcargo rustc
, this is useful for passing a flag to all compiler instances.CARGO_INCREMENTAL
— If this is set to 1 then Cargo will force incremental compilation to be enabled for the current compilation, and when set to 0 it will force disabling it. If this env var isn't present then cargo's defaults will otherwise be used.CARGO_CACHE_RUSTC_INFO
— If this is set to 0 then Cargo will not try to cache compiler version information.
Cargo 允许对特定包裹进行本地配置以及全局配置,比如 git.Cargo 将此扩展到分层战略.例如,如果 Cargo 在/projects/foo/bar/baz
,那么下面的配置文件会按此顺序探讨统一:
Hierarchical structure
Cargo allows local configuration for a particular package as well as global configuration, like git. Cargo extends this to a hierarchical strategy. If, for example, Cargo were invoked in
/projects/foo/bar/baz
, then the following configuration files would be probed for and unified in this order:
/projects/foo/bar/baz/.cargo/config
/projects/foo/bar/.cargo/config
/projects/foo/.cargo/config
/projects/.cargo/config
/.cargo/config
$HOME/.cargo/config
使用这种结构,您可以指定每个包的配置,并且甚至可能将其检查到版本控制中.您也可以指定个人默认设置,在您的主目录中有一个配置文件.
With this structure, you can specify configuration per-package, and even possibly check it into version control. You can also specify personal defaults with a configuration file in your home directory.
这篇关于Cargo 的配置目录的位置如何被覆盖?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!