Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/bin/cargo/commands/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions src/bin/cargo/commands/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
20 changes: 18 additions & 2 deletions src/cargo/util/command_prelude.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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"),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
opt("crate-type", "Override crate type for all libraries").value_name("CRATE-TYPE"),
opt("libs-crate-type", "Override crate type for all libraries").value_name("CRATE-TYPE"),

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this necessary? Since crate-type always applies to libraries and examples. I think there are two options:

  1. Call it --crate-type and apply the modification to both the library and all example targets. (This PR currently only applies it to libraries, not examples).
  2. Call it --libs-crate-type and apply the modification only to the library target.

)
}

fn arg_message_format(self) -> Self {
self._arg(multi_opt("message-format", "FMT", "Error format"))
}
Expand Down Expand Up @@ -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)
}

Expand Down