Stream: jco

Topic: Issues using Rust component from JS


view this post on Zulip Notification Bot (Dec 02 2024 at 07:03):

A message was moved here from #jco > Does jco always add import on wasi_cli terminal-* by Victor Adossi.

view this post on Zulip Victor Adossi (Dec 02 2024 at 07:15):

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?)

https://github.com/bytecodealliance/StarlingMonkey/issues/15 - cataggar/StarlingMonkey15
Given following WIT: package repro:component@0.1.0; world component { export wasi:io/poll@0.2.1; export wasi:http/types@0.2.1; } And following lib.rs: mod bindings { use super::Component; wit_bindg...

view this post on Zulip Cameron Taggart (Dec 02 2024 at 16:39):

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
https://github.com/bytecodealliance/StarlingMonkey/issues/15 - cataggar/StarlingMonkey15

view this post on Zulip Cameron Taggart (Dec 02 2024 at 17:12):

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
What version of Bun is running? 1.1.33+247456b67 What platform is your computer? Darwin 24.1.0 arm64 arm What steps can reproduce the bug? git clone git@github.com:cataggar/StarlingMonkey15.git --n...

view this post on Zulip Cameron Taggart (Dec 02 2024 at 17:47):

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

view this post on Zulip Cameron Taggart (Dec 02 2024 at 18:09):

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.

https://github.com/bytecodealliance/StarlingMonkey/issues/15 - put todo back · cataggar/StarlingMonkey15@28687c7

view this post on Zulip Cameron Taggart (Dec 03 2024 at 02:55):

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.

https://github.com/bytecodealliance/StarlingMonkey/issues/15 - GitHub - cataggar/StarlingMonkey15 at rs-rs-rs

view this post on Zulip Cameron Taggart (Dec 03 2024 at 04:08):

I created https://github.com/bytecodealliance/jco/issues/534 for this.

When I add import ts:typescript-system/types@0.1.0;, I get an error that the "module is invalid" and it "failed to find export of interface": $ bunx jco componentize world.js --wit wit -o ts-typesc...

view this post on Zulip Victor Adossi (Dec 03 2024 at 16:23):

Ah thanks for filing an issue to cover this!


Last updated: Dec 23 2024 at 12:05 UTC