@@ -549,7 +549,10 @@ impl<'a> EncodingState<'a> {
549549 log:: trace!( "encoding function type for `{}`" , func. name) ;
550550 let idx = encoder. encode_func_type ( resolve, func) ?;
551551
552- encoder. ty . export ( & func. name , ComponentTypeRef :: Func ( idx) ) ;
552+ encoder. ty . export (
553+ crate :: encoding:: types:: extern_name ( & func. name , func. external_id . as_deref ( ) ) ,
554+ ComponentTypeRef :: Func ( idx) ,
555+ ) ;
553556 }
554557
555558 let ty = encoder. ty ;
@@ -597,7 +600,10 @@ impl<'a> EncodingState<'a> {
597600 let idx = self
598601 . root_import_type_encoder ( None )
599602 . encode_func_type ( resolve, func) ?;
600- let func_idx = self . component . import ( & name, ComponentTypeRef :: Func ( idx) ) ;
603+ let func_idx = self . component . import (
604+ crate :: encoding:: types:: extern_name ( name. as_str ( ) , func. external_id . as_deref ( ) ) ,
605+ ComponentTypeRef :: Func ( idx) ,
606+ ) ;
601607 let prev = self . imported_funcs . insert ( name, func_idx) ;
602608 assert ! ( prev. is_none( ) ) ;
603609 }
@@ -735,8 +741,15 @@ impl<'a> EncodingState<'a> {
735741 . encode_func_type ( resolve, func) ?;
736742 let core_name = world_func_core_names[ & func. name ] ;
737743 let idx = self . encode_lift ( module, & core_name, export_name, func, ty) ?;
738- self . component
739- . export ( export_string, ComponentExportKind :: Func , idx, None ) ;
744+ self . component . export (
745+ crate :: encoding:: types:: extern_name (
746+ & export_string,
747+ func. external_id . as_deref ( ) ,
748+ ) ,
749+ ComponentExportKind :: Func ,
750+ idx,
751+ None ,
752+ ) ;
740753 }
741754 item @ WorldItem :: Interface { id, .. } => {
742755 let core_names = interface_func_core_names. get ( export_name) ;
@@ -913,7 +926,10 @@ impl<'a> EncodingState<'a> {
913926 match ty. kind {
914927 TypeDefKind :: Resource => {
915928 let idx = nested. component . export (
916- ty. name . as_ref ( ) . expect ( "resources must be named" ) ,
929+ crate :: encoding:: types:: extern_name (
930+ ty. name . as_ref ( ) . expect ( "resources must be named" ) ,
931+ ty. external_id . as_deref ( ) ,
932+ ) ,
917933 ComponentExportKind :: Type ,
918934 resources[ id] ,
919935 None ,
@@ -929,7 +945,7 @@ impl<'a> EncodingState<'a> {
929945 for ( i, ( _, func) ) in resolve. interfaces [ export] . functions . iter ( ) . enumerate ( ) {
930946 let ty = nested. encode_func_type ( resolve, func) ?;
931947 nested. component . export (
932- & func. name ,
948+ crate :: encoding :: types :: extern_name ( & func. name , func . external_id . as_deref ( ) ) ,
933949 ComponentExportKind :: Func ,
934950 i as u32 ,
935951 Some ( ComponentTypeRef :: Func ( ty) ) ,
@@ -994,26 +1010,30 @@ impl<'a> EncodingState<'a> {
9941010 fn define_function_type ( & mut self ) -> ( u32 , ComponentFuncTypeEncoder < ' _ > ) {
9951011 self . component . type_function ( None )
9961012 }
997- fn export_type ( & mut self , idx : u32 , name : & ' a str ) -> Option < u32 > {
1013+ fn export_type (
1014+ & mut self ,
1015+ idx : u32 ,
1016+ name : wasm_encoder:: ComponentExternName < ' a > ,
1017+ ) -> Option < u32 > {
9981018 if self . export_types {
9991019 Some (
10001020 self . component
10011021 . export ( name, ComponentExportKind :: Type , idx, None ) ,
10021022 )
10031023 } else {
1004- let name = self . unique_import_name ( name) ;
1024+ let name = self . unique_import_name ( & name . name ) ;
10051025 let ret = self
10061026 . component
10071027 . import ( & name, ComponentTypeRef :: Type ( TypeBounds :: Eq ( idx) ) ) ;
10081028 self . imports . insert ( name, ret) ;
10091029 Some ( ret)
10101030 }
10111031 }
1012- fn export_resource ( & mut self , name : & ' a str ) -> u32 {
1032+ fn export_resource ( & mut self , name : wasm_encoder :: ComponentExternName < ' a > ) -> u32 {
10131033 if self . export_types {
10141034 panic ! ( "resources should already be exported" )
10151035 } else {
1016- let name = self . unique_import_name ( name) ;
1036+ let name = self . unique_import_name ( & name . name ) ;
10171037 let ret = self
10181038 . component
10191039 . import ( & name, ComponentTypeRef :: Type ( TypeBounds :: SubResource ) ) ;
@@ -2944,6 +2964,7 @@ impl<'a> Shims<'a> {
29442964 docs : Default :: default ( ) ,
29452965 stability : Stability :: Unknown ,
29462966 span : Default :: default ( ) ,
2967+ external_id : None ,
29472968 } ,
29482969 if async_ {
29492970 AbiVariant :: GuestImportAsync
@@ -3046,6 +3067,7 @@ fn task_return_options_and_type(
30463067 docs : Default :: default ( ) ,
30473068 stability : Stability :: Unknown ,
30483069 span : Default :: default ( ) ,
3070+ external_id : None ,
30493071 } ;
30503072 let abi = AbiVariant :: GuestImport ;
30513073 let mut options = RequiredOptions :: for_import ( resolve, func, abi) ;
0 commit comments