Skip to content

Commit c96a2b4

Browse files
authored
Update to wasmtime v36 (#500)
* Update to wasmtime v36 Includes a couple of non-functional changes to the WASI layer, which reflect the code motion that happened in the upstream crate. * Dummy support for `AsyncWrite` * Lint
1 parent 5f4de3f commit c96a2b4

File tree

9 files changed

+401
-295
lines changed

9 files changed

+401
-295
lines changed

Cargo.lock

Lines changed: 341 additions & 270 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
wasmtime (34.0.0)
4+
wasmtime (36.0.0)
55
rb_sys (~> 0.9.116)
66

77
GEM

ext/Cargo.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "wasmtime-rb"
3-
version = "33.0.0"
3+
version = "36.0.0"
44
edition = "2021"
55
authors = ["The Wasmtime Project Developers"]
66
license = "Apache-2.0"
@@ -24,8 +24,8 @@ magnus = { version = "0.7", features = ["rb-sys"] }
2424
rb-sys = { version = "*", default-features = false, features = [
2525
"stable-api-compiled-fallback",
2626
] }
27-
wasmtime = { version = "=34.0.0", features = ["memory-protection-keys"] }
28-
wasmtime-wasi = "=34.0.0"
27+
wasmtime = { version = "=36.0.0", features = ["memory-protection-keys"] }
28+
wasmtime-wasi = "=36.0.0"
2929
cap-std = "3.4.0"
3030
wat = "1.236.0"
3131
tokio = { version = "1.47.1", features = [
@@ -38,8 +38,8 @@ async-timer = { version = "1.0.0-beta.15", features = [
3838
"tokio1",
3939
], optional = true }
4040
static_assertions = "1.1.0"
41-
wasmtime-environ = "=34.0.0"
42-
deterministic-wasi-ctx = { version = "=3.0.0" }
41+
wasmtime-environ = "=36.0.0"
42+
deterministic-wasi-ctx = { version = "=3.0.1" }
4343

4444
[build-dependencies]
4545
rb-sys-env = "0.2.2"

ext/src/helpers/output_limited_buffer.rs

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ use magnus::{
55
};
66
use std::io::Write;
77
use std::sync::{Arc, Mutex};
8-
use wasmtime_wasi::p2::{OutputStream, Pollable, StdoutStream, StreamError, StreamResult};
8+
use tokio::io::AsyncWrite;
9+
use wasmtime_wasi::cli::{IsTerminal, StdoutStream};
10+
use wasmtime_wasi::p2::{OutputStream, Pollable, StreamError, StreamResult};
911

1012
/// A buffer that limits the number of bytes that can be written to it.
1113
/// If the buffer is full, it will truncate the data.
@@ -14,6 +16,31 @@ pub struct OutputLimitedBuffer {
1416
inner: Arc<Mutex<OutputLimitedBufferInner>>,
1517
}
1618

19+
// No support for WASI P3, yet.
20+
impl AsyncWrite for OutputLimitedBuffer {
21+
fn poll_write(
22+
self: std::pin::Pin<&mut Self>,
23+
_cx: &mut std::task::Context<'_>,
24+
_buf: &[u8],
25+
) -> std::task::Poll<Result<usize, std::io::Error>> {
26+
std::task::Poll::Ready(Ok(0))
27+
}
28+
29+
fn poll_flush(
30+
self: std::pin::Pin<&mut Self>,
31+
_cx: &mut std::task::Context<'_>,
32+
) -> std::task::Poll<Result<(), std::io::Error>> {
33+
std::task::Poll::Ready(Ok(()))
34+
}
35+
36+
fn poll_shutdown(
37+
self: std::pin::Pin<&mut Self>,
38+
_cx: &mut std::task::Context<'_>,
39+
) -> std::task::Poll<Result<(), std::io::Error>> {
40+
std::task::Poll::Ready(Ok(()))
41+
}
42+
}
43+
1744
impl OutputLimitedBuffer {
1845
/// Creates a new [OutputLimitedBuffer] with the given underlying buffer
1946
/// and capacity.
@@ -33,12 +60,19 @@ impl Clone for OutputLimitedBuffer {
3360
}
3461

3562
impl StdoutStream for OutputLimitedBuffer {
36-
fn stream(&self) -> Box<dyn OutputStream> {
63+
fn p2_stream(&self) -> Box<dyn OutputStream> {
64+
let cloned = self.clone();
65+
Box::new(cloned)
66+
}
67+
68+
fn async_stream(&self) -> Box<dyn AsyncWrite + Send + Sync> {
3769
let cloned = self.clone();
3870
Box::new(cloned)
3971
}
72+
}
4073

41-
fn isatty(&self) -> bool {
74+
impl IsTerminal for OutputLimitedBuffer {
75+
fn is_terminal(&self) -> bool {
4276
false
4377
}
4478
}

ext/src/ruby_api/component/convert.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ pub(crate) fn component_val_to_rb(val: Val, _store: &StoreContextValue) -> Resul
9393
}
9494
Val::Flags(vec) => Ok(vec.into_value()),
9595
Val::Resource(_resource_any) => not_implemented!("Resource not implemented"),
96+
Val::Future(_) => not_implemented!("Future not implemented"),
97+
Val::ErrorContext(_) => not_implemented!("ErrorContext not implemented"),
98+
Val::Stream(_) => not_implemented!("Stream not implemented"),
9699
}
97100
}
98101

@@ -280,6 +283,9 @@ pub(crate) fn rb_to_component_val(
280283
Type::Flags(_) => Vec::<String>::try_convert(value).map(Val::Flags),
281284
Type::Own(_resource_type) => not_implemented!("Resource not implemented"),
282285
Type::Borrow(_resource_type) => not_implemented!("Resource not implemented"),
286+
Type::Future(_) => not_implemented!("Future not implemented"),
287+
Type::Stream(_) => not_implemented!("Stream not implemented"),
288+
Type::ErrorContext => not_implemented!("ErrorContext not implemented"),
283289
}
284290
}
285291

ext/src/ruby_api/component/linker.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,7 @@ use magnus::{
1818
DataTypeFunctions, Error, Module as _, Object, RModule, Ruby, TryConvert, TypedData, Value,
1919
};
2020
use wasmtime::component::{Linker as LinkerImpl, LinkerInstance as LinkerInstanceImpl};
21-
use wasmtime_wasi::{
22-
p2::{IoView, WasiCtx, WasiView},
23-
ResourceTable,
24-
};
21+
use wasmtime_wasi::{ResourceTable, WasiCtx};
2522

2623
/// @yard
2724
/// @rename Wasmtime::Component::Linker

ext/src/ruby_api/store.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ use wasmtime::{
1919
AsContext, AsContextMut, ResourceLimiter, Store as StoreImpl, StoreContext, StoreContextMut,
2020
StoreLimits, StoreLimitsBuilder,
2121
};
22-
use wasmtime_wasi::p2::{IoView, WasiCtx, WasiView};
2322
use wasmtime_wasi::preview1::WasiP1Ctx;
2423
use wasmtime_wasi::{I32Exit, ResourceTable};
24+
use wasmtime_wasi::{WasiCtx, WasiCtxView, WasiView};
2525

2626
define_rb_intern!(
2727
WASI_CONFIG => "wasi_config",
@@ -513,15 +513,13 @@ impl ResourceLimiter for TrackingResourceLimiter {
513513
}
514514

515515
impl WasiView for StoreData {
516-
fn ctx(&mut self) -> &mut WasiCtx {
517-
self.wasi
516+
fn ctx(&mut self) -> WasiCtxView<'_> {
517+
let ctx = self
518+
.wasi
518519
.as_mut()
519-
.expect("Should have WASI context defined if using WASI p2")
520-
}
521-
}
520+
.expect("Should have WASI context defined if using WASI p2");
521+
let table = &mut self.resource_table;
522522

523-
impl IoView for StoreData {
524-
fn table(&mut self) -> &mut ResourceTable {
525-
&mut self.resource_table
523+
WasiCtxView { ctx, table }
526524
}
527525
}

ext/src/ruby_api/wasi_config.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ use std::convert::TryFrom;
1414
use std::fs;
1515
use std::path::Path;
1616
use std::{fs::File, path::PathBuf};
17+
use wasmtime_wasi::cli::OutputFile;
1718
use wasmtime_wasi::p2::pipe::MemoryInputPipe;
18-
use wasmtime_wasi::p2::{OutputFile, WasiCtx, WasiCtxBuilder};
1919
use wasmtime_wasi::preview1::WasiP1Ctx;
20-
use wasmtime_wasi::{DirPerms, FilePerms};
20+
use wasmtime_wasi::{DirPerms, FilePerms, WasiCtx, WasiCtxBuilder};
2121

2222
define_rb_intern!(
2323
READ => "read",

lib/wasmtime/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module Wasmtime
4-
VERSION = "34.0.0"
4+
VERSION = "36.0.0"
55
end

0 commit comments

Comments
 (0)