Stream: wit-bindgen

Topic: js-component-tools


view this post on Zulip Daniel Macovei (Feb 08 2023 at 01:46):

Been playing around with js-component-tools to interact with wasm components. The js that is produced from transpilation seems to be making an attempt to import from packages that I don't believe I have access to. Is there a way that one is able to access these imports? Here are the import statements that appear to be problematic.

import { exit as lowering3Callee } from 'wasi-exit';
import { dropInputStream as lowering0Callee, dropOutputStream as lowering1Callee, write as lowering5Callee } from 'wasi-io';
import { print as lowering4Callee } from 'print';
import { print as lowering8Callee } from 'wasi-stderr';
import { close as lowering2Callee, writeViaStream as lowering6Callee, appendViaStream as lowering7Callee } from 'wasi-filesystem';

view this post on Zulip Alex Crichton (Feb 08 2023 at 14:06):

I believe the CLI should have various options to map these to different imports or local files, but I don't know the names of the options off-hand myself

view this post on Zulip Daniel Macovei (Feb 08 2023 at 16:21):

Thanks! I'll try looking into that

view this post on Zulip Daniel Macovei (Feb 09 2023 at 15:42):

So I see how to use the cli options to map to local files and things... but are there recommended implementations of these things to point to locally from this js setting?

view this post on Zulip Eduardo Rodrigues (Feb 21 2023 at 19:29):

You can find a shim (that implements the most basic functionality) for this here: https://github.com/bytecodealliance/jco/tree/main/packages/preview2-shim

JavaScript tooling for working with WebAssembly Components - jco/packages/preview2-shim at main · bytecodealliance/jco

view this post on Zulip Daniel Macovei (Feb 22 2023 at 17:20):

@Eduardo Rodrigues Thanks! great to know. Will have to tinker a bit with providing the shim implementations to the transpiled js now

view this post on Zulip Daniel Macovei (Feb 22 2023 at 17:31):

After some more experimentation, I noticed that when using the mapping flag to point to the local shim, that the import paths seem to be relative to the transpiled js file. Found the easiest way to make things work was to copy/paste the shim into the generated js, so as to avoid referencing file paths outside of the generated code. Would it be helpful to include the shim in the transpilation output? Or to make the possibility configurable?

view this post on Zulip Daniel Macovei (Feb 22 2023 at 17:33):

If it's helpful, I could open a PR

view this post on Zulip Eduardo Rodrigues (Feb 22 2023 at 21:22):

I agree is a little bit annoying, but we probably need to wait for more implementation coverage as well as stabilization of the WASI preview2 definition.


Last updated: Nov 22 2024 at 16:03 UTC