Skip to content

Commit 1f8b398

Browse files
committed
Add --all-features flag to cargo
1 parent 3e41b6b commit 1f8b398

25 files changed

+145
-9
lines changed

src/bin/bench.rs

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ pub struct Options {
99
flag_package: Vec<String>,
1010
flag_jobs: Option<u32>,
1111
flag_features: Vec<String>,
12+
flag_all_features: bool,
1213
flag_no_default_features: bool,
1314
flag_target: Option<String>,
1415
flag_manifest_path: Option<String>,
@@ -42,6 +43,7 @@ Options:
4243
-p SPEC, --package SPEC ... Package to run benchmarks for
4344
-j N, --jobs N Number of parallel jobs, defaults to # of CPUs
4445
--features FEATURES Space-separated list of features to also build
46+
--all-features Build all available features
4547
--no-default-features Do not build the `default` feature
4648
--target TRIPLE Build for the target triple
4749
--manifest-path PATH Path to the manifest to build benchmarks for
@@ -83,6 +85,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
8385
jobs: options.flag_jobs,
8486
target: options.flag_target.as_ref().map(|s| &s[..]),
8587
features: &options.flag_features,
88+
all_features: options.flag_all_features,
8689
no_default_features: options.flag_no_default_features,
8790
spec: &options.flag_package,
8891
exec_engine: None,

src/bin/build.rs

+3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ pub struct Options {
1111
flag_package: Vec<String>,
1212
flag_jobs: Option<u32>,
1313
flag_features: Vec<String>,
14+
flag_all_features: bool,
1415
flag_no_default_features: bool,
1516
flag_target: Option<String>,
1617
flag_manifest_path: Option<String>,
@@ -44,6 +45,7 @@ Options:
4445
--bench NAME Build only the specified benchmark target
4546
--release Build artifacts in release mode, with optimizations
4647
--features FEATURES Space-separated list of features to also build
48+
--all-features Build all available features
4749
--no-default-features Do not build the `default` feature
4850
--target TRIPLE Build for the target triple
4951
--manifest-path PATH Path to the manifest to compile
@@ -79,6 +81,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
7981
jobs: options.flag_jobs,
8082
target: options.flag_target.as_ref().map(|t| &t[..]),
8183
features: &options.flag_features,
84+
all_features: options.flag_all_features,
8285
no_default_features: options.flag_no_default_features,
8386
spec: &options.flag_package,
8487
exec_engine: None,

src/bin/doc.rs

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use cargo::util::important_paths::{find_root_manifest_for_wd};
77
pub struct Options {
88
flag_target: Option<String>,
99
flag_features: Vec<String>,
10+
flag_all_features: bool,
1011
flag_jobs: Option<u32>,
1112
flag_manifest_path: Option<String>,
1213
flag_no_default_features: bool,
@@ -39,6 +40,7 @@ Options:
3940
--bin NAME Document only the specified binary
4041
--release Build artifacts in release mode, with optimizations
4142
--features FEATURES Space-separated list of features to also build
43+
--all-features Build all available features
4244
--no-default-features Do not build the `default` feature
4345
--target TRIPLE Build for the target triple
4446
--manifest-path PATH Path to the manifest to document
@@ -74,6 +76,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
7476
jobs: options.flag_jobs,
7577
target: options.flag_target.as_ref().map(|t| &t[..]),
7678
features: &options.flag_features,
79+
all_features: options.flag_all_features,
7780
no_default_features: options.flag_no_default_features,
7881
spec: &options.flag_package,
7982
exec_engine: None,

src/bin/install.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use cargo::util::{CliResult, Config, ToUrl};
66
pub struct Options {
77
flag_jobs: Option<u32>,
88
flag_features: Vec<String>,
9+
flag_all_features: bool,
910
flag_no_default_features: bool,
1011
flag_debug: bool,
1112
flag_bin: Vec<String>,
@@ -48,8 +49,9 @@ Specifying what crate to install:
4849
Build and install options:
4950
-h, --help Print this message
5051
-j N, --jobs N Number of parallel jobs, defaults to # of CPUs
51-
--features FEATURES Space-separated list of features to activate
5252
-f, --force Force overwriting existing crates or binaries
53+
--features FEATURES Space-separated list of features to activate
54+
--all-features Build all available features
5355
--no-default-features Do not build the `default` feature
5456
--debug Build in debug mode instead of release mode
5557
--bin NAME Only install the binary NAME
@@ -104,6 +106,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
104106
jobs: options.flag_jobs,
105107
target: None,
106108
features: &options.flag_features,
109+
all_features: options.flag_all_features,
107110
no_default_features: options.flag_no_default_features,
108111
spec: &[],
109112
exec_engine: None,

src/bin/metadata.rs

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use cargo::util::{CliResult, Config};
77
pub struct Options {
88
flag_color: Option<String>,
99
flag_features: Vec<String>,
10+
flag_all_features: bool,
1011
flag_format_version: u32,
1112
flag_manifest_path: Option<String>,
1213
flag_no_default_features: bool,
@@ -27,6 +28,7 @@ Usage:
2728
Options:
2829
-h, --help Print this message
2930
--features FEATURES Space-separated list of features
31+
--all-features Build all available features
3032
--no-default-features Do not include the `default` feature
3133
--no-deps Output information only about the root package
3234
and don't fetch dependencies.
@@ -50,6 +52,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<ExportInfo
5052

5153
let options = OutputMetadataOptions {
5254
features: options.flag_features,
55+
all_features: options.flag_all_features,
5356
no_default_features: options.flag_no_default_features,
5457
no_deps: options.flag_no_deps,
5558
version: options.flag_format_version,

src/bin/run.rs

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ pub struct Options {
99
flag_example: Option<String>,
1010
flag_jobs: Option<u32>,
1111
flag_features: Vec<String>,
12+
flag_all_features: bool,
1213
flag_no_default_features: bool,
1314
flag_target: Option<String>,
1415
flag_manifest_path: Option<String>,
@@ -34,6 +35,7 @@ Options:
3435
-j N, --jobs N Number of parallel jobs, defaults to # of CPUs
3536
--release Build artifacts in release mode, with optimizations
3637
--features FEATURES Space-separated list of features to also build
38+
--all-features Build all available features
3739
--no-default-features Do not build the `default` feature
3840
--target TRIPLE Build for the target triple
3941
--manifest-path PATH Path to the manifest to execute
@@ -75,6 +77,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
7577
jobs: options.flag_jobs,
7678
target: options.flag_target.as_ref().map(|t| &t[..]),
7779
features: &options.flag_features,
80+
all_features: options.flag_all_features,
7881
no_default_features: options.flag_no_default_features,
7982
spec: &[],
8083
exec_engine: None,

src/bin/rustc.rs

+3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ pub struct Options {
1212
flag_package: Option<String>,
1313
flag_jobs: Option<u32>,
1414
flag_features: Vec<String>,
15+
flag_all_features: bool,
1516
flag_no_default_features: bool,
1617
flag_target: Option<String>,
1718
flag_manifest_path: Option<String>,
@@ -47,6 +48,7 @@ Options:
4748
--release Build artifacts in release mode, with optimizations
4849
--profile PROFILE Profile to build the selected target for
4950
--features FEATURES Features to compile for the package
51+
--all-features Build all available features
5052
--no-default-features Do not compile default features for the package
5153
--target TRIPLE Target triple which compiles will be for
5254
--manifest-path PATH Path to the manifest to fetch dependencies for
@@ -97,6 +99,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
9799
jobs: options.flag_jobs,
98100
target: options.flag_target.as_ref().map(|t| &t[..]),
99101
features: &options.flag_features,
102+
all_features: options.flag_all_features,
100103
no_default_features: options.flag_no_default_features,
101104
spec: &options.flag_package.map_or(Vec::new(), |s| vec![s]),
102105
exec_engine: None,

src/bin/rustdoc.rs

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ pub struct Options {
88
arg_opts: Vec<String>,
99
flag_target: Option<String>,
1010
flag_features: Vec<String>,
11+
flag_all_features: bool,
1112
flag_jobs: Option<u32>,
1213
flag_manifest_path: Option<String>,
1314
flag_no_default_features: bool,
@@ -44,6 +45,7 @@ Options:
4445
--bench NAME Build only the specified benchmark target
4546
--release Build artifacts in release mode, with optimizations
4647
--features FEATURES Space-separated list of features to also build
48+
--all-features Build all available features
4749
--no-default-features Do not build the `default` feature
4850
--target TRIPLE Build for the target triple
4951
--manifest-path PATH Path to the manifest to document
@@ -83,6 +85,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
8385
jobs: options.flag_jobs,
8486
target: options.flag_target.as_ref().map(|t| &t[..]),
8587
features: &options.flag_features,
88+
all_features: options.flag_all_features,
8689
no_default_features: options.flag_no_default_features,
8790
spec: &options.flag_package.map_or(Vec::new(), |s| vec![s]),
8891
exec_engine: None,

src/bin/test.rs

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use cargo::util::important_paths::{find_root_manifest_for_wd};
77
pub struct Options {
88
arg_args: Vec<String>,
99
flag_features: Vec<String>,
10+
flag_all_features: bool,
1011
flag_jobs: Option<u32>,
1112
flag_manifest_path: Option<String>,
1213
flag_no_default_features: bool,
@@ -47,6 +48,7 @@ Options:
4748
-j N, --jobs N Number of parallel jobs, defaults to # of CPUs
4849
--release Build artifacts in release mode, with optimizations
4950
--features FEATURES Space-separated list of features to also build
51+
--all-features Build all available features
5052
--no-default-features Do not build the `default` feature
5153
--target TRIPLE Build for the target triple
5254
--manifest-path PATH Path to the manifest to build tests for
@@ -115,6 +117,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
115117
jobs: options.flag_jobs,
116118
target: options.flag_target.as_ref().map(|s| &s[..]),
117119
features: &options.flag_features,
120+
all_features: options.flag_all_features,
118121
no_default_features: options.flag_no_default_features,
119122
spec: &options.flag_package,
120123
exec_engine: None,

src/cargo/core/package.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ impl Package {
7878
pub fn package_id(&self) -> &PackageId { self.manifest.package_id() }
7979
pub fn root(&self) -> &Path { self.manifest_path.parent().unwrap() }
8080
pub fn summary(&self) -> &Summary { self.manifest.summary() }
81-
pub fn targets(&self) -> &[Target] { self.manifest().targets() }
81+
pub fn targets(&self) -> &[Target] { self.manifest.targets() }
8282
pub fn version(&self) -> &Version { self.package_id().version() }
8383
pub fn authors(&self) -> &Vec<String> { &self.manifest.metadata().authors }
8484
pub fn publish(&self) -> bool { self.manifest.publish() }

src/cargo/ops/cargo_compile.rs

+14-6
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ pub struct CompileOptions<'a> {
4444
pub target: Option<&'a str>,
4545
/// Extra features to build for the root package
4646
pub features: &'a [String],
47+
/// Flag whether all available features should be built for the root package
48+
pub all_features: bool,
4749
/// Flag if the default feature should be built for the root package
4850
pub no_default_features: bool,
4951
/// Root package to build (if None it's the current one)
@@ -94,6 +96,7 @@ pub fn compile<'a>(ws: &Workspace<'a>, options: &CompileOptions<'a>)
9496
pub fn resolve_dependencies<'a>(ws: &Workspace<'a>,
9597
source: Option<Box<Source + 'a>>,
9698
features: Vec<String>,
99+
all_features: bool,
97100
no_default_features: bool)
98101
-> CargoResult<(PackageSet<'a>, Resolve)> {
99102

@@ -115,10 +118,14 @@ pub fn resolve_dependencies<'a>(ws: &Workspace<'a>,
115118

116119
try!(add_overrides(&mut registry, ws));
117120

118-
let method = Method::Required{
119-
dev_deps: true, // TODO: remove this option?
120-
features: &features,
121-
uses_default_features: !no_default_features,
121+
let method = if all_features {
122+
Method::Everything
123+
} else {
124+
Method::Required {
125+
dev_deps: true, // TODO: remove this option?
126+
features: &features,
127+
uses_default_features: !no_default_features,
128+
}
122129
};
123130

124131
let resolved_with_overrides =
@@ -137,7 +144,8 @@ pub fn compile_ws<'a>(ws: &Workspace<'a>,
137144
-> CargoResult<ops::Compilation<'a>> {
138145
let root_package = try!(ws.current());
139146
let CompileOptions { config, jobs, target, spec, features,
140-
no_default_features, release, mode,
147+
all_features, no_default_features,
148+
release, mode,
141149
ref filter, ref exec_engine,
142150
ref target_rustdoc_args,
143151
ref target_rustc_args } = *options;
@@ -157,7 +165,7 @@ pub fn compile_ws<'a>(ws: &Workspace<'a>,
157165
}
158166

159167
let (packages, resolve_with_overrides) = {
160-
try!(resolve_dependencies(ws, source, features, no_default_features))
168+
try!(resolve_dependencies(ws, source, features, all_features, no_default_features))
161169
};
162170

163171
let mut pkgids = Vec::new();

src/cargo/ops/cargo_output_metadata.rs

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const VERSION: u32 = 1;
1010
pub struct OutputMetadataOptions {
1111
pub features: Vec<String>,
1212
pub no_default_features: bool,
13+
pub all_features: bool,
1314
pub no_deps: bool,
1415
pub version: u32,
1516
}
@@ -45,6 +46,7 @@ fn metadata_full(ws: &Workspace,
4546
let deps = try!(ops::resolve_dependencies(ws,
4647
None,
4748
opt.features.clone(),
49+
opt.all_features,
4850
opt.no_default_features));
4951
let (packages, resolve) = deps;
5052

src/cargo/ops/cargo_package.rs

+1
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ fn run_verify(ws: &Workspace, tar: &File, opts: &PackageOpts) -> CargoResult<()>
275275
target: None,
276276
features: &[],
277277
no_default_features: false,
278+
all_features: false,
278279
spec: &[],
279280
filter: ops::CompileFilter::Everything,
280281
exec_engine: None,

src/etc/_cargo

+9
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ case $state in
2020
bench)
2121
_arguments \
2222
'--features=[space separated feature list]' \
23+
'--all-features[enable all available features]' \
2324
'(-h, --help)'{-h,--help}'[show help message]' \
2425
'(-j, --jobs)'{-j,--jobs}'[number of parallel jobs, defaults to # of CPUs]' \
2526
"${command_scope_spec[@]}" \
@@ -36,6 +37,7 @@ case $state in
3637
build)
3738
_arguments \
3839
'--features=[space separated feature list]' \
40+
'--all-features[enable all available features]' \
3941
'(-h, --help)'{-h,--help}'[show help message]' \
4042
'(-j, --jobs)'{-j,--jobs}'[number of parallel jobs, defaults to # of CPUs]' \
4143
"${command_scope_spec[@]}" \
@@ -64,6 +66,7 @@ case $state in
6466
doc)
6567
_arguments \
6668
'--features=[space separated feature list]' \
69+
'--all-features[enable all available features]' \
6770
'(-h, --help)'{-h,--help}'[show help message]' \
6871
'(-j, --jobs)'{-j,--jobs}'[number of parallel jobs, defaults to # of CPUs]' \
6972
'--manifest-path=[path to manifest]: :_files -/' \
@@ -131,6 +134,7 @@ case $state in
131134
'--debug[build in debug mode instead of release mode]' \
132135
'--example[install the specified example instead of binaries]' \
133136
'--features=[space separated feature list]' \
137+
'--all-features[enable all available features]' \
134138
'--git=[URL from which to install the crate]' \
135139
'(-h, --help)'{-h,--help}'[show help message]' \
136140
'(-j, --jobs)'{-j,--jobs}'[number of parallel jobs, defaults to # of CPUs]' \
@@ -168,6 +172,7 @@ case $state in
168172
'--no-default-features[do not include the default feature]' \
169173
'--manifest-path=[path to manifest]: :_files -/' \
170174
'--features=[space separated feature list]' \
175+
'--all-features[enable all available features]' \
171176
'--format-version=[format version(default: 1)]' \
172177
'--color=:colorization option:(auto always never)' \
173178
;;
@@ -241,6 +246,7 @@ case $state in
241246
_arguments \
242247
'--example=[name of the bin target]' \
243248
'--features=[space separated feature list]' \
249+
'--all-features[enable all available features]' \
244250
'(-h, --help)'{-h,--help}'[show help message]' \
245251
'(-j, --jobs)'{-j,--jobs}'[number of parallel jobs, defaults to # of CPUs]' \
246252
'--manifest-path=[path to manifest]: :_files -/' \
@@ -258,6 +264,7 @@ case $state in
258264
_arguments \
259265
'--color=:colorization option:(auto always never)' \
260266
'--features=[features to compile for the package]' \
267+
'--all-features[enable all available features]' \
261268
'(-h, --help)'{-h,--help}'[show help message]' \
262269
'(-j, --jobs)'{-j,--jobs}'=[number of parallel jobs, defaults to # of CPUs]' \
263270
'--manifest-path=[path to the manifest to fetch dependencies for]' \
@@ -275,6 +282,7 @@ case $state in
275282
_arguments \
276283
'--color=:colorization option:(auto always never)' \
277284
'--features=[space-separated list of features to also build]' \
285+
'--all-features[enable all available features]' \
278286
'(-h, --help)'{-h,--help}'[show help message]' \
279287
'(-j, --jobs)'{-j,--jobs}'=[number of parallel jobs, defaults to # of CPUs]' \
280288
'--manifest-path=[path to the manifest to document]' \
@@ -301,6 +309,7 @@ case $state in
301309
test)
302310
_arguments \
303311
'--features=[space separated feature list]' \
312+
'--all-features[enable all available features]' \
304313
'(-h, --help)'{-h,--help}'[show help message]' \
305314
'(-j, --jobs)'{-j,--jobs}'[number of parallel jobs, defaults to # of CPUs]' \
306315
'--manifest-path=[path to manifest]: :_files -/' \

src/etc/cargo.bashcomp.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ _cargo()
1717
local opt_color='--color'
1818
local opt_common="$opt_help $opt_verbose $opt_quiet $opt_color"
1919
local opt_pkg='-p --package'
20-
local opt_feat='--features --no-default-features'
20+
local opt_feat='--features --all-features --no-default-features'
2121
local opt_mani='--manifest-path'
2222
local opt_jobs='-j --jobs'
2323

src/etc/man/cargo-bench.1

+5
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ Space\-separated list of features to also build.
8383
.RS
8484
.RE
8585
.TP
86+
.B \-\-all\-features
87+
Build all available features.
88+
.RS
89+
.RE
90+
.TP
8691
.B \-\-no\-default\-features
8792
Do not build the \f[C]default\f[] feature.
8893
.RS

0 commit comments

Comments
 (0)