Skip to content

Commit

Permalink
Merge pull request #2 from golemcloud/wasmtime-15
Browse files Browse the repository at this point in the history
Update to wasmtime-15.0
  • Loading branch information
adamgfraser authored Dec 6, 2023
2 parents fa57a4c + 9416bf3 commit fa2fc91
Show file tree
Hide file tree
Showing 27 changed files with 947 additions and 1,409 deletions.
291 changes: 167 additions & 124 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion golem-wit
Submodule golem-wit updated 53 files
+ adapters/tier2/wasi_snapshot_preview1.wasm
+ adapters/tier3/wasi_snapshot_preview1.wasm
+9 −9 wit/deps/blobstore/blobstore.wit
+42 −48 wit/deps/blobstore/container.wit
+21 −20 wit/deps/blobstore/types.wit
+2 −2 wit/deps/blobstore/world.wit
+3 −29 wit/deps/cli/command.wit
+3 −3 wit/deps/cli/environment.wit
+1 −1 wit/deps/cli/exit.wit
+31 −0 wit/deps/cli/reactor.wit
+1 −1 wit/deps/cli/run.wit
+6 −6 wit/deps/cli/stdio.wit
+8 −20 wit/deps/cli/terminal.wit
+24 −13 wit/deps/clocks/monotonic-clock.wit
+0 −63 wit/deps/clocks/timezone.wit
+3 −4 wit/deps/clocks/wall-clock.wit
+6 −0 wit/deps/clocks/world.wit
+4 −2 wit/deps/filesystem/preopens.wit
+359 −549 wit/deps/filesystem/types.wit
+4 −4 wit/deps/filesystem/world.wit
+7 −7 wit/deps/golem/golem-host.wit
+43 −0 wit/deps/http/handler.wit
+0 −24 wit/deps/http/incoming-handler.wit
+0 −18 wit/deps/http/outgoing-handler.wit
+26 −27 wit/deps/http/proxy.wit
+537 −133 wit/deps/http/types.wit
+34 −0 wit/deps/io/error.wit
+41 −0 wit/deps/io/poll.wit
+230 −232 wit/deps/io/streams.wit
+6 −0 wit/deps/io/world.wit
+3 −3 wit/deps/keyvalue/atomic.wit
+5 −5 wit/deps/keyvalue/batch.wit
+27 −27 wit/deps/keyvalue/caching.wit
+3 −3 wit/deps/keyvalue/error.wit
+3 −3 wit/deps/keyvalue/handle-watch.wit
+5 −5 wit/deps/keyvalue/readwrite.wit
+23 −23 wit/deps/keyvalue/types.wit
+6 −6 wit/deps/keyvalue/world.wit
+3 −3 wit/deps/logging/logging.wit
+0 −39 wit/deps/poll/poll.wit
+2 −1 wit/deps/random/insecure-seed.wit
+3 −2 wit/deps/random/insecure.wit
+16 −15 wit/deps/random/random.wit
+7 −0 wit/deps/random/world.wit
+3 −3 wit/deps/sockets/instance-network.wit
+48 −66 wit/deps/sockets/ip-name-lookup.wit
+105 −145 wit/deps/sockets/network.wit
+22 −23 wit/deps/sockets/tcp-create-socket.wit
+299 −235 wit/deps/sockets/tcp.wit
+22 −23 wit/deps/sockets/udp-create-socket.wit
+274 −217 wit/deps/sockets/udp.wit
+11 −0 wit/deps/sockets/world.wit
+1 −1 wit/main.wit
4 changes: 2 additions & 2 deletions golem-worker-executor-base/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ url = { workspace = true }
uuid = { workspace = true }
value-bag = "1.4.2"
warp = { workspace = true }
wasmtime = { git = "https://github.com/bytecodealliance/wasmtime", rev = "134dddc8de5f9011aa7e4cf30cb8e9f9fa484e87", features = ["component-model"] }
wasmtime-runtime = { git = "https://github.com/bytecodealliance/wasmtime", rev = "134dddc8de5f9011aa7e4cf30cb8e9f9fa484e87" }
wasmtime = { version = "=15.0.0", features = ["component-model"] }
wasmtime-runtime = { version = "=15.0.0" }
windows-sys = "0.52.0"

