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

Allow makefile addition to build Go wasip1 .wasm binary #3779

Closed
wants to merge 1 commit into from

Conversation

WietseWind
Copy link

@WietseWind WietseWind commented May 24, 2024

With Go supporting wasi (wasip1 os) now (as mentioned here: https://go.dev/blog/wasi & here #3300), this PR adds a build option to the Makefile for a wasip1 wasm build.

Tested & runs prefectly fine with wasmtime:

wasmtime --dir=.::/ /npm/@esbuild/wasip1-wasm/bin/esbuild.wasm --help

^^ Heads up! In case of wasmtime, the dir arg needs exactly this content: .::/ - which means . (local dir) maps to (::) / (root virtual filesystem).

The advantage of building wasi over the current wasm build (platform-wasm) is that the wasi build can run natively using CLI tools like wasmtime, and running in a node / JS environment is also compatible with several wasi browser runtimes. So: no need for the specific esbuild-wasm package, as one can execute the built .wasm with e.g. @runno/wasi or any other wasi implementation.

To run the same thing not on CLI but in a browser, all you need is this in a <script type="module" ...:

import { WASI } from "@runno/wasi"

const esbuild_wasip1 = 'https://qkbtifg.dlvr.cloud/esbuild.wasm' // needs nginx mime type application/wasm wasm;

const result = WASI.start(fetch(esbuild_wasip1), {
  // env: { SOME_KEY: "some value" },
  args: ['esbuild', 'file.ts', '--bundle', '--minify', '--platform=browser', '--format=esm', '--target=es2017'],
  stdout: out => document.write(`<pre>${out}</pre>`),
  stderr: err => console.log("stderr:" + err),
  stdin: () => undefined,
  fs: {
    "/file.ts": {
      path: "/file.ts",
      timestamps: { access: new Date(), change: new Date(), modification: new Date(), },
      mode: "string",
      content: (`
        // Some TS content...
        const v: string = 'Trololo works like a charm!'
        console.log(v)
      `),
    },
  },
})

@evanw evanw closed this in b722000 Jun 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant