1
1
#![ allow( clippy:: type_complexity) ]
2
2
3
+ use core:: iter;
3
4
use core:: pin:: pin;
4
5
use core:: time:: Duration ;
5
6
@@ -88,6 +89,24 @@ impl<C: Invoke> WasiHttpView for Ctx<C> {
88
89
}
89
90
}
90
91
92
+ // https://github.com/bytecodealliance/wasmtime/blob/b943666650696f1eb7ff8b217762b58d5ef5779d/src/commands/serve.rs#L641-L656
93
+ fn use_pooling_allocator_by_default ( ) -> anyhow:: Result < Option < bool > > {
94
+ const BITS_TO_TEST : u32 = 42 ;
95
+ let mut config = wasmtime:: Config :: new ( ) ;
96
+ config. wasm_memory64 ( true ) ;
97
+ config. static_memory_maximum_size ( 1 << BITS_TO_TEST ) ;
98
+ let engine = wasmtime:: Engine :: new ( & config) ?;
99
+ let mut store = wasmtime:: Store :: new ( & engine, ( ) ) ;
100
+ // NB: the maximum size is in wasm pages to take out the 16-bits of wasm
101
+ // page size here from the maximum size.
102
+ let ty = wasmtime:: MemoryType :: new64 ( 0 , Some ( 1 << ( BITS_TO_TEST - 16 ) ) ) ;
103
+ if wasmtime:: Memory :: new ( & mut store, ty) . is_ok ( ) {
104
+ Ok ( Some ( true ) )
105
+ } else {
106
+ Ok ( None )
107
+ }
108
+ }
109
+
91
110
#[ instrument( level = "trace" , skip( adapter, cx) ) ]
92
111
async fn instantiate_pre < C > (
93
112
adapter : & [ u8 ] ,
@@ -98,12 +117,14 @@ where
98
117
C : Invoke ,
99
118
C :: Context : Clone + ' static ,
100
119
{
101
- let engine = Engine :: new (
102
- wasmtime:: Config :: new ( )
103
- . async_support ( true )
104
- . wasm_component_model ( true ) ,
105
- )
106
- . context ( "failed to initialize Wasmtime engine" ) ?;
120
+ let mut opts = wasmtime_cli_flags:: CommonOptions :: try_parse_from ( iter:: empty :: < & ' static str > ( ) )
121
+ . context ( "failed to construct common Wasmtime options" ) ?;
122
+ let mut config = opts
123
+ . config ( None , use_pooling_allocator_by_default ( ) . unwrap_or ( None ) )
124
+ . context ( "failed to construct Wasmtime config" ) ?;
125
+ config. wasm_component_model ( true ) ;
126
+ config. async_support ( true ) ;
127
+ let engine = wasmtime:: Engine :: new ( & config) . context ( "failed to initialize Wasmtime engine" ) ?;
107
128
108
129
let wasm = if workload. starts_with ( '.' ) || workload. starts_with ( '/' ) {
109
130
fs:: read ( & workload)
0 commit comments