File tree Expand file tree Collapse file tree 2 files changed +93
-0
lines changed Expand file tree Collapse file tree 2 files changed +93
-0
lines changed Original file line number Diff line number Diff line change @@ -206,6 +206,23 @@ fn clean_lib(
206
206
// A plugin requires exporting plugin_registrar so a crate cannot be
207
207
// both at once.
208
208
let crate_types = match ( lib. crate_types ( ) , lib. plugin , lib. proc_macro ( ) ) {
209
+ ( Some ( kinds) , _, _) if kinds. contains ( & "proc-macro" . to_string ( ) ) => {
210
+ if let Some ( true ) = lib. plugin {
211
+ // This is a warning to retain backwards compatibility.
212
+ warnings. push ( format ! (
213
+ "proc-macro library `{}` should not specify `plugin = true`" ,
214
+ lib. name( )
215
+ ) ) ;
216
+ }
217
+ warnings. push ( format ! (
218
+ "library `{}` should only specify `proc-macro = true` instead of setting `crate-type`" ,
219
+ lib. name( )
220
+ ) ) ;
221
+ if kinds. len ( ) > 1 {
222
+ bail ! ( "cannot mix `proc-macro` crate type with others" ) ;
223
+ }
224
+ vec ! [ LibKind :: ProcMacro ]
225
+ }
209
226
( _, Some ( true ) , Some ( true ) ) => bail ! ( "lib.plugin and lib.proc-macro cannot both be true" ) ,
210
227
( Some ( kinds) , _, _) => kinds. iter ( ) . map ( |s| s. into ( ) ) . collect ( ) ,
211
228
( None , Some ( true ) , _) => vec ! [ LibKind :: Dylib ] ,
Original file line number Diff line number Diff line change @@ -345,3 +345,79 @@ fn proc_macro_crate_type() {
345
345
. with_stdout_contains_n ( "test [..] ... ok" , 2 )
346
346
. run ( ) ;
347
347
}
348
+
349
+ #[ test]
350
+ fn proc_macro_crate_type_warning ( ) {
351
+ let foo = project ( )
352
+ . file (
353
+ "Cargo.toml" ,
354
+ r#"
355
+ [package]
356
+ name = "foo"
357
+ version = "0.1.0"
358
+ [lib]
359
+ crate-type = ["proc-macro"]
360
+ "# ,
361
+ )
362
+ . file ( "src/lib.rs" , "" )
363
+ . build ( ) ;
364
+
365
+ foo. cargo ( "build" )
366
+ . with_stderr_contains (
367
+ "[WARNING] library `foo` should only specify `proc-macro = true` instead of setting `crate-type`" )
368
+ . run ( ) ;
369
+ }
370
+
371
+ #[ test]
372
+ fn proc_macro_crate_type_warning_plugin ( ) {
373
+ let foo = project ( )
374
+ . file (
375
+ "Cargo.toml" ,
376
+ r#"
377
+ [package]
378
+ name = "foo"
379
+ version = "0.1.0"
380
+ [lib]
381
+ crate-type = ["proc-macro"]
382
+ plugin = true
383
+ "# ,
384
+ )
385
+ . file ( "src/lib.rs" , "" )
386
+ . build ( ) ;
387
+
388
+ foo. cargo ( "build" )
389
+ . with_stderr_contains (
390
+ "[WARNING] proc-macro library `foo` should not specify `plugin = true`" )
391
+ . with_stderr_contains (
392
+ "[WARNING] library `foo` should only specify `proc-macro = true` instead of setting `crate-type`" )
393
+ . run ( ) ;
394
+ }
395
+
396
+ #[ test]
397
+ fn proc_macro_crate_type_multiple ( ) {
398
+ let foo = project ( )
399
+ . file (
400
+ "Cargo.toml" ,
401
+ r#"
402
+ [package]
403
+ name = "foo"
404
+ version = "0.1.0"
405
+ [lib]
406
+ crate-type = ["proc-macro", "rlib"]
407
+ "# ,
408
+ )
409
+ . file ( "src/lib.rs" , "" )
410
+ . build ( ) ;
411
+
412
+ foo. cargo ( "build" )
413
+ . with_stderr (
414
+ "\
415
+ [ERROR] failed to parse manifest at `[..]/foo/Cargo.toml`
416
+
417
+ Caused by:
418
+ cannot mix `proc-macro` crate type with others
419
+ " ,
420
+ )
421
+ . with_status ( 101 )
422
+ . run ( ) ;
423
+ }
You can’t perform that action at this time.
0 commit comments