Skip to content

Commit 34a4bc7

Browse files
authored
Reimplement the host Python generator with worlds (#386)
* Reimplement the host Python generator with worlds This commit is the equivalent of #381 but for Wasmtime Python host bindings. This is a large-scale refactor of the internals of the Python host generator in which I took quite a few liberties in internal restructuring as well as output restructuring. The tests are probably the best to review and better reflect what changed, but there are some aspects of worlds that the tests are not currently exercising which we'll want to add with the introduction of worlds in the future. This means that all host generators are now working with worlds as input rather than individual `*.wit` files, and the only two remaining generators are the C and Java generators for guests (which I hope are easier). The high level summary of the new output is: out_dir/ __init__.py # top-level component exports/definitions types.py # shared type information, currently just `Result` imports/ __init__.py # only here if something is imported foo.py # type and protocol definition per interface exports/ __init__.py # only here if an instance is exported bar.py # one per exported instance "Default exports" will show up on the generated structure in `out_dir/__init__.py` so all runtime tests, for example, do not generate `exports` at this time. Lots of fiddly stuff went into structuring this all right to get past `mypy` and additionally try to avoid name conflicts. It's still somewhat easy to have name conflicts but ideally they're of the more esoteric category rather than "really easy to run into". * Try to fix windows
1 parent 5be459e commit 34a4bc7

27 files changed

Lines changed: 1962 additions & 1943 deletions

File tree

Cargo.lock

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

crates/gen-host-js/tests/helpers.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// @ts-ignore
22
import { readFile } from 'node:fs/promises';
33
// @ts-ignore
4-
import { argv, stdout } from 'node:process';
4+
import { argv, stdout, stderr } from 'node:process';
55

66
// This is a helper function used from `host.ts` test in the `tests/runtime/*`
77
// directory to pass as the `instantiateCore` argument to the `instantiate`
@@ -20,4 +20,7 @@ export const testwasi = {
2020
log(bytes: Uint8Array) {
2121
stdout.write(bytes);
2222
},
23+
logErr(bytes: Uint8Array) {
24+
stderr.write(bytes);
25+
},
2326
};

crates/gen-host-wasmtime-py/Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@ version.workspace = true
55
edition.workspace = true
66

77
[dependencies]
8-
wit-bindgen-core = { workspace = true }
8+
wit-bindgen-core = { workspace = true, features = ['component-generator'] }
99
heck = { workspace = true }
1010
clap = { workspace = true, optional = true }
11+
wit-component = { workspace = true }
12+
indexmap = "1.0"
13+
wasmtime-environ = { workspace = true, features = ['component-model'] }
1114

1215
[dev-dependencies]
1316
test-helpers = { path = '../test-helpers' }

0 commit comments

Comments
 (0)