From c4605bca951ca2299e7372547cd3f92661c0408b Mon Sep 17 00:00:00 2001 From: Jeff Charles Date: Thu, 10 Apr 2025 18:10:59 -0400 Subject: [PATCH] Switch to wasmtime-wasi --- .github/dependabot.yml | 1 - Cargo.lock | 333 +++++++---------------------------------- Cargo.toml | 41 +++-- src/engine.rs | 48 +++--- 4 files changed, 97 insertions(+), 326 deletions(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 3224f772..9ec20001 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -12,7 +12,6 @@ updates: patterns: - "wasmtime" - "wasmtime-wasi" - - "wasi-common" - "deterministic-wasi-ctx" - package-ecosystem: "github-actions" directory: "/" diff --git a/Cargo.lock b/Cargo.lock index 61f45a97..974ae63e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -487,15 +487,6 @@ dependencies = [ "cranelift-entity 0.115.1", ] -[[package]] -name = "cranelift-bforest" -version = "0.116.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e15d04a0ce86cb36ead88ad68cf693ffd6cda47052b9e0ac114bc47fd9cd23c4" -dependencies = [ - "cranelift-entity 0.116.1", -] - [[package]] name = "cranelift-bitset" version = "0.115.1" @@ -523,13 +514,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "aed3d2d9914d30b460eedd7fd507720203023997bef71452ce84873f9c93537c" dependencies = [ "bumpalo", - "cranelift-bforest 0.115.1", + "cranelift-bforest", "cranelift-bitset 0.115.1", - "cranelift-codegen-meta 0.115.1", - "cranelift-codegen-shared 0.115.1", - "cranelift-control 0.115.1", + "cranelift-codegen-meta", + "cranelift-codegen-shared", + "cranelift-control", "cranelift-entity 0.115.1", - "cranelift-isle 0.115.1", + "cranelift-isle", "gimli", "hashbrown 0.14.5", "log", @@ -541,46 +532,13 @@ dependencies = [ "target-lexicon 0.12.16", ] -[[package]] -name = "cranelift-codegen" -version = "0.116.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c22032c4cb42558371cf516bb47f26cdad1819d3475c133e93c49f50ebf304e" -dependencies = [ - "bumpalo", - "cranelift-bforest 0.116.1", - "cranelift-bitset 0.116.1", - "cranelift-codegen-meta 0.116.1", - "cranelift-codegen-shared 0.116.1", - "cranelift-control 0.116.1", - "cranelift-entity 0.116.1", - "cranelift-isle 0.116.1", - "gimli", - "hashbrown 0.14.5", - "log", - "regalloc2", - "rustc-hash", - "serde", - "smallvec", - "target-lexicon 0.13.1", -] - [[package]] name = "cranelift-codegen-meta" version = "0.115.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "888c188d32263ec9e048873ff0b68c700933600d553f4412417916828be25f8e" dependencies = [ - "cranelift-codegen-shared 0.115.1", -] - -[[package]] -name = "cranelift-codegen-meta" -version = "0.116.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c904bc71c61b27fc57827f4a1379f29de64fe95653b620a3db77d59655eee0b8" -dependencies = [ - "cranelift-codegen-shared 0.116.1", + "cranelift-codegen-shared", ] [[package]] @@ -589,12 +547,6 @@ version = "0.115.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4ddd5f4114d04ce7e073dd74e2ad16541fc61970726fcc8b2d5644a154ee4127" -[[package]] -name = "cranelift-codegen-shared" -version = "0.116.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40180f5497572f644ce88c255480981ae2ec1d7bb4d8e0c0136a13b87a2f2ceb" - [[package]] name = "cranelift-control" version = "0.115.1" @@ -604,15 +556,6 @@ dependencies = [ "arbitrary", ] -[[package]] -name = "cranelift-control" -version = "0.116.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26d132c6d0bd8a489563472afc171759da0707804a65ece7ceb15a8c6d7dd5ef" -dependencies = [ - "arbitrary", -] - [[package]] name = "cranelift-entity" version = "0.115.1" @@ -641,58 +584,29 @@ version = "0.115.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c0bf77ec0f470621655ec7539860b5c620d4f91326654ab21b075b83900f8831" dependencies = [ - "cranelift-codegen 0.115.1", + "cranelift-codegen", "log", "smallvec", "target-lexicon 0.12.16", ] -[[package]] -name = "cranelift-frontend" -version = "0.116.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fac41e16729107393174b0c9e3730fb072866100e1e64e80a1a963b2e484d57" -dependencies = [ - "cranelift-codegen 0.116.1", - "log", - "smallvec", - "target-lexicon 0.13.1", -] - [[package]] name = "cranelift-isle" version = "0.115.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4b665d0a6932c421620be184f9fc7f7adaf1b0bc2fa77bb7ac5177c49abf645b" -[[package]] -name = "cranelift-isle" -version = "0.116.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ca20d576e5070044d0a72a9effc2deacf4d6aa650403189d8ea50126483944d" - [[package]] name = "cranelift-native" version = "0.115.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bb2e75d1bd43dfec10924798f15e6474f1dbf63b0024506551aa19394dbe72ab" dependencies = [ - "cranelift-codegen 0.115.1", + "cranelift-codegen", "libc", "target-lexicon 0.12.16", ] -[[package]] -name = "cranelift-native" -version = "0.116.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8dee82f3f1f2c4cba9177f1cc5e350fe98764379bcd29340caa7b01f85076c7" -dependencies = [ - "cranelift-codegen 0.116.1", - "libc", - "target-lexicon 0.13.1", -] - [[package]] name = "crc32fast" version = "1.4.2" @@ -748,16 +662,19 @@ dependencies = [ [[package]] name = "deterministic-wasi-ctx" -version = "0.1.29" +version = "0.1.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fcd7639533f5bc6e577b1116c5f916a0d6ed171a8d7a09877080188ab2a4fa7a" +checksum = "f7149801e06c420d45e7100cb7481d6be1609edb7a7913b75c02a2ea4b6c4032" dependencies = [ "anyhow", "async-trait", "cap-primitives", "rand_core", "rand_pcg", + "wasi", "wasi-common", + "wasmtime 28.0.1", + "wasmtime-wasi", ] [[package]] @@ -983,7 +900,6 @@ dependencies = [ "rust-embed", "serde", "serde_json", - "wasi-common", "wasmprof", "wasmtime 28.0.1", "wasmtime-wasi", @@ -2209,9 +2125,9 @@ checksum = "61c41af27dd6d1e27b1b16b489db798443478cef1f06a660c96db617ba5de3b1" [[package]] name = "target-lexicon" -version = "0.13.1" +version = "0.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc12939a1c9b9d391e0b7135f72fd30508b73450753e28341fed159317582a77" +checksum = "e502f78cdbb8ba4718f566c418c52bc729126ffd16baee5baa718cf25dd5a69a" [[package]] name = "tempfile" @@ -2352,17 +2268,6 @@ dependencies = [ "once_cell", ] -[[package]] -name = "trait-variant" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70977707304198400eb4835a78f6a9f928bf41bba420deb8fdb175cd965d77a7" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "typenum" version = "1.17.0" @@ -2461,9 +2366,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasi-common" -version = "28.0.0" +version = "29.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6cb8b6f1ca9cc40aeca0f398163ce2c1305d0661f3311a25abcda1fc6012d8f2" +checksum = "fe3101bd34deeb64225431f8b1b1793c87e7cad94383464878b3f90da6995977" dependencies = [ "anyhow", "bitflags 2.6.0", @@ -2479,8 +2384,8 @@ dependencies = [ "system-interface", "thiserror", "tracing", - "wasmtime 28.0.1", - "wiggle 28.0.0", + "wasmtime 29.0.1", + "wiggle 29.0.1", "windows-sys 0.59.0", ] @@ -2629,16 +2534,16 @@ dependencies = [ "wasmparser", "wasmtime-asm-macros 28.0.1", "wasmtime-cache", - "wasmtime-component-macro 28.0.1", - "wasmtime-component-util 28.0.1", - "wasmtime-cranelift 28.0.1", + "wasmtime-component-macro", + "wasmtime-component-util", + "wasmtime-cranelift", "wasmtime-environ 28.0.1", - "wasmtime-fiber 28.0.1", + "wasmtime-fiber", "wasmtime-jit-debug", - "wasmtime-jit-icache-coherence 28.0.1", + "wasmtime-jit-icache-coherence", "wasmtime-slab 28.0.1", "wasmtime-versioned-export-macros 28.0.1", - "wasmtime-winch 28.0.1", + "wasmtime-winch", "wat", "windows-sys 0.59.0", ] @@ -2650,12 +2555,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "11976a250672556d1c4c04c6d5d7656ac9192ac9edc42a4587d6c21460010e69" dependencies = [ "anyhow", - "async-trait", "bitflags 2.6.0", "bumpalo", "cc", "cfg-if", - "encoding_rs", "hashbrown 0.14.5", "indexmap", "libc", @@ -2663,31 +2566,22 @@ dependencies = [ "mach2", "memfd", "object", - "once_cell", "paste", "postcard", "psm", "pulley-interpreter 29.0.1", "rustix", - "semver", "serde", "serde_derive", "smallvec", "sptr", - "target-lexicon 0.13.1", - "trait-variant", + "target-lexicon 0.13.2", "wasmparser", "wasmtime-asm-macros 29.0.1", - "wasmtime-component-macro 29.0.1", - "wasmtime-component-util 29.0.1", - "wasmtime-cranelift 29.0.1", "wasmtime-environ 29.0.1", - "wasmtime-fiber 29.0.1", - "wasmtime-jit-icache-coherence 29.0.1", "wasmtime-math", "wasmtime-slab 29.0.1", "wasmtime-versioned-export-macros 29.0.1", - "wasmtime-winch 29.0.1", "windows-sys 0.59.0", ] @@ -2739,23 +2633,8 @@ dependencies = [ "proc-macro2", "quote", "syn", - "wasmtime-component-util 28.0.1", - "wasmtime-wit-bindgen 28.0.1", - "wit-parser", -] - -[[package]] -name = "wasmtime-component-macro" -version = "29.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d74de6592ed945d0a602f71243982a304d5d02f1e501b638addf57f42d57dfaf" -dependencies = [ - "anyhow", - "proc-macro2", - "quote", - "syn", - "wasmtime-component-util 29.0.1", - "wasmtime-wit-bindgen 29.0.1", + "wasmtime-component-util", + "wasmtime-wit-bindgen", "wit-parser", ] @@ -2765,12 +2644,6 @@ version = "28.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b9275aa01ceaaa2fa6c0ecaa5267518d80b9d6e9ae7c7ea42f4c6e073e6a69ef" -[[package]] -name = "wasmtime-component-util" -version = "29.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "707dc7b3c112ab5a366b30cfe2fb5b2f8e6a0f682f16df96a5ec582bfe6f056e" - [[package]] name = "wasmtime-cranelift" version = "28.0.1" @@ -2779,11 +2652,11 @@ checksum = "0701a44a323267aae4499672dae422b266cee3135a23b640972ec8c0e10a44a2" dependencies = [ "anyhow", "cfg-if", - "cranelift-codegen 0.115.1", - "cranelift-control 0.115.1", + "cranelift-codegen", + "cranelift-control", "cranelift-entity 0.115.1", - "cranelift-frontend 0.115.1", - "cranelift-native 0.115.1", + "cranelift-frontend", + "cranelift-native", "gimli", "itertools 0.12.1", "log", @@ -2797,31 +2670,6 @@ dependencies = [ "wasmtime-versioned-export-macros 28.0.1", ] -[[package]] -name = "wasmtime-cranelift" -version = "29.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "366be722674d4bf153290fbcbc4d7d16895cc82fb3e869f8d550ff768f9e9e87" -dependencies = [ - "anyhow", - "cfg-if", - "cranelift-codegen 0.116.1", - "cranelift-control 0.116.1", - "cranelift-entity 0.116.1", - "cranelift-frontend 0.116.1", - "cranelift-native 0.116.1", - "gimli", - "itertools 0.12.1", - "log", - "object", - "smallvec", - "target-lexicon 0.13.1", - "thiserror", - "wasmparser", - "wasmtime-environ 29.0.1", - "wasmtime-versioned-export-macros 29.0.1", -] - [[package]] name = "wasmtime-environ" version = "28.0.1" @@ -2846,7 +2694,7 @@ dependencies = [ "wasm-encoder", "wasmparser", "wasmprinter", - "wasmtime-component-util 28.0.1", + "wasmtime-component-util", ] [[package]] @@ -2863,15 +2711,11 @@ dependencies = [ "log", "object", "postcard", - "semver", "serde", "serde_derive", "smallvec", - "target-lexicon 0.13.1", - "wasm-encoder", + "target-lexicon 0.13.2", "wasmparser", - "wasmprinter", - "wasmtime-component-util 29.0.1", ] [[package]] @@ -2889,21 +2733,6 @@ dependencies = [ "windows-sys 0.59.0", ] -[[package]] -name = "wasmtime-fiber" -version = "29.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ccba90d4119f081bca91190485650730a617be1fff5228f8c4757ce133d21117" -dependencies = [ - "anyhow", - "cc", - "cfg-if", - "rustix", - "wasmtime-asm-macros 29.0.1", - "wasmtime-versioned-export-macros 29.0.1", - "windows-sys 0.59.0", -] - [[package]] name = "wasmtime-jit-debug" version = "28.0.1" @@ -2927,18 +2756,6 @@ dependencies = [ "windows-sys 0.59.0", ] -[[package]] -name = "wasmtime-jit-icache-coherence" -version = "29.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec5e8552e01692e6c2e5293171704fed8abdec79d1a6995a0870ab190e5747d1" -dependencies = [ - "anyhow", - "cfg-if", - "libc", - "windows-sys 0.59.0", -] - [[package]] name = "wasmtime-math" version = "29.0.1" @@ -2984,9 +2801,9 @@ dependencies = [ [[package]] name = "wasmtime-wasi" -version = "29.0.1" +version = "28.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d1be69bfcab1bdac74daa7a1f9695ab992b9c8e21b9b061e7d66434097e0ca4" +checksum = "1a8e04b9a4c68ad018b330a4f4914b82b01dc3582d715ce21a93564c7f26b19f" dependencies = [ "anyhow", "async-trait", @@ -3006,10 +2823,9 @@ dependencies = [ "thiserror", "tokio", "tracing", - "trait-variant", "url", - "wasmtime 29.0.1", - "wiggle 29.0.1", + "wasmtime 28.0.1", + "wiggle 28.0.1", "windows-sys 0.59.0", ] @@ -3020,31 +2836,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b111d909dc604c741bd8ac2f4af373eaa5c68c34b5717271bcb687688212cef8" dependencies = [ "anyhow", - "cranelift-codegen 0.115.1", + "cranelift-codegen", "gimli", "object", "target-lexicon 0.12.16", "wasmparser", - "wasmtime-cranelift 28.0.1", + "wasmtime-cranelift", "wasmtime-environ 28.0.1", - "winch-codegen 28.0.1", -] - -[[package]] -name = "wasmtime-winch" -version = "29.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fdbabfb8f20502d5e1d81092b9ead3682ae59988487aafcd7567387b7a43cf8f" -dependencies = [ - "anyhow", - "cranelift-codegen 0.116.1", - "gimli", - "object", - "target-lexicon 0.13.1", - "wasmparser", - "wasmtime-cranelift 29.0.1", - "wasmtime-environ 29.0.1", - "winch-codegen 29.0.1", + "winch-codegen", ] [[package]] @@ -3059,18 +2858,6 @@ dependencies = [ "wit-parser", ] -[[package]] -name = "wasmtime-wit-bindgen" -version = "29.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8358319c2dd1e4db79e3c1c5d3a5af84956615343f9f89f4e4996a36816e06e6" -dependencies = [ - "anyhow", - "heck", - "indexmap", - "wit-parser", -] - [[package]] name = "wast" version = "35.0.2" @@ -3104,9 +2891,9 @@ dependencies = [ [[package]] name = "wiggle" -version = "28.0.0" +version = "28.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17bccfa2095b348aa6de0efcc4c621ba14d6ecc2371433232f337b1d2f089fa3" +checksum = "3b23e3dc273d1e35cab9f38a5f76487aeeedcfa6a3fb594e209ee7b6f8b41dcc" dependencies = [ "anyhow", "async-trait", @@ -3114,7 +2901,7 @@ dependencies = [ "thiserror", "tracing", "wasmtime 28.0.1", - "wiggle-macro 28.0.0", + "wiggle-macro 28.0.1", ] [[package]] @@ -3134,9 +2921,9 @@ dependencies = [ [[package]] name = "wiggle-generate" -version = "28.0.0" +version = "28.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a1fda112fc9de89fc4af51ea8b4c8e745ce1f01cd19f08c36c37aa11563ad41" +checksum = "8738c5a7ef3a9de0fae10f8b84091a2aa4e059d8fef23de202ab689812b6bc6e" dependencies = [ "anyhow", "heck", @@ -3164,14 +2951,14 @@ dependencies = [ [[package]] name = "wiggle-macro" -version = "28.0.0" +version = "28.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc9a143339de27ff05ce30366c58b741afb38c803b5ffb68e9546fd2e0629c4a" +checksum = "e882267ac583e013a38a5aaeb83a49b219456ba3aa6e6772440f7213b176e8ff" dependencies = [ "proc-macro2", "quote", "syn", - "wiggle-generate 28.0.0", + "wiggle-generate 28.0.1", ] [[package]] @@ -3224,34 +3011,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6232f40a795be2ce10fc761ed3b403825126a60d12491ac556ea104a932fd18a" dependencies = [ "anyhow", - "cranelift-codegen 0.115.1", + "cranelift-codegen", "gimli", "regalloc2", "smallvec", "target-lexicon 0.12.16", "wasmparser", - "wasmtime-cranelift 28.0.1", + "wasmtime-cranelift", "wasmtime-environ 28.0.1", ] -[[package]] -name = "winch-codegen" -version = "29.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f849ef2c5f46cb0a20af4b4487aaa239846e52e2c03f13fa3c784684552859c" -dependencies = [ - "anyhow", - "cranelift-codegen 0.116.1", - "gimli", - "regalloc2", - "smallvec", - "target-lexicon 0.13.1", - "thiserror", - "wasmparser", - "wasmtime-cranelift 29.0.1", - "wasmtime-environ 29.0.1", -] - [[package]] name = "windows-core" version = "0.52.0" diff --git a/Cargo.toml b/Cargo.toml index 0d339d9a..498858c3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,28 +23,27 @@ opt-level = 3 [dependencies] wasmtime = { version = "=28.0.1", default-features = false, features = [ - "addr2line", - "all-arch", - "async", - "cache", - "component-model", - "coredump", - "cranelift", - "debug-builtins", - "demangle", - "parallel-compilation", - "pooling-allocator", - "profiling", - "runtime", - "signals-based-traps", - "std", - "threads", - "wat", - "winch", + "addr2line", + "all-arch", + "async", + "cache", + "component-model", + "coredump", + "cranelift", + "debug-builtins", + "demangle", + "parallel-compilation", + "pooling-allocator", + "profiling", + "runtime", + "signals-based-traps", + "std", + "threads", + "wat", + "winch", ] } -wasmtime-wasi = "=29.0.1" -wasi-common = "=28.0.0" -deterministic-wasi-ctx = "=0.1.29" +wasmtime-wasi = "=28.0.1" +deterministic-wasi-ctx = "=0.1.31" anyhow = "1.0" clap = { version = "4.5", features = ["derive"] } serde_json = "1.0" diff --git a/src/engine.rs b/src/engine.rs index f7f68602..61dd8bdd 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -1,9 +1,11 @@ use anyhow::{anyhow, Result}; use rust_embed::RustEmbed; use std::string::String; -use std::{collections::HashSet, io::Cursor, path::PathBuf}; -use wasi_common::{I32Exit, WasiCtx}; +use std::{collections::HashSet, path::PathBuf}; use wasmtime::{AsContextMut, Config, Engine, Linker, Module, ResourceLimiter, Store}; +use wasmtime_wasi::pipe::{MemoryInputPipe, MemoryOutputPipe}; +use wasmtime_wasi::preview1::WasiP1Ctx; +use wasmtime_wasi::{I32Exit, WasiCtxBuilder}; use crate::function_run_result::{ FunctionOutput::{self, InvalidJsonOutput, JsonOutput}, @@ -58,12 +60,12 @@ const STARTING_FUEL: u64 = u64::MAX; const MAXIMUM_MEMORIES: usize = 2; // 1 for the module, 1 for Javy's provider struct FunctionContext { - wasi: WasiCtx, + wasi: WasiP1Ctx, limiter: MemoryLimiter, } impl FunctionContext { - fn new(wasi: WasiCtx) -> Self { + fn new(wasi: WasiP1Ctx) -> Self { Self { wasi, limiter: Default::default(), @@ -126,9 +128,9 @@ pub fn run(params: FunctionRunParams) -> Result { let module = Module::from_file(&engine, &function_path) .map_err(|e| anyhow!("Couldn't load the Function {:?}: {}", &function_path, e))?; - let input_stream = wasi_common::pipe::ReadPipe::new(Cursor::new(input.clone())); - let output_stream = wasi_common::pipe::WritePipe::new_in_memory(); - let error_stream = wasi_common::pipe::WritePipe::new_in_memory(); + let input_stream = MemoryInputPipe::new(input.clone()); + let output_stream = MemoryOutputPipe::new(usize::MAX); + let error_stream = MemoryOutputPipe::new(usize::MAX); let memory_usage: u64; let instructions: u64; @@ -138,11 +140,16 @@ pub fn run(params: FunctionRunParams) -> Result { { let mut linker = Linker::new(&engine); - wasi_common::sync::add_to_linker(&mut linker, |ctx: &mut FunctionContext| &mut ctx.wasi)?; - let wasi = deterministic_wasi_ctx::build_wasi_ctx(); - wasi.set_stdin(Box::new(input_stream)); - wasi.set_stdout(Box::new(output_stream.clone())); - wasi.set_stderr(Box::new(error_stream.clone())); + wasmtime_wasi::preview1::add_to_linker_sync(&mut linker, |ctx: &mut FunctionContext| { + &mut ctx.wasi + })?; + deterministic_wasi_ctx::replace_scheduling_functions(&mut linker)?; + let mut wasi_builder = WasiCtxBuilder::new(); + wasi_builder.stdin(input_stream); + wasi_builder.stdout(output_stream.clone()); + wasi_builder.stderr(error_stream.clone()); + deterministic_wasi_ctx::add_determinism_to_wasi_ctx_builder(&mut wasi_builder); + let wasi = wasi_builder.build_p1(); let function_context = FunctionContext::new(wasi); let mut store = Store::new(&engine, function_context); store.limiter(|s| &mut s.limiter); @@ -173,12 +180,11 @@ pub fn run(params: FunctionRunParams) -> Result { // modules may exit with a specific exit code, an exit code of 0 is considered success but is reported as // a GuestFault by wasmtime, so we need to map it to a success result. Any other exit code is considered // a failure. - module_result = - module_result.or_else(|error| match error.downcast_ref::() { - Some(I32Exit(0)) => Ok(()), - Some(I32Exit(code)) => Err(anyhow!("module exited with code: {}", code)), - None => Err(error), - }); + module_result = module_result.or_else(|error| match error.downcast_ref::() { + Some(I32Exit(0)) => Ok(()), + Some(I32Exit(code)) => Err(anyhow!("module exited with code: {}", code)), + None => Err(error), + }); memory_usage = store.data().max_memory_bytes() as u64 / 1024; instructions = STARTING_FUEL.saturating_sub(store.get_fuel().unwrap_or_default()); @@ -193,15 +199,13 @@ pub fn run(params: FunctionRunParams) -> Result { let mut logs = error_stream .try_into_inner() - .expect("Log stream reference still exists") - .into_inner(); + .expect("Log stream reference still exists"); logs.extend_from_slice(error_logs.as_bytes()); let raw_output = output_stream .try_into_inner() - .expect("Output stream reference still exists") - .into_inner(); + .expect("Output stream reference still exists"); let output: FunctionOutput = match serde_json::from_slice(&raw_output) { Ok(json_output) => JsonOutput(json_output),