Skip to content
This repository has been archived by the owner on Jul 1, 2021. It is now read-only.
/ wasmlink Public archive

A prototype WebAssembly linker that uses the module linking proposal.

License

Notifications You must be signed in to change notification settings

peterhuene/wasmlink

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Notice

This repository has moved to a Bytecode Alliance repository.

This repository has been archived.

wasmlink

A WebAssembly module linker that uses the module linking proposal.

A Bytecode Alliance project

build status supported rustc stable

Wasmlink

Please note: this is currently an experimental project.

wasmlink is a prototype WebAssembly module linker that can link together a module and its dependencies using module linking and the Canonical Interface Types ABI.

When used in combination with witx-bindgen, it is capable of generating interface adapter functions in WebAssembly that enables WebAssembly modules to exchange interface types such as strings, records, lists, and variants.

Building

To build wasmlink:

$ cargo build

Running

To run wasmlink:

$ cargo run

Testing

To run tests, first install the wasm32-wasi target:

$ rustup target install wasm32-wasi

With the target installed, run the tests:

$ cargo test --all

Demo

Prerequisites

The demo requires cargo-wasi, so install it using cargo:

$ cargo install cargo-wasi

Building the markdown module

The markdown module exposes an interface consisting of a render function that takes a string (the Markdown) as an argument and returns a string (the rendered HTML).

The interface for the markdown module is:

render: function(markdown: string) -> string

To build the markdown module:

$ cargo wasi build --manifest-path demo/markdown/Cargo.toml
$ cp demo/markdown/markdown.witx demo/markdown/target/wasm32-wasi/debug/markdown.witx

Note: the linker currently expects either an embedded witx file in a custom section of the module or a witx file of the same name next to the input wasm module, so we copy the witx file to the target directory above.

Building the renderer module

The renderer module will read input via stdin, pass the input as a string to the render function from the markdown module, and then print the returned HTML to stdout.

To build the renderer module:

$ cargo wasi build --manifest-path demo/renderer/Cargo.toml

Linking the two modules together

With the two modules now built, it is time to link them together so that they can be run directly with Wasmtime:

$ cargo run --release -- -i markdown=demo/markdown/target/wasm32-wasi/debug/markdown.wasm -p wasmtime -o linked.wasm demo/renderer/target/wasm32-wasi/debug/renderer.wasm

This command produces a linked module named linked.wasm in the current directory.

Running the linked module

As the linked module uses features from both the module linking and multi-memory WebAssembly proposals, support has to be explicitly enabled in Wasmtime to enable the module to run.

To run the linked module:

$ printf '# Hello\nworld' | wasmtime --enable-module-linking --enable-multi-memory linked.wasm

If everything worked correctly, this should render the Markdown echoed on the command line:

# Hello
world

as the following HTML:

<h1>Hello</h1>
<p>world</p>

About

A prototype WebAssembly linker that uses the module linking proposal.

Topics

Resources

License

Stars

Watchers

Forks

Languages