gpt4 book ai didi

rust - 如何覆盖 Cargo 配置目录的位置?

转载 作者:行者123 更新时间:2023-11-29 07:45:01 28 4
gpt4 key购买 nike

似乎 Cargo 在搜索其配置目录时的默认行为是在当前用户的主目录中查找(在我的系统上为 ~/.cargo)。如何修改此行为以使 Cargo 改为在用户提供的目录中查找?

最佳答案

Environment variables Cargo reads

You can override these environment variables to change Cargo's behavior on your system:

  • 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 running rustc, Cargo will execute this specified compiler instead.
  • RUSTC_WRAPPER — Instead of simply running rustc, Cargo will execute this specified wrapper instead, passing as its commandline arguments the rustc invocation, with the first argument being rustc.
  • RUSTDOC — Instead of running rustdoc, Cargo will execute this specified rustdoc instance instead.
  • RUSTDOCFLAGS — A space-separated list of custom flags to pass to all rustdoc invocations that Cargo performs. In contrast with cargo rustdoc, this is useful for passing a flag to all rustdoc instances.
  • RUSTFLAGS — A space-separated list of custom flags to pass to all compiler invocations that Cargo performs. In contrast with cargo 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.

The Cargo documentation


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.

The Cargo documentation

关于rust - 如何覆盖 Cargo 配置目录的位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38050995/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com