Skip to content

iamswethaa/wasm-modularize

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 

Repository files navigation

Web Assembly Conversion Using Modularize

This project demonstrates how to compile a C function (subtraction) into WebAssembly using Emscripten's MODULARIZE method and invoke it from a Node.js script.

Steps

  1. Clone the Repository

    git clone https://github.com/iamswethaa/wasm-modularize.git
    
  2. Install Emscripten

  • Clone the Emscripten SDK repository

    git clone https://github.com/emscripten-core/emsdk.git
    cd emsdk
    
  • Install and activate the latest version

    ./emsdk install latest
    ./emsdk activate latest
    
  • Set up the environment variables

    ./emsdk_env.sh
    
  1. Compile C to WebAssembly

    cd ..
    emcc sub.c -s WASM=1 -s MODULARIZE=1 -s ENVIRONMENT=node -s EXPORTED_FUNCTIONS='["_sub"]' -s EXPORTED_RUNTIME_METHODS='["ccall"]' -o sub.js

    This command produce two files :

    • sub.js - which is your JavScript Glue Code
    • sub.wasm - which is your compiled WebAssembly module
  2. Run the Script

    node main.js

About

Compiles a C function to WebAssembly using Emscripten's MODULARIZE method and runs it in Node.js

Topics

Resources

Stars

Watchers

Forks