Skip to content

Commit

Permalink
Auto merge of #13902 - heisen-li:plugin, r=weihanglo
Browse files Browse the repository at this point in the history
fix(toml): remove `lib.plugin` key support and make it warning

### What does this PR try to resolve?

Remove `lib.plugin` key, making it an "unused key" warning.

Remove some of the tests, which should look useless (I hope I'm understanding this

- [x] Remove key, and related tests.
- [x] Adjust the documentation about the plugin.
- [ ] Some of the comments and function names have not yet finished being modified.

part of #13629

Closes #13246
  • Loading branch information
bors committed Jun 9, 2024
2 parents fe7e283 + a969971 commit 54d9c33
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 466 deletions.
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 @@ -869,11 +847,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
3 changes: 1 addition & 2 deletions src/doc/src/reference/cargo-targets.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ test = true # Is tested by default.
doctest = true # Documentation examples are tested by default.
bench = true # Is benchmarked by default.
doc = true # Is documented by default.
plugin = false # Used as a compiler plugin (deprecated).
proc-macro = false # Set to `true` for a proc-macro library.
harness = true # Use libtest harness.
edition = "2015" # The edition of the target.
Expand Down Expand Up @@ -247,7 +246,7 @@ libraries and binaries.
### The `plugin` field

This field is used for `rustc` plugins, which are being deprecated.
This option is deprecated and unused.

### The `proc-macro` field

Expand Down
2 changes: 1 addition & 1 deletion src/doc/src/reference/environment-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ Cargo includes the following paths:
Cargo to properly set the environment if additional libraries on the system
are needed in the search path.
* The base output directory, such as `target/debug`, and the "deps" directory.
This is mostly for legacy support of `rustc` compiler plugins.
This is mostly for support of proc-macros.
* The rustc sysroot library path. This generally is not important to most
users.

Expand Down
55 changes: 0 additions & 55 deletions tests/testsuite/build_script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2178,61 +2178,6 @@ fn shared_dep_with_a_build_script() {
p.cargo("build -v").run();
}

#[cargo_test]
fn transitive_dep_host() {
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.5.0"
edition = "2015"
authors = []
build = "build.rs"
[build-dependencies.b]
path = "b"
"#,
)
.file("src/lib.rs", "")
.file("build.rs", "fn main() {}")
.file(
"a/Cargo.toml",
r#"
[package]
name = "a"
version = "0.5.0"
edition = "2015"
authors = []
links = "foo"
build = "build.rs"
"#,
)
.file("a/build.rs", "fn main() {}")
.file("a/src/lib.rs", "")
.file(
"b/Cargo.toml",
r#"
[package]
name = "b"
version = "0.5.0"
edition = "2015"
authors = []
[lib]
name = "b"
plugin = true
[dependencies.a]
path = "../a"
"#,
)
.file("b/src/lib.rs", "")
.build();
p.cargo("build").run();
}

#[cargo_test]
fn test_a_lib_with_a_build_command() {
let p = project()
Expand Down
41 changes: 0 additions & 41 deletions tests/testsuite/cross_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -883,47 +883,6 @@ fn build_script_only_host() {
p.cargo("build -v --target").arg(&target).run();
}

#[cargo_test]
fn plugin_build_script_right_arch() {
if cross_compile::disabled() {
return;
}
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.0.1"
edition = "2015"
authors = []
build = "build.rs"
[lib]
name = "foo"
plugin = true
"#,
)
.file("build.rs", "fn main() {}")
.file("src/lib.rs", "")
.build();

p.cargo("build -v --target")
.arg(cross_compile::alternate())
.with_stderr(
"\
[WARNING] support for rustc plugins has been removed from rustc. library `foo` should not specify `plugin = true`
[WARNING] support for `plugin = true` will be removed from cargo in the future
[COMPILING] foo v0.0.1 ([..])
[RUNNING] `rustc [..] build.rs [..]`
[RUNNING] `[..]/build-script-build`
[RUNNING] `rustc [..] src/lib.rs [..]`
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]
",
)
.run();
}

#[cargo_test]
fn build_script_with_platform_specific_dependencies() {
if cross_compile::disabled() {
Expand Down
36 changes: 25 additions & 11 deletions tests/testsuite/proc_macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ fn proc_macro_crate_type_warning() {
}

#[cargo_test]
fn proc_macro_crate_type_warning_plugin() {
fn lib_plugin_unused_key_warning() {
let foo = project()
.file(
"Cargo.toml",
Expand All @@ -356,26 +356,40 @@ fn proc_macro_crate_type_warning_plugin() {
version = "0.1.0"
edition = "2015"
[lib]
crate-type = ["proc-macro"]
plugin = true
"#,
)
.file("src/lib.rs", "")
.build();

foo.cargo("check")
.with_stderr_contains(
"[WARNING] support for rustc plugins has been removed from rustc. \
library `foo` should not specify `plugin = true`")
.with_stderr_contains(
"[WARNING] support for `plugin = true` will be removed from cargo in the future")
.with_stderr_contains(
"[WARNING] proc-macro library `foo` should not specify `plugin = true`")
.with_stderr_contains(
"[WARNING] library `foo` should only specify `proc-macro = true` instead of setting `crate-type`")
.with_stderr_contains("[WARNING] unused manifest key: lib.plugin")
.run();
}

#[cargo_test]
fn proc_macro_crate_type_warning_plugin() {
let foo = project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.1.0"
edition = "2015"
[lib]
crate-type = ["proc-macro"]
"#,
)
.file("src/lib.rs", "")
.build();

foo.cargo("check")
.with_stderr_contains(
"[WARNING] library `foo` should only specify `proc-macro = true` instead of setting `crate-type`")
.run();
}

#[cargo_test]
fn proc_macro_crate_type_multiple() {
let foo = project()
Expand Down
Loading

0 comments on commit 54d9c33

Please sign in to comment.