]> git.proxmox.com Git - cargo.git/blob - src/doc/src/reference/config.md
Auto merge of #10258 - joshtriplett:unconditional-pipelining, r=alexcrichton
[cargo.git] / src / doc / src / reference / config.md
1 ## Configuration
2
3 This document explains how Cargo’s configuration system works, as well as
4 available keys or configuration. For configuration of a package through its
5 manifest, see the [manifest format](manifest.md).
6
7 ### Hierarchical structure
8
9 Cargo allows local configuration for a particular package as well as global
10 configuration. It looks for configuration files in the current directory and
11 all parent directories. If, for example, Cargo were invoked in
12 `/projects/foo/bar/baz`, then the following configuration files would be
13 probed for and unified in this order:
14
15 * `/projects/foo/bar/baz/.cargo/config.toml`
16 * `/projects/foo/bar/.cargo/config.toml`
17 * `/projects/foo/.cargo/config.toml`
18 * `/projects/.cargo/config.toml`
19 * `/.cargo/config.toml`
20 * `$CARGO_HOME/config.toml` which defaults to:
21 * Windows: `%USERPROFILE%\.cargo\config.toml`
22 * Unix: `$HOME/.cargo/config.toml`
23
24 With this structure, you can specify configuration per-package, and even
25 possibly check it into version control. You can also specify personal defaults
26 with a configuration file in your home directory.
27
28 If a key is specified in multiple config files, the values will get merged
29 together. Numbers, strings, and booleans will use the value in the deeper
30 config directory taking precedence over ancestor directories, where the
31 home directory is the lowest priority. Arrays will be joined together.
32
33 At present, when being invoked from a workspace, Cargo does not read config
34 files from crates within the workspace. i.e. if a workspace has two crates in
35 it, named `/projects/foo/bar/baz/mylib` and `/projects/foo/bar/baz/mybin`, and
36 there are Cargo configs at `/projects/foo/bar/baz/mylib/.cargo/config.toml`
37 and `/projects/foo/bar/baz/mybin/.cargo/config.toml`, Cargo does not read
38 those configuration files if it is invoked from the workspace root
39 (`/projects/foo/bar/baz/`).
40
41 > **Note:** Cargo also reads config files without the `.toml` extension, such as
42 > `.cargo/config`. Support for the `.toml` extension was added in version 1.39
43 > and is the preferred form. If both files exist, Cargo will use the file
44 > without the extension.
45
46 ### Configuration format
47
48 Configuration files are written in the [TOML format][toml] (like the
49 manifest), with simple key-value pairs inside of sections (tables). The
50 following is a quick overview of all settings, with detailed descriptions
51 found below.
52
53 ```toml
54 paths = ["/path/to/override"] # path dependency overrides
55
56 [alias] # command aliases
57 b = "build"
58 c = "check"
59 t = "test"
60 r = "run"
61 rr = "run --release"
62 space_example = ["run", "--release", "--", "\"command list\""]
63
64 [build]
65 jobs = 1 # number of parallel jobs, defaults to # of CPUs
66 rustc = "rustc" # the rust compiler tool
67 rustc-wrapper = "…" # run this wrapper instead of `rustc`
68 rustc-workspace-wrapper = "…" # run this wrapper instead of `rustc` for workspace members
69 rustdoc = "rustdoc" # the doc generator tool
70 target = "triple" # build for the target triple (ignored by `cargo install`)
71 target-dir = "target" # path of where to place all generated artifacts
72 rustflags = ["…", "…"] # custom flags to pass to all compiler invocations
73 rustdocflags = ["…", "…"] # custom flags to pass to rustdoc
74 incremental = true # whether or not to enable incremental compilation
75 dep-info-basedir = "…" # path for the base directory for targets in depfiles
76
77 [doc]
78 browser = "chromium" # browser to use with `cargo doc --open`,
79 # overrides the `BROWSER` environment variable
80
81 [env]
82 # Set ENV_VAR_NAME=value for any process run by Cargo
83 ENV_VAR_NAME = "value"
84 # Set even if already present in environment
85 ENV_VAR_NAME_2 = { value = "value", force = true }
86 # Value is relative to .cargo directory containing `config.toml`, make absolute
87 ENV_VAR_NAME_3 = { value = "relative/path", relative = true }
88
89 [future-incompat-report]
90 frequency = 'always' # when to display a notification about a future incompat report
91
92 [cargo-new]
93 vcs = "none" # VCS to use ('git', 'hg', 'pijul', 'fossil', 'none')
94
95 [http]
96 debug = false # HTTP debugging
97 proxy = "host:port" # HTTP proxy in libcurl format
98 ssl-version = "tlsv1.3" # TLS version to use
99 ssl-version.max = "tlsv1.3" # maximum TLS version
100 ssl-version.min = "tlsv1.1" # minimum TLS version
101 timeout = 30 # timeout for each HTTP request, in seconds
102 low-speed-limit = 10 # network timeout threshold (bytes/sec)
103 cainfo = "cert.pem" # path to Certificate Authority (CA) bundle
104 check-revoke = true # check for SSL certificate revocation
105 multiplexing = true # HTTP/2 multiplexing
106 user-agent = "…" # the user-agent header
107
108 [install]
109 root = "/some/path" # `cargo install` destination directory
110
111 [net]
112 retry = 2 # network retries
113 git-fetch-with-cli = true # use the `git` executable for git operations
114 offline = true # do not access the network
115
116 [patch.<registry>]
117 # Same keys as for [patch] in Cargo.toml
118
119 [profile.<name>] # Modify profile settings via config.
120 opt-level = 0 # Optimization level.
121 debug = true # Include debug info.
122 split-debuginfo = '...' # Debug info splitting behavior.
123 debug-assertions = true # Enables debug assertions.
124 overflow-checks = true # Enables runtime integer overflow checks.
125 lto = false # Sets link-time optimization.
126 panic = 'unwind' # The panic strategy.
127 incremental = true # Incremental compilation.
128 codegen-units = 16 # Number of code generation units.
129 rpath = false # Sets the rpath linking option.
130 [profile.<name>.build-override] # Overrides build-script settings.
131 # Same keys for a normal profile.
132 [profile.<name>.package.<name>] # Override profile for a package.
133 # Same keys for a normal profile (minus `panic`, `lto`, and `rpath`).
134
135 [registries.<name>] # registries other than crates.io
136 index = "…" # URL of the registry index
137 token = "…" # authentication token for the registry
138
139 [registry]
140 default = "…" # name of the default registry
141 token = "…" # authentication token for crates.io
142
143 [source.<name>] # source definition and replacement
144 replace-with = "…" # replace this source with the given named source
145 directory = "…" # path to a directory source
146 registry = "…" # URL to a registry source
147 local-registry = "…" # path to a local registry source
148 git = "…" # URL of a git repository source
149 branch = "…" # branch name for the git repository
150 tag = "…" # tag name for the git repository
151 rev = "…" # revision for the git repository
152
153 [target.<triple>]
154 linker = "…" # linker to use
155 runner = "…" # wrapper to run executables
156 rustflags = ["…", "…"] # custom flags for `rustc`
157
158 [target.<cfg>]
159 runner = "…" # wrapper to run executables
160 rustflags = ["…", "…"] # custom flags for `rustc`
161
162 [target.<triple>.<links>] # `links` build script override
163 rustc-link-lib = ["foo"]
164 rustc-link-search = ["/path/to/foo"]
165 rustc-flags = ["-L", "/some/path"]
166 rustc-cfg = ['key="value"']
167 rustc-env = {key = "value"}
168 rustc-cdylib-link-arg = ["…"]
169 metadata_key1 = "value"
170 metadata_key2 = "value"
171
172 [term]
173 quiet = false # whether cargo output is quiet
174 verbose = false # whether cargo provides verbose output
175 color = 'auto' # whether cargo colorizes output
176 progress.when = 'auto' # whether cargo shows progress bar
177 progress.width = 80 # width of progress bar
178 ```
179
180 ### Environment variables
181
182 Cargo can also be configured through environment variables in addition to the
183 TOML configuration files. For each configuration key of the form `foo.bar` the
184 environment variable `CARGO_FOO_BAR` can also be used to define the value.
185 Keys are converted to uppercase, dots and dashes are converted to underscores.
186 For example the `target.x86_64-unknown-linux-gnu.runner` key can also be
187 defined by the `CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_RUNNER` environment
188 variable.
189
190 Environment variables will take precedence over TOML configuration files.
191 Currently only integer, boolean, string and some array values are supported to
192 be defined by environment variables. Descriptions below indicate which keys
193 support environment variables.
194
195 In addition to the system above, Cargo recognizes a few other specific
196 [environment variables][env].
197
198 ### Config-relative paths
199
200 Paths in config files may be absolute, relative, or a bare name without any
201 path separators. Paths for executables without a path separator will use the
202 `PATH` environment variable to search for the executable. Paths for
203 non-executables will be relative to where the config value is defined. For
204 config files, that is relative to the parent directory of the `.cargo`
205 directory where the value was defined. For environment variables it is
206 relative to the current working directory.
207
208 ```toml
209 # Relative path examples.
210
211 [target.x86_64-unknown-linux-gnu]
212 runner = "foo" # Searches `PATH` for `foo`.
213
214 [source.vendored-sources]
215 # Directory is relative to the parent where `.cargo/config.toml` is located.
216 # For example, `/my/project/.cargo/config.toml` would result in `/my/project/vendor`.
217 directory = "vendor"
218 ```
219
220 ### Executable paths with arguments
221
222 Some Cargo commands invoke external programs, which can be configured as a path
223 and some number of arguments.
224
225 The value may be an array of strings like `['/path/to/program', 'somearg']` or
226 a space-separated string like `'/path/to/program somearg'`. If the path to the
227 executable contains a space, the list form must be used.
228
229 If Cargo is passing other arguments to the program such as a path to open or
230 run, they will be passed after the last specified argument in the value of an
231 option of this format. If the specified program does not have path separators,
232 Cargo will search `PATH` for its executable.
233
234 ### Credentials
235
236 Configuration values with sensitive information are stored in the
237 `$CARGO_HOME/credentials.toml` file. This file is automatically created and updated
238 by [`cargo login`]. It follows the same format as Cargo config files.
239
240 ```toml
241 [registry]
242 token = "…" # Access token for crates.io
243
244 [registries.<name>]
245 token = "…" # Access token for the named registry
246 ```
247
248 Tokens are used by some Cargo commands such as [`cargo publish`] for
249 authenticating with remote registries. Care should be taken to protect the
250 tokens and to keep them secret.
251
252 As with most other config values, tokens may be specified with environment
253 variables. The token for [crates.io] may be specified with the
254 `CARGO_REGISTRY_TOKEN` environment variable. Tokens for other registries may
255 be specified with environment variables of the form
256 `CARGO_REGISTRIES_<name>_TOKEN` where `<name>` is the name of the registry in
257 all capital letters.
258
259 ### Configuration keys
260
261 This section documents all configuration keys. The description for keys with
262 variable parts are annotated with angled brackets like `target.<triple>` where
263 the `<triple>` part can be any target triple like
264 `target.x86_64-pc-windows-msvc`.
265
266 #### `paths`
267 * Type: array of strings (paths)
268 * Default: none
269 * Environment: not supported
270
271 An array of paths to local packages which are to be used as overrides for
272 dependencies. For more information see the [Overriding Dependencies
273 guide](overriding-dependencies.md#paths-overrides).
274
275 #### `[alias]`
276 * Type: string or array of strings
277 * Default: see below
278 * Environment: `CARGO_ALIAS_<name>`
279
280 The `[alias]` table defines CLI command aliases. For example, running `cargo
281 b` is an alias for running `cargo build`. Each key in the table is the
282 subcommand, and the value is the actual command to run. The value may be an
283 array of strings, where the first element is the command and the following are
284 arguments. It may also be a string, which will be split on spaces into
285 subcommand and arguments. The following aliases are built-in to Cargo:
286
287 ```toml
288 [alias]
289 b = "build"
290 c = "check"
291 d = "doc"
292 t = "test"
293 r = "run"
294 ```
295
296 Aliases are not allowed to redefine existing built-in commands.
297
298 #### `[build]`
299
300 The `[build]` table controls build-time operations and compiler settings.
301
302 ##### `build.jobs`
303 * Type: integer
304 * Default: number of logical CPUs
305 * Environment: `CARGO_BUILD_JOBS`
306
307 Sets the maximum number of compiler processes to run in parallel.
308
309 Can be overridden with the `--jobs` CLI option.
310
311 ##### `build.rustc`
312 * Type: string (program path)
313 * Default: "rustc"
314 * Environment: `CARGO_BUILD_RUSTC` or `RUSTC`
315
316 Sets the executable to use for `rustc`.
317
318 ##### `build.rustc-wrapper`
319 * Type: string (program path)
320 * Default: none
321 * Environment: `CARGO_BUILD_RUSTC_WRAPPER` or `RUSTC_WRAPPER`
322
323 Sets a wrapper to execute instead of `rustc`. The first argument passed to the
324 wrapper is the path to the actual `rustc`.
325
326 ##### `build.rustc-workspace-wrapper`
327 * Type: string (program path)
328 * Default: none
329 * Environment: `CARGO_BUILD_RUSTC_WORKSPACE_WRAPPER` or `RUSTC_WORKSPACE_WRAPPER`
330
331 Sets a wrapper to execute instead of `rustc`, for workspace members only.
332 The first argument passed to the wrapper is the path to the actual `rustc`.
333 It affects the filename hash so that artifacts produced by the wrapper are cached separately.
334
335 ##### `build.rustdoc`
336 * Type: string (program path)
337 * Default: "rustdoc"
338 * Environment: `CARGO_BUILD_RUSTDOC` or `RUSTDOC`
339
340 Sets the executable to use for `rustdoc`.
341
342 ##### `build.target`
343 * Type: string
344 * Default: host platform
345 * Environment: `CARGO_BUILD_TARGET`
346
347 The default target platform triple to compile to.
348
349 This may also be a relative path to a `.json` target spec file.
350
351 Can be overridden with the `--target` CLI option.
352
353 ##### `build.target-dir`
354 * Type: string (path)
355 * Default: "target"
356 * Environment: `CARGO_BUILD_TARGET_DIR` or `CARGO_TARGET_DIR`
357
358 The path to where all compiler output is placed. The default if not specified
359 is a directory named `target` located at the root of the workspace.
360
361 Can be overridden with the `--target-dir` CLI option.
362
363 ##### `build.rustflags`
364 * Type: string or array of strings
365 * Default: none
366 * Environment: `CARGO_BUILD_RUSTFLAGS` or `RUSTFLAGS`
367
368 Extra command-line flags to pass to `rustc`. The value may be a array of
369 strings or a space-separated string.
370
371 There are three mutually exclusive sources of extra flags. They are checked in
372 order, with the first one being used:
373
374 1. `RUSTFLAGS` environment variable.
375 2. All matching `target.<triple>.rustflags` and `target.<cfg>.rustflags`
376 config entries joined together.
377 3. `build.rustflags` config value.
378
379 Additional flags may also be passed with the [`cargo rustc`] command.
380
381 If the `--target` flag (or [`build.target`](#buildtarget)) is used, then the
382 flags will only be passed to the compiler for the target. Things being built
383 for the host, such as build scripts or proc macros, will not receive the args.
384 Without `--target`, the flags will be passed to all compiler invocations
385 (including build scripts and proc macros) because dependencies are shared. If
386 you have args that you do not want to pass to build scripts or proc macros and
387 are building for the host, pass `--target` with the host triple.
388
389 It is not recommended to pass in flags that Cargo itself usually manages. For
390 example, the flags driven by [profiles] are best handled by setting the
391 appropriate profile setting.
392
393 > **Caution**: Due to the low-level nature of passing flags directly to the
394 > compiler, this may cause a conflict with future versions of Cargo which may
395 > issue the same or similar flags on its own which may interfere with the
396 > flags you specify. This is an area where Cargo may not always be backwards
397 > compatible.
398
399 ##### `build.rustdocflags`
400 * Type: string or array of strings
401 * Default: none
402 * Environment: `CARGO_BUILD_RUSTDOCFLAGS` or `RUSTDOCFLAGS`
403
404 Extra command-line flags to pass to `rustdoc`. The value may be a array of
405 strings or a space-separated string.
406
407 There are two mutually exclusive sources of extra flags. They are checked in
408 order, with the first one being used:
409
410 1. `RUSTDOCFLAGS` environment variable.
411 2. `build.rustdocflags` config value.
412
413 Additional flags may also be passed with the [`cargo rustdoc`] command.
414
415 ##### `build.incremental`
416 * Type: bool
417 * Default: from profile
418 * Environment: `CARGO_BUILD_INCREMENTAL` or `CARGO_INCREMENTAL`
419
420 Whether or not to perform [incremental compilation]. The default if not set is
421 to use the value from the [profile]. Otherwise this overrides the setting of
422 all profiles.
423
424 The `CARGO_INCREMENTAL` environment variable can be set to `1` to force enable
425 incremental compilation for all profiles, or `0` to disable it. This env var
426 overrides the config setting.
427
428 ##### `build.dep-info-basedir`
429 * Type: string (path)
430 * Default: none
431 * Environment: `CARGO_BUILD_DEP_INFO_BASEDIR`
432
433 Strips the given path prefix from [dep
434 info](../guide/build-cache.md#dep-info-files) file paths. This config setting
435 is intended to convert absolute paths to relative paths for tools that require
436 relative paths.
437
438 The setting itself is a config-relative path. So, for example, a value of
439 `"."` would strip all paths starting with the parent directory of the `.cargo`
440 directory.
441
442 ##### `build.pipelining`
443
444 This option is deprecated and unused. Cargo always has pipelining enabled.
445
446 #### `[doc]`
447
448 The `[doc]` table defines options for the [`cargo doc`] command.
449
450 ##### `doc.browser`
451
452 * Type: string or array of strings ([program path and args])
453 * Default: `BROWSER` environment variable, or, if that is missing,
454 opening the link in a system specific way
455
456 This option sets the browser to be used by [`cargo doc`], overriding the
457 `BROWSER` environment variable when opening documentation with the `--open`
458 option.
459
460 #### `[cargo-new]`
461
462 The `[cargo-new]` table defines defaults for the [`cargo new`] command.
463
464 ##### `cargo-new.name`
465
466 This option is deprecated and unused.
467
468 ##### `cargo-new.email`
469
470 This option is deprecated and unused.
471
472 ##### `cargo-new.vcs`
473 * Type: string
474 * Default: "git" or "none"
475 * Environment: `CARGO_CARGO_NEW_VCS`
476
477 Specifies the source control system to use for initializing a new repository.
478 Valid values are `git`, `hg` (for Mercurial), `pijul`, `fossil` or `none` to
479 disable this behavior. Defaults to `git`, or `none` if already inside a VCS
480 repository. Can be overridden with the `--vcs` CLI option.
481
482 ### `[env]`
483
484 The `[env]` section allows you to set additional environment variables for
485 build scripts, rustc invocations, `cargo run` and `cargo build`.
486
487 ```toml
488 [env]
489 OPENSSL_DIR = "/opt/openssl"
490 ```
491
492 By default, the variables specified will not override values that already exist
493 in the environment. This behavior can be changed by setting the `force` flag.
494
495 Setting the `relative` flag evaluates the value as a config-relative path that
496 is relative to the parent directory of the `.cargo` directory that contains the
497 `config.toml` file. The value of the environment variable will be the full
498 absolute path.
499
500 ```toml
501 [env]
502 TMPDIR = { value = "/home/tmp", force = true }
503 OPENSSL_DIR = { value = "vendor/openssl", relative = true }
504 ```
505
506 ### `[future-incompat-report]`
507
508 The `[future-incompat-report]` table controls setting for [future incompat reporting](future-incompat-report.md)
509
510 #### `future-incompat-report.frequency`
511 * Type: string
512 * Default: "always"
513 * Environment: `CARGO_FUTURE_INCOMPAT_REPORT_FREQUENCY`
514
515 Controls how often we display a notification to the terminal when a future incompat report is available. Possible values:
516
517 * `always` (default): Always display a notification when a command (e.g. `cargo build`) produces a future incompat report
518 * `never`: Never display a notification
519
520 #### `[http]`
521
522 The `[http]` table defines settings for HTTP behavior. This includes fetching
523 crate dependencies and accessing remote git repositories.
524
525 ##### `http.debug`
526 * Type: boolean
527 * Default: false
528 * Environment: `CARGO_HTTP_DEBUG`
529
530 If `true`, enables debugging of HTTP requests. The debug information can be
531 seen by setting the `CARGO_LOG=cargo::ops::registry=debug` environment
532 variable (or use `trace` for even more information).
533
534 Be wary when posting logs from this output in a public location. The output
535 may include headers with authentication tokens which you don't want to leak!
536 Be sure to review logs before posting them.
537
538 ##### `http.proxy`
539 * Type: string
540 * Default: none
541 * Environment: `CARGO_HTTP_PROXY` or `HTTPS_PROXY` or `https_proxy` or `http_proxy`
542
543 Sets an HTTP and HTTPS proxy to use. The format is in [libcurl format] as in
544 `[protocol://]host[:port]`. If not set, Cargo will also check the `http.proxy`
545 setting in your global git configuration. If none of those are set, the
546 `HTTPS_PROXY` or `https_proxy` environment variables set the proxy for HTTPS
547 requests, and `http_proxy` sets it for HTTP requests.
548
549 ##### `http.timeout`
550 * Type: integer
551 * Default: 30
552 * Environment: `CARGO_HTTP_TIMEOUT` or `HTTP_TIMEOUT`
553
554 Sets the timeout for each HTTP request, in seconds.
555
556 ##### `http.cainfo`
557 * Type: string (path)
558 * Default: none
559 * Environment: `CARGO_HTTP_CAINFO`
560
561 Path to a Certificate Authority (CA) bundle file, used to verify TLS
562 certificates. If not specified, Cargo attempts to use the system certificates.
563
564 ##### `http.check-revoke`
565 * Type: boolean
566 * Default: true (Windows) false (all others)
567 * Environment: `CARGO_HTTP_CHECK_REVOKE`
568
569 This determines whether or not TLS certificate revocation checks should be
570 performed. This only works on Windows.
571
572 ##### `http.ssl-version`
573 * Type: string or min/max table
574 * Default: none
575 * Environment: `CARGO_HTTP_SSL_VERSION`
576
577 This sets the minimum TLS version to use. It takes a string, with one of the
578 possible values of "default", "tlsv1", "tlsv1.0", "tlsv1.1", "tlsv1.2", or
579 "tlsv1.3".
580
581 This may alternatively take a table with two keys, `min` and `max`, which each
582 take a string value of the same kind that specifies the minimum and maximum
583 range of TLS versions to use.
584
585 The default is a minimum version of "tlsv1.0" and a max of the newest version
586 supported on your platform, typically "tlsv1.3".
587
588 ##### `http.low-speed-limit`
589 * Type: integer
590 * Default: 10
591 * Environment: `CARGO_HTTP_LOW_SPEED_LIMIT`
592
593 This setting controls timeout behavior for slow connections. If the average
594 transfer speed in bytes per second is below the given value for
595 [`http.timeout`](#httptimeout) seconds (default 30 seconds), then the
596 connection is considered too slow and Cargo will abort and retry.
597
598 ##### `http.multiplexing`
599 * Type: boolean
600 * Default: true
601 * Environment: `CARGO_HTTP_MULTIPLEXING`
602
603 When `true`, Cargo will attempt to use the HTTP2 protocol with multiplexing.
604 This allows multiple requests to use the same connection, usually improving
605 performance when fetching multiple files. If `false`, Cargo will use HTTP 1.1
606 without pipelining.
607
608 ##### `http.user-agent`
609 * Type: string
610 * Default: Cargo's version
611 * Environment: `CARGO_HTTP_USER_AGENT`
612
613 Specifies a custom user-agent header to use. The default if not specified is a
614 string that includes Cargo's version.
615
616 #### `[install]`
617
618 The `[install]` table defines defaults for the [`cargo install`] command.
619
620 ##### `install.root`
621 * Type: string (path)
622 * Default: Cargo's home directory
623 * Environment: `CARGO_INSTALL_ROOT`
624
625 Sets the path to the root directory for installing executables for [`cargo
626 install`]. Executables go into a `bin` directory underneath the root.
627
628 To track information of installed executables, some extra files, such as
629 `.crates.toml` and `.crates2.json`, are also created under this root.
630
631 The default if not specified is Cargo's home directory (default `.cargo` in
632 your home directory).
633
634 Can be overridden with the `--root` command-line option.
635
636 #### `[net]`
637
638 The `[net]` table controls networking configuration.
639
640 ##### `net.retry`
641 * Type: integer
642 * Default: 2
643 * Environment: `CARGO_NET_RETRY`
644
645 Number of times to retry possibly spurious network errors.
646
647 ##### `net.git-fetch-with-cli`
648 * Type: boolean
649 * Default: false
650 * Environment: `CARGO_NET_GIT_FETCH_WITH_CLI`
651
652 If this is `true`, then Cargo will use the `git` executable to fetch registry
653 indexes and git dependencies. If `false`, then it uses a built-in `git`
654 library.
655
656 Setting this to `true` can be helpful if you have special authentication
657 requirements that Cargo does not support. See [Git
658 Authentication](../appendix/git-authentication.md) for more information about
659 setting up git authentication.
660
661 ##### `net.offline`
662 * Type: boolean
663 * Default: false
664 * Environment: `CARGO_NET_OFFLINE`
665
666 If this is `true`, then Cargo will avoid accessing the network, and attempt to
667 proceed with locally cached data. If `false`, Cargo will access the network as
668 needed, and generate an error if it encounters a network error.
669
670 Can be overridden with the `--offline` command-line option.
671
672 #### `[patch]`
673
674 Just as you can override dependencies using [`[patch]` in
675 `Cargo.toml`](overriding-dependencies.md#the-patch-section), you can
676 override them in the cargo configuration file to apply those patches to
677 any affected build. The format is identical to the one used in
678 `Cargo.toml`.
679
680 Since `.cargo/config.toml` files are not usually checked into source
681 control, you should prefer patching using `Cargo.toml` where possible to
682 ensure that other developers can compile your crate in their own
683 environments. Patching through cargo configuration files is generally
684 only appropriate when the patch section is automatically generated by an
685 external build tool.
686
687 If a given dependency is patched both in a cargo configuration file and
688 a `Cargo.toml` file, the patch in the configuration file is used. If
689 multiple configuration files patch the same dependency, standard cargo
690 configuration merging is used, which prefers the value defined closest
691 to the current directory, with `$HOME/.cargo/config.toml` taking the
692 lowest precedence.
693
694 Relative `path` dependencies in such a `[patch]` section are resolved
695 relative to the configuration file they appear in.
696
697 #### `[profile]`
698
699 The `[profile]` table can be used to globally change profile settings, and
700 override settings specified in `Cargo.toml`. It has the same syntax and
701 options as profiles specified in `Cargo.toml`. See the [Profiles chapter] for
702 details about the options.
703
704 [Profiles chapter]: profiles.md
705
706 ##### `[profile.<name>.build-override]`
707 * Environment: `CARGO_PROFILE_<name>_BUILD_OVERRIDE_<key>`
708
709 The build-override table overrides settings for build scripts, proc macros,
710 and their dependencies. It has the same keys as a normal profile. See the
711 [overrides section](profiles.md#overrides) for more details.
712
713 ##### `[profile.<name>.package.<name>]`
714 * Environment: not supported
715
716 The package table overrides settings for specific packages. It has the same
717 keys as a normal profile, minus the `panic`, `lto`, and `rpath` settings. See
718 the [overrides section](profiles.md#overrides) for more details.
719
720 ##### `profile.<name>.codegen-units`
721 * Type: integer
722 * Default: See profile docs.
723 * Environment: `CARGO_PROFILE_<name>_CODEGEN_UNITS`
724
725 See [codegen-units](profiles.md#codegen-units).
726
727 ##### `profile.<name>.debug`
728 * Type: integer or boolean
729 * Default: See profile docs.
730 * Environment: `CARGO_PROFILE_<name>_DEBUG`
731
732 See [debug](profiles.md#debug).
733
734 ##### `profile.<name>.split-debuginfo`
735 * Type: string
736 * Default: See profile docs.
737 * Environment: `CARGO_PROFILE_<name>_SPLIT_DEBUGINFO`
738
739 See [split-debuginfo](profiles.md#split-debuginfo).
740
741 ##### `profile.<name>.debug-assertions`
742 * Type: boolean
743 * Default: See profile docs.
744 * Environment: `CARGO_PROFILE_<name>_DEBUG_ASSERTIONS`
745
746 See [debug-assertions](profiles.md#debug-assertions).
747
748 ##### `profile.<name>.incremental`
749 * Type: boolean
750 * Default: See profile docs.
751 * Environment: `CARGO_PROFILE_<name>_INCREMENTAL`
752
753 See [incremental](profiles.md#incremental).
754
755 ##### `profile.<name>.lto`
756 * Type: string or boolean
757 * Default: See profile docs.
758 * Environment: `CARGO_PROFILE_<name>_LTO`
759
760 See [lto](profiles.md#lto).
761
762 ##### `profile.<name>.overflow-checks`
763 * Type: boolean
764 * Default: See profile docs.
765 * Environment: `CARGO_PROFILE_<name>_OVERFLOW_CHECKS`
766
767 See [overflow-checks](profiles.md#overflow-checks).
768
769 ##### `profile.<name>.opt-level`
770 * Type: integer or string
771 * Default: See profile docs.
772 * Environment: `CARGO_PROFILE_<name>_OPT_LEVEL`
773
774 See [opt-level](profiles.md#opt-level).
775
776 ##### `profile.<name>.panic`
777 * Type: string
778 * default: See profile docs.
779 * Environment: `CARGO_PROFILE_<name>_PANIC`
780
781 See [panic](profiles.md#panic).
782
783 ##### `profile.<name>.rpath`
784 * Type: boolean
785 * default: See profile docs.
786 * Environment: `CARGO_PROFILE_<name>_RPATH`
787
788 See [rpath](profiles.md#rpath).
789
790
791 #### `[registries]`
792
793 The `[registries]` table is used for specifying additional [registries]. It
794 consists of a sub-table for each named registry.
795
796 ##### `registries.<name>.index`
797 * Type: string (url)
798 * Default: none
799 * Environment: `CARGO_REGISTRIES_<name>_INDEX`
800
801 Specifies the URL of the git index for the registry.
802
803 ##### `registries.<name>.token`
804 * Type: string
805 * Default: none
806 * Environment: `CARGO_REGISTRIES_<name>_TOKEN`
807
808 Specifies the authentication token for the given registry. This value should
809 only appear in the [credentials](#credentials) file. This is used for registry
810 commands like [`cargo publish`] that require authentication.
811
812 Can be overridden with the `--token` command-line option.
813
814 #### `[registry]`
815
816 The `[registry]` table controls the default registry used when one is not
817 specified.
818
819 ##### `registry.index`
820
821 This value is no longer accepted and should not be used.
822
823 ##### `registry.default`
824 * Type: string
825 * Default: `"crates-io"`
826 * Environment: `CARGO_REGISTRY_DEFAULT`
827
828 The name of the registry (from the [`registries` table](#registries)) to use
829 by default for registry commands like [`cargo publish`].
830
831 Can be overridden with the `--registry` command-line option.
832
833 ##### `registry.token`
834 * Type: string
835 * Default: none
836 * Environment: `CARGO_REGISTRY_TOKEN`
837
838 Specifies the authentication token for [crates.io]. This value should only
839 appear in the [credentials](#credentials) file. This is used for registry
840 commands like [`cargo publish`] that require authentication.
841
842 Can be overridden with the `--token` command-line option.
843
844 #### `[source]`
845
846 The `[source]` table defines the registry sources available. See [Source
847 Replacement] for more information. It consists of a sub-table for each named
848 source. A source should only define one kind (directory, registry,
849 local-registry, or git).
850
851 ##### `source.<name>.replace-with`
852 * Type: string
853 * Default: none
854 * Environment: not supported
855
856 If set, replace this source with the given named source.
857
858 ##### `source.<name>.directory`
859 * Type: string (path)
860 * Default: none
861 * Environment: not supported
862
863 Sets the path to a directory to use as a directory source.
864
865 ##### `source.<name>.registry`
866 * Type: string (url)
867 * Default: none
868 * Environment: not supported
869
870 Sets the URL to use for a registry source.
871
872 ##### `source.<name>.local-registry`
873 * Type: string (path)
874 * Default: none
875 * Environment: not supported
876
877 Sets the path to a directory to use as a local registry source.
878
879 ##### `source.<name>.git`
880 * Type: string (url)
881 * Default: none
882 * Environment: not supported
883
884 Sets the URL to use for a git repository source.
885
886 ##### `source.<name>.branch`
887 * Type: string
888 * Default: none
889 * Environment: not supported
890
891 Sets the branch name to use for a git repository.
892
893 If none of `branch`, `tag`, or `rev` is set, defaults to the `master` branch.
894
895 ##### `source.<name>.tag`
896 * Type: string
897 * Default: none
898 * Environment: not supported
899
900 Sets the tag name to use for a git repository.
901
902 If none of `branch`, `tag`, or `rev` is set, defaults to the `master` branch.
903
904 ##### `source.<name>.rev`
905 * Type: string
906 * Default: none
907 * Environment: not supported
908
909 Sets the [revision] to use for a git repository.
910
911 If none of `branch`, `tag`, or `rev` is set, defaults to the `master` branch.
912
913
914 #### `[target]`
915
916 The `[target]` table is used for specifying settings for specific platform
917 targets. It consists of a sub-table which is either a platform triple or a
918 [`cfg()` expression]. The given values will be used if the target platform
919 matches either the `<triple>` value or the `<cfg>` expression.
920
921 ```toml
922 [target.thumbv7m-none-eabi]
923 linker = "arm-none-eabi-gcc"
924 runner = "my-emulator"
925 rustflags = ["…", "…"]
926
927 [target.'cfg(all(target_arch = "arm", target_os = "none"))']
928 runner = "my-arm-wrapper"
929 rustflags = ["…", "…"]
930 ```
931
932 `cfg` values come from those built-in to the compiler (run `rustc --print=cfg`
933 to view), values set by [build scripts], and extra `--cfg` flags passed to
934 `rustc` (such as those defined in `RUSTFLAGS`). Do not try to match on
935 `debug_assertions` or Cargo features like `feature="foo"`.
936
937 If using a target spec JSON file, the `<triple>` value is the filename stem.
938 For example `--target foo/bar.json` would match `[target.bar]`.
939
940 ##### `target.<triple>.ar`
941
942 This option is deprecated and unused.
943
944 ##### `target.<triple>.linker`
945 * Type: string (program path)
946 * Default: none
947 * Environment: `CARGO_TARGET_<triple>_LINKER`
948
949 Specifies the linker which is passed to `rustc` (via [`-C linker`]) when the
950 `<triple>` is being compiled for. By default, the linker is not overridden.
951
952 ##### `target.<triple>.runner`
953 * Type: string or array of strings ([program path and args])
954 * Default: none
955 * Environment: `CARGO_TARGET_<triple>_RUNNER`
956
957 If a runner is provided, executables for the target `<triple>` will be
958 executed by invoking the specified runner with the actual executable passed as
959 an argument. This applies to [`cargo run`], [`cargo test`] and [`cargo bench`]
960 commands. By default, compiled executables are executed directly.
961
962 ##### `target.<cfg>.runner`
963
964 This is similar to the [target runner](#targettriplerunner), but using
965 a [`cfg()` expression]. If both a `<triple>` and `<cfg>` runner match,
966 the `<triple>` will take precedence. It is an error if more than one
967 `<cfg>` runner matches the current target.
968
969 ##### `target.<triple>.rustflags`
970 * Type: string or array of strings
971 * Default: none
972 * Environment: `CARGO_TARGET_<triple>_RUSTFLAGS`
973
974 Passes a set of custom flags to the compiler for this `<triple>`. The value
975 may be a array of strings or a space-separated string.
976
977 See [`build.rustflags`](#buildrustflags) for more details on the different
978 ways to specific extra flags.
979
980 ##### `target.<cfg>.rustflags`
981
982 This is similar to the [target rustflags](#targettriplerustflags), but
983 using a [`cfg()` expression]. If several `<cfg>` and `<triple>` entries
984 match the current target, the flags are joined together.
985
986 ##### `target.<triple>.<links>`
987
988 The links sub-table provides a way to [override a build script]. When
989 specified, the build script for the given `links` library will not be
990 run, and the given values will be used instead.
991
992 ```toml
993 [target.x86_64-unknown-linux-gnu.foo]
994 rustc-link-lib = ["foo"]
995 rustc-link-search = ["/path/to/foo"]
996 rustc-flags = "-L /some/path"
997 rustc-cfg = ['key="value"']
998 rustc-env = {key = "value"}
999 rustc-cdylib-link-arg = ["…"]
1000 metadata_key1 = "value"
1001 metadata_key2 = "value"
1002 ```
1003
1004 #### `[term]`
1005
1006 The `[term]` table controls terminal output and interaction.
1007
1008 ##### `term.quiet`
1009 * Type: boolean
1010 * Default: false
1011 * Environment: `CARGO_TERM_QUIET`
1012
1013 Controls whether or not log messages are displayed by Cargo.
1014
1015 Specifying the `--quiet` flag will override and force quiet output.
1016 Specifying the `--verbose` flag will override and disable quiet output.
1017
1018 ##### `term.verbose`
1019 * Type: boolean
1020 * Default: false
1021 * Environment: `CARGO_TERM_VERBOSE`
1022
1023 Controls whether or not extra detailed messages are displayed by Cargo.
1024
1025 Specifying the `--quiet` flag will override and disable verbose output.
1026 Specifying the `--verbose` flag will override and force verbose output.
1027
1028 ##### `term.color`
1029 * Type: string
1030 * Default: "auto"
1031 * Environment: `CARGO_TERM_COLOR`
1032
1033 Controls whether or not colored output is used in the terminal. Possible values:
1034
1035 * `auto` (default): Automatically detect if color support is available on the
1036 terminal.
1037 * `always`: Always display colors.
1038 * `never`: Never display colors.
1039
1040 Can be overridden with the `--color` command-line option.
1041
1042 ##### `term.progress.when`
1043 * Type: string
1044 * Default: "auto"
1045 * Environment: `CARGO_TERM_PROGRESS_WHEN`
1046
1047 Controls whether or not progress bar is shown in the terminal. Possible values:
1048
1049 * `auto` (default): Intelligently guess whether to show progress bar.
1050 * `always`: Always show progress bar.
1051 * `never`: Never show progress bar.
1052
1053 ##### `term.progress.width`
1054 * Type: integer
1055 * Default: none
1056 * Environment: `CARGO_TERM_PROGRESS_WIDTH`
1057
1058 Sets the width for progress bar.
1059
1060 [`cargo bench`]: ../commands/cargo-bench.md
1061 [`cargo login`]: ../commands/cargo-login.md
1062 [`cargo doc`]: ../commands/cargo-doc.md
1063 [`cargo new`]: ../commands/cargo-new.md
1064 [`cargo publish`]: ../commands/cargo-publish.md
1065 [`cargo run`]: ../commands/cargo-run.md
1066 [`cargo rustc`]: ../commands/cargo-rustc.md
1067 [`cargo test`]: ../commands/cargo-test.md
1068 [`cargo rustdoc`]: ../commands/cargo-rustdoc.md
1069 [`cargo install`]: ../commands/cargo-install.md
1070 [env]: environment-variables.md
1071 [`cfg()` expression]: ../../reference/conditional-compilation.html
1072 [build scripts]: build-scripts.md
1073 [`-C linker`]: ../../rustc/codegen-options/index.md#linker
1074 [override a build script]: build-scripts.md#overriding-build-scripts
1075 [toml]: https://toml.io/
1076 [incremental compilation]: profiles.md#incremental
1077 [profile]: profiles.md
1078 [program path with args]: #executable-paths-with-arguments
1079 [libcurl format]: https://ec.haxx.se/usingcurl-proxies.html
1080 [source replacement]: source-replacement.md
1081 [revision]: https://git-scm.com/docs/gitrevisions
1082 [registries]: registries.md
1083 [crates.io]: https://crates.io/