[dev-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion golem-worker-executor-base/src/invocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ async fn call_exported_function<Ctx: FuelManagement + Send>(
result
};

let current_fuel_level = store.fuel_remaining().unwrap_or(0);
let current_fuel_level = store.get_fuel().unwrap_or(0);
let consumed_fuel_for_call = store
.data_mut()
.return_fuel(current_fuel_level as i64)
Expand Down
5 changes: 2 additions & 3 deletions golem-worker-executor-base/src/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ impl<Ctx: WorkerCtx> Worker<Ctx> {
this.config(),
WorkerConfig::new(worker_metadata.worker_id.clone(), worker_args, worker_env),
execution_status.clone(),
this.runtime().clone(),
)
.await?;

Expand All @@ -125,7 +124,7 @@ impl<Ctx: WorkerCtx> Worker<Ctx> {
let mut store = Store::new(&this.engine(), context);
store.set_epoch_deadline(1);
store.epoch_deadline_callback(|mut store| {
let current_level = store.fuel_remaining().unwrap_or(0);
let current_level = store.get_fuel().unwrap_or(0);
if store.data().is_out_of_fuel(current_level as i64) {
debug!("ran out of fuel, borrowing more");
store.data_mut().borrow_fuel_sync();
Expand All @@ -137,7 +136,7 @@ impl<Ctx: WorkerCtx> Worker<Ctx> {
}
});

store.add_fuel(i64::MAX as u64)?;
store.set_fuel(i64::MAX as u64)?;
store.data_mut().borrow_fuel().await?; // Borrowing fuel for initialization and also to make sure account is in cache

store.limiter_async(|ctx| ctx.resource_limiter());
Expand Down
3 changes: 0 additions & 3 deletions golem-worker-executor-base/src/workerctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use golem_common::model::{
WorkerStatus,
};
use golem_common::proto::golem::Val;
use tokio::runtime::Handle;
use wasmtime::{AsContextMut, ResourceLimiterAsync};

use crate::error::GolemError;
Expand Down Expand Up @@ -60,7 +59,6 @@ pub trait WorkerCtx:
/// - `config`: The shared worker configuration
/// - `worker_config`: Configuration for this specific worker
/// - `execution_status`: Lock created to store the execution status
/// - `runtime`: The tokio runtime
async fn create(
worker_id: VersionedWorkerId,
account_id: AccountId,
Expand All @@ -75,7 +73,6 @@ pub trait WorkerCtx:
config: Arc<GolemConfig>,
worker_config: WorkerConfig,
execution_status: Arc<RwLock<ExecutionStatus>>,
runtime: Handle,
) -> Result<Self, GolemError>;

/// Get the public part of the worker context
Expand Down
9 changes: 5 additions & 4 deletions golem-worker-executor-oss/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ async-trait = { workspace = true }
cap-std = "2.0.0"
console-subscriber = { workspace = true }
figment = { workspace = true }
flume = "0.11.0"
humantime-serde = { workspace = true }
prometheus = { workspace = true }
serde = { workspace = true }
Expand All @@ -33,7 +34,7 @@ tonic-reflection = { workspace = true }
tracing = { workspace = true }
tracing-subscriber = { workspace = true }
uuid = { workspace = true }
wasmtime = { git = "https://github.com/bytecodealliance/wasmtime", rev = "134dddc8de5f9011aa7e4cf30cb8e9f9fa484e87", features = ["component-model"] }
wasmtime-runtime = { git = "https://github.com/bytecodealliance/wasmtime", rev = "134dddc8de5f9011aa7e4cf30cb8e9f9fa484e87" }
wasmtime-wasi = { git = "https://github.com/bytecodealliance/wasmtime", rev = "134dddc8de5f9011aa7e4cf30cb8e9f9fa484e87", features = ["preview2", "tokio"] }
wasmtime-wasi-http = { git = "https://github.com/bytecodealliance/wasmtime", rev = "134dddc8de5f9011aa7e4cf30cb8e9f9fa484e87" }
wasmtime = { version = "=15.0.0", features = ["component-model"] }
wasmtime-runtime = { version = "=15.0.0" }
wasmtime-wasi = { version = "=15.0.0", features = ["preview2", "tokio"] }
wasmtime-wasi-http = { version = "=15.0.0" }
37 changes: 17 additions & 20 deletions golem-worker-executor-oss/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,12 @@ use golem_worker_executor_base::workerctx::{
PublicWorkerIo, StatusManagement, WorkerCtx,
};
use tempfile::TempDir;
use tokio::runtime::Handle;
use tonic::codegen::Bytes;
use tracing::debug;
use wasmtime::component::{Instance, Linker};
use wasmtime::{AsContextMut, Engine, ResourceLimiterAsync};
use wasmtime_wasi::preview2::{
stderr, DirPerms, FilePerms, I32Exit, IsATTY, Table, WasiCtx, WasiCtxBuilder, WasiView,
stderr, DirPerms, FilePerms, I32Exit, Table, WasiCtx, WasiCtxBuilder, WasiView,
};
use wasmtime_wasi_http::{WasiHttpCtx, WasiHttpView};

Expand Down Expand Up @@ -352,13 +351,11 @@ impl WorkerCtx for Context {
_config: Arc<GolemConfig>,
worker_config: WorkerConfig,
execution_status: Arc<RwLock<ExecutionStatus>>,
runtime: Handle,
) -> Result<Self, GolemError> {
let stdio =
ManagedStandardIo::new(worker_id.worker_id.clone(), invocation_key_service.clone());
let stdin = ManagedStdIn::from_standard_io(runtime.clone(), stdio.clone());
let stdout =
ManagedStdOut::from_standard_io(runtime.clone(), stdio.clone(), event_service.clone());
let stdin = ManagedStdIn::from_standard_io(stdio.clone()).await;
let stdout = ManagedStdOut::from_standard_io(stdio.clone(), event_service.clone());
let stderr = ManagedStdErr::from_stderr(stderr(), event_service.clone());

let temp_dir = Arc::new(tempfile::Builder::new().prefix("golem").tempdir().map_err(
Expand All @@ -367,13 +364,13 @@ impl WorkerCtx for Context {
let root_dir = cap_std::fs::Dir::open_ambient_dir(temp_dir.path(), ambient_authority())
.map_err(|e| GolemError::runtime(format!("Failed to open temporary directory: {e}")))?;

let mut table = Table::new();
let table = Table::new();
let wasi = WasiCtxBuilder::new()
.args(&worker_config.args)
.envs(&worker_config.env)
.stdin(stdin, IsATTY::No)
.stdout(stdout, IsATTY::No)
.stderr(stderr, IsATTY::No)
.stdin(stdin)
.stdout(stdout)
.stderr(stderr)
.preopened_dir(
root_dir
.try_clone()
Expand All @@ -383,8 +380,8 @@ impl WorkerCtx for Context {
"/",
)
.preopened_dir(root_dir, DirPerms::all(), FilePerms::all(), ".")
.build(&mut table)?;
let wasi_http = WasiHttpCtx::new();
.build();
let wasi_http = WasiHttpCtx;

Ok(Context {
active_workers,
Expand Down Expand Up @@ -470,12 +467,12 @@ impl WasiView for Context {
}

impl WasiHttpView for Context {
fn http_ctx(&self) -> &WasiHttpCtx {
&self.wasi_http
fn ctx(&mut self) -> &mut WasiHttpCtx {
&mut self.wasi_http
}

fn http_ctx_mut(&mut self) -> &mut WasiHttpCtx {
&mut self.wasi_http
fn table(&mut self) -> &mut Table {
&mut self.table
}
}

Expand Down Expand Up @@ -504,12 +501,12 @@ pub fn create_linker(engine: &Engine) -> wasmtime::Result<Linker<Context>> {
wasmtime_wasi::preview2::bindings::cli::terminal_stdin::add_to_linker(&mut linker, |x| x)?;
wasmtime_wasi::preview2::bindings::cli::terminal_stdout::add_to_linker(&mut linker, |x| x)?;
wasmtime_wasi::preview2::bindings::clocks::monotonic_clock::add_to_linker(&mut linker, |x| x)?;
wasmtime_wasi::preview2::bindings::clocks::timezone::add_to_linker(&mut linker, |x| x)?;
wasmtime_wasi::preview2::bindings::clocks::wall_clock::add_to_linker(&mut linker, |x| x)?;
wasmtime_wasi::preview2::bindings::filesystem::preopens::add_to_linker(&mut linker, |x| x)?;
wasmtime_wasi::preview2::bindings::filesystem::types::add_to_linker(&mut linker, |x| x)?;
wasmtime_wasi::preview2::bindings::io::error::add_to_linker(&mut linker, |x| x)?;
wasmtime_wasi::preview2::bindings::io::poll::add_to_linker(&mut linker, |x| x)?;
wasmtime_wasi::preview2::bindings::io::streams::add_to_linker(&mut linker, |x| x)?;
wasmtime_wasi::preview2::bindings::poll::poll::add_to_linker(&mut linker, |x| x)?;
wasmtime_wasi::preview2::bindings::random::random::add_to_linker(&mut linker, |x| x)?;
wasmtime_wasi::preview2::bindings::random::insecure::add_to_linker(&mut linker, |x| x)?;
wasmtime_wasi::preview2::bindings::random::insecure_seed::add_to_linker(&mut linker, |x| x)?;
Expand All @@ -524,8 +521,8 @@ pub fn create_linker(engine: &Engine) -> wasmtime::Result<Linker<Context>> {
|x| x,
)?;

wasmtime_wasi_http::wasi::http::outgoing_handler::add_to_linker(&mut linker, |x| x)?;
wasmtime_wasi_http::wasi::http::types::add_to_linker(&mut linker, |x| x)?;
wasmtime_wasi_http::bindings::wasi::http::outgoing_handler::add_to_linker(&mut linker, |x| x)?;
wasmtime_wasi_http::bindings::wasi::http::types::add_to_linker(&mut linker, |x| x)?;

crate::preview2::wasi::blobstore::blobstore::add_to_linker(&mut linker, |x| x)?;
crate::preview2::wasi::blobstore::container::add_to_linker(&mut linker, |x| x)?;
Expand Down
Loading

0 comments on commit fa2fc91

Please sign in to comment.