Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
594 changes: 298 additions & 296 deletions Cargo.lock

Large diffs are not rendered by default.

43 changes: 21 additions & 22 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,52 +9,51 @@ name = "componentize_py"
crate-type = ["cdylib", "rlib"]

[dependencies]
anyhow = { version = "1.0.86", features = ["backtrace"] }
clap = { version = "4.5.17", features = ["derive"] }
tar = "0.4.41"
tempfile = "3.12.0"
anyhow = { version = "1.0.89", features = ["backtrace"] }
clap = { version = "4.5.20", features = ["derive"] }
tar = "0.4.42"
tempfile = "3.13.0"
zstd = "0.13.2"
componentize-py-shared = { path = "shared" }
wasm-encoder = "0.216.0"
wit-parser = "0.216.0"
wit-component = "0.216.0"
wasmparser = "0.216.0"
indexmap = "2.5.0"
wasm-encoder = "0.219.0"
wit-parser = "0.219.0"
wit-component = "0.219.0"
wasmparser = "0.219.0"
indexmap = "2.6.0"
bincode = "1.3.3"
heck = "0.5.0"
pyo3 = { version = "0.20.0", features = [
"abi3-py37",
"extension-module",
], optional = true }
wasmtime = "24.0.0"
wasmtime-wasi = "24.0.0"
wasi-common = "24.0.0"
once_cell = "1.19.0"
component-init = { git = "https://github.com/dicej/component-init", rev = "bc276826" }
wasm-convert = { git = "https://github.com/dicej/wasm-convert", rev = "afbec48b" }
async-trait = "0.1.82"
futures = "0.3.30"
wasmtime = "25.0.1"
wasmtime-wasi = "25.0.1"
wasi-common = "25.0.1"
once_cell = "1.20.2"
component-init = { git = "https://github.com/benbrandt/component-init", rev = "01e18e7" }
wasm-convert = { git = "https://github.com/benbrandt/wasm-convert", rev = "afa8d0d" }
async-trait = "0.1.83"
futures = "0.3.31"
tokio = { version = "1.40.0", features = [
"macros",
"rt",
"rt-multi-thread",
"fs",
] }
bytes = "1.7.1"
bytes = "1.7.2"
pretty_env_logger = "0.5.0"
cap-std = "3.2.0"
cap-std = "3.3.0"
im-rc = "15.1.0"
serde = { version = "1.0.209", features = ["derive"] }
serde = { version = "1.0.210", features = ["derive"] }
toml = "0.8.19"
semver = "1.0.23"

[dev-dependencies]
async-trait = "0.1.82"
proptest = "1.5.0"
hex = "0.4.3"

[build-dependencies]
anyhow = "1.0.86"
anyhow = "1.0.89"
tar = "0.4.41"
zstd = "0.13.2"
test-generator = { path = "test-generator" }
Expand Down
6 changes: 3 additions & 3 deletions runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ edition = "2021"
crate-type = ["staticlib"]

[dependencies]
anyhow = "1.0.86"
once_cell = "1.19.0"
anyhow = "1.0.89"
once_cell = "1.20.2"
pyo3 = { version = "0.20.0", features = ["abi3-py311", "num-bigint"] }
componentize-py-shared = { path = "../shared" }
num-bigint = "0.4.6"
wit-bindgen = "0.16.0"
wit-bindgen = "0.18.0"
21 changes: 14 additions & 7 deletions src/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ pub fn make_bindings(

for (name, params, results) in IMPORT_SIGNATURES {
let offset = types.len();
types.function(params.iter().copied(), results.iter().copied());
types
.ty()
.function(params.iter().copied(), results.iter().copied());
imports.import("env", name, EntityType::Function(offset));
function_names.push((offset, (*name).to_owned()));
}
Expand Down Expand Up @@ -95,7 +97,7 @@ pub fn make_bindings(
let (params, results) = function.core_import_type(resolve);
let offset = types.len();

types.function(params, results);
types.ty().function(params, results);
imports.import(module, name, EntityType::Function(offset));
function_names.push((
offset,
Expand Down Expand Up @@ -176,7 +178,7 @@ pub fn make_bindings(
for (index, function) in summary.functions.iter().enumerate() {
let offset = types.len();
let (params, results) = function.core_export_type(resolve);
types.function(params, results);
types.ty().function(params, results);
functions.function(offset);
function_names.push((offset, function.internal_name(resolve)));
let mut gen = FunctionBindgen::new(summary, function, stack_pointer);
Expand Down Expand Up @@ -259,9 +261,13 @@ pub fn make_bindings(

{
let dispatch_offset = types.len();
types.function([ValType::I32; DISPATCH_CORE_PARAM_COUNT], []);
types
.ty()
.function([ValType::I32; DISPATCH_CORE_PARAM_COUNT], []);
let dispatchable_offset = types.len();
types.function([ValType::I32; DISPATCHABLE_CORE_PARAM_COUNT], []);
types
.ty()
.function([ValType::I32; DISPATCHABLE_CORE_PARAM_COUNT], []);
functions.function(dispatch_offset);
let name = "componentize-py#CallIndirect";
function_names.push((dispatch_offset, name.to_owned()));
Expand Down Expand Up @@ -300,7 +306,7 @@ pub fn make_bindings(
Some(0),
&ConstExpr::global_get(table_base),
Elements::Functions(
&summary
summary
.functions
.iter()
.enumerate()
Expand All @@ -309,7 +315,8 @@ pub fn make_bindings(
.is_dispatchable()
.then_some(import_function_count + u32::try_from(index).unwrap())
})
.collect::<Vec<_>>(),
.collect::<Vec<_>>()
.into(),
),
);

Expand Down
8 changes: 4 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ impl Invoker for MyInvoker {
Ok(result)
}

async fn call_float32(&mut self, function: &str) -> Result<f32> {
async fn call_f32(&mut self, function: &str) -> Result<f32> {
let func = self
.instance
.get_typed_func::<(), (f32,)>(&mut self.store, function)?;
Expand All @@ -148,7 +148,7 @@ impl Invoker for MyInvoker {
Ok(result)
}

async fn call_float64(&mut self, function: &str) -> Result<f64> {
async fn call_f64(&mut self, function: &str) -> Result<f64> {
let func = self
.instance
.get_typed_func::<(), (f64,)>(&mut self.store, function)?;
Expand Down Expand Up @@ -532,7 +532,7 @@ pub async fn componentize(

let pre = InitPre::new(linker.instantiate_pre(component)?)?;
let instance = pre.instance_pre.instantiate_async(&mut store).await?;
let guest = pre.interface0.load(&mut store, &instance)?;
let guest = pre.indices.interface0.load(&mut store, &instance)?;

guest
.call_init(&mut store, &app_name, &symbols, stub_wasi)
Expand Down Expand Up @@ -721,7 +721,7 @@ fn make_stub_adapter(_module: &str, stubs: &HashMap<&str, FuncType>) -> Vec<u8>

for (index, (name, ty)) in stubs.iter().enumerate() {
let index = u32::try_from(index).unwrap();
types.function(
types.ty().function(
ty.params().iter().map(|&v| IntoValType(v).into()),
ty.results().iter().map(|&v| IntoValType(v).into()),
);
Expand Down
8 changes: 4 additions & 4 deletions src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,18 +82,18 @@ async fn make_component(
}

#[derive(Debug, Copy, Clone)]
struct MyFloat32(f32);
struct MyF32(f32);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of these changes were motivated by the WIT spec changing from float to f prefix for these types


impl PartialEq<MyFloat32> for MyFloat32 {
impl PartialEq<MyF32> for MyF32 {
fn eq(&self, other: &Self) -> bool {
(self.0.is_nan() && other.0.is_nan()) || (self.0 == other.0)
}
}

#[derive(Debug, Copy, Clone)]
struct MyFloat64(f64);
struct MyF64(f64);

impl PartialEq<MyFloat64> for MyFloat64 {
impl PartialEq<MyF64> for MyF64 {
fn eq(&self, other: &Self) -> bool {
(self.0.is_nan() && other.0.is_nan()) || (self.0 == other.0)
}
Expand Down
70 changes: 32 additions & 38 deletions src/test/echoes.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use {
super::{Ctx, MyFloat32, MyFloat64, Tester, SEED},
super::{Ctx, MyF32, MyF64, Tester, SEED},
anyhow::Result,
async_trait::async_trait,
once_cell::sync::Lazy,
Expand Down Expand Up @@ -63,11 +63,11 @@ impl componentize_py::test::echoes::Host for Ctx {
Ok(v)
}

async fn echo_float32(&mut self, v: f32) -> Result<f32> {
async fn echo_f32(&mut self, v: f32) -> Result<f32> {
Ok(v)
}

async fn echo_float64(&mut self, v: f64) -> Result<f64> {
async fn echo_f64(&mut self, v: f64) -> Result<f64> {
Ok(v)
}

Expand Down Expand Up @@ -115,11 +115,11 @@ impl componentize_py::test::echoes::Host for Ctx {
Ok(v)
}

async fn echo_list_float32(&mut self, v: Vec<f32>) -> Result<Vec<f32>> {
async fn echo_list_f32(&mut self, v: Vec<f32>) -> Result<Vec<f32>> {
Ok(v)
}

async fn echo_list_float64(&mut self, v: Vec<f64>) -> Result<Vec<f64>> {
async fn echo_list_f64(&mut self, v: Vec<f64>) -> Result<Vec<f64>> {
Ok(v)
}

Expand Down Expand Up @@ -242,11 +242,11 @@ class Echoes(exports.Echoes):
def echo_s64(self, v):
return echoes.echo_s64(v)

def echo_float32(self, v):
return echoes.echo_float32(v)
def echo_f32(self, v):
return echoes.echo_f32(v)

def echo_float64(self, v):
return echoes.echo_float64(v)
def echo_f64(self, v):
return echoes.echo_f64(v)

def echo_string(self, v):
return echoes.echo_string(v)
Expand Down Expand Up @@ -281,11 +281,11 @@ class Echoes(exports.Echoes):
def echo_list_s64(self, v):
return echoes.echo_list_s64(v)

def echo_list_float32(self, v):
return echoes.echo_list_float32(v)
def echo_list_f32(self, v):
return echoes.echo_list_f32(v)

def echo_list_float64(self, v):
return echoes.echo_list_float64(v)
def echo_list_f64(self, v):
return echoes.echo_list_f64(v)

def echo_list_string(self, v):
return echoes.echo_list_string(v)
Expand Down Expand Up @@ -433,31 +433,31 @@ fn chars() -> Result<()> {
}

#[test]
fn float32s() -> Result<()> {
fn f32s() -> Result<()> {
TESTER.all_eq(
&proptest::num::f32::ANY.prop_map(MyFloat32),
&proptest::num::f32::ANY.prop_map(MyF32),
|v, instance, store, runtime| {
Ok(MyFloat32(
Ok(MyF32(
runtime.block_on(
instance
.componentize_py_test_echoes()
.call_echo_float32(store, v.0),
.call_echo_f32(store, v.0),
)?,
))
},
)
}

#[test]
fn float64s() -> Result<()> {
fn f64s() -> Result<()> {
TESTER.all_eq(
&proptest::num::f64::ANY.prop_map(MyFloat64),
&proptest::num::f64::ANY.prop_map(MyF64),
|v, instance, store, runtime| {
Ok(MyFloat64(
Ok(MyF64(
runtime.block_on(
instance
.componentize_py_test_echoes()
.call_echo_float64(store, v.0),
.call_echo_f64(store, v.0),
)?,
))
},
Expand Down Expand Up @@ -686,42 +686,36 @@ fn list_chars() -> Result<()> {
}

#[test]
fn list_float32s() -> Result<()> {
fn list_f32s() -> Result<()> {
TESTER.all_eq(
&proptest::collection::vec(proptest::num::f32::ANY.prop_map(MyFloat32), 0..MAX_SIZE),
&proptest::collection::vec(proptest::num::f32::ANY.prop_map(MyF32), 0..MAX_SIZE),
|v, instance, store, runtime| {
Ok(runtime
.block_on(
instance
.componentize_py_test_echoes()
.call_echo_list_float32(
store,
&v.into_iter().map(|v| v.0).collect::<Vec<_>>(),
),
.call_echo_list_f32(store, &v.into_iter().map(|v| v.0).collect::<Vec<_>>()),
)?
.into_iter()
.map(MyFloat32)
.map(MyF32)
.collect())
},
)
}

#[test]
fn list_float64s() -> Result<()> {
fn list_f64s() -> Result<()> {
TESTER.all_eq(
&proptest::collection::vec(proptest::num::f64::ANY.prop_map(MyFloat64), 0..MAX_SIZE),
&proptest::collection::vec(proptest::num::f64::ANY.prop_map(MyF64), 0..MAX_SIZE),
|v, instance, store, runtime| {
Ok(runtime
.block_on(
instance
.componentize_py_test_echoes()
.call_echo_list_float64(
store,
&v.into_iter().map(|v| v.0).collect::<Vec<_>>(),
),
.call_echo_list_f64(store, &v.into_iter().map(|v| v.0).collect::<Vec<_>>()),
)?
.into_iter()
.map(MyFloat64)
.map(MyF64)
.collect())
},
)
Expand All @@ -743,8 +737,8 @@ fn many() -> Result<()> {
),
(
proptest::num::i64::ANY,
proptest::num::f32::ANY.prop_map(MyFloat32),
proptest::num::f64::ANY.prop_map(MyFloat64),
proptest::num::f32::ANY.prop_map(MyF32),
proptest::num::f64::ANY.prop_map(MyF64),
proptest::char::any(),
proptest::string::string_regex(".*")?,
proptest::collection::vec(proptest::bool::ANY, 0..MAX_SIZE),
Expand All @@ -764,7 +758,7 @@ fn many() -> Result<()> {

Ok((
(v1, v2, v3, v4, v5, v6, v7, v8),
(v9, MyFloat32(v10), MyFloat64(v11), v12, v13, v14, v15, v16),
(v9, MyF32(v10), MyF64(v11), v12, v13, v14, v15, v16),
))
},
)
Expand Down
Loading
Loading