cargo_hakari/docs/
config.rs

1// Copyright (c) The cargo-guppy Contributors
2// SPDX-License-Identifier: MIT OR Apache-2.0
3
4//! Configuration for `cargo hakari`.
5//!
6//! # Configuration file location
7//!
8//! The default config path for cargo-hakari versions 0.9.8 or above is `.config/hakari.toml`,
9//! relative to the root of the workspace. Previous versions used `.guppy/hakari.toml`, which
10//! continues to be supported as a fallback.
11//!
12//! # Common options
13//!
14//! ## hakari-package
15//!
16//! The name of the hakari-managed crate in the workspace. Must be specified. For example:
17//!
18//! ```toml
19//! hakari-package = "my-workspace-hack"
20//! ```
21//!
22//! ## resolver
23//!
24//! The version of the Cargo feature resolver to use. Version 2 is highly recommended.
25//! For more, see this [Rust blog post](https://blog.rust-lang.org/2021/03/25/Rust-1.51.0.html#cargos-new-feature-resolver).
26//!
27//! Defaults to "1", but `.config/hakari.toml` files created by `cargo hakari init` set it to "2".
28//!
29//! ```toml
30//! resolver = "2"
31//! ```
32//!
33//! ## dep-format-version
34//!
35//! The format version to use.
36//!
37//! Possible values:
38//! * *"1"*: `workspace-hack = { path = ...}` in other `Cargo.toml` files. (Note the lack of a
39//!   trailing space.)
40//! * *"2"*: `workspace-hack = { version = "0.1", path = ... }` in other `Cargo.toml` files. This is
41//!   required for the advanced setup documented in the [Publishing](crate::publishing) section.
42//! * *"3"*: Has the following changes:
43//!   - Simplifies workspace-hack output by eliding private and other non-root features from its
44//!     `Cargo.toml`.
45//!   - Elides build metadata from version strings in the workspace-hack's `Cargo.toml`. (Cargo
46//!     warns if build metadata is added to version strings.)
47//! * *"4"*: Fixes dependency name sorting in the workspace-hack's `Cargo.toml` to always be
48//!   alphabetical. Previously, dependencies would sometimes not be sorted correctly.
49//!
50//! Defaults to "1", but
51//! - starting `cargo hakari 0.9.8`, `.config/hakari.toml` files created by
52//!   `cargo hakari init` set it to "2".
53//! - starting `cargo hakari 0.9.18`, `.config/hakari.toml` files created by
54//!   `cargo hakari init` set it to "3".
55//! - starting `cargo hakari 0.9.22`, `.config/hakari.toml` files created by
56//!   `cargo hakari init` set it to "4".
57//!
58//! In general, it is best to be on the latest version.
59//!
60//! ```toml
61//! dep-format-version = "4"
62//! ```
63//!
64//! ## workspace-hack-line-style
65//!
66//! Style of `workspace-hack` lines to output. After changing this, you must run:
67//!
68//! ```sh
69//! cargo hakari remove-deps
70//! cargo hakari manage-deps
71//! ```
72//!
73//! Possible values:
74//! * *"full"*: `my-workspace-hack = { version = "0.1", path = ... }`.
75//! * *"version-only"*: `my-workspace-hack = { version = "0.1" }`.
76//! * *"workspace-dotted"*: `my-workspace-hack.workspace = true`.
77//!
78//! For more about this, see the [`[patch]` directive](crate::patch_directive) section.
79//!
80//! ## platforms
81//!
82//! Platforms to run specific queries on.
83//!
84//! By default, `cargo hakari` produces the minimal set of features that can be unified across
85//! all possible platforms. However, in practice, most developers on a codebase use one of a
86//! few platforms. `cargo hakari` can run specific queries for a few platforms, producing better
87//! results for them.
88//!
89//! Defaults to an empty list.
90//!
91//! ```toml
92//! ## Unify features on x86_64 Linux, Mac and Windows.
93//! platforms = [
94//!      "x86_64-unknown-linux-gnu",
95//!      "x86_64-apple-darwin",
96//!      "x86_64-pc-windows-msvc",
97//! ]
98//! ```
99//!
100//! ## traversal-excludes
101//!
102//! Crates to exclude while traversing the dependency graph.
103//!
104//! Packages specified in `traversal-excludes` will be omitted while searching for dependencies.
105//! These packages will not be included in the final output. Any transitive dependencies of
106//! these packages will not be included in the final result, unless those dependencies are reachable
107//! from other crates.
108//!
109//! Workspace crates excluded from traversals will not depend on the workspace-hack crate, and
110//! `cargo hakari manage-deps` will *remove* dependency edges rather than adding them.
111//!
112//! This is generally useful for crates that have mutually exclusive features, and that turn on
113//! mutually exclusive features in their transitive dependencies.
114//!
115//! Defaults to an empty set.
116//!
117//! ```toml
118//! [traversal-excludes]
119//! workspace-members = ["my-crate", "my-other-crate"]
120//! third-party = [
121//!     ## Third-party crates accept semver ranges.
122//!     { name = "mutually-exclusive-crate", version = "1.0" },
123//!
124//!     ## The version specifier can be skipped to include all versions of a crate.
125//!     ## (Cryptography-related crates often use features to switch on different backends.)
126//!     { name = "my-cryptography" },
127//!
128//!     ## Git and path dependencies can also be specified
129//!     { name = "git-dependency", git = "https://github.com/my-org/git-dependency" },
130//!     { name = "path-dependency", path = "../my/path/dependency" }
131//! ]
132//! ```
133//!
134//! ## final-excludes
135//!
136//! Crates to remove at the end of computation.
137//!
138//! Packages specified in `final-excludes` will be removed from the output at the very end. This
139//! means that any transitive dependencies of theirs will still be included.
140//!
141//! Workspace crates excluded from the final output will not depend on the workspace-hack crate, and
142//! `cargo hakari manage-deps` will *remove* dependency edges rather than adding them.
143//!
144//! This is generally useful for crates that have mutually exclusive features.
145//!
146//! This accepts configuration in the same format as `traversal-excludes` above.
147//!
148//! Defaults to an empty set.
149//!
150//! ```toml
151//! [final-excludes]
152//! workspace-members = ["my-crate", "your-crate"]
153//! third-party = [
154//!     ## The "fail" crate uses the "failpoints" feature to enable random errors at runtime.
155//!     ## It is a good candidate for exclusion from the final output.
156//!     { name = "fail" },
157//!
158//!     ## Version specifiers and git/path dependencies work similarly to traversal-excludes
159//!     ## above.
160//! ]
161//! ```
162//!
163//! ## registries
164//!
165//! Alternate registries,
166//! [in the same format](https://doc.rust-lang.org/cargo/reference/registries.html) as
167//! `.cargo/config.toml`.
168//!
169//! This is a temporary workaround until [Cargo issue #9052](https://github.com/rust-lang/cargo/issues/9052)
170//! is resolved.
171//!
172//! Defaults to an empty set.
173//!
174//! ```toml
175//! [registries]
176//! my-registry = { index = "https://my-intranet:8080/git/index" }
177//! ```
178//!
179//! # Output options
180//!
181//! ## exact-versions
182//!
183//! By default, the workspace-hack crate's `Cargo.toml` file will contain a semver range. With
184//! `exact-versions` turned on, the exact version currently in use will be output.
185//!
186//! This is most useful for situations where the `Cargo.lock` file is checked in, and if
187//! version numbers are kept in sync across `Cargo.toml` and `Cargo.lock`. This includes some
188//! configurations of [Dependabot](https://dependabot.com/).
189//!
190//! Defaults to false.
191//!
192//! ```toml
193//! exact-versions = true
194//! ```
195//!
196//! # Advanced options
197//!
198//! ## unify-target-host
199//!
200//! Controls unification across target and host platforms.
201//!
202//! If the same dependency is built on both the target and host platforms, this option controls
203//! whether and how they should be unified.
204//!
205//! The possible options are `"none"`, `"auto"`, `"unify-if-both"`, and
206//! `"replicate-target-on-host"`. For more about these options, see the documentation for
207//! [`UnifyTargetHost`](hakari::UnifyTargetHost).
208//!
209//! Defaults to `"auto"`.
210//!
211//! ```toml
212//! unify-target-host = "replicate-target-on-host"
213//! ```
214//!
215//! ## output-single-feature
216//!
217//! By default, `cargo hakari` only outputs lines corresponding to third-party dependencies which
218//! are built with at least two different sets of features. Setting this option to true will
219//! cause `cargo hakari` to output lines corresponding to dependencies built with just one set
220//! of features.
221//!
222//! This is generally not needed but may be useful in some situations.
223//!
224//! Defaults to false.
225//!
226//! ```toml
227//! output-single-feature = true
228//! ```