@@ -172,6 +172,16 @@ impl Packages {
172
172
}
173
173
}
174
174
175
+ #[ derive( Debug , PartialEq , Eq ) ]
176
+ pub enum LibRule {
177
+ /// Include the library, fail if not present
178
+ True ,
179
+ /// Include the library if present
180
+ Default ,
181
+ /// Exclude the library
182
+ False ,
183
+ }
184
+
175
185
#[ derive( Debug ) ]
176
186
pub enum FilterRule {
177
187
All ,
@@ -186,7 +196,7 @@ pub enum CompileFilter {
186
196
} ,
187
197
Only {
188
198
all_targets : bool ,
189
- lib : bool ,
199
+ lib : LibRule ,
190
200
bins : FilterRule ,
191
201
examples : FilterRule ,
192
202
tests : FilterRule ,
@@ -389,6 +399,7 @@ impl CompileFilter {
389
399
all_bens : bool ,
390
400
all_targets : bool ,
391
401
) -> CompileFilter {
402
+ let rule_lib = if lib_only { LibRule :: True } else { LibRule :: False } ;
392
403
let rule_bins = FilterRule :: new ( bins, all_bins) ;
393
404
let rule_tsts = FilterRule :: new ( tsts, all_tsts) ;
394
405
let rule_exms = FilterRule :: new ( exms, all_exms) ;
@@ -397,34 +408,34 @@ impl CompileFilter {
397
408
if all_targets {
398
409
CompileFilter :: Only {
399
410
all_targets : true ,
400
- lib : true ,
411
+ lib : LibRule :: Default ,
401
412
bins : FilterRule :: All ,
402
413
examples : FilterRule :: All ,
403
414
benches : FilterRule :: All ,
404
415
tests : FilterRule :: All ,
405
416
}
406
417
} else {
407
- CompileFilter :: new ( lib_only , rule_bins, rule_tsts, rule_exms, rule_bens)
418
+ CompileFilter :: new ( rule_lib , rule_bins, rule_tsts, rule_exms, rule_bens)
408
419
}
409
420
}
410
421
411
422
/// Construct a CompileFilter from underlying primitives.
412
423
pub fn new (
413
- lib_only : bool ,
424
+ rule_lib : LibRule ,
414
425
rule_bins : FilterRule ,
415
426
rule_tsts : FilterRule ,
416
427
rule_exms : FilterRule ,
417
428
rule_bens : FilterRule ,
418
429
) -> CompileFilter {
419
- if lib_only
430
+ if rule_lib == LibRule :: True
420
431
|| rule_bins. is_specific ( )
421
432
|| rule_tsts. is_specific ( )
422
433
|| rule_exms. is_specific ( )
423
434
|| rule_bens. is_specific ( )
424
435
{
425
436
CompileFilter :: Only {
426
437
all_targets : false ,
427
- lib : lib_only ,
438
+ lib : rule_lib ,
428
439
bins : rule_bins,
429
440
examples : rule_exms,
430
441
benches : rule_bens,
@@ -460,7 +471,7 @@ impl CompileFilter {
460
471
match * self {
461
472
CompileFilter :: Default { .. } => true ,
462
473
CompileFilter :: Only {
463
- lib,
474
+ ref lib,
464
475
ref bins,
465
476
ref examples,
466
477
ref tests,
@@ -472,7 +483,11 @@ impl CompileFilter {
472
483
TargetKind :: Test => tests,
473
484
TargetKind :: Bench => benches,
474
485
TargetKind :: ExampleBin | TargetKind :: ExampleLib ( ..) => examples,
475
- TargetKind :: Lib ( ..) => return lib,
486
+ TargetKind :: Lib ( ..) => return match * lib {
487
+ LibRule :: True => true ,
488
+ LibRule :: Default => true ,
489
+ LibRule :: False => false ,
490
+ } ,
476
491
TargetKind :: CustomBuild => return false ,
477
492
} ;
478
493
rule. matches ( target)
@@ -626,13 +641,13 @@ fn generate_targets<'a>(
626
641
}
627
642
CompileFilter :: Only {
628
643
all_targets,
629
- lib,
644
+ ref lib,
630
645
ref bins,
631
646
ref examples,
632
647
ref tests,
633
648
ref benches,
634
649
} => {
635
- if lib {
650
+ if * lib != LibRule :: False {
636
651
let mut libs = Vec :: new ( ) ;
637
652
for proposal in filter_targets ( packages, Target :: is_lib, false , build_config. mode ) {
638
653
let Proposal { target, pkg, .. } = proposal;
@@ -646,7 +661,7 @@ fn generate_targets<'a>(
646
661
libs. push ( proposal)
647
662
}
648
663
}
649
- if !all_targets && libs. is_empty ( ) {
664
+ if !all_targets && libs. is_empty ( ) && * lib == LibRule :: True {
650
665
let names = packages. iter ( ) . map ( |pkg| pkg. name ( ) ) . collect :: < Vec < _ > > ( ) ;
651
666
if names. len ( ) == 1 {
652
667
failure:: bail!( "no library targets found in package `{}`" , names[ 0 ] ) ;
0 commit comments