@@ -71,6 +71,8 @@ pub struct CompileOptions {
71
71
/// The specified target will be compiled with all the available arguments,
72
72
/// note that this only accounts for the *final* invocation of rustc
73
73
pub target_rustc_args : Option < Vec < String > > ,
74
+ /// Crate types to be passed to rustc (single target only)
75
+ pub target_rustc_crate_types : Option < Vec < String > > ,
74
76
/// Extra arguments passed to all selected targets for rustdoc.
75
77
pub local_rustdoc_args : Option < Vec < String > > ,
76
78
/// Whether the `--document-private-items` flags was specified and should
@@ -92,6 +94,7 @@ impl<'a> CompileOptions {
92
94
} ,
93
95
target_rustdoc_args : None ,
94
96
target_rustc_args : None ,
97
+ target_rustc_crate_types : None ,
95
98
local_rustdoc_args : None ,
96
99
rustdoc_document_private_items : false ,
97
100
honor_rust_version : true ,
@@ -332,6 +335,7 @@ pub fn create_bcx<'a, 'cfg>(
332
335
ref filter,
333
336
ref target_rustdoc_args,
334
337
ref target_rustc_args,
338
+ ref target_rustc_crate_types,
335
339
ref local_rustdoc_args,
336
340
rustdoc_document_private_items,
337
341
honor_rust_version,
@@ -644,6 +648,28 @@ pub fn create_bcx<'a, 'cfg>(
644
648
}
645
649
}
646
650
651
+ let mut crate_types = HashMap :: new ( ) ;
652
+ if let Some ( args) = target_rustc_crate_types {
653
+ if units. len ( ) != 1 {
654
+ anyhow:: bail!(
655
+ "crate types to rustc can only be passed to one \
656
+ target, consider filtering\n the package by passing, \
657
+ e.g., `--lib` or `--example` to specify a single target"
658
+ ) ;
659
+ }
660
+ match units[ 0 ] . target . kind ( ) {
661
+ TargetKind :: Lib ( _) | TargetKind :: ExampleLib ( _) => {
662
+ crate_types. insert ( units[ 0 ] . clone ( ) , args. clone ( ) ) ;
663
+ }
664
+ _ => {
665
+ anyhow:: bail!(
666
+ "crate types can only be specified for libraries and example libraries.\n \
667
+ Binaries, tests, and benchmarks are always the `bin` crate type"
668
+ ) ;
669
+ }
670
+ }
671
+ }
672
+
647
673
if honor_rust_version {
648
674
// Remove any pre-release identifiers for easier comparison
649
675
let current_version = & target_data. rustc . version ;
@@ -680,6 +706,7 @@ pub fn create_bcx<'a, 'cfg>(
680
706
build_config,
681
707
profiles,
682
708
extra_compiler_args,
709
+ crate_types,
683
710
target_data,
684
711
units,
685
712
unit_graph,
0 commit comments