Skip to content

Commit efce864

Browse files
authored
Update component-init to published component-init-transform (#159)
* nonfunctional change: switch from `wasmtime serve --wasi common` to `wasmtime serve -Scli` * update dependencies to match component-init * eliminate dependency on wasm-convert * for the moment, using my branch of component-init. we should publish to crates.io once this is validated. * update to wasm-tools versions matching component-init * update wasmtime to latest, not required but just nice to do while we're here * eliminate wasi-common dependency, which is unnecessary * bindgen: changes to float reprs in wasm-encoder * changes to wasmtime-wasi crate layout * swap wasm-convert for wasm-encoder::reencode * test fixes * new clippy lint * component-init was published as component-init-transform
1 parent 31c9e66 commit efce864

File tree

12 files changed

+351
-288
lines changed

12 files changed

+351
-288
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ tar = "0.4.42"
1515
tempfile = "3.13.0"
1616
zstd = "0.13.2"
1717
componentize-py-shared = { path = "shared" }
18-
wasm-encoder = "0.227.0"
19-
wit-parser = "0.227.0"
20-
wit-component = "0.227.0"
21-
wasmparser = "0.227.0"
18+
wasm-encoder = "0.235.0"
19+
wit-parser = "0.235.0"
20+
wit-component = "0.235.0"
21+
wasmparser = "0.235.0"
2222
indexmap = "2.6.0"
2323
bincode = "1.3.3"
2424
heck = "0.5.0"
@@ -28,12 +28,10 @@ pyo3 = { git = "https://github.com/dicej/pyo3", branch = "v0.25.0-no-wasm32-unwi
2828
"abi3-py39",
2929
"extension-module",
3030
], optional = true }
31-
wasmtime = "30.0.2"
32-
wasmtime-wasi = "30.0.2"
33-
wasi-common = "30.0.2"
31+
wasmtime = "34.0.1"
32+
wasmtime-wasi = "34.0.1"
3433
once_cell = "1.20.2"
35-
component-init = { git = "https://github.com/dicej/component-init", rev = "2db53ece" }
36-
wasm-convert = { git = "https://github.com/dicej/wasm-convert", rev = "713e2d6a" }
34+
component-init-transform = "0.1"
3735
async-trait = "0.1.83"
3836
futures = "0.3.31"
3937
tokio = { version = "1.41.0", features = [

examples/http/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ First, build the app and run it:
2727

2828
```
2929
componentize-py -d ../../wit -w wasi:http/[email protected] componentize app -o http.wasm
30-
wasmtime serve --wasi common http.wasm
30+
wasmtime serve -Scli http.wasm
3131
```
3232

3333
Then, in another terminal, use cURL to send a request to the app:

src/bindgen.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2200,8 +2200,8 @@ impl<'a> FunctionBindgen<'a> {
22002200
self.push(match ty {
22012201
ValType::I32 => Ins::I32Const(0),
22022202
ValType::I64 => Ins::I64Const(0),
2203-
ValType::F32 => Ins::F32Const(0.0),
2204-
ValType::F64 => Ins::F64Const(0.0),
2203+
ValType::F32 => Ins::F32Const(0.0.into()),
2204+
ValType::F64 => Ins::F64Const(0.0.into()),
22052205
_ => unreachable!(),
22062206
})
22072207
}

src/lib.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use {
44
anyhow::{anyhow, bail, ensure, Context, Error, Result},
55
async_trait::async_trait,
66
bytes::Bytes,
7-
component_init::Invoker,
7+
component_init_transform::Invoker,
88
futures::future::FutureExt,
99
heck::ToSnakeCase,
1010
indexmap::{IndexMap, IndexSet},
@@ -22,8 +22,11 @@ use {
2222
Config, Engine, Store,
2323
},
2424
wasmtime_wasi::{
25-
pipe::{MemoryInputPipe, MemoryOutputPipe},
26-
DirPerms, FilePerms, IoView, WasiCtx, WasiCtxBuilder, WasiView,
25+
p2::{
26+
pipe::{MemoryInputPipe, MemoryOutputPipe},
27+
IoView, WasiCtx, WasiCtxBuilder, WasiView,
28+
},
29+
DirPerms, FilePerms,
2730
},
2831
wit_parser::{Resolve, TypeDefKind, UnresolvedPackageGroup, WorldId, WorldItem, WorldKey},
2932
};
@@ -348,9 +351,10 @@ pub async fn componentize(
348351
None
349352
};
350353

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

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

513517
let app_name = app_name.to_owned();
514-
let component = component_init::initialize_staged(
518+
let component = component_init_transform::initialize_staged(
515519
&component,
516520
stubbed_component
517521
.as_ref()
@@ -585,7 +589,7 @@ fn add_wasi_and_stubs(
585589
worlds: &IndexSet<WorldId>,
586590
linker: &mut Linker<Ctx>,
587591
) -> Result<()> {
588-
wasmtime_wasi::add_to_linker_async(linker)?;
592+
wasmtime_wasi::p2::add_to_linker_async(linker)?;
589593

590594
enum Stub<'a> {
591595
Function(&'a String),

src/stubwasi.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use std::collections::HashMap;
22

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

112+
use wasm_encoder::reencode::{Reencode, RoundtripReencoder as R};
113+
113114
for (index, (name, ty)) in stubs.iter().enumerate() {
114115
let index = u32::try_from(index).unwrap();
115116
types.ty().function(
116-
ty.params().iter().map(|&v| IntoValType(v).into()),
117-
ty.results().iter().map(|&v| IntoValType(v).into()),
117+
ty.params().iter().map(|&v| R.val_type(v).unwrap()),
118+
ty.results().iter().map(|&v| R.val_type(v).unwrap()),
118119
);
119120
functions.function(index);
120121
exports.export(name, ExportKind::Func, index);

src/summary.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,13 +1111,11 @@ impl<'a> Summary<'a> {
11111111
if packages.len() == 1 {
11121112
(*name).to_owned()
11131113
} else {
1114-
format!("{}-{}-{name}", package_namespace, package_name)
1114+
format!("{package_namespace}-{package_name}-{name}")
11151115
}
11161116
} else {
11171117
format!(
1118-
"{}-{}-{name}-{}",
1119-
package_namespace,
1120-
package_name,
1118+
"{package_namespace}-{package_name}-{name}-{}",
11211119
version.to_string().replace('.', "-")
11221120
)
11231121
}
@@ -1128,7 +1126,7 @@ impl<'a> Summary<'a> {
11281126
} else if packages.len() == 1 {
11291127
(*name).to_owned()
11301128
} else {
1131-
format!("{}-{}-{name}", package_namespace, package_name)
1129+
format!("{package_namespace}-{package_name}-{name}",)
11321130
}
11331131
)
11341132
.is_none());

src/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use {
1414
component::{Component, InstancePre, Linker, ResourceTable},
1515
Config, Engine, Store,
1616
},
17-
wasmtime_wasi::{WasiCtx, WasiCtxBuilder},
17+
wasmtime_wasi::p2::{WasiCtx, WasiCtxBuilder},
1818
};
1919

2020
mod echoes;

src/test/echoes.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use {
44
once_cell::sync::Lazy,
55
proptest::strategy::{Just, Strategy},
66
wasmtime::{
7-
component::{InstancePre, Linker},
7+
component::{HasSelf, InstancePre, Linker},
88
Store,
99
},
1010
};
@@ -189,8 +189,8 @@ impl super::Host for Host {
189189
type World = EchoesTest;
190190

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

src/test/tests.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,13 @@ use {
66
once_cell::sync::Lazy,
77
std::str,
88
wasmtime::{
9-
component::{InstancePre, Linker, Resource, ResourceAny},
9+
component::{HasSelf, InstancePre, Linker, Resource, ResourceAny},
1010
Store,
1111
},
12-
wasmtime_wasi::{DirPerms, FilePerms, IoView, WasiCtxBuilder},
12+
wasmtime_wasi::{
13+
p2::{IoView, WasiCtxBuilder},
14+
DirPerms, FilePerms,
15+
},
1316
};
1417

1518
wasmtime::component::bindgen!({
@@ -93,9 +96,9 @@ impl super::Host for Host {
9396
type World = Tests;
9497

9598
fn add_to_linker(linker: &mut Linker<Ctx>) -> Result<()> {
96-
wasmtime_wasi::add_to_linker_async(linker)?;
97-
Tests::add_to_linker(linker, |ctx| ctx)?;
98-
foo_sdk::FooWorld::add_to_linker(linker, |ctx| ctx)?;
99+
wasmtime_wasi::p2::add_to_linker_async(linker)?;
100+
Tests::add_to_linker::<_, HasSelf<_>>(linker, |ctx| ctx)?;
101+
foo_sdk::FooWorld::add_to_linker::<_, HasSelf<_>>(linker, |ctx| ctx)?;
99102
Ok(())
100103
}
101104

0 commit comments

Comments
 (0)