@@ -5,6 +5,10 @@ use std::{
55} ;
66use wit_parser:: { PackageId , Resolve , WorldId } ;
77
8+ // In the rare case the snapshot needs to be updated, the latest version
9+ // can be found here: https://github.com/bytecodealliance/wasmtime/releases
10+ const WASIP1_SNAPSHOT_ADAPT : & [ u8 ] = include_bytes ! ( "wasi_snapshot_preview1.reactor.wasm" ) ;
11+
812pub fn parse_wit (
913 paths : & [ impl AsRef < Path > ] ,
1014 world : Option < & str > ,
@@ -73,15 +77,18 @@ pub fn embed_wit(
7377}
7478
7579/// Update the wasm module to use the current component model ABI.
76- pub fn module_to_component ( wasm_file : & PathBuf ) -> Result < ( ) > {
77- // In the rare case the snapshot needs to be updated, the latest version
78- // can be found here: https://github.com/bytecodealliance/wasmtime/releases
79- const WASIP1_SNAPSHOT : & [ u8 ] = include_bytes ! ( "wasi_snapshot_preview1.reactor.wasm" ) ;
80+ pub fn module_to_component ( wasm_file : & PathBuf , adapt_file : & Option < PathBuf > ) -> Result < ( ) > {
8081 let wasm: Vec < u8 > = wat:: Parser :: new ( ) . parse_file ( wasm_file) ?;
8182
8283 let mut encoder = wit_component:: ComponentEncoder :: default ( ) . validate ( true ) ;
8384 encoder = encoder. module ( & wasm) ?;
84- encoder = encoder. adapter ( "wasi_snapshot_preview1" , WASIP1_SNAPSHOT ) ?;
85+ let adapt_bytes = if let Some ( adapt) = adapt_file {
86+ std:: fs:: read ( adapt)
87+ . with_context ( || format ! ( "failed to read adapt file '{}'" , adapt. display( ) ) ) ?
88+ } else {
89+ WASIP1_SNAPSHOT_ADAPT . to_vec ( )
90+ } ;
91+ encoder = encoder. adapter ( "wasi_snapshot_preview1" , & adapt_bytes) ?;
8592
8693 let bytes = encoder
8794 . encode ( )
0 commit comments