Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a --crate-type override to build and check. #8789

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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_ignore_rust_version()
.arg_message_format()
.arg_build_plan()
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_ignore_rust_version()
.arg_message_format()
.arg_unit_graph()
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 @@ -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"),
Copy link
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
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 @@ -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)
}

Expand Down