Skip to content

Commit

Permalink
Auto merge of #3038 - esclear:master, r=alexcrichton
Browse files Browse the repository at this point in the history
Add --all-features flag to cargo

As (more or less) requested in #1173 I added a `--all-features` flag to cargo that builds all available features.

I hope I documented it in all the right places.

If there's something weird or wrong, please give me a heads up.
  • Loading branch information
bors authored Aug 31, 2016
2 parents 3e41b6b + 1f8b398 commit e713e7f
Show file tree
Hide file tree
Showing 25 changed files with 145 additions and 9 deletions.
3 changes: 3 additions & 0 deletions src/bin/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub struct Options {
flag_package: Vec<String>,
flag_jobs: Option<u32>,
flag_features: Vec<String>,
flag_all_features: bool,
flag_no_default_features: bool,
flag_target: Option<String>,
flag_manifest_path: Option<String>,
Expand Down Expand Up @@ -42,6 +43,7 @@ Options:
-p SPEC, --package SPEC ... Package to run benchmarks for
-j N, --jobs N Number of parallel jobs, defaults to # of CPUs
--features FEATURES Space-separated list of features to also build
--all-features Build all available features
--no-default-features Do not build the `default` feature
--target TRIPLE Build for the target triple
--manifest-path PATH Path to the manifest to build benchmarks for
Expand Down Expand Up @@ -83,6 +85,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
jobs: options.flag_jobs,
target: options.flag_target.as_ref().map(|s| &s[..]),
features: &options.flag_features,
all_features: options.flag_all_features,
no_default_features: options.flag_no_default_features,
spec: &options.flag_package,
exec_engine: None,
Expand Down
3 changes: 3 additions & 0 deletions src/bin/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub struct Options {
flag_package: Vec<String>,
flag_jobs: Option<u32>,
flag_features: Vec<String>,
flag_all_features: bool,
flag_no_default_features: bool,
flag_target: Option<String>,
flag_manifest_path: Option<String>,
Expand Down Expand Up @@ -44,6 +45,7 @@ Options:
--bench NAME Build only the specified benchmark target
--release Build artifacts in release mode, with optimizations
--features FEATURES Space-separated list of features to also build
--all-features Build all available features
--no-default-features Do not build the `default` feature
--target TRIPLE Build for the target triple
--manifest-path PATH Path to the manifest to compile
Expand Down Expand Up @@ -79,6 +81,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
jobs: options.flag_jobs,
target: options.flag_target.as_ref().map(|t| &t[..]),
features: &options.flag_features,
all_features: options.flag_all_features,
no_default_features: options.flag_no_default_features,
spec: &options.flag_package,
exec_engine: None,
Expand Down
3 changes: 3 additions & 0 deletions src/bin/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use cargo::util::important_paths::{find_root_manifest_for_wd};
pub struct Options {
flag_target: Option<String>,
flag_features: Vec<String>,
flag_all_features: bool,
flag_jobs: Option<u32>,
flag_manifest_path: Option<String>,
flag_no_default_features: bool,
Expand Down Expand Up @@ -39,6 +40,7 @@ Options:
--bin NAME Document only the specified binary
--release Build artifacts in release mode, with optimizations
--features FEATURES Space-separated list of features to also build
--all-features Build all available features
--no-default-features Do not build the `default` feature
--target TRIPLE Build for the target triple
--manifest-path PATH Path to the manifest to document
Expand Down Expand Up @@ -74,6 +76,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
jobs: options.flag_jobs,
target: options.flag_target.as_ref().map(|t| &t[..]),
features: &options.flag_features,
all_features: options.flag_all_features,
no_default_features: options.flag_no_default_features,
spec: &options.flag_package,
exec_engine: None,
Expand Down
5 changes: 4 additions & 1 deletion src/bin/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use cargo::util::{CliResult, Config, ToUrl};
pub struct Options {
flag_jobs: Option<u32>,
flag_features: Vec<String>,
flag_all_features: bool,
flag_no_default_features: bool,
flag_debug: bool,
flag_bin: Vec<String>,
Expand Down Expand Up @@ -48,8 +49,9 @@ Specifying what crate to install:
Build and install options:
-h, --help Print this message
-j N, --jobs N Number of parallel jobs, defaults to # of CPUs
--features FEATURES Space-separated list of features to activate
-f, --force Force overwriting existing crates or binaries
--features FEATURES Space-separated list of features to activate
--all-features Build all available features
--no-default-features Do not build the `default` feature
--debug Build in debug mode instead of release mode
--bin NAME Only install the binary NAME
Expand Down Expand Up @@ -104,6 +106,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
jobs: options.flag_jobs,
target: None,
features: &options.flag_features,
all_features: options.flag_all_features,
no_default_features: options.flag_no_default_features,
spec: &[],
exec_engine: None,
Expand Down
3 changes: 3 additions & 0 deletions src/bin/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use cargo::util::{CliResult, Config};
pub struct Options {
flag_color: Option<String>,
flag_features: Vec<String>,
flag_all_features: bool,
flag_format_version: u32,
flag_manifest_path: Option<String>,
flag_no_default_features: bool,
Expand All @@ -27,6 +28,7 @@ Usage:
Options:
-h, --help Print this message
--features FEATURES Space-separated list of features
--all-features Build all available features
--no-default-features Do not include the `default` feature
--no-deps Output information only about the root package
and don't fetch dependencies.
Expand All @@ -50,6 +52,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<ExportInfo

let options = OutputMetadataOptions {
features: options.flag_features,
all_features: options.flag_all_features,
no_default_features: options.flag_no_default_features,
no_deps: options.flag_no_deps,
version: options.flag_format_version,
Expand Down
3 changes: 3 additions & 0 deletions src/bin/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub struct Options {
flag_example: Option<String>,
flag_jobs: Option<u32>,
flag_features: Vec<String>,
flag_all_features: bool,
flag_no_default_features: bool,
flag_target: Option<String>,
flag_manifest_path: Option<String>,
Expand All @@ -34,6 +35,7 @@ Options:
-j N, --jobs N Number of parallel jobs, defaults to # of CPUs
--release Build artifacts in release mode, with optimizations
--features FEATURES Space-separated list of features to also build
--all-features Build all available features
--no-default-features Do not build the `default` feature
--target TRIPLE Build for the target triple
--manifest-path PATH Path to the manifest to execute
Expand Down Expand Up @@ -75,6 +77,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
jobs: options.flag_jobs,
target: options.flag_target.as_ref().map(|t| &t[..]),
features: &options.flag_features,
all_features: options.flag_all_features,
no_default_features: options.flag_no_default_features,
spec: &[],
exec_engine: None,
Expand Down
3 changes: 3 additions & 0 deletions src/bin/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub struct Options {
flag_package: Option<String>,
flag_jobs: Option<u32>,
flag_features: Vec<String>,
flag_all_features: bool,
flag_no_default_features: bool,
flag_target: Option<String>,
flag_manifest_path: Option<String>,
Expand Down Expand Up @@ -47,6 +48,7 @@ Options:
--release Build artifacts in release mode, with optimizations
--profile PROFILE Profile to build the selected target for
--features FEATURES Features to compile for the package
--all-features Build all available features
--no-default-features Do not compile default features for the package
--target TRIPLE Target triple which compiles will be for
--manifest-path PATH Path to the manifest to fetch dependencies for
Expand Down Expand Up @@ -97,6 +99,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
jobs: options.flag_jobs,
target: options.flag_target.as_ref().map(|t| &t[..]),
features: &options.flag_features,
all_features: options.flag_all_features,
no_default_features: options.flag_no_default_features,
spec: &options.flag_package.map_or(Vec::new(), |s| vec![s]),
exec_engine: None,
Expand Down
3 changes: 3 additions & 0 deletions src/bin/rustdoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ pub struct Options {
arg_opts: Vec<String>,
flag_target: Option<String>,
flag_features: Vec<String>,
flag_all_features: bool,
flag_jobs: Option<u32>,
flag_manifest_path: Option<String>,
flag_no_default_features: bool,
Expand Down Expand Up @@ -44,6 +45,7 @@ Options:
--bench NAME Build only the specified benchmark target
--release Build artifacts in release mode, with optimizations
--features FEATURES Space-separated list of features to also build
--all-features Build all available features
--no-default-features Do not build the `default` feature
--target TRIPLE Build for the target triple
--manifest-path PATH Path to the manifest to document
Expand Down Expand Up @@ -83,6 +85,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
jobs: options.flag_jobs,
target: options.flag_target.as_ref().map(|t| &t[..]),
features: &options.flag_features,
all_features: options.flag_all_features,
no_default_features: options.flag_no_default_features,
spec: &options.flag_package.map_or(Vec::new(), |s| vec![s]),
exec_engine: None,
Expand Down
3 changes: 3 additions & 0 deletions src/bin/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use cargo::util::important_paths::{find_root_manifest_for_wd};
pub struct Options {
arg_args: Vec<String>,
flag_features: Vec<String>,
flag_all_features: bool,
flag_jobs: Option<u32>,
flag_manifest_path: Option<String>,
flag_no_default_features: bool,
Expand Down Expand Up @@ -47,6 +48,7 @@ Options:
-j N, --jobs N Number of parallel jobs, defaults to # of CPUs
--release Build artifacts in release mode, with optimizations
--features FEATURES Space-separated list of features to also build
--all-features Build all available features
--no-default-features Do not build the `default` feature
--target TRIPLE Build for the target triple
--manifest-path PATH Path to the manifest to build tests for
Expand Down Expand Up @@ -115,6 +117,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
jobs: options.flag_jobs,
target: options.flag_target.as_ref().map(|s| &s[..]),
features: &options.flag_features,
all_features: options.flag_all_features,
no_default_features: options.flag_no_default_features,
spec: &options.flag_package,
exec_engine: None,
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/core/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ impl Package {
pub fn package_id(&self) -> &PackageId { self.manifest.package_id() }
pub fn root(&self) -> &Path { self.manifest_path.parent().unwrap() }
pub fn summary(&self) -> &Summary { self.manifest.summary() }
pub fn targets(&self) -> &[Target] { self.manifest().targets() }
pub fn targets(&self) -> &[Target] { self.manifest.targets() }
pub fn version(&self) -> &Version { self.package_id().version() }
pub fn authors(&self) -> &Vec<String> { &self.manifest.metadata().authors }
pub fn publish(&self) -> bool { self.manifest.publish() }
Expand Down
20 changes: 14 additions & 6 deletions src/cargo/ops/cargo_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ pub struct CompileOptions<'a> {
pub target: Option<&'a str>,
/// Extra features to build for the root package
pub features: &'a [String],
/// Flag whether all available features should be built for the root package
pub all_features: bool,
/// Flag if the default feature should be built for the root package
pub no_default_features: bool,
/// Root package to build (if None it's the current one)
Expand Down Expand Up @@ -94,6 +96,7 @@ pub fn compile<'a>(ws: &Workspace<'a>, options: &CompileOptions<'a>)
pub fn resolve_dependencies<'a>(ws: &Workspace<'a>,
source: Option<Box<Source + 'a>>,
features: Vec<String>,
all_features: bool,
no_default_features: bool)
-> CargoResult<(PackageSet<'a>, Resolve)> {

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

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

let method = Method::Required{
dev_deps: true, // TODO: remove this option?
features: &features,
uses_default_features: !no_default_features,
let method = if all_features {
Method::Everything
} else {
Method::Required {
dev_deps: true, // TODO: remove this option?
features: &features,
uses_default_features: !no_default_features,
}
};

let resolved_with_overrides =
Expand All @@ -137,7 +144,8 @@ pub fn compile_ws<'a>(ws: &Workspace<'a>,
-> CargoResult<ops::Compilation<'a>> {
let root_package = try!(ws.current());
let CompileOptions { config, jobs, target, spec, features,
no_default_features, release, mode,
all_features, no_default_features,
release, mode,
ref filter, ref exec_engine,
ref target_rustdoc_args,
ref target_rustc_args } = *options;
Expand All @@ -157,7 +165,7 @@ pub fn compile_ws<'a>(ws: &Workspace<'a>,
}

let (packages, resolve_with_overrides) = {
try!(resolve_dependencies(ws, source, features, no_default_features))
try!(resolve_dependencies(ws, source, features, all_features, no_default_features))
};

let mut pkgids = Vec::new();
Expand Down
2 changes: 2 additions & 0 deletions src/cargo/ops/cargo_output_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const VERSION: u32 = 1;
pub struct OutputMetadataOptions {
pub features: Vec<String>,
pub no_default_features: bool,
pub all_features: bool,
pub no_deps: bool,
pub version: u32,
}
Expand Down Expand Up @@ -45,6 +46,7 @@ fn metadata_full(ws: &Workspace,
let deps = try!(ops::resolve_dependencies(ws,
None,
opt.features.clone(),
opt.all_features,
opt.no_default_features));
let (packages, resolve) = deps;

Expand Down
1 change: 1 addition & 0 deletions src/cargo/ops/cargo_package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ fn run_verify(ws: &Workspace, tar: &File, opts: &PackageOpts) -> CargoResult<()>
target: None,
features: &[],
no_default_features: false,
all_features: false,
spec: &[],
filter: ops::CompileFilter::Everything,
exec_engine: None,
Expand Down
9 changes: 9 additions & 0 deletions src/etc/_cargo
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ case $state in
bench)
_arguments \
'--features=[space separated feature list]' \
'--all-features[enable all available features]' \
'(-h, --help)'{-h,--help}'[show help message]' \
'(-j, --jobs)'{-j,--jobs}'[number of parallel jobs, defaults to # of CPUs]' \
"${command_scope_spec[@]}" \
Expand All @@ -36,6 +37,7 @@ case $state in
build)
_arguments \
'--features=[space separated feature list]' \
'--all-features[enable all available features]' \
'(-h, --help)'{-h,--help}'[show help message]' \
'(-j, --jobs)'{-j,--jobs}'[number of parallel jobs, defaults to # of CPUs]' \
"${command_scope_spec[@]}" \
Expand Down Expand Up @@ -64,6 +66,7 @@ case $state in
doc)
_arguments \
'--features=[space separated feature list]' \
'--all-features[enable all available features]' \
'(-h, --help)'{-h,--help}'[show help message]' \
'(-j, --jobs)'{-j,--jobs}'[number of parallel jobs, defaults to # of CPUs]' \
'--manifest-path=[path to manifest]: :_files -/' \
Expand Down Expand Up @@ -131,6 +134,7 @@ case $state in
'--debug[build in debug mode instead of release mode]' \
'--example[install the specified example instead of binaries]' \
'--features=[space separated feature list]' \
'--all-features[enable all available features]' \
'--git=[URL from which to install the crate]' \
'(-h, --help)'{-h,--help}'[show help message]' \
'(-j, --jobs)'{-j,--jobs}'[number of parallel jobs, defaults to # of CPUs]' \
Expand Down Expand Up @@ -168,6 +172,7 @@ case $state in
'--no-default-features[do not include the default feature]' \
'--manifest-path=[path to manifest]: :_files -/' \
'--features=[space separated feature list]' \
'--all-features[enable all available features]' \
'--format-version=[format version(default: 1)]' \
'--color=:colorization option:(auto always never)' \
;;
Expand Down Expand Up @@ -241,6 +246,7 @@ case $state in
_arguments \
'--example=[name of the bin target]' \
'--features=[space separated feature list]' \
'--all-features[enable all available features]' \
'(-h, --help)'{-h,--help}'[show help message]' \
'(-j, --jobs)'{-j,--jobs}'[number of parallel jobs, defaults to # of CPUs]' \
'--manifest-path=[path to manifest]: :_files -/' \
Expand All @@ -258,6 +264,7 @@ case $state in
_arguments \
'--color=:colorization option:(auto always never)' \
'--features=[features to compile for the package]' \
'--all-features[enable all available features]' \
'(-h, --help)'{-h,--help}'[show help message]' \
'(-j, --jobs)'{-j,--jobs}'=[number of parallel jobs, defaults to # of CPUs]' \
'--manifest-path=[path to the manifest to fetch dependencies for]' \
Expand All @@ -275,6 +282,7 @@ case $state in
_arguments \
'--color=:colorization option:(auto always never)' \
'--features=[space-separated list of features to also build]' \
'--all-features[enable all available features]' \
'(-h, --help)'{-h,--help}'[show help message]' \
'(-j, --jobs)'{-j,--jobs}'=[number of parallel jobs, defaults to # of CPUs]' \
'--manifest-path=[path to the manifest to document]' \
Expand All @@ -301,6 +309,7 @@ case $state in
test)
_arguments \
'--features=[space separated feature list]' \
'--all-features[enable all available features]' \
'(-h, --help)'{-h,--help}'[show help message]' \
'(-j, --jobs)'{-j,--jobs}'[number of parallel jobs, defaults to # of CPUs]' \
'--manifest-path=[path to manifest]: :_files -/' \
Expand Down
2 changes: 1 addition & 1 deletion src/etc/cargo.bashcomp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ _cargo()
local opt_color='--color'
local opt_common="$opt_help $opt_verbose $opt_quiet $opt_color"
local opt_pkg='-p --package'
local opt_feat='--features --no-default-features'
local opt_feat='--features --all-features --no-default-features'
local opt_mani='--manifest-path'
local opt_jobs='-j --jobs'

Expand Down
5 changes: 5 additions & 0 deletions src/etc/man/cargo-bench.1
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ Space\-separated list of features to also build.
.RS
.RE
.TP
.B \-\-all\-features
Build all available features.
.RS
.RE
.TP
.B \-\-no\-default\-features
Do not build the \f[C]default\f[] feature.
.RS
Expand Down
Loading

0 comments on commit e713e7f

Please sign in to comment.