Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 7da4ff3

Browse files
committedJun 9, 2024
Auto merge of #13902 - heisen-li:plugin, r=<try>
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
2 parents 580dbc6 + a969971 commit 7da4ff3

File tree

9 files changed

+37
-466
lines changed

9 files changed

+37
-466
lines changed
 

‎crates/cargo-util-schemas/src/manifest/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1223,7 +1223,6 @@ pub struct TomlTarget {
12231223
pub doctest: Option<bool>,
12241224
pub bench: Option<bool>,
12251225
pub doc: Option<bool>,
1226-
pub plugin: Option<bool>,
12271226
pub doc_scrape_examples: Option<bool>,
12281227
pub proc_macro: Option<bool>,
12291228
#[serde(rename = "proc_macro")]

‎src/cargo/core/manifest.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -905,7 +905,7 @@ impl Target {
905905
pub fn documented(&self) -> bool {
906906
self.inner.doc
907907
}
908-
// A plugin, proc-macro, or build-script.
908+
// A proc-macro or build-script.
909909
pub fn for_host(&self) -> bool {
910910
self.inner.for_host
911911
}

‎src/cargo/util/toml/targets.rs

+8-33
Original file line numberDiff line numberDiff line change
@@ -188,17 +188,6 @@ fn to_lib_target(
188188
let path = lib.path.as_ref().expect("previously resolved");
189189
let path = package_root.join(&path.0);
190190

191-
if lib.plugin == Some(true) {
192-
warnings.push(format!(
193-
"support for rustc plugins has been removed from rustc. \
194-
library `{}` should not specify `plugin = true`",
195-
name_or_panic(lib)
196-
));
197-
warnings.push(format!(
198-
"support for `plugin = true` will be removed from cargo in the future"
199-
));
200-
}
201-
202191
// Per the Macros 1.1 RFC:
203192
//
204193
// > Initially if a crate is compiled with the `proc-macro` crate type
@@ -208,8 +197,8 @@ fn to_lib_target(
208197
//
209198
// A plugin requires exporting plugin_registrar so a crate cannot be
210199
// both at once.
211-
let crate_types = match (lib.crate_types(), lib.plugin, lib.proc_macro()) {
212-
(Some(kinds), _, _)
200+
let crate_types = match (lib.crate_types(), lib.proc_macro()) {
201+
(Some(kinds), _)
213202
if kinds.contains(&CrateType::Dylib.as_str().to_owned())
214203
&& kinds.contains(&CrateType::Cdylib.as_str().to_owned()) =>
215204
{
@@ -218,14 +207,7 @@ fn to_lib_target(
218207
name_or_panic(lib)
219208
));
220209
}
221-
(Some(kinds), _, _) if kinds.contains(&"proc-macro".to_string()) => {
222-
if let Some(true) = lib.plugin {
223-
// This is a warning to retain backwards compatibility.
224-
warnings.push(format!(
225-
"proc-macro library `{}` should not specify `plugin = true`",
226-
name_or_panic(lib)
227-
));
228-
}
210+
(Some(kinds), _) if kinds.contains(&"proc-macro".to_string()) => {
229211
warnings.push(format!(
230212
"library `{}` should only specify `proc-macro = true` instead of setting `crate-type`",
231213
name_or_panic(lib)
@@ -235,13 +217,9 @@ fn to_lib_target(
235217
}
236218
vec![CrateType::ProcMacro]
237219
}
238-
(_, Some(true), Some(true)) => {
239-
anyhow::bail!("`lib.plugin` and `lib.proc-macro` cannot both be `true`")
240-
}
241-
(Some(kinds), _, _) => kinds.iter().map(|s| s.into()).collect(),
242-
(None, Some(true), _) => vec![CrateType::Dylib],
243-
(None, _, Some(true)) => vec![CrateType::ProcMacro],
244-
(None, _, _) => vec![CrateType::Lib],
220+
(Some(kinds), _) => kinds.iter().map(|s| s.into()).collect(),
221+
(None, Some(true)) => vec![CrateType::ProcMacro],
222+
(None, _) => vec![CrateType::Lib],
245223
};
246224

247225
let mut target = Target::lib_target(name_or_panic(lib), crate_types, path, edition);
@@ -869,11 +847,8 @@ fn configure(toml: &TomlTarget, target: &mut Target) -> CargoResult<()> {
869847
Some(false) => RustdocScrapeExamples::Disabled,
870848
Some(true) => RustdocScrapeExamples::Enabled,
871849
})
872-
.set_for_host(match (toml.plugin, toml.proc_macro()) {
873-
(None, None) => t2.for_host(),
874-
(Some(true), _) | (_, Some(true)) => true,
875-
(Some(false), _) | (_, Some(false)) => false,
876-
});
850+
.set_for_host(toml.proc_macro().unwrap_or_else(|| t2.for_host()));
851+
877852
if let Some(edition) = toml.edition.clone() {
878853
target.set_edition(
879854
edition

‎src/doc/src/reference/cargo-targets.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,6 @@ test = true # Is tested by default.
184184
doctest = true # Documentation examples are tested by default.
185185
bench = true # Is benchmarked by default.
186186
doc = true # Is documented by default.
187-
plugin = false # Used as a compiler plugin (deprecated).
188187
proc-macro = false # Set to `true` for a proc-macro library.
189188
harness = true # Use libtest harness.
190189
edition = "2015" # The edition of the target.
@@ -247,7 +246,7 @@ libraries and binaries.
247246
248247
### The `plugin` field
249248

250-
This field is used for `rustc` plugins, which are being deprecated.
249+
This option is deprecated and unused.
251250

252251
### The `proc-macro` field
253252

‎src/doc/src/reference/environment-variables.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ Cargo includes the following paths:
299299
Cargo to properly set the environment if additional libraries on the system
300300
are needed in the search path.
301301
* The base output directory, such as `target/debug`, and the "deps" directory.
302-
This is mostly for legacy support of `rustc` compiler plugins.
302+
This is mostly for support of proc-macros.
303303
* The rustc sysroot library path. This generally is not important to most
304304
users.
305305

‎tests/testsuite/build_script.rs

-55
Original file line numberDiff line numberDiff line change
@@ -2178,61 +2178,6 @@ fn shared_dep_with_a_build_script() {
21782178
p.cargo("build -v").run();
21792179
}
21802180

2181-
#[cargo_test]
2182-
fn transitive_dep_host() {
2183-
let p = project()
2184-
.file(
2185-
"Cargo.toml",
2186-
r#"
2187-
[package]
2188-
name = "foo"
2189-
version = "0.5.0"
2190-
edition = "2015"
2191-
authors = []
2192-
build = "build.rs"
2193-
2194-
[build-dependencies.b]
2195-
path = "b"
2196-
"#,
2197-
)
2198-
.file("src/lib.rs", "")
2199-
.file("build.rs", "fn main() {}")
2200-
.file(
2201-
"a/Cargo.toml",
2202-
r#"
2203-
[package]
2204-
name = "a"
2205-
version = "0.5.0"
2206-
edition = "2015"
2207-
authors = []
2208-
links = "foo"
2209-
build = "build.rs"
2210-
"#,
2211-
)
2212-
.file("a/build.rs", "fn main() {}")
2213-
.file("a/src/lib.rs", "")
2214-
.file(
2215-
"b/Cargo.toml",
2216-
r#"
2217-
[package]
2218-
name = "b"
2219-
version = "0.5.0"
2220-
edition = "2015"
2221-
authors = []
2222-
2223-
[lib]
2224-
name = "b"
2225-
plugin = true
2226-
2227-
[dependencies.a]
2228-
path = "../a"
2229-
"#,
2230-
)
2231-
.file("b/src/lib.rs", "")
2232-
.build();
2233-
p.cargo("build").run();
2234-
}
2235-
22362181
#[cargo_test]
22372182
fn test_a_lib_with_a_build_command() {
22382183
let p = project()

‎tests/testsuite/cross_compile.rs

-41
Original file line numberDiff line numberDiff line change
@@ -883,47 +883,6 @@ fn build_script_only_host() {
883883
p.cargo("build -v --target").arg(&target).run();
884884
}
885885

886-
#[cargo_test]
887-
fn plugin_build_script_right_arch() {
888-
if cross_compile::disabled() {
889-
return;
890-
}
891-
let p = project()
892-
.file(
893-
"Cargo.toml",
894-
r#"
895-
[package]
896-
name = "foo"
897-
version = "0.0.1"
898-
edition = "2015"
899-
authors = []
900-
build = "build.rs"
901-
902-
[lib]
903-
name = "foo"
904-
plugin = true
905-
"#,
906-
)
907-
.file("build.rs", "fn main() {}")
908-
.file("src/lib.rs", "")
909-
.build();
910-
911-
p.cargo("build -v --target")
912-
.arg(cross_compile::alternate())
913-
.with_stderr(
914-
"\
915-
[WARNING] support for rustc plugins has been removed from rustc. library `foo` should not specify `plugin = true`
916-
[WARNING] support for `plugin = true` will be removed from cargo in the future
917-
[COMPILING] foo v0.0.1 ([..])
918-
[RUNNING] `rustc [..] build.rs [..]`
919-
[RUNNING] `[..]/build-script-build`
920-
[RUNNING] `rustc [..] src/lib.rs [..]`
921-
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]
922-
",
923-
)
924-
.run();
925-
}
926-
927886
#[cargo_test]
928887
fn build_script_with_platform_specific_dependencies() {
929888
if cross_compile::disabled() {

‎tests/testsuite/proc_macro.rs

+25-11
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ fn proc_macro_crate_type_warning() {
346346
}
347347

348348
#[cargo_test]
349-
fn proc_macro_crate_type_warning_plugin() {
349+
fn lib_plugin_unused_key_warning() {
350350
let foo = project()
351351
.file(
352352
"Cargo.toml",
@@ -356,26 +356,40 @@ fn proc_macro_crate_type_warning_plugin() {
356356
version = "0.1.0"
357357
edition = "2015"
358358
[lib]
359-
crate-type = ["proc-macro"]
360359
plugin = true
361360
"#,
362361
)
363362
.file("src/lib.rs", "")
364363
.build();
365364

366365
foo.cargo("check")
367-
.with_stderr_contains(
368-
"[WARNING] support for rustc plugins has been removed from rustc. \
369-
library `foo` should not specify `plugin = true`")
370-
.with_stderr_contains(
371-
"[WARNING] support for `plugin = true` will be removed from cargo in the future")
372-
.with_stderr_contains(
373-
"[WARNING] proc-macro library `foo` should not specify `plugin = true`")
374-
.with_stderr_contains(
375-
"[WARNING] library `foo` should only specify `proc-macro = true` instead of setting `crate-type`")
366+
.with_stderr_contains("[WARNING] unused manifest key: lib.plugin")
376367
.run();
377368
}
378369

370+
#[cargo_test]
371+
fn proc_macro_crate_type_warning_plugin() {
372+
let foo = project()
373+
.file(
374+
"Cargo.toml",
375+
r#"
376+
[package]
377+
name = "foo"
378+
version = "0.1.0"
379+
edition = "2015"
380+
[lib]
381+
crate-type = ["proc-macro"]
382+
"#,
383+
)
384+
.file("src/lib.rs", "")
385+
.build();
386+
387+
foo.cargo("check")
388+
.with_stderr_contains(
389+
"[WARNING] library `foo` should only specify `proc-macro = true` instead of setting `crate-type`")
390+
.run();
391+
}
392+
379393
#[cargo_test]
380394
fn proc_macro_crate_type_multiple() {
381395
let foo = project()
There was a problem loading the remainder of the diff.

0 commit comments

Comments
 (0)
Failed to load comments.