From e508111130757f39a5c9c06c459e56d6e40feef7 Mon Sep 17 00:00:00 2001 From: Ava Hahn Date: Wed, 28 Aug 2024 12:50:45 -0700 Subject: [PATCH] bump wasmtime to v24 Signed-off-by: Ava Hahn --- docs/changes.xml | 5 + pkg/contrib/src/wasmtime/Makefile | 8 +- pkg/contrib/src/wasmtime/SHA512SUMS | 2 +- pkg/contrib/src/wasmtime/version | 2 +- src/wasm-wasi-component/Cargo.lock | 563 +++++++++++++++------------- src/wasm-wasi-component/Cargo.toml | 7 +- src/wasm-wasi-component/src/lib.rs | 59 ++- 7 files changed, 344 insertions(+), 302 deletions(-) diff --git a/docs/changes.xml b/docs/changes.xml index 014155d4c..d4418bb24 100644 --- a/docs/changes.xml +++ b/docs/changes.xml @@ -29,6 +29,11 @@ NGINX Unit updated to 1.33.0. + + +wasm and wasm-wasi-component now built against libwasmtime 24.0.0 + + /dev/null 2>&1 || echo FAIL),) +CMAKE = cmake +else +cmake = $(error Cmake not found) +endif + ifeq ($(shell uname -s),Linux) WASMTIME_ARGS=-Clink-arg=-Wl,-soname,libwasmtime.so endif @@ -26,5 +32,5 @@ wasmtime: wasmtime-v$(WASMTIME_VERSION)-src.tar.gz .sum-wasmtime .wasmtime: wasmtime cd $< && $(CARGO) rustc --release -p wasmtime-c-api -- $(WASMTIME_ARGS) - cp $, + component: ProxyPre, global_config: &'static GlobalConfig, sender: mpsc::Sender, } @@ -209,11 +210,15 @@ impl GlobalState { let component = Component::from_file(&engine, &global_config.component) .context("failed to compile component")?; let mut linker = Linker::::new(&engine); - wasmtime_wasi::preview2::command::add_to_linker(&mut linker)?; - wasmtime_wasi_http::proxy::add_only_http_to_linker(&mut linker)?; + add_to_linker_async(&mut linker) + .context("failed to add to linker")?; + //add_only_http_to_linker_sync(&mut linker) + // .context("failed to add http to linker")?; let component = linker .instantiate_pre(&component) .context("failed to pre-instantiate the provided component")?; + let proxy = ProxyPre::new(component) + .context("failed to conform to proxy")?; // Spin up the Tokio async runtime in a separate thread with a // communication channel into it. This thread will send requests to @@ -223,7 +228,7 @@ impl GlobalState { Ok(GlobalState { engine, - component, + component: proxy, sender, global_config, }) @@ -257,21 +262,17 @@ impl GlobalState { cx.inherit_stdout(); cx.inherit_stderr(); for dir in self.global_config.dirs.iter() { - let fd = Dir::open_ambient_dir(dir, ambient_authority()) - .with_context(|| { - format!("failed to open directory '{dir}'") - })?; cx.preopened_dir( - fd, + dir, + dir, DirPerms::all(), FilePerms::all(), - dir, - ); + )?; } cx.build() }, table: ResourceTable::default(), - http: WasiHttpCtx, + http: WasiHttpCtx::new(), }; let mut store = Store::new(&self.engine, data); @@ -292,15 +293,9 @@ impl GlobalState { // generate headers, write those below, and then compute the body // afterwards. let task = tokio::spawn(async move { - let (proxy, _) = wasmtime_wasi_http::proxy::Proxy::instantiate_pre( - &mut store, - &self.component, - ) - .await - .context("failed to instantiate")?; - let req = store.data_mut().new_incoming_request(request)?; + let req = store.data_mut().new_incoming_request(Scheme::Http, request)?; let out = store.data_mut().new_response_outparam(sender)?; - proxy + self.component.instantiate_async(&mut store).await? .wasi_http_incoming_handler() .call_handle(&mut store, req, out) .await @@ -376,7 +371,7 @@ impl GlobalState { fn to_request_body( &self, info: &mut NxtRequestInfo, - ) -> BoxBody { + ) -> BoxBody { // TODO: should convert the body into a form of `Stream` to become an // async stream of frames. The return value can represent that here // but for now this slurps up the entire body into memory and puts it @@ -594,16 +589,10 @@ struct StoreState { } impl WasiView for StoreState { - fn table(&self) -> &ResourceTable { - &self.table - } - fn table_mut(&mut self) -> &mut ResourceTable { + fn table(&mut self) -> &mut ResourceTable { &mut self.table } - fn ctx(&self) -> &WasiCtx { - &self.ctx - } - fn ctx_mut(&mut self) -> &mut WasiCtx { + fn ctx(&mut self) -> &mut WasiCtx { &mut self.ctx } }