Run WebAssembly Components Inside Node.js With Jco |
Written by Nikos Vaggalis |
Thursday, 28 March 2024 |
Jco 1.0 has been just announced by the Bytecode Alliance.It's a native JavaScript WebAssembly toolchain and runtime that runs Wasm components inside Node.js. Why is that useful? In simple terms, a Wasm component is like a shared library, which maybe linked to other code and so on. Jco's mission then is to take such libraries written in a variety of programming languages and execute them from Node.js. As such Jco is comprised of both a runtime that adheres to WASI 0.2 specification and a toolchain that turns programs in various languages to WASI interface's components. WASI (WebAssembly System Interface) is a modular system interface for WebAssembly (Wasm) that enables developers to run Wasm programs on any platform, including the browser, the cloud, and the edge. WASI is designed to be secure, fast, and portable, allowing developers to write their programs once and run them anywhere. Under the WASI 0.2 API surface, components can access the network, filesystem, and other system APIs available in the runtime. However Wasm Components do not just provide a way for JavaScript and Wasm to talk to each other. They can do so for any programming language. The point of Wasm Components and WASI is that we can connect any number of languages to each other via a strongly typed ABI, while Jco is the toolchain specifically for the JavaScript bindings. Jco features include:
To transpile a component into JS from the CLI you do: jco transpile component.wasm -o out-dir The resultant file then can be imported providing the bindings of the component as if it were imported directly: import { fn } from './out-dir/component.js'; fn(); For Wasm components that implement the WASI CLI world, a jco run utility is provided to run these applications in Node.js as: jco run component. wasm Of course you have to write the component in some language, say Rust. At this point it's important to note that there's a similar project, that of Wasmer JS SDK, not from the Bytecode Alliance but from Wasmer. That SDK supports WASIX, a propriety extension to WASI which also runs wasm applications on both the browser and server. The added bonus is that the SDK, can run any UNIX program that can use threads, signals, subprocesses and other POSIX features all inside the browser! However WASIX has lately been caught in the middle of a turmoil, with the Alliance claiming that WASIX is non standard and that the Alliance doesn't promote non-standard system interfaces. In any case and whichever interface you choose to go for, you can now port your programs written in any language to WebAssembly and enjoy all the advantages such a move bears.
More InformationRelated ArticlesWasmer JS SDK - WebAssembly In The Browser
To be informed about new articles on I Programmer, sign up for our weekly newsletter, subscribe to the RSS feed and follow us on Twitter, Facebook or Linkedin.
Comments
or email your comment to: comments@i-programmer.info |
Last Updated ( Thursday, 28 March 2024 ) |