@@ -172,6 +172,16 @@ impl Packages {
172172 }
173173}
174174
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+
175185#[ derive( Debug ) ]
176186pub enum FilterRule {
177187 All ,
@@ -186,7 +196,7 @@ pub enum CompileFilter {
186196 } ,
187197 Only {
188198 all_targets : bool ,
189- lib : bool ,
199+ lib : LibRule ,
190200 bins : FilterRule ,
191201 examples : FilterRule ,
192202 tests : FilterRule ,
@@ -389,6 +399,7 @@ impl CompileFilter {
389399 all_bens : bool ,
390400 all_targets : bool ,
391401 ) -> CompileFilter {
402+ let rule_lib = if lib_only { LibRule :: True } else { LibRule :: False } ;
392403 let rule_bins = FilterRule :: new ( bins, all_bins) ;
393404 let rule_tsts = FilterRule :: new ( tsts, all_tsts) ;
394405 let rule_exms = FilterRule :: new ( exms, all_exms) ;
@@ -397,34 +408,34 @@ impl CompileFilter {
397408 if all_targets {
398409 CompileFilter :: Only {
399410 all_targets : true ,
400- lib : true ,
411+ lib : LibRule :: Default ,
401412 bins : FilterRule :: All ,
402413 examples : FilterRule :: All ,
403414 benches : FilterRule :: All ,
404415 tests : FilterRule :: All ,
405416 }
406417 } 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)
408419 }
409420 }
410421
411422 /// Construct a CompileFilter from underlying primitives.
412423 pub fn new (
413- lib_only : bool ,
424+ rule_lib : LibRule ,
414425 rule_bins : FilterRule ,
415426 rule_tsts : FilterRule ,
416427 rule_exms : FilterRule ,
417428 rule_bens : FilterRule ,
418429 ) -> CompileFilter {
419- if lib_only
430+ if rule_lib == LibRule :: True
420431 || rule_bins. is_specific ( )
421432 || rule_tsts. is_specific ( )
422433 || rule_exms. is_specific ( )
423434 || rule_bens. is_specific ( )
424435 {
425436 CompileFilter :: Only {
426437 all_targets : false ,
427- lib : lib_only ,
438+ lib : rule_lib ,
428439 bins : rule_bins,
429440 examples : rule_exms,
430441 benches : rule_bens,
@@ -460,7 +471,7 @@ impl CompileFilter {
460471 match * self {
461472 CompileFilter :: Default { .. } => true ,
462473 CompileFilter :: Only {
463- lib,
474+ ref lib,
464475 ref bins,
465476 ref examples,
466477 ref tests,
@@ -472,7 +483,11 @@ impl CompileFilter {
472483 TargetKind :: Test => tests,
473484 TargetKind :: Bench => benches,
474485 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+ } ,
476491 TargetKind :: CustomBuild => return false ,
477492 } ;
478493 rule. matches ( target)
@@ -626,13 +641,13 @@ fn generate_targets<'a>(
626641 }
627642 CompileFilter :: Only {
628643 all_targets,
629- lib,
644+ ref lib,
630645 ref bins,
631646 ref examples,
632647 ref tests,
633648 ref benches,
634649 } => {
635- if lib {
650+ if * lib != LibRule :: False {
636651 let mut libs = Vec :: new ( ) ;
637652 for proposal in filter_targets ( packages, Target :: is_lib, false , build_config. mode ) {
638653 let Proposal { target, pkg, .. } = proposal;
@@ -646,7 +661,7 @@ fn generate_targets<'a>(
646661 libs. push ( proposal)
647662 }
648663 }
649- if !all_targets && libs. is_empty ( ) {
664+ if !all_targets && libs. is_empty ( ) && * lib == LibRule :: True {
650665 let names = packages. iter ( ) . map ( |pkg| pkg. name ( ) ) . collect :: < Vec < _ > > ( ) ;
651666 if names. len ( ) == 1 {
652667 failure:: bail!( "no library targets found in package `{}`" , names[ 0 ] ) ;
0 commit comments