@@ -36,6 +36,7 @@ use wit_component::ComponentEncoder;
3636use crate :: target:: install_wasm32_wasip1;
3737
3838use config:: { CargoArguments , CargoPackageSpec , Config } ;
39+ use git:: GitMetadata ;
3940use lock:: { acquire_lock_file_ro, acquire_lock_file_rw} ;
4041use metadata:: ComponentMetadata ;
4142use registry:: { PackageDependencyResolution , PackageResolutionMap } ;
@@ -44,6 +45,7 @@ mod bindings;
4445pub mod commands;
4546pub mod config;
4647mod generator;
48+ mod git;
4749mod lock;
4850mod metadata;
4951mod registry;
@@ -971,12 +973,14 @@ fn componentize(
971973 . validate ( true ) ;
972974
973975 let package = & cargo_metadata[ & artifact. package_id ] ;
974- let component = add_component_metadata ( & package, & encoder. encode ( ) ?) . with_context ( || {
975- format ! (
976- "failed to add metadata to output component `{path}`" ,
977- path = path. display( )
978- )
979- } ) ?;
976+ let git = GitMetadata :: from_package ( package) ?;
977+ let component = add_component_metadata ( package, git. as_ref ( ) , & encoder. encode ( ) ?)
978+ . with_context ( || {
979+ format ! (
980+ "failed to add metadata to output component `{path}`" ,
981+ path = path. display( )
982+ )
983+ } ) ?;
980984
981985 // To make the write atomic, first write to a temp file and then rename the file
982986 let temp_dir = cargo_metadata. target_directory . join ( "tmp" ) ;
@@ -1021,7 +1025,11 @@ pub struct PublishOptions<'a> {
10211025}
10221026
10231027/// Read metadata from `Cargo.toml` and add it to the component
1024- fn add_component_metadata ( package : & Package , wasm : & [ u8 ] ) -> Result < Vec < u8 > > {
1028+ fn add_component_metadata (
1029+ package : & Package ,
1030+ git : Option < & GitMetadata > ,
1031+ wasm : & [ u8 ] ,
1032+ ) -> Result < Vec < u8 > > {
10251033 let metadata = wasm_metadata:: AddMetadata {
10261034 name : Some ( package. name . clone ( ) ) ,
10271035 language : vec ! [ ( "Rust" . to_string( ) , "" . to_string( ) ) ] ,
@@ -1055,8 +1063,7 @@ fn add_component_metadata(package: &Package, wasm: &[u8]) -> Result<Vec<u8>> {
10551063 . as_ref ( )
10561064 . map ( |s| wasm_metadata:: Homepage :: new ( s. to_string ( ) . as_str ( ) ) )
10571065 . transpose ( ) ?,
1058- // TODO: get the git commit hash
1059- revision : None ,
1066+ revision : git. map ( |git| wasm_metadata:: Revision :: new ( git. commit ( ) . to_string ( ) ) ) ,
10601067 version : Some ( wasm_metadata:: Version :: new ( package. version . to_string ( ) ) ) ,
10611068 } ;
10621069 metadata. to_wasm ( wasm)
0 commit comments