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

fix(toml): remove lib.plugin key support and make it warning #13902

Merged
merged 3 commits into from
Jun 9, 2024
Merged
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
Next Next commit
fix(toml): remove lib.plugin key
  • Loading branch information
heisen-li committed May 16, 2024
commit 1f48eab757c627b80d79d6ac6e6088bc434f09ae
1 change: 0 additions & 1 deletion crates/cargo-util-schemas/src/manifest/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1223,7 +1223,6 @@ pub struct TomlTarget {
pub doctest: Option<bool>,
pub bench: Option<bool>,
pub doc: Option<bool>,
pub plugin: Option<bool>,
pub doc_scrape_examples: Option<bool>,
pub proc_macro: Option<bool>,
#[serde(rename = "proc_macro")]
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/core/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -905,7 +905,7 @@ impl Target {
pub fn documented(&self) -> bool {
self.inner.doc
}
// A plugin, proc-macro, or build-script.
// A proc-macro or build-script.
pub fn for_host(&self) -> bool {
self.inner.for_host
}
Expand Down
41 changes: 8 additions & 33 deletions src/cargo/util/toml/targets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,17 +188,6 @@ fn to_lib_target(
let path = lib.path.as_ref().expect("previously resolved");
let path = package_root.join(&path.0);

if lib.plugin == Some(true) {
warnings.push(format!(
"support for rustc plugins has been removed from rustc. \
library `{}` should not specify `plugin = true`",
name_or_panic(lib)
));
warnings.push(format!(
"support for `plugin = true` will be removed from cargo in the future"
));
}

// Per the Macros 1.1 RFC:
//
// > Initially if a crate is compiled with the `proc-macro` crate type
Expand All @@ -208,8 +197,8 @@ fn to_lib_target(
//
// A plugin requires exporting plugin_registrar so a crate cannot be
// both at once.
let crate_types = match (lib.crate_types(), lib.plugin, lib.proc_macro()) {
(Some(kinds), _, _)
let crate_types = match (lib.crate_types(), lib.proc_macro()) {
(Some(kinds), _)
if kinds.contains(&CrateType::Dylib.as_str().to_owned())
&& kinds.contains(&CrateType::Cdylib.as_str().to_owned()) =>
{
Expand All @@ -218,14 +207,7 @@ fn to_lib_target(
name_or_panic(lib)
));
}
(Some(kinds), _, _) if kinds.contains(&"proc-macro".to_string()) => {
if let Some(true) = lib.plugin {
// This is a warning to retain backwards compatibility.
warnings.push(format!(
"proc-macro library `{}` should not specify `plugin = true`",
name_or_panic(lib)
));
}
(Some(kinds), _) if kinds.contains(&"proc-macro".to_string()) => {
warnings.push(format!(
"library `{}` should only specify `proc-macro = true` instead of setting `crate-type`",
name_or_panic(lib)
Expand All @@ -235,13 +217,9 @@ fn to_lib_target(
}
vec![CrateType::ProcMacro]
}
(_, Some(true), Some(true)) => {
anyhow::bail!("`lib.plugin` and `lib.proc-macro` cannot both be `true`")
}
(Some(kinds), _, _) => kinds.iter().map(|s| s.into()).collect(),
(None, Some(true), _) => vec![CrateType::Dylib],
(None, _, Some(true)) => vec![CrateType::ProcMacro],
(None, _, _) => vec![CrateType::Lib],
(Some(kinds), _) => kinds.iter().map(|s| s.into()).collect(),
(None, Some(true)) => vec![CrateType::ProcMacro],
(None, _) => vec![CrateType::Lib],
};

let mut target = Target::lib_target(name_or_panic(lib), crate_types, path, edition);
Expand Down Expand Up @@ -863,11 +841,8 @@ fn configure(toml: &TomlTarget, target: &mut Target) -> CargoResult<()> {
Some(false) => RustdocScrapeExamples::Disabled,
Some(true) => RustdocScrapeExamples::Enabled,
})
.set_for_host(match (toml.plugin, toml.proc_macro()) {
(None, None) => t2.for_host(),
(Some(true), _) | (_, Some(true)) => true,
(Some(false), _) | (_, Some(false)) => false,
});
.set_for_host(toml.proc_macro().unwrap_or_else(|| t2.for_host()));

if let Some(edition) = toml.edition.clone() {
target.set_edition(
edition
Expand Down