]> git.proxmox.com Git - cargo.git/blob - src/doc/src/reference/unstable.md
348936aba86d8317b86df73ae03c3690192b1a4a
[cargo.git] / src / doc / src / reference / unstable.md
1 ## Unstable Features
2
3 Experimental Cargo features are only available on the [nightly channel]. You
4 are encouraged to experiment with these features to see if they meet your
5 needs, and if there are any issues or problems. Check the linked tracking
6 issues listed below for more information on the feature, and click the GitHub
7 subscribe button if you want future updates.
8
9 After some period of time, if the feature does not have any major concerns, it
10 can be [stabilized], which will make it available on stable once the current
11 nightly release reaches the stable channel (anywhere from 6 to 12 weeks).
12
13 There are three different ways that unstable features can be enabled based on
14 how the feature works:
15
16 * New syntax in `Cargo.toml` requires a `cargo-features` key at the top of
17 `Cargo.toml`, before any tables. For example:
18
19 ```toml
20 # This specifies which new Cargo.toml features are enabled.
21 cargo-features = ["test-dummy-unstable"]
22
23 [package]
24 name = "my-package"
25 version = "0.1.0"
26 im-a-teapot = true # This is a new option enabled by test-dummy-unstable.
27 ```
28
29 * New command-line flags, options, and subcommands require the `-Z
30 unstable-options` CLI option to also be included. For example, the new
31 `--out-dir` option is only available on nightly:
32
33 ```cargo +nightly build --out-dir=out -Z unstable-options```
34
35 * `-Z` command-line flags are used to enable new functionality that may not
36 have an interface, or the interface has not yet been designed, or for more
37 complex features that affect multiple parts of Cargo. For example, the
38 [timings](#timings) feature can be enabled with:
39
40 ```cargo +nightly build -Z timings```
41
42 Run `cargo -Z help` to see a list of flags available.
43
44 Anything which can be configured with a `-Z` flag can also be set in the
45 cargo [config file] (`.cargo/config.toml`) in the `unstable` table. For
46 example:
47
48 ```toml
49 [unstable]
50 mtime-on-use = true
51 multitarget = true
52 timings = ["html"]
53 ```
54
55 Each new feature described below should explain how to use it.
56
57 [config file]: config.md
58 [nightly channel]: ../../book/appendix-07-nightly-rust.html
59 [stabilized]: https://doc.crates.io/contrib/process/unstable.html#stabilization
60
61 ### List of unstable features
62
63 * Unstable-specific features
64 * [-Z allow-features](#allow-features) — Provides a way to restrict which unstable features are used.
65 * Build scripts and linking
66 * [extra-link-arg](#extra-link-arg) — Allows build scripts to pass extra link arguments in more cases.
67 * [Metabuild](#metabuild) — Provides declarative build scripts.
68 * Resolver and features
69 * [no-index-update](#no-index-update) — Prevents cargo from updating the index cache.
70 * [avoid-dev-deps](#avoid-dev-deps) — Prevents the resolver from including dev-dependencies during resolution.
71 * [minimal-versions](#minimal-versions) — Forces the resolver to use the lowest compatible version instead of the highest.
72 * [public-dependency](#public-dependency) — Allows dependencies to be classified as either public or private.
73 * [Namespaced features](#namespaced-features) — Separates optional dependencies into a separate namespace from regular features, and allows feature names to be the same as some dependency name.
74 * [Weak dependency features](#weak-dependency-features) — Allows setting features for dependencies without enabling optional dependencies.
75 * Output behavior
76 * [out-dir](#out-dir) — Adds a directory where artifacts are copied to.
77 * [terminal-width](#terminal-width) — Tells rustc the width of the terminal so that long diagnostic messages can be truncated to be more readable.
78 * Compile behavior
79 * [mtime-on-use](#mtime-on-use) — Updates the last-modified timestamp on every dependency every time it is used, to provide a mechanism to delete unused artifacts.
80 * [doctest-xcompile](#doctest-xcompile) — Supports running doctests with the `--target` flag.
81 * [multitarget](#multitarget) — Supports building for multiple targets at the same time.
82 * [build-std](#build-std) — Builds the standard library instead of using pre-built binaries.
83 * [build-std-features](#build-std-features) — Sets features to use with the standard library.
84 * [binary-dep-depinfo](#binary-dep-depinfo) — Causes the dep-info file to track binary dependencies.
85 * [panic-abort-tests](#panic-abort-tests) — Allows running tests with the "abort" panic strategy.
86 * rustdoc
87 * [`doctest-in-workspace`](#doctest-in-workspace) — Fixes workspace-relative paths when running doctests.
88 * [rustdoc-map](#rustdoc-map) — Provides mappings for documentation to link to external sites like [docs.rs](https://docs.rs/).
89 * `Cargo.toml` extensions
90 * [Custom named profiles](#custom-named-profiles) — Adds custom named profiles in addition to the standard names.
91 * [Profile `strip` option](#profile-strip-option) — Forces the removal of debug information and symbols from executables.
92 * [per-package-target](#per-package-target) — Sets the `--target` to use for each individual package.
93 * [rust-version](#rust-version) — Allows to declare the minimum supported Rust version.
94 * [Edition 2021](#edition-2021) — Adds support for the 2021 Edition.
95 * Information and metadata
96 * [Build-plan](#build-plan) — Emits JSON information on which commands will be run.
97 * [timings](#timings) — Generates a report on how long individual dependencies took to run.
98 * [unit-graph](#unit-graph) — Emits JSON for Cargo's internal graph structure.
99 * [future incompat report](#future-incompat-report) — Displays a report for future incompatibilities that may error in the future.
100 * Configuration
101 * [config-cli](#config-cli) — Adds the ability to pass configuration options on the command-line.
102 * [config-include](#config-include) — Adds the ability for config files to include other files.
103 * [configurable-env](#configurable-env) — Adds support for defining environment variables that will be set when building and running.
104 * [patch-in-config](#patch-in-config) — Adds support for specifying the `[patch]` table in config files.
105 * [`cargo config`](#cargo-config) — Adds a new subcommand for viewing config files.
106 * Registries
107 * [credential-process](#credential-process) — Adds support for fetching registry tokens from an external authentication program.
108 * [`cargo logout`](#cargo-logout) — Adds the `logout` command to remove the currently saved registry token.
109
110 ### allow-features
111
112 This permanently-unstable flag makes it so that only a listed set of
113 unstable features can be used. Specifically, if you pass
114 `-Zallow-features=foo,bar`, you'll continue to be able to pass `-Zfoo`
115 and `-Zbar` to `cargo`, but you will be unable to pass `-Zbaz`. You can
116 pass an empty string (`-Zallow-features=`) to disallow all unstable
117 features.
118
119 `-Zallow-features` also restricts which unstable features can be passed
120 to the `cargo-features` entry in `Cargo.toml`. If, for example, you want
121 to allow
122
123 ```toml
124 cargo-features = ["test-dummy-unstable"]
125 ```
126
127 where `test-dummy-unstable` is unstable, that features would also be
128 disallowed by `-Zallow-features=`, and allowed with
129 `-Zallow-features=test-dummy-unstable`.
130
131 The list of features passed to cargo's `-Zallow-features` is also passed
132 to any Rust tools that cargo ends up calling (like `rustc` or
133 `rustdoc`). Thus, if you run `cargo -Zallow-features=`, no unstable
134 Cargo _or_ Rust features can be used.
135
136 ### extra-link-arg
137 * Tracking Issue: [#9426](https://github.com/rust-lang/cargo/issues/9426)
138 * Original Pull Request: [#7811](https://github.com/rust-lang/cargo/pull/7811)
139
140 The `-Z extra-link-arg` flag makes the following two instructions available
141 in build scripts:
142
143 * [`cargo:rustc-link-arg-bins=FLAG`](#rustc-link-arg-bins) – Passes custom
144 flags to a linker for binaries.
145 * [`cargo:rustc-link-arg=FLAG`](#rustc-link-arg) – Passes custom flags to a
146 linker for benchmarks, binaries, `cdylib` crates, examples, and tests.
147
148 <a id="rustc-link-arg-bins"></a>
149 #### `cargo:rustc-link-arg-bins=FLAG`
150
151 The `rustc-link-arg-bins` instruction tells Cargo to pass the [`-C
152 link-arg=FLAG` option][link-arg] to the compiler, but only when building a
153 binary target. Its usage is highly platform specific. It is useful
154 to set a linker script or other linker options.
155
156 [link-arg]: ../../rustc/codegen-options/index.md#link-arg
157
158 <a id="rustc-link-arg"></a>
159 #### `cargo:rustc-link-arg=FLAG`
160
161 The `rustc-link-arg` instruction tells Cargo to pass the [`-C link-arg=FLAG`
162 option][link-arg] to the compiler, but only when building supported targets
163 (benchmarks, binaries, `cdylib` crates, examples, and tests). Its usage is
164 highly platform specific. It is useful to set the shared library version or
165 linker script.
166
167 [link-arg]: ../../rustc/codegen-options/index.md#link-arg
168
169 ### no-index-update
170 * Original Issue: [#3479](https://github.com/rust-lang/cargo/issues/3479)
171 * Tracking Issue: [#7404](https://github.com/rust-lang/cargo/issues/7404)
172
173 The `-Z no-index-update` flag ensures that Cargo does not attempt to update
174 the registry index. This is intended for tools such as Crater that issue many
175 Cargo commands, and you want to avoid the network latency for updating the
176 index each time.
177
178 ### mtime-on-use
179 * Original Issue: [#6477](https://github.com/rust-lang/cargo/pull/6477)
180 * Cache usage meta tracking issue: [#7150](https://github.com/rust-lang/cargo/issues/7150)
181
182 The `-Z mtime-on-use` flag is an experiment to have Cargo update the mtime of
183 used files to make it easier for tools like cargo-sweep to detect which files
184 are stale. For many workflows this needs to be set on *all* invocations of cargo.
185 To make this more practical setting the `unstable.mtime_on_use` flag in `.cargo/config.toml`
186 or the corresponding ENV variable will apply the `-Z mtime-on-use` to all
187 invocations of nightly cargo. (the config flag is ignored by stable)
188
189 ### avoid-dev-deps
190 * Original Issue: [#4988](https://github.com/rust-lang/cargo/issues/4988)
191 * Tracking Issue: [#5133](https://github.com/rust-lang/cargo/issues/5133)
192
193 When running commands such as `cargo install` or `cargo build`, Cargo
194 currently requires dev-dependencies to be downloaded, even if they are not
195 used. The `-Z avoid-dev-deps` flag allows Cargo to avoid downloading
196 dev-dependencies if they are not needed. The `Cargo.lock` file will not be
197 generated if dev-dependencies are skipped.
198
199 ### minimal-versions
200 * Original Issue: [#4100](https://github.com/rust-lang/cargo/issues/4100)
201 * Tracking Issue: [#5657](https://github.com/rust-lang/cargo/issues/5657)
202
203 > Note: It is not recommended to use this feature. Because it enforces minimal
204 > versions for all transitive dependencies, its usefulness is limited since
205 > not all external dependencies declare proper lower version bounds. It is
206 > intended that it will be changed in the future to only enforce minimal
207 > versions for direct dependencies.
208
209 When a `Cargo.lock` file is generated, the `-Z minimal-versions` flag will
210 resolve the dependencies to the minimum SemVer version that will satisfy the
211 requirements (instead of the greatest version).
212
213 The intended use-case of this flag is to check, during continuous integration,
214 that the versions specified in Cargo.toml are a correct reflection of the
215 minimum versions that you are actually using. That is, if Cargo.toml says
216 `foo = "1.0.0"` that you don't accidentally depend on features added only in
217 `foo 1.5.0`.
218
219 ### out-dir
220 * Original Issue: [#4875](https://github.com/rust-lang/cargo/issues/4875)
221 * Tracking Issue: [#6790](https://github.com/rust-lang/cargo/issues/6790)
222
223 This feature allows you to specify the directory where artifacts will be
224 copied to after they are built. Typically artifacts are only written to the
225 `target/release` or `target/debug` directories. However, determining the
226 exact filename can be tricky since you need to parse JSON output. The
227 `--out-dir` flag makes it easier to predictably access the artifacts. Note
228 that the artifacts are copied, so the originals are still in the `target`
229 directory. Example:
230
231 ```sh
232 cargo +nightly build --out-dir=out -Z unstable-options
233 ```
234
235 This can also be specified in `.cargo/config.toml` files.
236
237 ```toml
238 [build]
239 out-dir = "out"
240 ```
241
242 ### doctest-xcompile
243 * Tracking Issue: [#7040](https://github.com/rust-lang/cargo/issues/7040)
244 * Tracking Rustc Issue: [#64245](https://github.com/rust-lang/rust/issues/64245)
245
246 This flag changes `cargo test`'s behavior when handling doctests when
247 a target is passed. Currently, if a target is passed that is different
248 from the host cargo will simply skip testing doctests. If this flag is
249 present, cargo will continue as normal, passing the tests to doctest,
250 while also passing it a `--target` option, as well as enabling
251 `-Zunstable-features --enable-per-target-ignores` and passing along
252 information from `.cargo/config.toml`. See the rustc issue for more information.
253
254 ```sh
255 cargo test --target foo -Zdoctest-xcompile
256 ```
257
258 ### multitarget
259 * Tracking Issue: [#8176](https://github.com/rust-lang/cargo/issues/8176)
260
261 This flag allows passing multiple `--target` flags to the `cargo` subcommand
262 selected. When multiple `--target` flags are passed the selected build targets
263 will be built for each of the selected architectures.
264
265 For example to compile a library for both 32 and 64-bit:
266
267 ```
268 cargo build --target x86_64-unknown-linux-gnu --target i686-unknown-linux-gnu
269 ```
270
271 or running tests for both targets:
272
273 ```
274 cargo test --target x86_64-unknown-linux-gnu --target i686-unknown-linux-gnu
275 ```
276
277 ### Custom named profiles
278
279 * Tracking Issue: [rust-lang/cargo#6988](https://github.com/rust-lang/cargo/issues/6988)
280 * RFC: [#2678](https://github.com/rust-lang/rfcs/pull/2678)
281
282 With this feature you can define custom profiles having new names. With the
283 custom profile enabled, build artifacts can be emitted by default to
284 directories other than `release` or `debug`, based on the custom profile's
285 name.
286
287 For example:
288
289 ```toml
290 cargo-features = ["named-profiles"]
291
292 [profile.release-lto]
293 inherits = "release"
294 lto = true
295 ````
296
297 An `inherits` key is used in order to receive attributes from other profiles,
298 so that a new custom profile can be based on the standard `dev` or `release`
299 profile presets. Cargo emits errors in case `inherits` loops are detected. When
300 considering inheritance hierarchy, all profiles directly or indirectly inherit
301 from either from `release` or from `dev`.
302
303 Valid profile names are: must not be empty, use only alphanumeric characters or
304 `-` or `_`.
305
306 Passing `--profile` with the profile's name to various Cargo commands, directs
307 operations to use the profile's attributes. Overrides that are specified in the
308 profiles from which the custom profile inherits are inherited too.
309
310 For example, using `cargo build` with `--profile` and the manifest from above:
311
312 ```sh
313 cargo +nightly build --profile release-lto -Z unstable-options
314 ```
315
316 When a custom profile is used, build artifacts go to a different target by
317 default. In the example above, you can expect to see the outputs under
318 `target/release-lto`.
319
320
321 #### New `dir-name` attribute
322
323 Some of the paths generated under `target/` have resulted in a de-facto "build
324 protocol", where `cargo` is invoked as a part of a larger project build. So, to
325 preserve the existing behavior, there is also a new attribute `dir-name`, which
326 when left unspecified, defaults to the name of the profile. For example:
327
328 ```toml
329 [profile.release-lto]
330 inherits = "release"
331 dir-name = "lto" # Emits to target/lto instead of target/release-lto
332 lto = true
333 ```
334
335
336 ### Namespaced features
337 * Original issue: [#1286](https://github.com/rust-lang/cargo/issues/1286)
338 * Tracking Issue: [#5565](https://github.com/rust-lang/cargo/issues/5565)
339
340 The `namespaced-features` option makes two changes to how features can be
341 specified:
342
343 * Features may now be defined with the same name as a dependency.
344 * Optional dependencies can be explicitly enabled in the `[features]` table
345 with the `dep:` prefix, which enables the dependency without enabling a
346 feature of the same name.
347
348 By default, an optional dependency `foo` will define a feature `foo =
349 ["dep:foo"]` *unless* `dep:foo` is mentioned in any other feature, or the
350 `foo` feature is already defined. This helps prevent unnecessary boilerplate
351 of listing every optional dependency, but still allows you to override the
352 implicit feature.
353
354 This allows two use cases that were previously not possible:
355
356 * You can "hide" an optional dependency, so that external users cannot
357 explicitly enable that optional dependency.
358 * There is no longer a need to create "funky" feature names to work around the
359 restriction that features cannot shadow dependency names.
360
361 To enable namespaced-features, use the `-Z namespaced-features` command-line
362 flag.
363
364 An example of hiding an optional dependency:
365
366 ```toml
367 [dependencies]
368 regex = { version = "1.4.1", optional = true }
369 lazy_static = { version = "1.4.0", optional = true }
370
371 [features]
372 regex = ["dep:regex", "dep:lazy_static"]
373 ```
374
375 In this example, the "regex" feature enables both `regex` and `lazy_static`.
376 The `lazy_static` feature does not exist, and a user cannot explicitly enable
377 it. This helps hide internal details of how your package is implemented.
378
379 An example of avoiding "funky" names:
380
381 ```toml
382 [dependencies]
383 bigdecimal = "0.1"
384 chrono = "0.4"
385 num-bigint = "0.2"
386 serde = {version = "1.0", optional = true }
387
388 [features]
389 serde = ["dep:serde", "bigdecimal/serde", "chrono/serde", "num-bigint/serde"]
390 ```
391
392 In this case, `serde` is a natural name to use for a feature, because it is
393 relevant to your exported API. However, previously you would need to use a
394 name like `serde1` to work around the naming limitation if you wanted to also
395 enable other features.
396
397 ### Build-plan
398 * Tracking Issue: [#5579](https://github.com/rust-lang/cargo/issues/5579)
399
400 The `--build-plan` argument for the `build` command will output JSON with
401 information about which commands would be run without actually executing
402 anything. This can be useful when integrating with another build tool.
403 Example:
404
405 ```sh
406 cargo +nightly build --build-plan -Z unstable-options
407 ```
408
409 ### Metabuild
410 * Tracking Issue: [rust-lang/rust#49803](https://github.com/rust-lang/rust/issues/49803)
411 * RFC: [#2196](https://github.com/rust-lang/rfcs/blob/master/text/2196-metabuild.md)
412
413 Metabuild is a feature to have declarative build scripts. Instead of writing
414 a `build.rs` script, you specify a list of build dependencies in the
415 `metabuild` key in `Cargo.toml`. A build script is automatically generated
416 that runs each build dependency in order. Metabuild packages can then read
417 metadata from `Cargo.toml` to specify their behavior.
418
419 Include `cargo-features` at the top of `Cargo.toml`, a `metabuild` key in the
420 `package`, list the dependencies in `build-dependencies`, and add any metadata
421 that the metabuild packages require under `package.metadata`. Example:
422
423 ```toml
424 cargo-features = ["metabuild"]
425
426 [package]
427 name = "mypackage"
428 version = "0.0.1"
429 metabuild = ["foo", "bar"]
430
431 [build-dependencies]
432 foo = "1.0"
433 bar = "1.0"
434
435 [package.metadata.foo]
436 extra-info = "qwerty"
437 ```
438
439 Metabuild packages should have a public function called `metabuild` that
440 performs the same actions as a regular `build.rs` script would perform.
441
442 ### public-dependency
443 * Tracking Issue: [#44663](https://github.com/rust-lang/rust/issues/44663)
444
445 The 'public-dependency' feature allows marking dependencies as 'public'
446 or 'private'. When this feature is enabled, additional information is passed to rustc to allow
447 the 'exported_private_dependencies' lint to function properly.
448
449 This requires the appropriate key to be set in `cargo-features`:
450
451 ```toml
452 cargo-features = ["public-dependency"]
453
454 [dependencies]
455 my_dep = { version = "1.2.3", public = true }
456 private_dep = "2.0.0" # Will be 'private' by default
457 ```
458
459 ### build-std
460 * Tracking Repository: https://github.com/rust-lang/wg-cargo-std-aware
461
462 The `build-std` feature enables Cargo to compile the standard library itself as
463 part of a crate graph compilation. This feature has also historically been known
464 as "std-aware Cargo". This feature is still in very early stages of development,
465 and is also a possible massive feature addition to Cargo. This is a very large
466 feature to document, even in the minimal form that it exists in today, so if
467 you're curious to stay up to date you'll want to follow the [tracking
468 repository](https://github.com/rust-lang/wg-cargo-std-aware) and its set of
469 issues.
470
471 The functionality implemented today is behind a flag called `-Z build-std`. This
472 flag indicates that Cargo should compile the standard library from source code
473 using the same profile as the main build itself. Note that for this to work you
474 need to have the source code for the standard library available, and at this
475 time the only supported method of doing so is to add the `rust-src` rust rustup
476 component:
477
478 ```console
479 $ rustup component add rust-src --toolchain nightly
480 ```
481
482 It is also required today that the `-Z build-std` flag is combined with the
483 `--target` flag. Note that you're not forced to do a cross compilation, you're
484 just forced to pass `--target` in one form or another.
485
486 Usage looks like:
487
488 ```console
489 $ cargo new foo
490 $ cd foo
491 $ cargo +nightly run -Z build-std --target x86_64-unknown-linux-gnu
492 Compiling core v0.0.0 (...)
493 ...
494 Compiling foo v0.1.0 (...)
495 Finished dev [unoptimized + debuginfo] target(s) in 21.00s
496 Running `target/x86_64-unknown-linux-gnu/debug/foo`
497 Hello, world!
498 ```
499
500 Here we recompiled the standard library in debug mode with debug assertions
501 (like `src/main.rs` is compiled) and everything was linked together at the end.
502
503 Using `-Z build-std` will implicitly compile the stable crates `core`, `std`,
504 `alloc`, and `proc_macro`. If you're using `cargo test` it will also compile the
505 `test` crate. If you're working with an environment which does not support some
506 of these crates, then you can pass an argument to `-Zbuild-std` as well:
507
508 ```console
509 $ cargo +nightly build -Z build-std=core,alloc
510 ```
511
512 The value here is a comma-separated list of standard library crates to build.
513
514 #### Requirements
515
516 As a summary, a list of requirements today to use `-Z build-std` are:
517
518 * You must install libstd's source code through `rustup component add rust-src`
519 * You must pass `--target`
520 * You must use both a nightly Cargo and a nightly rustc
521 * The `-Z build-std` flag must be passed to all `cargo` invocations.
522
523 #### Reporting bugs and helping out
524
525 The `-Z build-std` feature is in the very early stages of development! This
526 feature for Cargo has an extremely long history and is very large in scope, and
527 this is just the beginning. If you'd like to report bugs please either report
528 them to:
529
530 * Cargo - https://github.com/rust-lang/cargo/issues/new - for implementation bugs
531 * The tracking repository -
532 https://github.com/rust-lang/wg-cargo-std-aware/issues/new - for larger design
533 questions.
534
535 Also if you'd like to see a feature that's not yet implemented and/or if
536 something doesn't quite work the way you'd like it to, feel free to check out
537 the [issue tracker](https://github.com/rust-lang/wg-cargo-std-aware/issues) of
538 the tracking repository, and if it's not there please file a new issue!
539
540 ### build-std-features
541 * Tracking Repository: https://github.com/rust-lang/wg-cargo-std-aware
542
543 This flag is a sibling to the `-Zbuild-std` feature flag. This will configure
544 the features enabled for the standard library itself when building the standard
545 library. The default enabled features, at this time, are `backtrace` and
546 `panic_unwind`. This flag expects a comma-separated list and, if provided, will
547 override the default list of features enabled.
548
549 ### timings
550 * Tracking Issue: [#7405](https://github.com/rust-lang/cargo/issues/7405)
551
552 The `timings` feature gives some information about how long each compilation
553 takes, and tracks concurrency information over time.
554
555 ```sh
556 cargo +nightly build -Z timings
557 ```
558
559 The `-Ztimings` flag can optionally take a comma-separated list of the
560 following values:
561
562 - `html` — Saves a file called `cargo-timing.html` to the current directory
563 with a report of the compilation. Files are also saved with a timestamp in
564 the filename if you want to look at older runs.
565 - `info` — Displays a message to stdout after each compilation finishes with
566 how long it took.
567 - `json` — Emits some JSON information about timing information.
568
569 The default if none are specified is `html,info`.
570
571 #### Reading the graphs
572
573 There are two graphs in the output. The "unit" graph shows the duration of
574 each unit over time. A "unit" is a single compiler invocation. There are lines
575 that show which additional units are "unlocked" when a unit finishes. That is,
576 it shows the new units that are now allowed to run because their dependencies
577 are all finished. Hover the mouse over a unit to highlight the lines. This can
578 help visualize the critical path of dependencies. This may change between runs
579 because the units may finish in different orders.
580
581 The "codegen" times are highlighted in a lavender color. In some cases, build
582 pipelining allows units to start when their dependencies are performing code
583 generation. This information is not always displayed (for example, binary
584 units do not show when code generation starts).
585
586 The "custom build" units are `build.rs` scripts, which when run are
587 highlighted in orange.
588
589 The second graph shows Cargo's concurrency over time. The three lines are:
590 - "Waiting" (red) — This is the number of units waiting for a CPU slot to
591 open.
592 - "Inactive" (blue) — This is the number of units that are waiting for their
593 dependencies to finish.
594 - "Active" (green) — This is the number of units currently running.
595
596 Note: This does not show the concurrency in the compiler itself. `rustc`
597 coordinates with Cargo via the "job server" to stay within the concurrency
598 limit. This currently mostly applies to the code generation phase.
599
600 Tips for addressing compile times:
601 - Look for slow dependencies.
602 - Check if they have features that you may wish to consider disabling.
603 - Consider trying to remove the dependency completely.
604 - Look for a crate being built multiple times with different versions. Try to
605 remove the older versions from the dependency graph.
606 - Split large crates into smaller pieces.
607 - If there are a large number of crates bottlenecked on a single crate, focus
608 your attention on improving that one crate to improve parallelism.
609
610 ### binary-dep-depinfo
611 * Tracking rustc issue: [#63012](https://github.com/rust-lang/rust/issues/63012)
612
613 The `-Z binary-dep-depinfo` flag causes Cargo to forward the same flag to
614 `rustc` which will then cause `rustc` to include the paths of all binary
615 dependencies in the "dep info" file (with the `.d` extension). Cargo then uses
616 that information for change-detection (if any binary dependency changes, then
617 the crate will be rebuilt). The primary use case is for building the compiler
618 itself, which has implicit dependencies on the standard library that would
619 otherwise be untracked for change-detection.
620
621 ### panic-abort-tests
622 * Tracking Issue: [#67650](https://github.com/rust-lang/rust/issues/67650)
623 * Original Pull Request: [#7460](https://github.com/rust-lang/cargo/pull/7460)
624
625 The `-Z panic-abort-tests` flag will enable nightly support to compile test
626 harness crates with `-Cpanic=abort`. Without this flag Cargo will compile tests,
627 and everything they depend on, with `-Cpanic=unwind` because it's the only way
628 `test`-the-crate knows how to operate. As of [rust-lang/rust#64158], however,
629 the `test` crate supports `-C panic=abort` with a test-per-process, and can help
630 avoid compiling crate graphs multiple times.
631
632 It's currently unclear how this feature will be stabilized in Cargo, but we'd
633 like to stabilize it somehow!
634
635 [rust-lang/rust#64158]: https://github.com/rust-lang/rust/pull/64158
636
637 ### config-cli
638 * Tracking Issue: [#7722](https://github.com/rust-lang/cargo/issues/7722)
639
640 The `--config` CLI option allows arbitrary config values to be passed
641 in via the command-line. The argument should be in TOML syntax of KEY=VALUE:
642
643 ```console
644 cargo +nightly -Zunstable-options --config net.git-fetch-with-cli=true fetch
645 ```
646
647 The `--config` option may be specified multiple times, in which case the
648 values are merged in left-to-right order, using the same merging logic that
649 multiple config files use. CLI values take precedence over environment
650 variables, which take precedence over config files.
651
652 Some examples of what it looks like using Bourne shell syntax:
653
654 ```console
655 # Most shells will require escaping.
656 cargo --config http.proxy=\"http://example.com\" …
657
658 # Spaces may be used.
659 cargo --config "net.git-fetch-with-cli = true" …
660
661 # TOML array example. Single quotes make it easier to read and write.
662 cargo --config 'build.rustdocflags = ["--html-in-header", "header.html"]' …
663
664 # Example of a complex TOML key.
665 cargo --config "target.'cfg(all(target_arch = \"arm\", target_os = \"none\"))'.runner = 'my-runner'" …
666
667 # Example of overriding a profile setting.
668 cargo --config profile.dev.package.image.opt-level=3 …
669 ```
670
671 ### config-include
672 * Tracking Issue: [#7723](https://github.com/rust-lang/cargo/issues/7723)
673
674 The `include` key in a config file can be used to load another config file. It
675 takes a string for a path to another file relative to the config file, or a
676 list of strings. It requires the `-Zconfig-include` command-line option.
677
678 ```toml
679 # .cargo/config
680 include = '../../some-common-config.toml'
681 ```
682
683 The config values are first loaded from the include path, and then the config
684 file's own values are merged on top of it.
685
686 This can be paired with [config-cli](#config-cli) to specify a file to load
687 from the command-line. Pass a path to a config file as the argument to
688 `--config`:
689
690 ```console
691 cargo +nightly -Zunstable-options -Zconfig-include --config somefile.toml build
692 ```
693
694 CLI paths are relative to the current working directory.
695
696 ### unit-graph
697 * Tracking Issue: [#8002](https://github.com/rust-lang/cargo/issues/8002)
698
699 The `--unit-graph` flag can be passed to any build command (`build`, `check`,
700 `run`, `test`, `bench`, `doc`, etc.) to emit a JSON object to stdout which
701 represents Cargo's internal unit graph. Nothing is actually built, and the
702 command returns immediately after printing. Each "unit" corresponds to an
703 execution of the compiler. These objects also include which unit each unit
704 depends on.
705
706 ```
707 cargo +nightly build --unit-graph -Z unstable-options
708 ```
709
710 This structure provides a more complete view of the dependency relationship as
711 Cargo sees it. In particular, the "features" field supports the new feature
712 resolver where a dependency can be built multiple times with different
713 features. `cargo metadata` fundamentally cannot represent the relationship of
714 features between different dependency kinds, and features now depend on which
715 command is run and which packages and targets are selected. Additionally it
716 can provide details about intra-package dependencies like build scripts or
717 tests.
718
719 The following is a description of the JSON structure:
720
721 ```javascript
722 {
723 /* Version of the JSON output structure. If any backwards incompatible
724 changes are made, this value will be increased.
725 */
726 "version": 1,
727 /* Array of all build units. */
728 "units": [
729 {
730 /* An opaque string which indicates the package.
731 Information about the package can be obtained from `cargo metadata`.
732 */
733 "pkg_id": "my-package 0.1.0 (path+file:///path/to/my-package)",
734 /* The Cargo target. See the `cargo metadata` documentation for more
735 information about these fields.
736 https://doc.rust-lang.org/cargo/commands/cargo-metadata.html
737 */
738 "target": {
739 "kind": ["lib"],
740 "crate_types": ["lib"],
741 "name": "my-package",
742 "src_path": "/path/to/my-package/src/lib.rs",
743 "edition": "2018",
744 "test": true,
745 "doctest": true
746 },
747 /* The profile settings for this unit.
748 These values may not match the profile defined in the manifest.
749 Units can use modified profile settings. For example, the "panic"
750 setting can be overridden for tests to force it to "unwind".
751 */
752 "profile": {
753 /* The profile name these settings are derived from. */
754 "name": "dev",
755 /* The optimization level as a string. */
756 "opt_level": "0",
757 /* The LTO setting as a string. */
758 "lto": "false",
759 /* The codegen units as an integer.
760 `null` if it should use the compiler's default.
761 */
762 "codegen_units": null,
763 /* The debug information level as an integer.
764 `null` if it should use the compiler's default (0).
765 */
766 "debuginfo": 2,
767 /* Whether or not debug-assertions are enabled. */
768 "debug_assertions": true,
769 /* Whether or not overflow-checks are enabled. */
770 "overflow_checks": true,
771 /* Whether or not rpath is enabled. */
772 "rpath": false,
773 /* Whether or not incremental is enabled. */
774 "incremental": true,
775 /* The panic strategy, "unwind" or "abort". */
776 "panic": "unwind"
777 },
778 /* Which platform this target is being built for.
779 A value of `null` indicates it is for the host.
780 Otherwise it is a string of the target triple (such as
781 "x86_64-unknown-linux-gnu").
782 */
783 "platform": null,
784 /* The "mode" for this unit. Valid values:
785
786 * "test" — Build using `rustc` as a test.
787 * "build" — Build using `rustc`.
788 * "check" — Build using `rustc` in "check" mode.
789 * "doc" — Build using `rustdoc`.
790 * "doctest" — Test using `rustdoc`.
791 * "run-custom-build" — Represents the execution of a build script.
792 */
793 "mode": "build",
794 /* Array of features enabled on this unit as strings. */
795 "features": ["somefeat"],
796 /* Whether or not this is a standard-library unit,
797 part of the unstable build-std feature.
798 If not set, treat as `false`.
799 */
800 "is_std": false,
801 /* Array of dependencies of this unit. */
802 "dependencies": [
803 {
804 /* Index in the "units" array for the dependency. */
805 "index": 1,
806 /* The name that this dependency will be referred as. */
807 "extern_crate_name": "unicode_xid",
808 /* Whether or not this dependency is "public",
809 part of the unstable public-dependency feature.
810 If not set, the public-dependency feature is not enabled.
811 */
812 "public": false,
813 /* Whether or not this dependency is injected into the prelude,
814 currently used by the build-std feature.
815 If not set, treat as `false`.
816 */
817 "noprelude": false
818 }
819 ]
820 },
821 // ...
822 ],
823 /* Array of indices in the "units" array that are the "roots" of the
824 dependency graph.
825 */
826 "roots": [0],
827 }
828 ```
829
830 ### Profile `strip` option
831 * Tracking Issue: [rust-lang/rust#72110](https://github.com/rust-lang/rust/issues/72110)
832
833 This feature provides a new option in the `[profile]` section to strip either
834 symbols or debuginfo from a binary. This can be enabled like so:
835
836 ```toml
837 cargo-features = ["strip"]
838
839 [package]
840 # ...
841
842 [profile.release]
843 strip = "debuginfo"
844 ```
845
846 Other possible string values of `strip` are `none`, `symbols`, and `off`. The default is `none`.
847
848 You can also configure this option with the two absolute boolean values
849 `true` and `false`. The former enables `strip` at its higher level, `symbols`,
850 while the latter disables `strip` completely.
851
852 ### rustdoc-map
853 * Tracking Issue: [#8296](https://github.com/rust-lang/cargo/issues/8296)
854
855 This feature adds configuration settings that are passed to `rustdoc` so that
856 it can generate links to dependencies whose documentation is hosted elsewhere
857 when the dependency is not documented. First, add this to `.cargo/config`:
858
859 ```toml
860 [doc.extern-map.registries]
861 crates-io = "https://docs.rs/"
862 ```
863
864 Then, when building documentation, use the following flags to cause links
865 to dependencies to link to [docs.rs](https://docs.rs/):
866
867 ```
868 cargo +nightly doc --no-deps -Zrustdoc-map
869 ```
870
871 The `registries` table contains a mapping of registry name to the URL to link
872 to. The URL may have the markers `{pkg_name}` and `{version}` which will get
873 replaced with the corresponding values. If neither are specified, then Cargo
874 defaults to appending `{pkg_name}/{version}/` to the end of the URL.
875
876 Another config setting is available to redirect standard library links. By
877 default, rustdoc creates links to <https://doc.rust-lang.org/nightly/>. To
878 change this behavior, use the `doc.extern-map.std` setting:
879
880 ```toml
881 [doc.extern-map]
882 std = "local"
883 ```
884
885 A value of `"local"` means to link to the documentation found in the `rustc`
886 sysroot. If you are using rustup, this documentation can be installed with
887 `rustup component add rust-docs`.
888
889 The default value is `"remote"`.
890
891 The value may also take a URL for a custom location.
892
893 ### terminal-width
894
895 * Tracking Issue: [#84673](https://github.com/rust-lang/rust/issues/84673)
896
897 This feature provides a new flag, `-Z terminal-width`, which is used to pass
898 a terminal width to `rustc` so that error messages containing long lines
899 can be intelligently truncated.
900
901 For example, passing `-Z terminal-width=20` (an arbitrarily low value) might
902 produce the following error:
903
904 ```text
905 error[E0308]: mismatched types
906 --> src/main.rs:2:17
907 |
908 2 | ..._: () = 42;
909 | -- ^^ expected `()`, found integer
910 | |
911 | expected due to this
912
913 error: aborting due to previous error
914 ```
915
916 In contrast, without `-Z terminal-width`, the error would look as shown below:
917
918 ```text
919 error[E0308]: mismatched types
920 --> src/main.rs:2:17
921 |
922 2 | let _: () = 42;
923 | -- ^^ expected `()`, found integer
924 | |
925 | expected due to this
926
927 error: aborting due to previous error
928 ```
929
930 ### Weak dependency features
931 * Tracking Issue: [#8832](https://github.com/rust-lang/cargo/issues/8832)
932
933 The `-Z weak-dep-features` command-line options enables the ability to use
934 `dep_name?/feat_name` syntax in the `[features]` table. The `?` indicates that
935 the optional dependency `dep_name` will not be automatically enabled. The
936 feature `feat_name` will only be added if something else enables the
937 `dep_name` dependency.
938
939 Example:
940
941 ```toml
942 [dependencies]
943 serde = { version = "1.0.117", optional = true, default-features = false }
944
945 [features]
946 std = ["serde?/std"]
947 ```
948
949 In this example, the `std` feature enables the `std` feature on the `serde`
950 dependency. However, unlike the normal `serde/std` syntax, it will not enable
951 the optional dependency `serde` unless something else has included it.
952
953 ### per-package-target
954 * Tracking Issue: [#9406](https://github.com/rust-lang/cargo/pull/9406)
955 * Original Pull Request: [#9030](https://github.com/rust-lang/cargo/pull/9030)
956 * Original Issue: [#7004](https://github.com/rust-lang/cargo/pull/7004)
957
958 The `per-package-target` feature adds two keys to the manifest:
959 `package.default-target` and `package.forced-target`. The first makes
960 the package be compiled by default (ie. when no `--target` argument is
961 passed) for some target. The second one makes the package always be
962 compiled for the target.
963
964 Example:
965
966 ```toml
967 [package]
968 forced-target = "wasm32-unknown-unknown"
969 ```
970
971 In this example, the crate is always built for
972 `wasm32-unknown-unknown`, for instance because it is going to be used
973 as a plugin for a main program that runs on the host (or provided on
974 the command line) target.
975
976 ### credential-process
977 * Tracking Issue: [#8933](https://github.com/rust-lang/cargo/issues/8933)
978 * RFC: [#2730](https://github.com/rust-lang/rfcs/pull/2730)
979
980 The `credential-process` feature adds a config setting to fetch registry
981 authentication tokens by calling an external process.
982
983 Token authentication is used by the [`cargo login`], [`cargo publish`],
984 [`cargo owner`], and [`cargo yank`] commands. Additionally, this feature adds
985 a new `cargo logout` command.
986
987 To use this feature, you must pass the `-Z credential-process` flag on the
988 command-line. Additionally, you must remove any current tokens currently saved
989 in the [`credentials` file] (which can be done with the new `logout` command).
990
991 #### `credential-process` Configuration
992
993 To configure which process to run to fetch the token, specify the process in
994 the `registry` table in a [config file]:
995
996 ```toml
997 [registry]
998 credential-process = "/usr/bin/cargo-creds"
999 ```
1000
1001 If you want to use a different process for a specific registry, it can be
1002 specified in the `registries` table:
1003
1004 ```toml
1005 [registries.my-registry]
1006 credential-process = "/usr/bin/cargo-creds"
1007 ```
1008
1009 The value can be a string with spaces separating arguments or it can be a TOML
1010 array of strings.
1011
1012 Command-line arguments allow special placeholders which will be replaced with
1013 the corresponding value:
1014
1015 * `{name}` — The name of the registry.
1016 * `{api_url}` — The base URL of the registry API endpoints.
1017 * `{action}` — The authentication action (described below).
1018
1019 Process names with the prefix `cargo:` are loaded from the `libexec` directory
1020 next to cargo. Several experimental credential wrappers are included with
1021 Cargo, and this provides convenient access to them:
1022
1023 ```toml
1024 [registry]
1025 credential-process = "cargo:macos-keychain"
1026 ```
1027
1028 The current wrappers are:
1029
1030 * `cargo:macos-keychain`: Uses the macOS Keychain to store the token.
1031 * `cargo:wincred`: Uses the Windows Credential Manager to store the token.
1032 * `cargo:1password`: Uses the 1password `op` CLI to store the token. You must
1033 install the `op` CLI from the [1password
1034 website](https://1password.com/downloads/command-line/). You must run `op
1035 signin` at least once with the appropriate arguments (such as `op signin
1036 my.1password.com user@example.com`), unless you provide the sign-in-address
1037 and email arguments. The master password will be required on each request
1038 unless the appropriate `OP_SESSION` environment variable is set. It supports
1039 the following command-line arguments:
1040 * `--account`: The account shorthand name to use.
1041 * `--vault`: The vault name to use.
1042 * `--sign-in-address`: The sign-in-address, which is a web address such as `my.1password.com`.
1043 * `--email`: The email address to sign in with.
1044
1045 A wrapper is available for GNOME
1046 [libsecret](https://wiki.gnome.org/Projects/Libsecret) to store tokens on
1047 Linux systems. Due to build limitations, this wrapper is not available as a
1048 pre-compiled binary. This can be built and installed manually. First, install
1049 libsecret using your system package manager (for example, `sudo apt install
1050 libsecret-1-dev`). Then build and install the wrapper with `cargo install
1051 cargo-credential-gnome-secret`.
1052 In the config, use a path to the binary like this:
1053
1054 ```toml
1055 [registry]
1056 credential-process = "cargo-credential-gnome-secret {action}"
1057 ```
1058
1059 #### `credential-process` Interface
1060
1061 There are two different kinds of token processes that Cargo supports. The
1062 simple "basic" kind will only be called by Cargo when it needs a token. This
1063 is intended for simple and easy integration with password managers, that can
1064 often use pre-existing tooling. The more advanced "Cargo" kind supports
1065 different actions passed as a command-line argument. This is intended for more
1066 pleasant integration experience, at the expense of requiring a Cargo-specific
1067 process to glue to the password manager. Cargo will determine which kind is
1068 supported by the `credential-process` definition. If it contains the
1069 `{action}` argument, then it uses the advanced style, otherwise it assumes it
1070 only supports the "basic" kind.
1071
1072 ##### Basic authenticator
1073
1074 A basic authenticator is a process that returns a token on stdout. Newlines
1075 will be trimmed. The process inherits the user's stdin and stderr. It should
1076 exit 0 on success, and nonzero on error.
1077
1078 With this form, [`cargo login`] and `cargo logout` are not supported and
1079 return an error if used.
1080
1081 ##### Cargo authenticator
1082
1083 The protocol between the Cargo and the process is very basic, intended to
1084 ensure the credential process is kept as simple as possible. Cargo will
1085 execute the process with the `{action}` argument indicating which action to
1086 perform:
1087
1088 * `store` — Store the given token in secure storage.
1089 * `get` — Get a token from storage.
1090 * `erase` — Remove a token from storage.
1091
1092 The `cargo login` command uses `store` to save a token. Commands that require
1093 authentication, like `cargo publish`, uses `get` to retrieve a token. `cargo
1094 logout` uses the `erase` command to remove a token.
1095
1096 The process inherits the user's stderr, so the process can display messages.
1097 Some values are passed in via environment variables (see below). The expected
1098 interactions are:
1099
1100 * `store` — The token is sent to the process's stdin, terminated by a newline.
1101 The process should store the token keyed off the registry name. If the
1102 process fails, it should exit with a nonzero exit status.
1103
1104 * `get` — The process should send the token to its stdout (trailing newline
1105 will be trimmed). The process inherits the user's stdin, should it need to
1106 receive input.
1107
1108 If the process is unable to fulfill the request, it should exit with a
1109 nonzero exit code.
1110
1111 * `erase` — The process should remove the token associated with the registry
1112 name. If the token is not found, the process should exit with a 0 exit
1113 status.
1114
1115 ##### Environment
1116
1117 The following environment variables will be provided to the executed command:
1118
1119 * `CARGO` — Path to the `cargo` binary executing the command.
1120 * `CARGO_REGISTRY_NAME` — Name of the registry the authentication token is for.
1121 * `CARGO_REGISTRY_API_URL` — The URL of the registry API.
1122
1123 #### `cargo logout`
1124
1125 A new `cargo logout` command has been added to make it easier to remove a
1126 token from storage. This supports both [`credentials` file] tokens and
1127 `credential-process` tokens.
1128
1129 When used with `credentials` file tokens, it needs the `-Z unstable-options`
1130 command-line option:
1131
1132 ```console
1133 cargo logout -Z unstable-options
1134 ```
1135
1136 When used with the `credential-process` config, use the `-Z
1137 credential-process` command-line option:
1138
1139
1140 ```console
1141 cargo logout -Z credential-process
1142 ```
1143
1144 [`cargo login`]: ../commands/cargo-login.md
1145 [`cargo publish`]: ../commands/cargo-publish.md
1146 [`cargo owner`]: ../commands/cargo-owner.md
1147 [`cargo yank`]: ../commands/cargo-yank.md
1148 [`credentials` file]: config.md#credentials
1149 [crates.io]: https://crates.io/
1150 [config file]: config.md
1151
1152 ### rust-version
1153 * RFC: [#2495](https://github.com/rust-lang/rfcs/blob/master/text/2495-min-rust-version.md)
1154 * rustc Tracking Issue: [#65262](https://github.com/rust-lang/rust/issues/65262)
1155
1156 The `-Z rust-version` flag enables the reading of the `rust-version` field in the
1157 Cargo manifest `package` section. This can be used by a package to state a minimal
1158 version of the compiler required to build the package. An error is generated if
1159 the version of rustc is older than the stated `rust-version`. The
1160 `--ignore-rust-version` flag can be used to override the check.
1161
1162 ```toml
1163 cargo-features = ["rust-version"]
1164
1165 [package]
1166 name = "mypackage"
1167 version = "0.0.1"
1168 rust-version = "1.42"
1169 ```
1170
1171 ### edition 2021
1172
1173 Support for the 2021 [edition] can be enabled by adding the `edition2021`
1174 unstable feature to the top of `Cargo.toml`:
1175
1176 ```toml
1177 cargo-features = ["edition2021"]
1178
1179 [package]
1180 name = "my-package"
1181 version = "0.1.0"
1182 edition = "2021"
1183 ```
1184
1185 If you want to transition an existing project from a previous edition, then
1186 `cargo fix --edition` can be used on the nightly channel. After running `cargo
1187 fix`, you can switch the edition to 2021 as illustrated above.
1188
1189 This feature is very unstable, and is only intended for early testing and
1190 experimentation. Future nightly releases may introduce changes for the 2021
1191 edition that may break your build.
1192
1193 The 2021 edition will set the default [resolver version] to "2".
1194
1195 [edition]: ../../edition-guide/index.html
1196 [resolver version]: resolver.md#resolver-versions
1197
1198 ### future incompat report
1199 * RFC: [#2834](https://github.com/rust-lang/rfcs/blob/master/text/2834-cargo-report-future-incompat.md)
1200 * rustc Tracking Issue: [#71249](https://github.com/rust-lang/rust/issues/71249)
1201
1202 The `-Z future-incompat-report` flag causes Cargo to check for
1203 future-incompatible warnings in all dependencies. These are warnings for
1204 changes that may become hard errors in the future, causing the dependency to
1205 stop building in a future version of rustc. If any warnings are found, a small
1206 notice is displayed indicating that the warnings were found, and provides
1207 instructions on how to display a full report.
1208
1209 A full report can be displayed with the `cargo report future-incompatibilities
1210 -Z future-incompat-report --id ID` command, or by running the build again with
1211 the `--future-incompat-report` flag. The developer should then update their
1212 dependencies to a version where the issue is fixed, or work with the
1213 developers of the dependencies to help resolve the issue.
1214
1215 ### configurable-env
1216 * Original Pull Request: [#9175](https://github.com/rust-lang/cargo/pull/9175)
1217
1218 The `-Z configurable-env` flag enables the `[env]` section in the
1219 `.cargo/config.toml` file. This section allows you to set additional environment
1220 variables for build scripts, rustc invocations, `cargo run` and `cargo build`.
1221
1222 ```toml
1223 [env]
1224 OPENSSL_DIR = "/opt/openssl"
1225 ```
1226
1227 By default, the variables specified will not override values that already exist
1228 in the environment. This behavior can be changed by setting the `force` flag.
1229
1230 Setting the `relative` flag evaluates the value as a config-relative path that
1231 is relative to the parent directory of the `.cargo` directory that contains the
1232 `config.toml` file. The value of the environment variable will be the full
1233 absolute path.
1234
1235 ```toml
1236 [env]
1237 TMPDIR = { value = "/home/tmp", force = true }
1238 OPENSSL_DIR = { value = "vendor/openssl", relative = true }
1239 ```
1240
1241 ### patch-in-config
1242 * Original Pull Request: [#9204](https://github.com/rust-lang/cargo/pull/9204)
1243 * Tracking Issue: [#9269](https://github.com/rust-lang/cargo/issues/9269)
1244
1245 The `-Z patch-in-config` flag enables the use of `[patch]` sections in
1246 cargo configuration files (`.cargo/config.toml`). The format of such
1247 `[patch]` sections is identical to the one used in `Cargo.toml`.
1248
1249 Since `.cargo/config.toml` files are not usually checked into source
1250 control, you should prefer patching using `Cargo.toml` where possible to
1251 ensure that other developers can compile your crate in their own
1252 environments. Patching through cargo configuration files is generally
1253 only appropriate when the patch section is automatically generated by an
1254 external build tool.
1255
1256 If a given dependency is patched both in a cargo configuration file and
1257 a `Cargo.toml` file, the patch in `Cargo.toml` is used. If multiple
1258 configuration files patch the same dependency, standard cargo
1259 configuration merging is used, which prefers the value defined closest
1260 to the current directory, with `$HOME/.cargo/config.toml` taking the
1261 lowest precedence.
1262
1263 Relative `path` dependencies in such a `[patch]` section are resolved
1264 relative to the configuration file they appear in.
1265
1266 ### `cargo config`
1267
1268 * Original Issue: [#2362](https://github.com/rust-lang/cargo/issues/2362)
1269 * Tracking Issue: [#9301](https://github.com/rust-lang/cargo/issues/9301)
1270
1271 The `cargo config` subcommand provides a way to display the configuration
1272 files that cargo loads. It currently includes the `get` subcommand which
1273 can take an optional config value to display.
1274
1275 ```console
1276 cargo +nightly -Zunstable-options config get build.rustflags
1277 ```
1278
1279 If no config value is included, it will display all config values. See the
1280 `--help` output for more options available.
1281
1282 ### `doctest-in-workspace`
1283
1284 * Tracking Issue: [#9427](https://github.com/rust-lang/cargo/issues/9427)
1285
1286 The `-Z doctest-in-workspace` flag changes the behavior of the current working
1287 directory used when running doctests. Historically, Cargo has run `rustdoc
1288 --test` relative to the root of the package, with paths relative from that
1289 root. However, this is inconsistent with how `rustc` and `rustdoc` are
1290 normally run in a workspace, where they are run relative to the workspace
1291 root. This inconsistency causes problems in various ways, such as when passing
1292 RUSTDOCFLAGS with relative paths, or dealing with diagnostic output.
1293
1294 The `-Z doctest-in-workspace` flag causes cargo to switch to running `rustdoc`
1295 from the root of the workspace. It also passes the `--test-run-directory` to
1296 `rustdoc` so that when *running* the tests, they are run from the root of the
1297 package. This preserves backwards compatibility and is consistent with how
1298 normal unittests are run.
1299
1300 ### rustc `--print`
1301
1302 * Tracking Issue: [#9357](https://github.com/rust-lang/cargo/issues/9357)
1303
1304 `cargo rustc --print=VAL` forwards the `--print` flag to `rustc` in order to
1305 extract information from `rustc`. This runs `rustc` with the corresponding
1306 [`--print`](https://doc.rust-lang.org/rustc/command-line-arguments.html#--print-print-compiler-information)
1307 flag, and then immediately exits without compiling. Exposing this as a cargo
1308 flag allows cargo to inject the correct target and RUSTFLAGS based on the
1309 current configuration.
1310
1311 The primary use case is to run `cargo rustc --print=cfg` to get config values
1312 for the appropriate target and influenced by any other RUSTFLAGS.
1313
1314 <script>
1315 (function() {
1316 var fragments = {
1317 "#edition": "manifest.html#the-edition-field",
1318 "#compile-progress": "config.html#termprogresswhen",
1319 "#rename-dependency": "specifying-dependencies.html#renaming-dependencies-in-cargotoml",
1320 "#alternate-registries": "registries.html",
1321 "#offline-mode": "../commands/cargo.html",
1322 "#publish-lockfile": "../commands/cargo-package.html",
1323 "#default-run": "manifest.html#the-default-run-field",
1324 "#cache-messages": "https://github.com/rust-lang/cargo/pull/7450",
1325 "#install-upgrade": "../commands/cargo-install.html",
1326 "#profile-overrides": "profiles.html#overrides",
1327 "#config-profiles": "config.html#profile",
1328 "#crate-versions": "https://github.com/rust-lang/cargo/pull/8509",
1329 "#features": "features.html#feature-resolver-version-2",
1330 "#package-features": "features.html#resolver-version-2-command-line-flags",
1331 "#resolver": "resolver.html#resolver-versions",
1332 };
1333 var target = fragments[window.location.hash];
1334 if (target) {
1335 if (target.startsWith('https')) {
1336 window.location.replace(target);
1337 } else {
1338 var url = window.location.toString();
1339 var base = url.substring(0, url.lastIndexOf('/'));
1340 window.location.replace(base + "/" + target);
1341 }
1342 }
1343 })();
1344 </script>