From ca833bfdda6779fc53cb9e928c4c078206e62549 Mon Sep 17 00:00:00 2001 From: Tim Date: Fri, 16 Oct 2020 23:37:02 +0200 Subject: [PATCH] Added `--crate-type` override to build and check. --- src/bin/cargo/commands/build.rs | 1 + src/bin/cargo/commands/check.rs | 1 + src/cargo/util/command_prelude.rs | 20 ++++++++++++++++++-- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/bin/cargo/commands/build.rs b/src/bin/cargo/commands/build.rs index e165b250d69..cce1c994b83 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_message_format() .arg_build_plan() .arg_unit_graph() diff --git a/src/bin/cargo/commands/check.rs b/src/bin/cargo/commands/check.rs index 6d26ef2d765..205ee4aa918 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_message_format() .arg_unit_graph() .after_help("Run `cargo help check` for more detailed information.\n") diff --git a/src/cargo/util/command_prelude.rs b/src/cargo/util/command_prelude.rs index 48615358252..61d5dd83551 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; @@ -152,6 +152,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")) } @@ -315,6 +321,16 @@ pub trait ArgMatchesExt { } } } + 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) }