11extern crate alloc;
22
3- mod bindings {
4- hyperlight_component_macro:: host_bindgen!( ) ;
5- }
3+ mod wasi_impl;
64
7- mod resource;
8- mod types;
9- mod worker;
5+ use wasi_impl:: {
6+ Resource ,
7+ bindings:: { RootSandbox , register_host_functions, wasi, wasi:: http:: IncomingHandler } ,
8+ types,
9+ types:: { WasiImpl , http_incoming_body:: IncomingBody , io_stream:: Stream } ,
10+ worker:: RUNTIME ,
11+ } ;
1012
1113use std:: { convert:: Infallible , net:: SocketAddr , str:: FromStr , sync:: Arc } ;
1214
13- use bindings:: RootSandbox ;
1415use bytes:: Bytes ;
1516use http_body_util:: { BodyExt , Full } ;
1617use hyper:: { server:: conn:: http1, service:: service_fn} ;
1718use hyper_util:: rt:: TokioIo ;
1819use hyperlight_host:: sandbox:: SandboxConfiguration ;
1920use hyperlight_wasm:: LoadedWasmSandbox ;
20- use resource:: Resource ;
2121use tokio:: { net:: TcpListener , sync:: Mutex } ;
22- use types:: { WasiImpl , http_incoming_body:: IncomingBody , io_stream:: Stream } ;
23- use worker:: RUNTIME ;
24-
25- use crate :: bindings:: wasi:: http:: IncomingHandler ;
2622
2723fn main ( ) {
2824 let args = std:: env:: args ( ) . collect :: < Vec < _ > > ( ) ;
@@ -46,13 +42,13 @@ fn main() {
4642
4743 let mut sb = builder. build ( ) . unwrap ( ) ;
4844
49- let state = types :: WasiImpl :: new ( ) ;
50- let rt = bindings :: register_host_functions ( & mut sb, state) ;
45+ let state = WasiImpl :: new ( ) ;
46+ let rt = register_host_functions ( & mut sb, state) ;
5147
5248 let sb = sb. load_runtime ( ) . unwrap ( ) ;
5349 let sb = sb. load_module ( wasm_path) . unwrap ( ) ;
5450
55- let sb = bindings :: RootSandbox { sb, rt } ;
51+ let sb = RootSandbox { sb, rt } ;
5652 let sb = Arc :: new ( Mutex :: new ( sb) ) ;
5753
5854 RUNTIME . block_on ( async move {
@@ -92,7 +88,7 @@ async fn hello(
9288 mut req : hyper:: Request < hyper:: body:: Incoming > ,
9389) -> Result < hyper:: Response < Full < Bytes > > , Infallible > {
9490 let mut sb = sb. lock ( ) . await ;
95- let inst = bindings:: root:: component:: RootExports :: incoming_handler ( & mut * sb) ;
91+ let inst = wasi_impl :: bindings:: root:: component:: RootExports :: incoming_handler ( & mut * sb) ;
9692
9793 let body = req. body_mut ( ) ;
9894 let mut full_body = Vec :: new ( ) ;
@@ -124,9 +120,9 @@ async fn hello(
124120 . unwrap_or_default ( ) ,
125121 ) ,
126122 scheme : Some ( if req. uri ( ) . scheme_str ( ) == Some ( "https" ) {
127- bindings:: wasi:: http:: types:: Scheme :: HTTPS
123+ wasi_impl :: bindings:: wasi:: http:: types:: Scheme :: HTTPS
128124 } else {
129- bindings:: wasi:: http:: types:: Scheme :: HTTP
125+ wasi_impl :: bindings:: wasi:: http:: types:: Scheme :: HTTP
130126 } ) ,
131127 authority : req
132128 . uri ( )
@@ -188,19 +184,19 @@ async fn hello(
188184 }
189185}
190186
191- impl From < & hyper:: Method > for bindings :: wasi:: http:: types:: Method {
187+ impl From < & hyper:: Method > for wasi:: http:: types:: Method {
192188 fn from ( method : & hyper:: Method ) -> Self {
193189 match method. as_str ( ) {
194- "GET" => bindings:: wasi:: http:: types:: Method :: Get ,
195- "POST" => bindings:: wasi:: http:: types:: Method :: Post ,
196- "PUT" => bindings:: wasi:: http:: types:: Method :: Put ,
197- "DELETE" => bindings:: wasi:: http:: types:: Method :: Delete ,
198- "HEAD" => bindings:: wasi:: http:: types:: Method :: Head ,
199- "OPTIONS" => bindings:: wasi:: http:: types:: Method :: Options ,
200- "CONNECT" => bindings:: wasi:: http:: types:: Method :: Connect ,
201- "TRACE" => bindings:: wasi:: http:: types:: Method :: Trace ,
202- "PATCH" => bindings:: wasi:: http:: types:: Method :: Patch ,
203- other => bindings:: wasi:: http:: types:: Method :: Other ( other. to_string ( ) ) ,
190+ "GET" => wasi_impl :: bindings:: wasi:: http:: types:: Method :: Get ,
191+ "POST" => wasi_impl :: bindings:: wasi:: http:: types:: Method :: Post ,
192+ "PUT" => wasi_impl :: bindings:: wasi:: http:: types:: Method :: Put ,
193+ "DELETE" => wasi_impl :: bindings:: wasi:: http:: types:: Method :: Delete ,
194+ "HEAD" => wasi_impl :: bindings:: wasi:: http:: types:: Method :: Head ,
195+ "OPTIONS" => wasi_impl :: bindings:: wasi:: http:: types:: Method :: Options ,
196+ "CONNECT" => wasi_impl :: bindings:: wasi:: http:: types:: Method :: Connect ,
197+ "TRACE" => wasi_impl :: bindings:: wasi:: http:: types:: Method :: Trace ,
198+ "PATCH" => wasi_impl :: bindings:: wasi:: http:: types:: Method :: Patch ,
199+ other => wasi_impl :: bindings:: wasi:: http:: types:: Method :: Other ( other. to_string ( ) ) ,
204200 }
205201 }
206202}
0 commit comments