Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeScript generation not supporting map configuration #106

Open
kajacx opened this issue Jul 16, 2023 · 1 comment
Open

TypeScript generation not supporting map configuration #106

kajacx opened this issue Jul 16, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@kajacx
Copy link
Contributor

kajacx commented Jul 16, 2023

When I compile a rust wasi component with cargo component build --release and I run jco on the result with

jco transpile plugin-wasi/target/wasm32-wasi/release/plugin_wasi.wasm --instantiation -o out-dir/

Then the generated TS bindings do not match what the JS actually does in the instantiate function.

Genrated TS bindings:

export interface ImportObject {
  'import-point': {
    default(pnt: Point): Point,
  },
  print: {
    default(msg: string): void,
  },
  'wasi:cli-base/environment': typeof ImportsEnvironment,
  'wasi:cli-base/exit': typeof ImportsExit,
  'wasi:cli-base/preopens': typeof ImportsPreopens,
  'wasi:cli-base/stderr': typeof ImportsStderr,
  'wasi:cli-base/stdin': typeof ImportsStdin,
  'wasi:cli-base/stdout': typeof ImportsStdout,
  'wasi:filesystem/filesystem': typeof ImportsFilesystem,
  'wasi:io/streams': typeof ImportsStreams,
}

Actual JS code:

export async function instantiate(compileCore, imports, instantiateCore = WebAssembly.instantiate) {
  const module0 = compileCore('plugin_wasi.core.wasm');
  const module1 = compileCore('plugin_wasi.core2.wasm');
  const module2 = compileCore('plugin_wasi.core3.wasm');
  const module3 = compileCore('plugin_wasi.core4.wasm');
  
  const { environment, exit: exit$1, preopens, stderr, stdin, stdout } = imports['@bytecodealliance/preview2-shim/cli-base'];
  const { filesystem } = imports['@bytecodealliance/preview2-shim/filesystem'];
  const { streams } = imports['@bytecodealliance/preview2-shim/io'];
  const importPoint = imports['import-point'].default;
  const print = imports.print.default;

The custom imported functions are fine, but the wasi import object does not match.

Edit: jco version 0.9.4

@guybedford
Copy link
Collaborator

Try adding the --no-wasi-shim flag. The WASI bindings are automatically mapped using mapping configuration - https://github.com/bytecodealliance/jco/blob/main/src/cmd/transpile.js#L92.

The bug here is that TypeScript output does not yet support the map configuration itself, so whenever using --map typings and JS will be out of sync.

Changing to title to match the issue, but your problem should be resolved with that flag for now.

@guybedford guybedford added the bug Something isn't working label Jul 16, 2023
@guybedford guybedford changed the title Incorrect typescript import signatures when using wasi component TypeScript generation not supporting map configuration Jul 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants