|
|
||
|---|---|---|
| assemblyscript | ||
| src | ||
| .envrc | ||
| .gitignore | ||
| Cargo.lock | ||
| Cargo.toml | ||
| flake.lock | ||
| flake.nix | ||
| LICENSE-APACHE | ||
| LICENSE-MIT | ||
| README.md | ||
WASM Scripting
A test for adding scripting to a Rust program using WASM.
In this project I'll be testing these two languages with Wasmer:
- MoonBit
- AssemblyScript
Running the project and working with WASM
Running the Rust code
cargo run
The Wasmer page on GitHub tells you to install Wasmer. This is only necessary if you want to run WASM programs in your machine without embedding it.
We don't have to do any of that since we use the SDK to embed WASM.
NixOS users, you know how it works, either use direnv or nix develop
and then do a cargo run.
Working with AssemblyScript
To use AssemblyScript you only need Node! This is already pretty good.
For NixOS users, I've included Node with this project's flake so just
nix develop.
You initialize a project with these commands:
npm init # Set the type to module, not commonjs!
npm install --save-dev assemblyscript
npx asinit .
You should now have an assembly folder with your index.ts file, which
is the main file. We can compile this code with this command:
npm run asbuild
Working with MoonBit
To use MoonBit for scripting you need to install it.
You can install it with the instructions indicated here: https://www.moonbitlang.com/download
In my case, since I use NixOS I included this overlay:
https://github.com/moonbit-community/moonbit-overlay
into this project's flake. If you use NixOS you should have access to the
moonbit toolchain if you activate the included flake with nix develop.
I tried to create a new project and running it made compilation errors. I didn't continue.