Skip to content

Commit ee78456

Browse files
committed
Only avoid dev deps in cargo install and cargo build --avoid-dev-deps
1 parent 7de30dd commit ee78456

File tree

4 files changed

+17
-3
lines changed

4 files changed

+17
-3
lines changed

src/bin/build.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ pub struct Options {
1212
flag_features: Vec<String>,
1313
flag_all_features: bool,
1414
flag_no_default_features: bool,
15+
flag_avoid_dev_deps: bool,
1516
flag_target: Option<String>,
1617
flag_manifest_path: Option<String>,
1718
flag_verbose: u32,
@@ -63,6 +64,7 @@ Options:
6364
--features FEATURES Space-separated list of features to also build
6465
--all-features Build all available features
6566
--no-default-features Do not build the `default` feature
67+
--avoid-dev-deps Avoid installing dev-dependencies if possible
6668
--target TRIPLE Build for the target triple
6769
--manifest-path PATH Path to the manifest to compile
6870
-v, --verbose ... Use verbose output (-vv very verbose/build.rs output)
@@ -98,7 +100,10 @@ pub fn execute(options: Options, config: &mut Config) -> CliResult {
98100
&options.flag_z)?;
99101

100102
let root = find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())?;
101-
let ws = Workspace::new(&root, config)?;
103+
let mut ws = Workspace::new(&root, config)?;
104+
if options.flag_avoid_dev_deps {
105+
ws.set_require_optional_deps(false);
106+
}
102107

103108
let spec = Packages::from_flags(options.flag_all,
104109
&options.flag_exclude,

src/cargo/core/workspace.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,11 @@ impl<'cfg> Workspace<'cfg> {
300300
self.require_optional_deps
301301
}
302302

303+
pub fn set_require_optional_deps<'a>(&'a mut self, require_optional_deps: bool) -> &mut Workspace<'cfg> {
304+
self.require_optional_deps = require_optional_deps;
305+
self
306+
}
307+
303308
/// Finds the root of a workspace for the crate whose manifest is located
304309
/// at `manifest_path`.
305310
///

src/cargo/ops/cargo_compile.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ pub fn compile_ws<'a>(ws: &Workspace<'a>,
228228
let specs = spec.into_package_id_specs(ws)?;
229229
let features = Method::split_features(features);
230230
let method = Method::Required {
231-
dev_deps: filter.need_dev_deps(),
231+
dev_deps: ws.require_optional_deps() || filter.need_dev_deps(),
232232
features: &features,
233233
all_features,
234234
uses_default_features: !no_default_features,

src/cargo/ops/cargo_install.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,11 @@ fn install_one(root: &Filesystem,
175175

176176
let ws = match overidden_target_dir {
177177
Some(dir) => Workspace::ephemeral(pkg, config, Some(dir), false)?,
178-
None => Workspace::new(pkg.manifest_path(), config)?,
178+
None => {
179+
let mut ws = Workspace::new(pkg.manifest_path(), config)?;
180+
ws.set_require_optional_deps(false);
181+
ws
182+
}
179183
};
180184
let pkg = ws.current()?;
181185

0 commit comments

Comments
 (0)