Skip to content

Commit 01bd9fb

Browse files
committed
Rearrange and try to clarify resolver 2 docs.
* Avoid terms like "new", "previously", and "now". * Add link for `resolver` field in manifest.md. * Move the resolver version specification to the resolver chapter. * Break up the version 2 section in features.md into subsections. * Try to clarify some of the wording, and make it clearer when talking about resolver versions. * Rewrite the section on version 2 command-line flags to hopefully be clearer.
1 parent f731d25 commit 01bd9fb

File tree

3 files changed

+81
-47
lines changed

3 files changed

+81
-47
lines changed

src/doc/src/reference/features.md

+40-41
Original file line numberDiff line numberDiff line change
@@ -304,9 +304,8 @@ enabled. Some options to try:
304304

305305
### Feature resolver version 2
306306

307-
Cargo has a new feature resolver which uses a different algorithm for
308-
resolving which features are enabled. This can be enabled by specifying the
309-
resolver version in `Cargo.toml` like this:
307+
A different feature resolver can be specified with the `resolver` field in
308+
`Cargo.toml`, like this:
310309

311310
```toml
312311
[package]
@@ -315,11 +314,16 @@ version = "1.0.0"
315314
resolver = "2"
316315
```
317316

318-
This new resolver avoids unifying features in a few situations where that
319-
unification can be unwanted. The exact situations are described in the
320-
[resolver chapter], but in short, it avoids unifying:
317+
See the [resolver versions] section for more detail on specifying resolver
318+
versions.
321319

322-
* Target-specific dependencies for targets not currently being built.
320+
The version `"2"` resolver avoids unifying features in a few situations where
321+
that unification can be unwanted. The exact situations are described in the
322+
[resolver chapter][resolver-v2], but in short, it avoids unifying in these
323+
situations:
324+
325+
* Features enabled on [platform-specific dependencies] for targets not
326+
currently being built are ignored.
323327
* [Build-dependencies] and proc-macros do not share features with normal
324328
dependencies.
325329
* [Dev-dependencies] do not activate features unless building a target that
@@ -332,54 +336,49 @@ build.
332336

