A message was moved here from #jco > Does jco always add import on wasi_cli terminal-* by Victor Adossi.
Hey @Cameron Taggart moved the issue in here, hopefully that's fine!
I noticed that you currently have the import commented out, why is that? I assume you commented it out because things failed to build.
It's just a guess but you MIGHT be running into issues trying to import and export the same interface. The ts:typescript-system/types@0.1.0;
import tries to make use of the system
type, but then that is part of the export (typescript
which contains that resource you're building, which would usesystem
in the constructor).
The problem is complex, but in the past this has been solved by exporting more things (which in your case might be ts:typescript-system/types@0.1.0
itself?)
Do you know how the Rust component should be imported into the JavaScript component? If I do this import { TsTypescriptSystemTypes as tssystem } from 'ts-typescript-system-types';
, I end up with:
$ bunx jco componentize src/world.js --wit wit -o ts-typescript.wasm -d all
Error opening file ./ts-typescript-system-types.js (resolved to /var/folders/xm/hr4sq0d567vfs0xdth9t38zc0000gn/T/d8c2e742d292/sources/ts-typescript-system-types.js): No such file or directory
Error while evaluating top-level script, but no exception is pending. Aborting, since that doesn't seem recoverable at all.
Error: the `componentize.wizer` function trapped
If I bundle the JavaScript and do a workaround for https://github.com/oven-sh/bun/issues/15537 , then I get the error about needing to export the components from the Rust component:
$ bunx jco componentize world.js --wit wit -o ts-typescript.wasm -d all
ComponentError: failed to encode a component from module
$failed to decode world from module
Caused by:
0: module was not valid
1: failed to find export of interface `ts:typescript-system/types@0.1.0` function `[method]system.get-arguments`
If I add the export to the wit:
world root {
import ts:typescript-system/types@0.1.0;
export ts:typescript-system/types@0.1.0;
it fails with this error, which I don't know how to resolve:
$ bunx jco componentize world.js --wit wit -o ts-typescript.wasm -d all
ComponentError: Expected a JS export definition for 'types'
at spliceBindings (file:///Users/cataggar/ms/StarlingMonkey15/typescript/node_modules/@bytecodealliance/componentize-js/lib/spidermonkey-embedding-splicer.js:3959:11)
at componentize (file:///Users/cataggar/ms/StarlingMonkey15/typescript/node_modules/@bytecodealliance/componentize-js/src/componentize.js:87:64)
at async componentize (file:///Users/cataggar/ms/StarlingMonkey15/typescript/node_modules/@bytecodealliance/jco/src/cmd/componentize.js:11:25)
at async file:///Users/cataggar/ms/StarlingMonkey15/typescript/node_modules/@bytecodealliance/jco/src/jco.js:200:9
error: script "componentize" exited with code 1
(jco componentize)
In 'typescript' script 'componentize' failed with exit code 1
I commented out the potential fixes, so having it print "todo" should work again. Just run bun run build.ts
.
~/ms/StarlingMonkey15> bun run build.ts
$ wkg wit fetch
$ cargo component build
Generating bindings for typescript-system (src/bindings.rs)
Compiling typescript-system v0.1.0 (/Users/cataggar/ms/StarlingMonkey15/typescript-system)
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.28s
Creating component target/wasm32-wasip1/debug/typescript_system.wasm
$ wkg wit fetch
$ bunx jco types wit -o .
Generated Type Files:
- ./interfaces/ts-typescript-typescript.d.ts 0.17 KiB
- ./interfaces/wasi-io-poll.d.ts 1.36 KiB
- ./wit.d.ts 0.19 KiB
$ bun run bundle.ts
$ bunx jco componentize world.js --wit wit -o ts-typescript.wasm -d all
OK Successfully written ts-typescript.wasm.
$ wkg wit fetch
$ cargo component build
Generating bindings for test-rs (src/bindings.rs)
Compiling test-rs v0.1.0 (/Users/cataggar/ms/StarlingMonkey15/test-rs)
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.16s
Creating component target/wasm32-wasip1/debug/test-rs.wasm
$ wac plug target/wasm32-wasip1/debug/test-rs.wasm --plug ../typescript/ts-typescript.wasm -o target/test.wasm --plug ../typescript-system/target/wasm32-wasip1/debug/typescript_system.wasm
$ wasmtime run target/test.wasm a b c
all arguments: todo
So making it use the Rust component and print a__b__c
instead of todo
may be reverting some of these changes and something else.
I got the all-rust equivalent working. One surprise was needing to wac plug
twice. Otherwise not too difficult. It is in the rs-rs-rs branch. Now back to hacking the rs-ts-rs branch.
I created https://github.com/bytecodealliance/jco/issues/534 for this.
Ah thanks for filing an issue to cover this!
Last updated: Dec 23 2024 at 12:05 UTC