Skip to content

Commit

Permalink
Merge pull request #3005 from alexcrichton/update-wasmtime
Browse files Browse the repository at this point in the history
Update Wasmtime to 29.0.1
  • Loading branch information
lann authored Feb 6, 2025
2 parents e5c6a13 + badc3b1 commit e721610
Show file tree
Hide file tree
Showing 36 changed files with 698 additions and 619 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
6 changes: 1 addition & 5 deletions crates/componentize/src/abi_conformance/test_config.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
use super::{config, Context, TestConfig};
use anyhow::{ensure, Result};
use std::collections::HashMap;
use wasmtime::{
component::{InstancePre, __internal::async_trait},
Engine,
};
use wasmtime::{component::InstancePre, Engine};

#[derive(Default)]
pub(super) struct Config {
map: HashMap<String, String>,
}

#[async_trait]
impl config::Host for Config {
async fn get_config(&mut self, key: String) -> Result<Result<String, config::Error>> {
Ok(self
Expand Down
2 changes: 0 additions & 2 deletions crates/componentize/src/abi_conformance/test_http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use super::{
Context, TestConfig,
};
use anyhow::{ensure, Result};
use async_trait::async_trait;
use std::collections::HashMap;
use wasmtime::{component::InstancePre, Engine};

Expand All @@ -13,7 +12,6 @@ pub(crate) struct Http {
map: HashMap<String, String>,
}

#[async_trait]
impl http::Host for Http {
async fn send_request(&mut self, req: Request) -> Result<Result<Response, HttpError>> {
Ok(self
Expand Down
2 changes: 0 additions & 2 deletions crates/componentize/src/abi_conformance/test_key_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use super::{
Context, TestConfig,
};
use anyhow::{anyhow, ensure, Result};
use async_trait::async_trait;
use serde::Serialize;
use std::{
collections::{HashMap, HashSet},
Expand Down Expand Up @@ -34,7 +33,6 @@ pub(crate) struct KeyValue {
close_set: HashSet<KvStore>,
}

#[async_trait]
impl key_value::Host for KeyValue {
async fn open(&mut self, name: String) -> Result<Result<KvStore, Error>> {
Ok(self.open_map.remove(&name).ok_or_else(|| {
Expand Down
2 changes: 0 additions & 2 deletions crates/componentize/src/abi_conformance/test_llm.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::collections::HashMap;

use anyhow::{ensure, Result};
use async_trait::async_trait;
use serde::Serialize;

use super::llm;
Expand All @@ -18,7 +17,6 @@ pub struct Llm {
embeddings: HashMap<(String, Vec<String>), Vec<Vec<f32>>>,
}

#[async_trait]
impl llm::Host for Llm {
async fn infer(
&mut self,
Expand Down
2 changes: 0 additions & 2 deletions crates/componentize/src/abi_conformance/test_mysql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use super::{
Context, TestConfig,
};
use anyhow::{ensure, Result};
use async_trait::async_trait;
use serde::Serialize;
use std::{
collections::{HashMap, HashSet},
Expand Down Expand Up @@ -40,7 +39,6 @@ pub(crate) struct Mysql {
query_map: HashMap<(String, String, String), RowSet>,
}

#[async_trait]
impl mysql::Host for Mysql {
async fn execute(
&mut self,
Expand Down
2 changes: 0 additions & 2 deletions crates/componentize/src/abi_conformance/test_postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use super::{
Context, TestConfig,
};
use anyhow::{ensure, Result};
use async_trait::async_trait;
use serde::Serialize;
use std::{collections::HashMap, iter};
use wasmtime::{component::InstancePre, Engine};
Expand Down Expand Up @@ -37,7 +36,6 @@ pub(crate) struct Postgres {
query_map: HashMap<(String, String, String), RowSet>,
}

#[async_trait]
impl postgres::Host for Postgres {
async fn execute(
&mut self,
Expand Down
2 changes: 0 additions & 2 deletions crates/componentize/src/abi_conformance/test_redis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use super::{
Context, TestConfig,
};
use anyhow::{ensure, Result};
use async_trait::async_trait;
use serde::Serialize;
use std::collections::{HashMap, HashSet};
use wasmtime::{component::InstancePre, Engine};
Expand Down Expand Up @@ -103,7 +102,6 @@ pub(crate) struct Redis {
execute_map: HashMap<(String, String, Vec<Vec<u8>>), Vec<RedisResult>>,
}

#[async_trait]
impl redis::Host for Redis {
async fn publish(
&mut self,
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
9 changes: 1 addition & 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,9 +277,9 @@ 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"))]
#[allow(clippy::type_complexity)]
async fn get_many(
&mut self,
bucket: Resource<wasi_keyvalue::batch::Bucket>,
Expand Down Expand Up @@ -323,7 +319,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 +358,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 +433,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
14 changes: 4 additions & 10 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 All @@ -62,11 +59,10 @@ impl<C: Client> v2::HostConnection for InstanceState<C> {
statement: String,
params: Vec<ParameterValue>,
) -> Result<(), v2::Error> {
Ok(self
.get_client(connection)
self.get_client(connection)
.await?
.execute(statement, params)
.await?)
.await
}

#[instrument(name = "spin_outbound_mysql.query", skip(self, connection, params), err(level = Level::INFO), fields(otel.kind = "client", db.system = "mysql", otel.name = statement))]
Expand All @@ -76,11 +72,10 @@ impl<C: Client> v2::HostConnection for InstanceState<C> {
statement: String,
params: Vec<ParameterValue>,
) -> Result<v2_types::RowSet, v2::Error> {
Ok(self
.get_client(connection)
self.get_client(connection)
.await?
.query(statement, params)
.await?)
.await
}

async fn drop(&mut self, connection: Resource<Connection>) -> Result<()> {
Expand Down Expand Up @@ -113,7 +108,6 @@ macro_rules! delegate {
}};
}

#[async_trait]
impl<C: Client> v1::Host for InstanceState<C> {
async fn execute(
&mut self,
Expand Down
Loading

0 comments on commit e721610

Please sign in to comment.