333337
However, one drawback is that this can increase build times because the
334338
dependency is built multiple times (each with different features). When using
335-
the new resolver, it is recommended to check for dependencies that are built
336-
multiple times to reduce overall build time. If it is not *required* to build
337-
them with separate features, consider adding features to the `features` list
338-
in the [dependency declaration](#dependency-features) so that the duplicates
339-
end up with the same features (and thus Cargo will build it only once). You
340-
can detect these duplicate dependencies with the [`cargo tree
341-
--duplicates`][`cargo tree`] command. It will show which packages are built
342-
multiple times; look for any entries listed with the same version. See
343-
[Inspecting resolved features](#inspecting-resolved-features) for more on
344-
fetching information on the resolved features. For build dependencies, this
345-
is not necessary if you are cross-compiling with the `--target` flag because
346-
build dependencies are always built separately from normal dependencies in
347-
that scenario.
339+
the version `"2"` resolver, it is recommended to check for dependencies that
340+
are built multiple times to reduce overall build time. If it is not *required*
341+
to build those duplicated packages with separate features, consider adding
342+
features to the `features` list in the [dependency
343+
declaration](#dependency-features) so that the duplicates end up with the same
344+
features (and thus Cargo will build it only once). You can detect these
345+
duplicate dependencies with the [`cargo tree --duplicates`][`cargo tree`]
346+
command. It will show which packages are built multiple times; look for any
347+
entries listed with the same version. See [Inspecting resolved
348+
features](#inspecting-resolved-features) for more on fetching information on
349+
the resolved features. For build dependencies, this is not necessary if you
350+
are cross-compiling with the `--target` flag because build dependencies are
351+
always built separately from normal dependencies in that scenario.
352+
353+
#### Resolver version 2 command-line flags
348354

349355
The `resolver = "2"` setting also changes the behavior of the `--features` and
350356
`--no-default-features` [command-line options](#command-line-feature-options).
351-
Previously, you could only enable features for the package in the current
352-
working directory, regardless of which `-p` flags were used. With `resolver =
353-
"2"`, the flags will enable the given features for the packages selected on
354-
the command-line with `-p` flags. For example:
357+
358+
With version `"1"`, you can only enable features for the package in the
359+
current working directory. For example, in a workspace with packages `foo` and
360+
`bar`, and you are in the directory for package `foo`, and ran the command
361+
`cargo build -p bar --features bar-feat`, this would fail because the
362+
`--features` flag only allowed enabling features on `foo`.
363+
364+
With `resolver = "2"`, the features flags allow enabling features for any of
365+
the packages selected on the command-line with `-p` and `--workspace` flags.
366+
For example:
355367

356368
```sh
357-
# This command is now allowed, regardless of which directory you are in.
369+
# This command is allowed with resolver = "2", regardless of which directory
370+
# you are in.
358371
cargo build -p foo -p bar --features foo-feat,bar-feat
359372
```
360373

361374
Additionally, with `resolver = "1"`, the `--no-default-features` flag only
362375
disables the default feature for the package in the current directory. With
363376
version "2", it will disable the default features for all workspace members.
364377

365-
The resolver is a global option that affects the entire workspace. The
366-
`resolver` version in dependencies is ignored, only the value in the top-level
367-
package will be used. If using a [virtual workspace], the version should be
368-
specified in the `[workspace]` table, for example:
369-
370-
```toml
371-
[workspace]
372-
members = ["member1", "member2"]
373-
resolver = "2"
374-
```
375-
376-
The default if the `resolver` is not specified is the value `"1"` which will
377-
use the original resolver behavior.
378-
378+
[resolver versions]: resolver.md#resolver-versions
379379
[build-dependencies]: specifying-dependencies.md#build-dependencies
380380
[dev-dependencies]: specifying-dependencies.md#development-dependencies
381-
[resolver chapter]: resolver.md#feature-resolver-version-2
382-
[virtual workspace]: workspaces.md#virtual-manifest
381+
[resolver-v2]: resolver.md#feature-resolver-version-2
383382

384383
### Build scripts
385384

src/doc/src/reference/manifest.md

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ in the [TOML] format. Every manifest file consists of the following sections:
3030
* [`autoexamples`](cargo-targets.md#target-auto-discovery) — Disables example auto discovery.
3131
* [`autotests`](cargo-targets.md#target-auto-discovery) — Disables test auto discovery.
3232
* [`autobenches`](cargo-targets.md#target-auto-discovery) — Disables bench auto discovery.
33+
* [`resolver`](resolver.md#resolver-versions) — Sets the dependency resolver to use.
3334
* Target tables: (see [configuration](cargo-targets.md#configuring-a-target) for settings)
3435
* [`[lib]`](cargo-targets.md#library) — Library target settings.
3536
* [`[[bin]]`](cargo-targets.md#binaries) — Binary target settings.

src/doc/src/reference/resolver.md

+40-6
Original file line numberDiff line numberDiff line change
@@ -237,11 +237,12 @@ optional dependency].
237237

238238
#### Feature resolver version 2
239239

240-
A new feature resolver can be enabled by specifying `resolver = "2"` in
241-
`Cargo.toml` (see [the features chapter][features-2]). This resolver has a
242-
different algorithm for unifying features. The version `"1"` resolver will
243-
unify features for a package no matter where it is specified. The version
244-
`"2"` resolver will avoid unifying features in the following situations:
240+
When `resolver = "2"` is specified in `Cargo.toml` (see [resolver
241+
versions](#resolver-versions) below), a different feature resolver is used
242+
which uses a different algorithm for unifying features. The version `"1"`
243+
resolver will unify features for a package no matter where it is specified.
244+
The version `"2"` resolver will avoid unifying features in the following
245+
situations:
245246

246247
* Features for target-specific dependencies are not enabled if the target is
247248
not currently being built. For example:
@@ -295,7 +296,7 @@ unify features for a package no matter where it is specified. The version
295296

296297
[build-dependencies]: specifying-dependencies.md#build-dependencies
297298
[dev-dependencies]: specifying-dependencies.md#development-dependencies
298-
[features-2]: features.md#feature-resolver-version-2
299+
[resolver-field]: features.md#resolver-versions
299300

300301
### `links`
301302

@@ -395,6 +396,39 @@ types.
395396
If possible, try to split your package into multiple packages and restructure
396397
it so that it remains strictly acyclic.
397398

399+
## Resolver versions
400+
401+
A different feature resolver algorithm can be used by specifying the resolver
402+
version in `Cargo.toml` like this:
403+
404+
```toml
405+
[package]
406+
name = "my-package"
407+
version = "1.0.0"
408+
resolver = "2"
409+
```
410+
411+
The version `"1"` resolver is the original resolver that shipped with Cargo up
412+
to version 1.50, and is the default if the `resolver` is not specified.
413+
414+
The version `"2"` resolver introduces changes in [feature
415+
unification](#features). See the [features chapter][features-2] for more
416+
details.
417+
418+
The resolver is a global option that affects the entire workspace. The
419+
`resolver` version in dependencies is ignored, only the value in the top-level
420+
package will be used. If using a [virtual workspace], the version should be
421+
specified in the `[workspace]` table, for example:
422+
423+
```toml
424+
[workspace]
425+
members = ["member1", "member2"]
426+
resolver = "2"
427+
```
428+
429+
[virtual workspace]: workspaces.md#virtual-manifest
430+
[features-2]: features.md#feature-resolver-version-2
431+
398432
## Recommendations
399433

400434
The following are some recommendations for setting the version within your

0 commit comments

Comments
 (0)