@@ -463,6 +463,9 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
463
463
// - OSX encodes the dylib name in the executable
464
464
// - Windows rustc multiple files of which we can't easily link all of them
465
465
//
466
+ // No metadata for bin because of an issue
467
+ // - wasm32 rustc/emcc encodes the .wasm name in the .js (rust-lang/cargo#4535)
468
+ //
466
469
// Two exceptions
467
470
// 1) Upstream dependencies (we aren't exporting + need to resolve name conflict)
468
471
// 2) __CARGO_DEFAULT_LIB_METADATA env var
@@ -478,9 +481,11 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
478
481
// doing this eventually.
479
482
let __cargo_default_lib_metadata = env:: var ( "__CARGO_DEFAULT_LIB_METADATA" ) ;
480
483
if !unit. profile . test &&
481
- ( unit. target . is_dylib ( ) || unit. target . is_cdylib ( ) ) &&
484
+ ( unit. target . is_dylib ( ) || unit. target . is_cdylib ( ) ||
485
+ ( unit. target . is_bin ( ) && self . target_triple ( ) . starts_with ( "wasm32-" ) ) ) &&
482
486
unit. pkg . package_id ( ) . source_id ( ) . is_path ( ) &&
483
- !__cargo_default_lib_metadata. is_ok ( ) {
487
+ !__cargo_default_lib_metadata. is_ok ( )
488
+ {
484
489
return None ;
485
490
}
486
491
@@ -652,11 +657,21 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
652
657
suffix,
653
658
linkable,
654
659
) ;
655
- for ( suffix, linkable) in suffixes {
660
+ for ( suffix, linkable, should_replace_hyphens) in suffixes {
661
+ // wasm bin target will generate two files in deps such as
662
+ // "web-stuff.js" and "web_stuff.wasm". Note the different usages of
663
+ // "-" and "_". should_replace_hyphens is a flag to indicate that
664
+ // we need to convert the stem "web-stuff" to "web_stuff", so we
665
+ // won't miss "web_stuff.wasm".
666
+ let conv = |s : String | if should_replace_hyphens {
667
+ s. replace ( "-" , "_" )
668
+ } else {
669
+ s
670
+ } ;
656
671
let filename =
657
- out_dir. join ( format ! ( "{}{}{}" , prefix, stem, suffix) ) ;
672
+ out_dir. join ( format ! ( "{}{}{}" , prefix, conv ( stem. clone ( ) ) , suffix) ) ;
658
673
let link_dst = link_stem. clone ( ) . map ( |( ld, ls) | {
659
- ld. join ( format ! ( "{}{}{}" , prefix, ls , suffix) )
674
+ ld. join ( format ! ( "{}{}{}" , prefix, conv ( ls ) , suffix) )
660
675
} ) ;
661
676
ret. push ( ( filename, link_dst, linkable) ) ;
662
677
}
@@ -1174,27 +1189,32 @@ fn parse_crate_type(
1174
1189
Ok ( Some ( ( prefix. to_string ( ) , suffix. to_string ( ) ) ) )
1175
1190
}
1176
1191
1192
+ // (not a rustdoc)
1193
+ // Return a list of 3-tuples (suffix, linkable, should_replace_hyphens).
1194
+ //
1195
+ // should_replace_hyphens will be used by the caller to replace "-" with "_"
1196
+ // in a bin_stem. See the caller side (calc_target_filenames()) for details.
1177
1197
fn add_target_specific_suffixes (
1178
1198
target_triple : & str ,
1179
1199
crate_type : & str ,
1180
1200
suffix : & str ,
1181
1201
linkable : bool ,
1182
- ) -> Vec < ( String , bool ) > {
1183
- let mut suffixes = vec ! [ ( suffix. to_string( ) , linkable) ] ;
1202
+ ) -> Vec < ( String , bool , bool ) > {
1203
+ let mut ret = vec ! [ ( suffix. to_string( ) , linkable, false ) ] ;
1184
1204
1185
1205
// rust-lang/cargo#4500
1186
1206
if target_triple. ends_with ( "pc-windows-msvc" ) && crate_type. ends_with ( "dylib" ) &&
1187
1207
suffix == ".dll"
1188
1208
{
1189
- suffixes . push ( ( format ! ( "{}. lib", suffix ) , false ) ) ;
1209
+ ret . push ( ( ".dll. lib". to_string ( ) , false , false ) ) ;
1190
1210
}
1191
1211
1192
1212
// rust-lang/cargo#4535
1193
- if target_triple == "wasm32-unknown-emscripten" && crate_type == "bin" &&
1213
+ if target_triple. starts_with ( "wasm32-" ) && crate_type == "bin" &&
1194
1214
suffix == ".js"
1195
1215
{
1196
- suffixes . push ( ( ".wasm" . to_string ( ) , false ) ) ;
1216
+ ret . push ( ( ".wasm" . to_string ( ) , false , true ) ) ;
1197
1217
}
1198
1218
1199
- suffixes
1219
+ ret
1200
1220
}
0 commit comments