@@ -60,6 +60,17 @@ pub struct Unit<'a> {
60
60
pub kind : Kind ,
61
61
}
62
62
63
+ /// Type of each file generated by a Unit.
64
+ #[ derive( Copy , Clone , PartialEq , Eq , Debug ) ]
65
+ pub enum TargetFileType {
66
+ /// Not a special file type.
67
+ Normal ,
68
+ /// It is something you can link against (e.g. a library)
69
+ Linkable ,
70
+ /// It is a piece of external debug information (e.g. *.dSYM and *.pdb)
71
+ DebugInfo ,
72
+ }
73
+
63
74
/// The build context, containing all information about a build task
64
75
pub struct Context < ' a , ' cfg : ' a > {
65
76
/// The workspace the build is for
@@ -96,8 +107,8 @@ pub struct Context<'a, 'cfg: 'a> {
96
107
/// - File name that will be produced by the build process (in `deps`)
97
108
/// - If it should be linked into `target`, and what it should be called (e.g. without
98
109
/// metadata).
99
- /// - Whether it is something you can link against (e.g. a library )
100
- target_filenames : HashMap < Unit < ' a > , Arc < Vec < ( PathBuf , Option < PathBuf > , bool ) > > > ,
110
+ /// - Type of the file (library / debug symbol / else )
111
+ target_filenames : HashMap < Unit < ' a > , Arc < Vec < ( PathBuf , Option < PathBuf > , TargetFileType ) > > > ,
101
112
target_metadatas : HashMap < Unit < ' a > , Option < Metadata > > ,
102
113
}
103
114
@@ -649,7 +660,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
649
660
/// - link_dst: Optional file to link/copy the result to (without metadata suffix)
650
661
/// - linkable: Whether possible to link against file (eg it's a library)
651
662
pub fn target_filenames ( & mut self , unit : & Unit < ' a > )
652
- -> CargoResult < Arc < Vec < ( PathBuf , Option < PathBuf > , bool ) > > > {
663
+ -> CargoResult < Arc < Vec < ( PathBuf , Option < PathBuf > , TargetFileType ) > > > {
653
664
if let Some ( cache) = self . target_filenames . get ( unit) {
654
665
return Ok ( Arc :: clone ( cache) )
655
666
}
@@ -662,7 +673,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
662
673
}
663
674
664
675
fn calc_target_filenames ( & mut self , unit : & Unit < ' a > )
665
- -> CargoResult < Arc < Vec < ( PathBuf , Option < PathBuf > , bool ) > > > {
676
+ -> CargoResult < Arc < Vec < ( PathBuf , Option < PathBuf > , TargetFileType ) > > > {
666
677
let out_dir = self . out_dir ( unit) ;
667
678
let stem = self . file_stem ( unit) ;
668
679
let link_stem = self . link_stem ( unit) ;
@@ -680,9 +691,9 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
680
691
let link_dst = link_stem. clone ( ) . map ( |( ld, ls) | {
681
692
ld. join ( format ! ( "lib{}.rmeta" , ls) )
682
693
} ) ;
683
- ret. push ( ( filename, link_dst, true ) ) ;
694
+ ret. push ( ( filename, link_dst, TargetFileType :: Linkable ) ) ;
684
695
} else {
685
- let mut add = |crate_type : & str , linkable : bool | -> CargoResult < ( ) > {
696
+ let mut add = |crate_type : & str , file_type : TargetFileType | -> CargoResult < ( ) > {
686
697
let crate_type = if crate_type == "lib" { "rlib" } else { crate_type} ;
687
698
let mut crate_types = info. crate_types . borrow_mut ( ) ;
688
699
let entry = crate_types. entry ( crate_type. to_string ( ) ) ;
@@ -698,10 +709,11 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
698
709
let suffixes = add_target_specific_suffixes (
699
710
& self . target_triple ( ) ,
700
711
& crate_type,
712
+ unit. target . kind ( ) ,
701
713
suffix,
702
- linkable ,
714
+ file_type ,
703
715
) ;
704
- for ( suffix, linkable , should_replace_hyphens) in suffixes {
716
+ for ( suffix, file_type , should_replace_hyphens) in suffixes {
705
717
// wasm bin target will generate two files in deps such as
706
718
// "web-stuff.js" and "web_stuff.wasm". Note the different usages of
707
719
// "-" and "_". should_replace_hyphens is a flag to indicate that
@@ -717,7 +729,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
717
729
let link_dst = link_stem. clone ( ) . map ( |( ld, ls) | {
718
730
ld. join ( format ! ( "{}{}{}" , prefix, conv( ls) , suffix) )
719
731
} ) ;
720
- ret. push ( ( filename, link_dst, linkable ) ) ;
732
+ ret. push ( ( filename, link_dst, file_type ) ) ;
721
733
}
722
734
Ok ( ( ) )
723
735
}
@@ -735,17 +747,21 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
735
747
TargetKind :: ExampleBin |
736
748
TargetKind :: Bench |
737
749
TargetKind :: Test => {
738
- add ( "bin" , false ) ?;
750
+ add ( "bin" , TargetFileType :: Normal ) ?;
739
751
}
740
752
TargetKind :: Lib ( ..) |
741
753
TargetKind :: ExampleLib ( ..)
742
754
if unit. profile . test => {
743
- add ( "bin" , false ) ?;
755
+ add ( "bin" , TargetFileType :: Normal ) ?;
744
756
}
745
757
TargetKind :: ExampleLib ( ref kinds) |
746
758
TargetKind :: Lib ( ref kinds) => {
747
759
for kind in kinds {
748
- add ( kind. crate_type ( ) , kind. linkable ( ) ) ?;
760
+ add ( kind. crate_type ( ) , if kind. linkable ( ) {
761
+ TargetFileType :: Linkable
762
+ } else {
763
+ TargetFileType :: Normal
764
+ } ) ?;
749
765
}
750
766
}
751
767
}
@@ -1257,30 +1273,40 @@ fn parse_crate_type(
1257
1273
}
1258
1274
1259
1275
// (not a rustdoc)
1260
- // Return a list of 3-tuples (suffix, linkable , should_replace_hyphens).
1276
+ // Return a list of 3-tuples (suffix, file_type , should_replace_hyphens).
1261
1277
//
1262
1278
// should_replace_hyphens will be used by the caller to replace "-" with "_"
1263
1279
// in a bin_stem. See the caller side (calc_target_filenames()) for details.
1264
1280
fn add_target_specific_suffixes (
1265
1281
target_triple : & str ,
1266
1282
crate_type : & str ,
1283
+ target_kind : & TargetKind ,
1267
1284
suffix : & str ,
1268
- linkable : bool ,
1269
- ) -> Vec < ( String , bool , bool ) > {
1270
- let mut ret = vec ! [ ( suffix. to_string( ) , linkable , false ) ] ;
1285
+ file_type : TargetFileType ,
1286
+ ) -> Vec < ( String , TargetFileType , bool ) > {
1287
+ let mut ret = vec ! [ ( suffix. to_string( ) , file_type , false ) ] ;
1271
1288
1272
1289
// rust-lang/cargo#4500
1273
1290
if target_triple. ends_with ( "pc-windows-msvc" ) && crate_type. ends_with ( "dylib" ) &&
1274
1291
suffix == ".dll"
1275
1292
{
1276
- ret. push ( ( ".dll.lib" . to_string ( ) , false , false ) ) ;
1293
+ ret. push ( ( ".dll.lib" . to_string ( ) , TargetFileType :: Normal , false ) ) ;
1277
1294
}
1278
1295
1279
1296
// rust-lang/cargo#4535
1280
1297
if target_triple. starts_with ( "wasm32-" ) && crate_type == "bin" &&
1281
1298
suffix == ".js"
1282
1299
{
1283
- ret. push ( ( ".wasm" . to_string ( ) , false , true ) ) ;
1300
+ ret. push ( ( ".wasm" . to_string ( ) , TargetFileType :: Normal , true ) ) ;
1301
+ }
1302
+
1303
+ // rust-lang/cargo#4490
1304
+ // - only uplift *.dSYM for binaries.
1305
+ // tests are run directly from target/debug/deps/
1306
+ // and examples are inside target/debug/examples/ which already have *.dSYM next to them
1307
+ // so no need to do anything.
1308
+ if target_triple. contains ( "-apple-" ) && * target_kind == TargetKind :: Bin {
1309
+ ret. push ( ( ".dSYM" . to_string ( ) , TargetFileType :: DebugInfo , false ) ) ;
1284
1310
}
1285
1311
1286
1312
ret
0 commit comments