@@ -970,14 +970,8 @@ fn componentize(
970970 } ) ?
971971 . validate ( true ) ;
972972
973- let mut producers = wasm_metadata:: Producers :: empty ( ) ;
974- producers. add (
975- "processed-by" ,
976- env ! ( "CARGO_PKG_NAME" ) ,
977- option_env ! ( "CARGO_VERSION_INFO" ) . unwrap_or ( env ! ( "CARGO_PKG_VERSION" ) ) ,
978- ) ;
979-
980- let component = producers. add_to_wasm ( & encoder. encode ( ) ?) . with_context ( || {
973+ let package = & cargo_metadata[ & artifact. package_id ] ;
974+ let component = add_component_metadata ( & package, & encoder. encode ( ) ?) . with_context ( || {
981975 format ! (
982976 "failed to add metadata to output component `{path}`" ,
983977 path = path. display( )
@@ -1026,8 +1020,43 @@ pub struct PublishOptions<'a> {
10261020 pub dry_run : bool ,
10271021}
10281022
1029- fn add_registry_metadata ( _package : & Package , bytes : & [ u8 ] , _path : & Path ) -> Result < Vec < u8 > > {
1030- Ok ( bytes. to_owned ( ) )
1023+ /// Read metadata from `Cargo.toml` and add it to the component
1024+ fn add_component_metadata ( package : & Package , wasm : & [ u8 ] ) -> Result < Vec < u8 > > {
1025+ let metadata = wasm_metadata:: AddMetadata {
1026+ name : Some ( package. name . clone ( ) ) ,
1027+ language : vec ! [ ( "Rust" . to_string( ) , "" . to_string( ) ) ] ,
1028+ processed_by : vec ! [ (
1029+ env!( "CARGO_PKG_NAME" ) . to_string( ) ,
1030+ option_env!( "CARGO_VERSION_INFO" )
1031+ . unwrap_or( env!( "CARGO_PKG_VERSION" ) )
1032+ . to_string( ) ,
1033+ ) ] ,
1034+ sdk : vec ! [ ] ,
1035+ author : Some ( wasm_metadata:: Author :: new ( package. authors . join ( "," ) ) ) ,
1036+ description : package
1037+ . description
1038+ . as_ref ( )
1039+ . map ( |d| wasm_metadata:: Description :: new ( d. clone ( ) ) ) ,
1040+ licenses : package
1041+ . license
1042+ . as_ref ( )
1043+ . map ( |s| wasm_metadata:: Licenses :: new ( & s) )
1044+ . transpose ( ) ?,
1045+ source : package
1046+ . repository
1047+ . as_ref ( )
1048+ . map ( |s| wasm_metadata:: Source :: new ( s. to_string ( ) . as_str ( ) ) )
1049+ . transpose ( ) ?,
1050+ homepage : package
1051+ . homepage
1052+ . as_ref ( )
1053+ . map ( |s| wasm_metadata:: Homepage :: new ( s. to_string ( ) . as_str ( ) ) )
1054+ . transpose ( ) ?,
1055+ // TODO: get the git commit hash
1056+ revision : None ,
1057+ version : Some ( wasm_metadata:: Version :: new ( package. version . to_string ( ) ) ) ,
1058+ } ;
1059+ metadata. to_wasm ( wasm)
10311060}
10321061
10331062/// Publish a component for the given workspace and publish options.
@@ -1050,8 +1079,6 @@ pub async fn publish(
10501079 )
10511080 } ) ?;
10521081
1053- let bytes = add_registry_metadata ( options. package , & bytes, options. path ) ?;
1054-
10551082 config. terminal ( ) . status (
10561083 "Publishing" ,
10571084 format ! ( "component {path}" , path = options. path. display( ) ) ,
0 commit comments