Skip to content
This repository has been archived by the owner on Oct 30, 2023. It is now read-only.

Latest commit

 

History

History
81 lines (53 loc) · 2.42 KB

README.livemd

File metadata and controls

81 lines (53 loc) · 2.42 KB

Kino Wasm

Mix.install([{:kino_wasm, git: "https://github.com/spawnfest/kino_wasm.git"}])

Kino WASM - WebAssembly for multilanguage support in Livebook!

This Smart Cell leverages WebAssembly to achieve multi language support in Livebook.

It includes a secondary library (wasm_runner) that receives the code, compiles it to web assembly and executes said code using wasmex.

Supported languages:

  • Rust
  • Zig

Usage

When you add the cell Rust Code Cell it will include two fields:

  • A Monaco editor for the target language
  • Second editor to specify the arguments

When you change the code in the first editor, it will trigger the blur event and send the altered source code to wasm_runner to compile and run based on the args given

output =
  WasmRunner.Backend.run(
    :rust,
    "#[no_mangle]\npub extern fn run(x: i32, y: i32) -> i32 {\n    x + y\n}\n",
    [4, 2]
  )

The output of the function is stored in a variable called output so it can be used in other livebook cells

output

With Zig Code Cell we can follow the same idea, some code and then the arguments

output =
  WasmRunner.Backend.run(:zig, "export fn run(a: i32, b: i32) i32 {\n    return a + b;\n}\n", [
    10,
    20
  ])
output

Requirements

This were only tested in OSX.

Rust backend

You'll need to install this two dependencies

Zig backend

  • Install Zig 0.11.0 with Homebrew
  • Zig binary in /opt/homebrew/Cellar/zig/0.11.0/bin/zig

Known issues

  • Paths are not properly assigned when running System.cmd so at the moment paths for executables are too hard coded... This is the first thing I will need to fix!