1- use anyhow:: Result ;
1+ use anyhow:: { anyhow , Result } ;
22use serde:: Deserialize ;
33use std:: { collections:: HashMap , str} ;
4- use wasmtime:: { AsContextMut , Engine , Linker } ;
5- use wasmtime_wasi:: { pipe :: MemoryOutputPipe , WasiCtxBuilder } ;
4+ use wasmtime:: { AsContext , AsContextMut , Engine , Linker } ;
5+ use wasmtime_wasi:: WasiCtxBuilder ;
66
77use crate :: { CliPlugin , PluginKind } ;
88
@@ -21,18 +21,23 @@ impl ConfigSchema {
2121 let module = wasmtime:: Module :: new ( & engine, cli_plugin. as_plugin ( ) . as_bytes ( ) ) ?;
2222 let mut linker = Linker :: new ( & engine) ;
2323 wasmtime_wasi:: preview1:: add_to_linker_sync ( & mut linker, |s| s) ?;
24- let stdout = MemoryOutputPipe :: new ( usize:: MAX ) ;
25- let wasi = WasiCtxBuilder :: new ( )
26- . inherit_stderr ( )
27- . stdout ( stdout. clone ( ) )
28- . build_p1 ( ) ;
24+ let wasi = WasiCtxBuilder :: new ( ) . inherit_stderr ( ) . build_p1 ( ) ;
2925 let mut store = wasmtime:: Store :: new ( & engine, wasi) ;
3026 let instance = linker. instantiate ( store. as_context_mut ( ) , & module) ?;
31- instance
32- . get_typed_func :: < ( ) , ( ) > ( store. as_context_mut ( ) , "config_schema" ) ?
27+
28+ let ret_area = instance
29+ . get_typed_func :: < ( ) , i32 > ( store. as_context_mut ( ) , "config-schema" ) ?
3330 . call ( store. as_context_mut ( ) , ( ) ) ?;
34- drop ( store) ;
35- let config_json = stdout. try_into_inner ( ) . unwrap ( ) . to_vec ( ) ;
31+ let memory = instance
32+ . get_memory ( store. as_context_mut ( ) , "memory" )
33+ . ok_or_else ( || anyhow ! ( "Missing memory export" ) ) ?;
34+ let mut buf = [ 0 ; 8 ] ;
35+ memory. read ( store. as_context ( ) , ret_area as usize , & mut buf) ?;
36+ let offset = u32:: from_le_bytes ( buf[ 0 ..4 ] . try_into ( ) . unwrap ( ) ) ;
37+ let len = u32:: from_le_bytes ( buf[ 4 ..8 ] . try_into ( ) . unwrap ( ) ) ;
38+ let mut config_json = vec ! [ 0 ; len as usize ] ;
39+ memory. read ( store. as_context ( ) , offset as usize , & mut config_json) ?;
40+
3641 let config_schema = serde_json:: from_slice :: < ConfigSchema > ( & config_json) ?;
3742 let mut configs = Vec :: with_capacity ( config_schema. supported_properties . len ( ) ) ;
3843 for config in config_schema. supported_properties {
0 commit comments