Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
545 changes: 302 additions & 243 deletions Cargo.lock

Large diffs are not rendered by default.

16 changes: 7 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ tar = "0.4.42"
tempfile = "3.13.0"
zstd = "0.13.2"
componentize-py-shared = { path = "shared" }
wasm-encoder = "0.227.0"
wit-parser = "0.227.0"
wit-component = "0.227.0"
wasmparser = "0.227.0"
wasm-encoder = "0.235.0"
wit-parser = "0.235.0"
wit-component = "0.235.0"
wasmparser = "0.235.0"
indexmap = "2.6.0"
bincode = "1.3.3"
heck = "0.5.0"
Expand All @@ -28,12 +28,10 @@ pyo3 = { git = "https://github.com/dicej/pyo3", branch = "v0.25.0-no-wasm32-unwi
"abi3-py39",
"extension-module",
], optional = true }
wasmtime = "30.0.2"
wasmtime-wasi = "30.0.2"
wasi-common = "30.0.2"
wasmtime = "34.0.1"
wasmtime-wasi = "34.0.1"
once_cell = "1.20.2"
component-init = { git = "https://github.com/dicej/component-init", rev = "2db53ece" }
wasm-convert = { git = "https://github.com/dicej/wasm-convert", rev = "713e2d6a" }
component-init-transform = "0.1"
async-trait = "0.1.83"
futures = "0.3.31"
tokio = { version = "1.41.0", features = [
Expand Down
2 changes: 1 addition & 1 deletion examples/http/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ First, build the app and run it:

```
componentize-py -d ../../wit -w wasi:http/[email protected] componentize app -o http.wasm
wasmtime serve --wasi common http.wasm
wasmtime serve -Scli http.wasm
```

Then, in another terminal, use cURL to send a request to the app:
Expand Down
4 changes: 2 additions & 2 deletions src/bindgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2200,8 +2200,8 @@ impl<'a> FunctionBindgen<'a> {
self.push(match ty {
ValType::I32 => Ins::I32Const(0),
ValType::I64 => Ins::I64Const(0),
ValType::F32 => Ins::F32Const(0.0),
ValType::F64 => Ins::F64Const(0.0),
ValType::F32 => Ins::F32Const(0.0.into()),
ValType::F64 => Ins::F64Const(0.0.into()),
_ => unreachable!(),
})
}
Expand Down
20 changes: 12 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use {
anyhow::{anyhow, bail, ensure, Context, Error, Result},
async_trait::async_trait,
bytes::Bytes,
component_init::Invoker,
component_init_transform::Invoker,
futures::future::FutureExt,
heck::ToSnakeCase,
indexmap::{IndexMap, IndexSet},
Expand All @@ -22,8 +22,11 @@ use {
Config, Engine, Store,
},
wasmtime_wasi::{
pipe::{MemoryInputPipe, MemoryOutputPipe},
DirPerms, FilePerms, IoView, WasiCtx, WasiCtxBuilder, WasiView,
p2::{
pipe::{MemoryInputPipe, MemoryOutputPipe},
IoView, WasiCtx, WasiCtxBuilder, WasiView,
},
DirPerms, FilePerms,
},
wit_parser::{Resolve, TypeDefKind, UnresolvedPackageGroup, WorldId, WorldItem, WorldKey},
};
Expand Down Expand Up @@ -348,9 +351,10 @@ pub async fn componentize(
None
};

// Pre-initialize the component by running it through `component_init::initialize`. Currently, this is the
// application's first and only chance to load any standard or third-party modules since we do not yet include
// a virtual filesystem in the component to make those modules available at runtime.
// Pre-initialize the component by running it through `component_init_transform::initialize`.
// Currently, this is the application's first and only chance to load any standard or
// third-party modules since we do not yet include a virtual filesystem in the component to
// make those modules available at runtime.

let stdout = MemoryOutputPipe::new(10000);
let stderr = MemoryOutputPipe::new(10000);
Expand Down Expand Up @@ -511,7 +515,7 @@ pub async fn componentize(
let mut store = Store::new(&engine, Ctx { wasi, table });

let app_name = app_name.to_owned();
let component = component_init::initialize_staged(
let component = component_init_transform::initialize_staged(
&component,
stubbed_component
.as_ref()
Expand Down Expand Up @@ -585,7 +589,7 @@ fn add_wasi_and_stubs(
worlds: &IndexSet<WorldId>,
linker: &mut Linker<Ctx>,
) -> Result<()> {
wasmtime_wasi::add_to_linker_async(linker)?;
wasmtime_wasi::p2::add_to_linker_async(linker)?;

enum Stub<'a> {
Function(&'a String),
Expand Down
11 changes: 6 additions & 5 deletions src/stubwasi.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::collections::HashMap;

use anyhow::{bail, Error};
use wasm_convert::IntoValType;
use wasm_encoder::{
CodeSection, ExportKind, ExportSection, Function, FunctionSection, Instruction as Ins, Module,
TypeSection,
Expand Down Expand Up @@ -37,8 +36,8 @@ pub fn link_stub_modules(libraries: Vec<Library>) -> Result<LinkedStubModules, E
// As of this writing, `wit_component::Linker` generates a component such that the first module is the
// `main` one, followed by any adapters, followed by any libraries, followed by the `init` module, which is
// finally followed by any shim modules. Given that the stubbed component may contain more adapters than
// the non-stubbed version, we need to tell `component-init` how to translate module indexes from the
// former to the latter.
// the non-stubbed version, we need to tell `component-init-transform` how to translate module indexes from
// the former to the latter.
//
// TODO: this is pretty fragile in that it could silently break if `wit_component::Linker`'s implementation
// changes. Can we make it more robust?
Expand Down Expand Up @@ -110,11 +109,13 @@ fn make_stub_adapter(_module: &str, stubs: &HashMap<&str, FuncType>) -> Vec<u8>
let mut exports = ExportSection::new();
let mut code = CodeSection::new();

use wasm_encoder::reencode::{Reencode, RoundtripReencoder as R};

for (index, (name, ty)) in stubs.iter().enumerate() {
let index = u32::try_from(index).unwrap();
types.ty().function(
ty.params().iter().map(|&v| IntoValType(v).into()),
ty.results().iter().map(|&v| IntoValType(v).into()),
ty.params().iter().map(|&v| R.val_type(v).unwrap()),
ty.results().iter().map(|&v| R.val_type(v).unwrap()),
);
functions.function(index);
exports.export(name, ExportKind::Func, index);
Expand Down
8 changes: 3 additions & 5 deletions src/summary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1111,13 +1111,11 @@ impl<'a> Summary<'a> {
if packages.len() == 1 {
(*name).to_owned()
} else {
format!("{}-{}-{name}", package_namespace, package_name)
format!("{package_namespace}-{package_name}-{name}")
}
} else {
format!(
"{}-{}-{name}-{}",
package_namespace,
package_name,
"{package_namespace}-{package_name}-{name}-{}",
version.to_string().replace('.', "-")
)
}
Expand All @@ -1128,7 +1126,7 @@ impl<'a> Summary<'a> {
} else if packages.len() == 1 {
(*name).to_owned()
} else {
format!("{}-{}-{name}", package_namespace, package_name)
format!("{package_namespace}-{package_name}-{name}",)
}
)
.is_none());
Expand Down
2 changes: 1 addition & 1 deletion src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use {
component::{Component, InstancePre, Linker, ResourceTable},
Config, Engine, Store,
},
wasmtime_wasi::{WasiCtx, WasiCtxBuilder},
wasmtime_wasi::p2::{WasiCtx, WasiCtxBuilder},
};

mod echoes;
Expand Down
6 changes: 3 additions & 3 deletions src/test/echoes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use {
once_cell::sync::Lazy,
proptest::strategy::{Just, Strategy},
wasmtime::{
component::{InstancePre, Linker},
component::{HasSelf, InstancePre, Linker},
Store,
},
};
Expand Down Expand Up @@ -189,8 +189,8 @@ impl super::Host for Host {
type World = EchoesTest;

fn add_to_linker(linker: &mut Linker<Ctx>) -> Result<()> {
wasmtime_wasi::add_to_linker_async(&mut *linker)?;
componentize_py::test::echoes::add_to_linker(linker, |ctx| ctx)?;
wasmtime_wasi::p2::add_to_linker_async(&mut *linker)?;
componentize_py::test::echoes::add_to_linker::<_, HasSelf<_>>(linker, |ctx| ctx)?;
Ok(())
}

Expand Down
13 changes: 8 additions & 5 deletions src/test/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ use {
once_cell::sync::Lazy,
std::str,
wasmtime::{
component::{InstancePre, Linker, Resource, ResourceAny},
component::{HasSelf, InstancePre, Linker, Resource, ResourceAny},
Store,
},
wasmtime_wasi::{DirPerms, FilePerms, IoView, WasiCtxBuilder},
wasmtime_wasi::{
p2::{IoView, WasiCtxBuilder},
DirPerms, FilePerms,
},
};

wasmtime::component::bindgen!({
Expand Down Expand Up @@ -93,9 +96,9 @@ impl super::Host for Host {
type World = Tests;

fn add_to_linker(linker: &mut Linker<Ctx>) -> Result<()> {
wasmtime_wasi::add_to_linker_async(linker)?;
Tests::add_to_linker(linker, |ctx| ctx)?;
foo_sdk::FooWorld::add_to_linker(linker, |ctx| ctx)?;
wasmtime_wasi::p2::add_to_linker_async(linker)?;
Tests::add_to_linker::<_, HasSelf<_>>(linker, |ctx| ctx)?;
foo_sdk::FooWorld::add_to_linker::<_, HasSelf<_>>(linker, |ctx| ctx)?;
Ok(())
}

Expand Down
10 changes: 5 additions & 5 deletions test-generator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ pub fn generate() -> Result<()> {

writeln!(
&mut typed_function_inits,
r#"echo{test_index}: instance.get_typed_func::<({params}), ({result_type},)>(&mut *store, component.export_index(Some(&index), "echo{test_index}").unwrap().1)?,"#
r#"echo{test_index}: instance.get_typed_func::<({params}), ({result_type},)>(&mut *store, component.get_export_index(Some(&index), "echo{test_index}").unwrap())?,"#
)
.unwrap();
}
Expand Down Expand Up @@ -802,7 +802,7 @@ use {{
once_cell::sync::Lazy,
proptest::strategy::{{Just, Strategy}},
wasmtime::{{
component::{{Instance, InstancePre, Linker, TypedFunc}},
component::{{Instance, InstancePre, Linker, TypedFunc, HasSelf}},
Store,
}},
}};
Expand All @@ -828,8 +828,8 @@ impl super::Host for Host {{
type World = Exports;

fn add_to_linker(linker: &mut Linker<Ctx>) -> Result<()> {{
wasmtime_wasi::add_to_linker_async(&mut *linker)?;
{PREFIX}::add_to_linker(linker, |ctx| ctx)?;
wasmtime_wasi::p2::add_to_linker_async(&mut *linker)?;
{PREFIX}::add_to_linker::<_, HasSelf<_>>(linker, |ctx| ctx)?;
Ok(())
}}

Expand All @@ -838,7 +838,7 @@ impl super::Host for Host {{
pre: InstancePre<Ctx>,
) -> Result<Self::World> {{
let component = pre.component();
let (_, index) = component.export_index(None, "componentize-py:test/echoes-generated").unwrap();
let index = component.get_export_index(None, "componentize-py:test/echoes-generated").unwrap();
let instance = pre.instantiate_async(&mut *store).await?;
Ok((Self::World {{
{typed_function_inits}
Expand Down
2 changes: 1 addition & 1 deletion tests/componentize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ fn http_example() -> anyhow::Result<()> {

let mut handle = std::process::Command::new("wasmtime")
.current_dir(&path)
.args(["serve", "--wasi", "common", "http.wasm"])
.args(["serve", "-Scli", "http.wasm"])
.spawn()?;

let content = "’Twas brillig, and the slithy toves
Expand Down
Loading