File tree 2 files changed +87
-0
lines changed
2 files changed +87
-0
lines changed Original file line number Diff line number Diff line change @@ -44,6 +44,7 @@ pub fn targets(
44
44
package_root,
45
45
package_name,
46
46
warnings,
47
+ errors,
47
48
has_lib,
48
49
) ?) ;
49
50
@@ -164,6 +165,7 @@ fn clean_bins(
164
165
package_root : & Path ,
165
166
package_name : & str ,
166
167
warnings : & mut Vec < String > ,
168
+ errors : & mut Vec < String > ,
167
169
has_lib : bool ,
168
170
) -> CargoResult < Vec < Target > > {
169
171
let inferred = inferred_bins ( package_root, package_name) ;
@@ -183,6 +185,26 @@ fn clean_bins(
183
185
validate_has_name ( bin, "binary" , "bin" ) ?;
184
186
185
187
let name = bin. name ( ) ;
188
+
189
+ if let Some ( crate_types) = bin. crate_types ( ) {
190
+ if !crate_types. is_empty ( ) {
191
+ errors. push ( format ! (
192
+ "the target `{}` is a binary and can't have any \
193
+ crate-types set (currently \" {}\" )",
194
+ name,
195
+ crate_types. join( ", " )
196
+ ) ) ;
197
+ }
198
+ }
199
+
200
+ if bin. proc_macro ( ) == Some ( true ) {
201
+ errors. push ( format ! (
202
+ "the target `{}` is a binary and can't have `proc-macro` \
203
+ set `true`",
204
+ name
205
+ ) ) ;
206
+ }
207
+
186
208
if is_bad_artifact_name ( & name) {
187
209
bail ! ( "the binary target name `{}` is forbidden" , name)
188
210
}
Original file line number Diff line number Diff line change @@ -449,6 +449,71 @@ Caused by:
449
449
)
450
450
}
451
451
452
+ #[ test]
453
+ fn cargo_compile_with_bin_and_crate_type ( ) {
454
+ let p = project ( "foo" )
455
+ . file (
456
+ "Cargo.toml" ,
457
+ r#"
458
+ [package]
459
+ name = "foo"
460
+ authors = []
461
+ version = "0.0.0"
462
+
463
+ [[bin]]
464
+ name = "the_foo_bin"
465
+ path = "src/foo.rs"
466
+ crate-type = ["cdylib", "rlib"]
467
+ "# ,
468
+ )
469
+ . file ( "src/foo.rs" , "fn main() {}" )
470
+ . build ( ) ;
471
+
472
+ assert_that (
473
+ p. cargo ( "build" ) ,
474
+ execs ( ) . with_status ( 101 ) . with_stderr (
475
+ "\
476
+ [ERROR] failed to parse manifest at `[..]`
477
+
478
+ Caused by:
479
+ the target `the_foo_bin` is a binary and can't have any crate-types set \
480
+ (currently \" cdylib, rlib\" )",
481
+ ) ,
482
+ )
483
+ }
484
+
485
+ #[ test]
486
+ fn cargo_compile_with_bin_and_proc ( ) {
487
+ let p = project ( "foo" )
488
+ . file (
489
+ "Cargo.toml" ,
490
+ r#"
491
+ [package]
492
+ name = "foo"
493
+ authors = []
494
+ version = "0.0.0"
495
+
496
+ [[bin]]
497
+ name = "the_foo_bin"
498
+ path = "src/foo.rs"
499
+ proc-macro = true
500
+ "# ,
501
+ )
502
+ . file ( "src/foo.rs" , "fn main() {}" )
503
+ . build ( ) ;
504
+
505
+ assert_that (
506
+ p. cargo ( "build" ) ,
507
+ execs ( ) . with_status ( 101 ) . with_stderr (
508
+ "\
509
+ [ERROR] failed to parse manifest at `[..]`
510
+
511
+ Caused by:
512
+ the target `the_foo_bin` is a binary and can't have `proc-macro` set `true`" ,
513
+ ) ,
514
+ )
515
+ }
516
+
452
517
#[ test]
453
518
fn cargo_compile_with_invalid_lib_target_name ( ) {
454
519
let p = project ( "foo" )
You can’t perform that action at this time.
0 commit comments