Skip to content

Commit

Permalink
Update Wasmtime to 29.0.1
Browse files Browse the repository at this point in the history
This commit updates Wasmtime from 25.0.3 to 29.0.1, the latest release
of Wasmtime. This update is accompanied with few minor changes around
bindings generation such as traits no longer needing `#[async_trait]`.

Otherwise one of the main features is that the WITs included with
Wasmtime's WASI implementation have been updated to 0.2.3 as well. This
should continue to still work with guests using 0.2.2 and prior, though.
  • Loading branch information
alexcrichton committed Feb 4, 2025
1 parent 24b8f0a commit 7787d40
Show file tree
Hide file tree
Showing 27 changed files with 686 additions and 588 deletions.
447 changes: 249 additions & 198 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,9 @@ wasi-common-preview1 = { version = "25.0.0", package = "wasi-common", features =
] }
wasm-pkg-common = "0.8"
wasm-pkg-client = "0.8"
wasmtime = "25.0.3"
wasmtime-wasi = "25.0.0"
wasmtime-wasi-http = "25.0.0"
wasmtime = "29.0.1"
wasmtime-wasi = "29.0.1"
wasmtime-wasi-http = "29.0.1"

spin-componentize = { path = "crates/componentize" }

Expand Down
4 changes: 2 additions & 2 deletions crates/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ impl Default for Config {
)
.max_core_instances_per_component(env("SPIN_WASMTIME_CORE_INSTANCE_COUNT", 200))
.max_tables_per_component(env("SPIN_WASMTIME_INSTANCE_TABLES", 20))
.table_elements(env("SPIN_WASMTIME_INSTANCE_TABLE_ELEMENTS", 100_000))
.table_elements(env("SPIN_WASMTIME_INSTANCE_TABLE_ELEMENTS", 100_000) as usize)
// The number of memories an instance can have effectively limits the number of inner components
// a composed component can have (since each inner component has its own memory). We default to 32 for now, and
// we'll see how often this limit gets reached.
Expand Down Expand Up @@ -175,7 +175,7 @@ fn use_pooling_allocator_by_default() -> bool {
// If the env var isn't set then perform the dynamic runtime probe
let mut config = wasmtime::Config::new();
config.wasm_memory64(true);
config.static_memory_maximum_size(1 << BITS_TO_TEST);
config.memory_reservation(1 << BITS_TO_TEST);

match wasmtime::Engine::new(&config) {
Ok(engine) => {
Expand Down
10 changes: 5 additions & 5 deletions crates/core/src/limits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use wasmtime::ResourceLimiterAsync;
#[derive(Default)]
pub struct StoreLimitsAsync {
max_memory_size: Option<usize>,
max_table_elements: Option<u32>,
max_table_elements: Option<usize>,
memory_consumed: u64,
}

Expand All @@ -33,9 +33,9 @@ impl ResourceLimiterAsync for StoreLimitsAsync {

async fn table_growing(
&mut self,
_current: u32,
desired: u32,
_maximum: Option<u32>,
_current: usize,
desired: usize,
_maximum: Option<usize>,
) -> Result<bool> {
let can_grow = if let Some(limit) = self.max_table_elements {
desired <= limit
Expand All @@ -47,7 +47,7 @@ impl ResourceLimiterAsync for StoreLimitsAsync {
}

impl StoreLimitsAsync {
pub fn new(max_memory_size: Option<usize>, max_table_elements: Option<u32>) -> Self {
pub fn new(max_memory_size: Option<usize>, max_table_elements: Option<usize>) -> Self {
Self {
max_memory_size,
max_table_elements,
Expand Down
8 changes: 0 additions & 8 deletions crates/factor-key-value/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,8 @@ impl KeyValueDispatch {
}
}

#[async_trait]
impl key_value::Host for KeyValueDispatch {}

#[async_trait]
impl key_value::HostStore for KeyValueDispatch {
#[instrument(name = "spin_key_value.open", skip(self), err(level = Level::INFO), fields(otel.kind = "client", kv.backend=self.manager.summary(&name).unwrap_or("unknown".to_string())))]
async fn open(&mut self, name: String) -> Result<Result<Resource<key_value::Store>, Error>> {
Expand Down Expand Up @@ -191,7 +189,6 @@ fn to_wasi_err(e: Error) -> wasi_keyvalue::store::Error {
}
}

#[async_trait]
impl wasi_keyvalue::store::Host for KeyValueDispatch {
async fn open(
&mut self,
Expand Down Expand Up @@ -219,7 +216,6 @@ impl wasi_keyvalue::store::Host for KeyValueDispatch {
}

use wasi_keyvalue::store::Bucket;
#[async_trait]
impl wasi_keyvalue::store::HostBucket for KeyValueDispatch {
async fn get(
&mut self,
Expand Down Expand Up @@ -281,7 +277,6 @@ impl wasi_keyvalue::store::HostBucket for KeyValueDispatch {
}
}

#[async_trait]
impl wasi_keyvalue::batch::Host for KeyValueDispatch {
#[instrument(name = "spin_key_value.get_many", skip(self, bucket, keys), err(level = Level::INFO), fields(otel.kind = "client"))]
async fn get_many(
Expand Down Expand Up @@ -323,7 +318,6 @@ impl wasi_keyvalue::batch::Host for KeyValueDispatch {
}
}

#[async_trait]
impl wasi_keyvalue::atomics::HostCas for KeyValueDispatch {
async fn new(
&mut self,
Expand Down Expand Up @@ -363,7 +357,6 @@ impl wasi_keyvalue::atomics::HostCas for KeyValueDispatch {
}
}

#[async_trait]
impl wasi_keyvalue::atomics::Host for KeyValueDispatch {
fn convert_cas_error(
&mut self,
Expand Down Expand Up @@ -439,7 +432,6 @@ fn to_legacy_error(value: key_value::Error) -> LegacyError {
}
}

#[async_trait]
impl spin_world::v1::key_value::Host for KeyValueDispatch {
async fn open(&mut self, name: String) -> Result<Result<u32, LegacyError>> {
let result = <Self as key_value::HostStore>::open(self, name).await?;
Expand Down
3 changes: 0 additions & 3 deletions crates/factor-llm/src/host.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
use async_trait::async_trait;
use spin_world::v1::llm::{self as v1};
use spin_world::v2::llm::{self as v2};
use tracing::field::Empty;
use tracing::{instrument, Level};

use crate::InstanceState;

#[async_trait]
impl v2::Host for InstanceState {
#[instrument(name = "spin_llm.infer", skip(self, prompt), err(level = Level::INFO), fields(otel.kind = "client", llm.backend = Empty))]
async fn infer(
Expand Down Expand Up @@ -55,7 +53,6 @@ impl v2::Host for InstanceState {
}
}

#[async_trait]
impl v1::Host for InstanceState {
async fn infer(
&mut self,
Expand Down
10 changes: 3 additions & 7 deletions crates/factor-outbound-http/src/spin.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
use http_body_util::BodyExt;
use spin_world::{
async_trait,
v1::{
http as spin_http,
http_types::{self, HttpError, Method, Request, Response},
},
use spin_world::v1::{
http as spin_http,
http_types::{self, HttpError, Method, Request, Response},
};
use tracing::{field::Empty, instrument, Level, Span};

use crate::intercept::InterceptOutcome;

#[async_trait]
impl spin_http::Host for crate::InstanceState {
#[instrument(name = "spin_outbound_http.send_request", skip_all, err(level = Level::INFO),
fields(otel.kind = "client", url.full = Empty, http.request.method = Empty,
Expand Down
4 changes: 1 addition & 3 deletions crates/factor-outbound-http/src/wasi_2023_10_18.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ mod bindings {

wasmtime::component::bindgen!({
path: "../../wit",
interfaces: r#"
include wasi:http/[email protected];
"#,
world: "wasi:http/[email protected]",
async: {
// Only need async exports
only_imports: [],
Expand Down
4 changes: 1 addition & 3 deletions crates/factor-outbound-http/src/wasi_2023_11_10.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ mod bindings {

wasmtime::component::bindgen!({
path: "../../wit",
interfaces: r#"
include wasi:http/[email protected];
"#,
world: "wasi:http/[email protected]",
async: {
// Only need async exports
only_imports: [],
Expand Down
1 change: 0 additions & 1 deletion crates/factor-outbound-mqtt/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ impl v2::Host for InstanceState {
}
}

#[async_trait]
impl v2::HostConnection for InstanceState {
#[instrument(name = "spin_outbound_mqtt.open_connection", skip(self, password), err(level = Level::INFO), fields(otel.kind = "client"))]
async fn open(
Expand Down
4 changes: 0 additions & 4 deletions crates/factor-outbound-mysql/src/host.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use anyhow::Result;
use spin_core::async_trait;
use spin_core::wasmtime::component::Resource;
use spin_world::v1::mysql as v1;
use spin_world::v2::mysql::{self as v2, Connection};
Expand Down Expand Up @@ -34,10 +33,8 @@ impl<C: Client> InstanceState<C> {
}
}

#[async_trait]
impl<C: Client> v2::Host for InstanceState<C> {}

#[async_trait]
impl<C: Client> v2::HostConnection for InstanceState<C> {
#[instrument(name = "spin_outbound_mysql.open", skip(self, address), err(level = Level::INFO), fields(otel.kind = "client", db.system = "mysql", db.address = Empty, server.port = Empty, db.namespace = Empty))]
async fn open(&mut self, address: String) -> Result<Resource<Connection>, v2::Error> {
Expand Down Expand Up @@ -113,7 +110,6 @@ macro_rules! delegate {
}};
}

#[async_trait]
impl<C: Client> v1::Host for InstanceState<C> {
async fn execute(
&mut self,
Expand Down
6 changes: 1 addition & 5 deletions crates/factor-outbound-pg/src/host.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use anyhow::Result;
use spin_core::{async_trait, wasmtime::component::Resource};
use spin_core::wasmtime::component::Resource;
use spin_world::spin::postgres::postgres::{self as v3};
use spin_world::v1::postgres as v1;
use spin_world::v1::rdbms_types as v1_types;
Expand Down Expand Up @@ -71,7 +71,6 @@ fn v2_params_to_v3(
params.into_iter().map(|p| p.try_into()).collect()
}

#[async_trait]
impl<C: Send + Sync + Client> spin_world::spin::postgres::postgres::HostConnection
for InstanceState<C>
{
Expand Down Expand Up @@ -155,10 +154,8 @@ macro_rules! delegate {
}};
}

#[async_trait]
impl<C: Send + Sync + Client> v2::Host for InstanceState<C> {}

#[async_trait]
impl<C: Send + Sync + Client> v2::HostConnection for InstanceState<C> {
#[instrument(name = "spin_outbound_pg.open", skip(self, address), err(level = Level::INFO), fields(otel.kind = "client", db.system = "postgresql", db.address = Empty, server.port = Empty, db.namespace = Empty))]
async fn open(&mut self, address: String) -> Result<Resource<v2::Connection>, v2::Error> {
Expand Down Expand Up @@ -211,7 +208,6 @@ impl<C: Send + Sync + Client> v2::HostConnection for InstanceState<C> {
}
}

#[async_trait]
impl<C: Send + Sync + Client> v1::Host for InstanceState<C> {
async fn execute(
&mut self,
Expand Down
4 changes: 1 addition & 3 deletions crates/factor-outbound-redis/src/host.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use anyhow::Result;
use redis::{aio::MultiplexedConnection, AsyncCommands, FromRedisValue, Value};
use spin_core::{async_trait, wasmtime::component::Resource};
use spin_core::wasmtime::component::Resource;
use spin_factor_outbound_networking::OutboundAllowedHosts;
use spin_world::v1::{redis as v1, redis_types};
use spin_world::v2::redis::{
Expand Down Expand Up @@ -52,7 +52,6 @@ impl v2::Host for crate::InstanceState {
}
}

#[async_trait]
impl v2::HostConnection for crate::InstanceState {
#[instrument(name = "spin_outbound_redis.open_connection", skip(self, address), err(level = Level::INFO), fields(otel.kind = "client", db.system = "redis", db.address = Empty, server.port = Empty, db.namespace = Empty))]
async fn open(&mut self, address: String) -> Result<Resource<RedisConnection>, Error> {
Expand Down Expand Up @@ -224,7 +223,6 @@ macro_rules! delegate {
}};
}

#[async_trait]
impl v1::Host for crate::InstanceState {
async fn publish(
&mut self,
Expand Down
4 changes: 0 additions & 4 deletions crates/factor-sqlite/src/host.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use std::collections::{HashMap, HashSet};
use std::sync::Arc;

use async_trait::async_trait;

use spin_factors::wasmtime::component::Resource;
use spin_factors::{anyhow, SelfInstanceBuilder};
use spin_world::v1::sqlite as v1;
Expand Down Expand Up @@ -60,7 +58,6 @@ impl v2::Host for InstanceState {
}
}

#[async_trait]
impl v2::HostConnection for InstanceState {
#[instrument(name = "spin_sqlite.open", skip(self), err(level = Level::INFO), fields(otel.kind = "client", db.system = "sqlite", sqlite.backend = Empty))]
async fn open(&mut self, database: String) -> Result<Resource<v2::Connection>, v2::Error> {
Expand Down Expand Up @@ -107,7 +104,6 @@ impl v2::HostConnection for InstanceState {
}
}

#[async_trait]
impl v1::Host for InstanceState {
async fn open(&mut self, database: String) -> Result<u32, v1::Error> {
let result = <Self as v2::HostConnection>::open(self, database).await;
Expand Down
5 changes: 1 addition & 4 deletions crates/factor-variables/src/host.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use spin_factors::anyhow;
use spin_world::{async_trait, v1, v2::variables, wasi::config as wasi_config};
use spin_world::{v1, v2::variables, wasi::config as wasi_config};
use tracing::{instrument, Level};

use crate::InstanceState;

#[async_trait]
impl variables::Host for InstanceState {
#[instrument(name = "spin_variables.get", skip(self), err(level = Level::INFO), fields(otel.kind = "client"))]
async fn get(&mut self, key: String) -> Result<String, variables::Error> {
Expand All @@ -20,7 +19,6 @@ impl variables::Host for InstanceState {
}
}

#[async_trait]
impl v1::config::Host for InstanceState {
async fn get_config(&mut self, key: String) -> Result<String, v1::config::Error> {
<Self as variables::Host>::get(self, key)
Expand All @@ -37,7 +35,6 @@ impl v1::config::Host for InstanceState {
}
}

#[async_trait]
impl wasi_config::store::Host for InstanceState {
async fn get(&mut self, key: String) -> Result<Option<String>, wasi_config::store::Error> {
match <Self as variables::Host>::get(self, key).await {
Expand Down
4 changes: 2 additions & 2 deletions crates/factor-wasi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ impl Factor for WasiFactor {
bindings::random::random::add_to_linker_get_host(linker, closure)?;
bindings::random::insecure::add_to_linker_get_host(linker, closure)?;
bindings::random::insecure_seed::add_to_linker_get_host(linker, closure)?;
bindings::cli::exit::add_to_linker_get_host(linker, closure)?;
bindings::cli::exit::add_to_linker_get_host(linker, &Default::default(), closure)?;
bindings::cli::environment::add_to_linker_get_host(linker, closure)?;
bindings::cli::stdin::add_to_linker_get_host(linker, closure)?;
bindings::cli::stdout::add_to_linker_get_host(linker, closure)?;
Expand All @@ -91,7 +91,7 @@ impl Factor for WasiFactor {
bindings::sockets::udp::add_to_linker_get_host(linker, closure)?;
bindings::sockets::udp_create_socket::add_to_linker_get_host(linker, closure)?;
bindings::sockets::instance_network::add_to_linker_get_host(linker, closure)?;
bindings::sockets::network::add_to_linker_get_host(linker, closure)?;
bindings::sockets::network::add_to_linker_get_host(linker, &Default::default(), closure)?;
bindings::sockets::ip_name_lookup::add_to_linker_get_host(linker, closure)?;

wasi_2023_10_18::add_to_linker(linker, closure)?;
Expand Down
Loading

0 comments on commit 7787d40

Please sign in to comment.