@@ -304,9 +304,8 @@ enabled. Some options to try:
304
304
305
305
### Feature resolver version 2
306
306
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:
310
309
311
310
``` toml
312
311
[package ]
@@ -315,11 +314,16 @@ version = "1.0.0"
315
314
resolver = " 2"
316
315
```
317
316
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.
321
319
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.
323
327
* [ Build-dependencies] and proc-macros do not share features with normal
324
328
dependencies.
325
329
* [ Dev-dependencies] do not activate features unless building a target that
@@ -332,54 +336,49 @@ build.
332
336
333
337
However, one drawback is that this can increase build times because the
334
338
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
348
354
349
355
The ` resolver = "2" ` setting also changes the behavior of the ` --features ` and
350
356
` --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:
355
367
356
368
``` 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.
358
371
cargo build -p foo -p bar --features foo-feat,bar-feat
359
372
```
360
373
361
374
Additionally, with ` resolver = "1" ` , the ` --no-default-features ` flag only
362
375
disables the default feature for the package in the current directory. With
363
376
version "2", it will disable the default features for all workspace members.
364
377
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
379
379
[ build-dependencies ] : specifying-dependencies.md#build-dependencies
380
380
[ 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
383
382
384
383
### Build scripts
385
384
0 commit comments