diff --git a/src/bin/cargo/commands/build.rs b/src/bin/cargo/commands/build.rs index 238d0864808..63d593c7fa7 100644 --- a/src/bin/cargo/commands/build.rs +++ b/src/bin/cargo/commands/build.rs @@ -39,6 +39,7 @@ pub fn cli() -> App { .value_name("PATH"), ) .arg_manifest_path() + .arg_crate_type() .arg_ignore_rust_version() .arg_message_format() .arg_build_plan() diff --git a/src/bin/cargo/commands/check.rs b/src/bin/cargo/commands/check.rs index fec00ad8b7e..14bd1cbe219 100644 --- a/src/bin/cargo/commands/check.rs +++ b/src/bin/cargo/commands/check.rs @@ -32,6 +32,7 @@ pub fn cli() -> App { .arg_target_triple("Check for the target triple") .arg_target_dir() .arg_manifest_path() + .arg_crate_type() .arg_ignore_rust_version() .arg_message_format() .arg_unit_graph() diff --git a/src/cargo/util/command_prelude.rs b/src/cargo/util/command_prelude.rs index 4f56ab242f4..0c9513a375e 100644 --- a/src/cargo/util/command_prelude.rs +++ b/src/cargo/util/command_prelude.rs @@ -1,5 +1,5 @@ -use crate::core::compiler::{BuildConfig, MessageFormat}; -use crate::core::Workspace; +use crate::core::compiler::{BuildConfig, CrateType, MessageFormat}; +use crate::core::{TargetKind, Workspace}; use crate::ops::{CompileFilter, CompileOptions, NewOptions, Packages, VersionControl}; use crate::sources::CRATES_IO_REGISTRY; use crate::util::important_paths::find_root_manifest_for_wd; @@ -157,6 +157,12 @@ pub trait AppExt: Sized { self._arg(opt("manifest-path", "Path to Cargo.toml").value_name("PATH")) } + fn arg_crate_type(self) -> Self { + self._arg( + opt("crate-type", "Override crate type for all libraries").value_name("CRATE-TYPE"), + ) + } + fn arg_message_format(self) -> Self { self._arg(multi_opt("message-format", "FMT", "Error format")) } @@ -317,6 +323,16 @@ pub trait ArgMatchesExt { if config.cli_unstable().avoid_dev_deps { ws.set_require_optional_deps(false); } + if let Some(crate_type) = self._value_of("crate-type") { + if let Ok(current) = ws.current_mut() { + for target in current.manifest_mut().targets_mut() { + if let TargetKind::Lib(_) = target.kind() { + let crate_type = CrateType::from(&crate_type.to_owned()); + target.set_kind(TargetKind::Lib(vec![crate_type])); + } + } + } + } Ok(ws) }