Wasmer JavaScript SDK
wasmer.io
wasmer.io
No shade intended towards the Wasmer folks, I appreciate the work they've done.
Hopefully it will not take long for Wasmer to serve packages with a minimum bundle size, stay tuned for updates!
I tried it with Bun and I feel weird showing examples that don't seem to run.
> $ npm install @wasmer/sdk
```js import { Wasmer } from "@wasmer/sdk";
let cowsay = Wasmer.fromRegistry("cowsay"); let instance = await cowsay.entrypoint.run({ args: "\"Hello world\"" }); let output = await instance.wait(); ```
I also tried to use the <script> approach and I cannot get it working on a local dev server due to CORS.
Seems like they still have to update their stuff a fair few places...
Now I'm just struggling to use the package registry, none of the copy and paste examples have worked for me, but I'm sure I can figure it out. Will post here if I do.
For the CORS with Vite you can just set a config like so in vite.config.ts
import { defineConfig } from "vite";
export default defineConfig({ server: { headers: { "Cross-Origin-Embedder-Policy": "require-corp", "Cross-Origin-Opener-Policy": "same-origin", }, }, });
I was then able to just use this code example with one caveat (https://github.com/wasmerio/wasmer-js?tab=readme-ov-file#use...)
I had to update the SDK import with crossorigin="anonymous"
rather off-topic, but i've noticed quite a few "modern" cli apps do the "--" thing and make it mandatory; am i alone in finding it weird that flag parsing does not automatically stop after the positional argument for a program that expects to accept a command line?
e.g. it's
sudo -E env -v
not sudo -E -- env -v
or sudo -E env -- -v
(sudo stops parsing its own flags after 'env', the positional argument).edit: relevant GNU docs https://www.gnu.org/software/libc/manual/html_node/Argument-...
> The first -- argument that is not an option-argument should be accepted as a delimiter indicating the end of options. Any following arguments should be treated as operands, even if they begin with the '-' character.
> All options should precede operands on the command line.
> If an argument can be identified according to Guidelines 3 through 10 as an option, or as a group of options without option-arguments behind one '-' delimiter, then it should be treated as such.
I think that the rule "all options should precede operands" has been broken so much in practice (particularly since any subcommand must break it) that it may as well not be a rule. And if it's not a rule, then the only way to unambiguously distinguish options from operands-that-start-with-a-dash-but-should-be-passed-verbatim-as-operands... is to require a double-dash.
Many of these are flag-position-agnostic though, and for that the -- is a very long-time standard pattern for either "end of this command, forward the rest to the wrapped command" or a list of files (to make a file named --help unambiguous).
Many. Definitely not all. CLI interfaces are even more varied than GUIs in many ways.
The community is also friendly and inviting for folks trying to get started.
Their main benefit, from what I can tell, is their “retargetable” compiler architecture, but Wasmtime is improving here as well. Wasmtime is also generally faster at implementing standards.
This is not a zero-sum game.
If you find Wasmer useful, use it! If you don’t and you prefer others, feel free to use them. There are plenty of choices.
Happy holidays!
Classic.
In any case I just updated it. Happy holidays!
I thought it was slower until I saw the 1000x. Even 1000x seems kinda meaningless.
Happy holidays to you as well!
I sometimes assume people have the same context as I do, and your comment made me realize that it was not the case. Here's some context: https://wasmer.io/posts/wasmer-and-trademarks
Regarding standards, I assume the mention is referring to Wasmer push for WASIX [1]. Which is a specification & implementation that welcomes anyone to participate (even on it's governance model), so I don't think the stance of the previous comment is accurate.
Things I learned: TinyGo works to get the package size down. Translating values between JS and Go is straightforward (with a lot of boilerplate), but trying to do the JSON dance wasn't worth it - too brittle. Creating SVG in Go and then using it as the innerHTML for a div actually works really well :)
Edit: to be clear, I'm using Go's WASM implementation, not Wasmer
That will open up a lot of use cases (at least for me)
It seems to say it can run any wasix, so yes? But GitHub page says no networking, so no?
I guess that's not quite what you wanted, but browsers don't allow making arbitrary direct TCP connections, so in general I don't think there _is_ a way to do what you wanted.
Endless use-cases for this. Servers, games, collaboration tools, clients for non-HTTP protocols (email, gopher, Gemini etc), file sharing. You name it.
E.g get it to generate a PDF for the user to “download”
It should be possible though, see: http://trevorlinton.github.io/
This left me scratching my head. How are JS workers sharing memory with the WASM process?
My boss once told me he wanted the next release to be "cool". I had no idea what that meant so I thought about it and decided:
"Things are cool when they change how you see the world. When you will never quite see the world the same way again."
Starry Night is cool. Raising metal is cool. Threejs is cool. Webrtc is cool. WASM & wasmer are also cool.
So webassembly is a VM for the browser.
You can compile non-browsery things, like ffmpeg, into webassembly to run on the browser. You usually use emscripten compiler to do that.
Wasmer is a way to run webassembly outside the browser, making portable apps.
Now, wasmer is shipping an SDK for browsers... to bring webassembly back to the browsers?
So it's an emscripten alternative, right?
wasm is just a bytecode assembly format - you can compile something like "int a = 1; int b = 2; return a+b", but to actually do anything interesting you usually need some kind of runtime environment where you can spawn threads, access a filesystem, print to stdout, etc etc. WASI, for example, is an interface for accessing system libraries via wasm; runtimes like wasmer/wasmtime (for native) or v8 (Chromium) will expose their own implementations of WASI. WASIX is wasmer's own extension for WASI (a point of some contention in the wasm community).
Running wasm in a browser, though, still requires some manual setup with Javascript, along with crossing your fingers that the browser runtime actually supports the system calls for whatever you've compiled.
I guess what wasmer has created here is a Javascript SDK so you can:
1) easily download wasm binaries from a central registry
2) ensure those binaries actually run as intended in a browser environment
3) avoid the manual setup Javascript code currently needed to run wasm modules.
emscripten is a (non-WASI) runtime + compiler so this isn't an exact alternative to emscripten (I guess in theory you could compile something via emscripten, publish to the wasmer registry, then consume solely in Javascript). It does, however, replace the manual JS wiring you need to do to run emscripten-compiled binaries in the browser.