Native WebAssembly loader for Webpack


  • administrators

    With the new wasm32-unknown-unknown target being available in rustc, I made a simple POC library for easily importing Rust code from Javascript (both node.js and browsers). There are other similar libraries using Emscripten that served as inspiration but I tried to keep this one quite a bit simpler in comparison.

    Some tl;dr example Javascript (ES6) code:

    import loadRustlib from './path/to/rustlib/src/lib.rs'

    loadRustlib().then(result => {
      // This is a normal #[no_mangle] Rust function: fn add(i32, i32) -> i32
      const add = result.instance.exports['add'];
      console.log('return value was', add(2, 3));
    });
    

    GitHub: https://github.com/dflemstr/rust-native-wasm-loader


 

A community for developers looking to put WebAssembly to use today. Come rock WebAssembly with us!