GithubHelp home page GithubHelp logo

wasm2bin's Introduction

Wasm2bin

Wasm2bin is a tool that compiles Webassembly modules to native binaries. It uses either w2c2 or wasm2c to compile Webassembly to C, and from there calls a C compiler and links the code with a WASI runtime to produce a native binary. For w2c2 it uses its internal WASI runtime, and for wasm2c it uses uvwasi.

Example usage:

$ export WASM2BIN=/path/to/wasm2bin-src
$ wasm2bin -n hello -o hello hello.wasm
$ ./hello
hello world!

Installation

First clone the repository and initialize submodules.

git clone https://github.com/zyedidia/wasm2bin
cd wasm2bin
git submodule update --init --recursive

Then build the wrapper tool:

go install

Now choose the backend you would like to use (w2c2 or wasm2c) and build it.

w2c2

Build w2c2:

cd w2c2
cmake -B build
cmake --build build

cd wasi
cmake -B build
cmake --build build

Wasm2c

Build Wasm2c:

cd wabt
mkdir build
cd build
cmake .. -G Ninja -DWITH_WASI=ON
ninja wasm2c libuvwasi_a.a

Note: uses version 1.0.33 of wasm2c.

Usage

Usage of wasm2bin:
      --cc string       C compiler (default "clang")
  -f, --flags string    C compiler flags (default "-O2")
  -n, --name string     module name (default "main")
  -o, --output string   output file (default "a.out")
  -V, --verbose         verbose output
      --wasm2c          Use Wasm2c instead of w2c2
$ export WASM2BIN=/path/to/wasm2bin-src
$ wasm2bin -n hello -o hello hello.wasm          # compile with w2c2
$ wasm2bin --wasm2c -n hello -o hello hello.wasm # compile with wasm2c

Note:

The wasm2c runtime files have been adapted from the wasm2native project and this pull request.

wasm2bin's People

Contributors

zyedidia avatar

Stargazers

Darío Clavijo avatar  avatar Mark Vainomaa avatar  avatar Frank Denis avatar  avatar Jin Li avatar Bastian Müller avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.