@@ -190,26 +190,19 @@ pub fn redis_component(_attr: TokenStream, item: TokenStream) -> TokenStream {
190190pub fn wasi_http_component ( _attr : TokenStream , item : TokenStream ) -> TokenStream {
191191 let func = syn:: parse_macro_input!( item as syn:: ItemFn ) ;
192192 let func_name = & func. sig . ident ;
193+ let preamble = preamble ( Export :: WasiHttp ) ;
193194
194195 quote ! (
195- :: spin_sdk:: wit_bindgen:: generate!( {
196- runtime_path: "::spin_sdk::wit_bindgen::rt" ,
197- world: "wasi-http-trigger" ,
198- path: #WIT_PATH ,
199- exports: {
200- "wasi:http/incoming-handler" : __spin_wasi_http:: Spin ,
201- }
202- } ) ;
203-
204196 #func
205-
197+ // We export wasi here since `wit-bindgen` currently has no way of using types
198+ // declared somewhere else as part of its generated code. If we want users to be able to
199+ // use `wasi-http` types, they have to be generated in this macro. This should be solved once
200+ // `with` is supported in wit-bindgen [ref: https://github.com/bytecodealliance/wit-bindgen/issues/694].
201+ use __spin_wasi_http:: wasi;
206202 mod __spin_wasi_http {
207- use super :: {
208- exports:: wasi:: http:: incoming_handler,
209- wasi:: http:: types:: { IncomingRequest , ResponseOutparam }
210- } ;
211-
212- pub struct Spin ;
203+ #preamble
204+ use exports:: wasi:: http:: incoming_handler;
205+ use wasi:: http:: types:: { IncomingRequest , ResponseOutparam } ;
213206
214207 impl incoming_handler:: Guest for Spin {
215208 fn handle( request: IncomingRequest , response_out: ResponseOutparam ) {
@@ -454,16 +447,19 @@ pub fn wasi_http_component(_attr: TokenStream, item: TokenStream) -> TokenStream
454447
455448#[ derive( Copy , Clone ) ]
456449enum Export {
450+ WasiHttp ,
457451 Http ,
458452 Redis ,
459453}
460454
461455fn preamble ( export : Export ) -> proc_macro2:: TokenStream {
462456 let export_decl = match export {
457+ Export :: WasiHttp => quote ! ( "wasi:http/incoming-handler" : Spin ) ,
463458 Export :: Http => quote ! ( "fermyon:spin/inbound-http" : Spin ) ,
464459 Export :: Redis => quote ! ( "fermyon:spin/inbound-redis" : Spin ) ,
465460 } ;
466461 let world = match export {
462+ Export :: WasiHttp => quote ! ( "wasi-http-trigger" ) ,
467463 Export :: Http => quote ! ( "http-trigger" ) ,
468464 Export :: Redis => quote ! ( "redis-trigger" ) ,
469465 } ;
0 commit comments