This is a webpack loader that loads Rust code as a WebAssembly module

Overview

rust-native-wasm-loader

Build Status rust-native-wasm-loader npm

This is a webpack loader that loads Rust code as a WebAssembly module. It uses the native Rust support for compiling to wasm32 and does not require Emscripten.

Usage

If you already know how to use Rust and Webpack, read the "Short version" of this section. If you want a full example, read the "Long version."

Short version

Add both this loader and wasm-loader to your Webpack loaders in webpack.config.js:

module.exports = {
  // ...
  module: {
    rules: [
      {
        test: /\.rs$/,
        use: [{
          loader: 'wasm-loader'
        }, {
          loader: 'rust-native-wasm-loader',
          options: {
            release: true
          }
        }]
      }
    ]
  }
}

Then, specify that your Rust library should be a cdylib in Cargo.toml:

[lib]
crate-type = ["cdylib"]

Now you can import any functions marked with #[no_mangle] as WebAssembly functions:

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

loadWasm().then(result => {
  const add = result.instance.exports['add'];
  console.log('return value was', add(2, 3));
});

Available loader options

  • release: boolean; whether to compile the WebAssembly module in debug or release mode; defaults to false.
  • gc: boolean; whether to run wasm-gc on the WebAssembly output. Reduces binary size but requires installing wasm-gc. Defaults to false and is a no-op in wasmBindgen or cargoWeb mode.
  • target: string; the Rust target to use; this defaults to wasm32-unknown-unknown
  • wasmBindgen: boolean or object; use wasm-bindgen to post-process the wasm file. This probably means that you need to chain this loader with babel-loader as well since wasm-bindgen outputs ES6 (or typescript).
    • wasmBindgen.debug: boolean; run wasm-bindgen in debug mode.
    • wasmBindgen.wasm2es6js: boolean; use wasm2es6js to inline the wasm file into generated Javascript. Useful if webpack is not configured to load wasm files via some other loader.
    • wasmBindgen.typescript: boolean; emit a typescript declaration file as part of the build. This file will automatically be referenced, and in a way that ts-loader will pick it up but it's still possible to treat the output from this loader like a normal Javascript module compatible with babel-loader.
  • cargoWeb: boolean or object; use cargo-web to compile the project instead of only building a wasm module. Defaults to false.
    • cargoWeb.name: string; the file name to use for emitting the wasm file for cargo-web, e.g. 'static/wasm/[name].[hash:8].wasm'.
    • cargoWeb.regExp: string; a regexp to extract additional variables for use in name.

Long version

First, you need Rust installed. The easiest way is to follow the instructions at rustup.rs.

Then, you need to add support for WebAssembly cross-compilation. At the time of writing, this requires using the nightly compiler:

rustup toolchain install nightly
rustup target add wasm32-unknown-unknown --toolchain nightly

The next step is to integrate a cargo/node project. Let's assume we don't already have one, so we create one:

cargo init add
cd add

If nightly is not your system default toolchain, create a file named rust-toolchain containing the toolchain name you want to associate with the project:

echo nightly > rust-toolchain

We can add the Rust code that should be available in the WebAssembly module to src/lib.rs. All functions that should be reachable from WebAssembly should be marked with #[no_mangle]:

#[no_mangle]
pub fn add(a: i32, b: i32) -> i32 {
    eprintln!("add({:?}, {:?}) was called", a, b);
    a + b
}

Then, specify that your Rust library should be a cdylib in Cargo.toml:

[lib]
crate-type = ["cdylib"]

Now you can actually start to use this loader. This loader itself does not create Javascript code for loading a WebAssembly module, so you need to compose it with another loader, like wasm-loader:

yarn init
yarn add --dev webpack
yarn add --dev rust-native-wasm-loader wasm-loader

The loaders can be registered the usual way by adding them to your webpack.config.js:

const path = require('path');

module.exports = {
  entry: './src/index.js',
  output: {
    filename: 'index.js',
    path: path.resolve(__dirname, 'dist')
  },
  module: {
    rules: [
      {
        test: /\.rs$/,
        use: [{
          loader: 'wasm-loader'
        }, {
          loader: 'rust-native-wasm-loader',
          options: {
            release: true
          }
        }]
      }
    ]
  }
};

You can now import the WebAssembly module by using the main .rs file from your Cargo project (lib.rs or main.rs); e.g. from your index.js:

import loadAdd from './lib.rs'

loadAdd().then(result => {
  const add = result.instance.exports['add'];
  console.log('return value was', add(2, 3));
});

You can now run webpack and the resulting code from node.js or a browser:

$ yarn run webpack
$ node dist/index.js
return value was 5

wasm-bindgen experimental support

You can use experimental wasm-bindgen support with the following options:

{
  test: /\.rs$/,
  use: [
    {
      loader: 'babel-loader',
      options: {
        compact: true,
      }
    },
    {
      loader: 'rust-native-wasm-loader',
      options: {
        release: true,
        wasmBindgen: {
          wasm2es6js: true,
        },
      }
    }
  ]
}

and edit your lib.rs:

extern crate wasm_bindgen;
use wasm_bindgen::prelude::*;

#[wasm_bindgen]
pub fn add(a: i32, b: i32) -> i32 {
    a + b
}

The loader now uses wasm-bindgen to build the project. If you are using webpack 4, it has experimental native support for importing WASM files, so you probably don't need the wasm2es6js flag. If you are using webpack 3 (or bundling for Chrome and it's 4K limit on main thread WASM), it is needed in order to inline the loading of the wasm file correctly. By using wasm2es6js, the loader returns a normal Javascript module that can be loaded like so:

import { add, wasmBooted } from './path/to/rustlib/src/lib.rs'

wasmBooted.then(() => {
  console.log('return value was', add(2, 3));
});

cargo-web experimental support

You can use experimental cargo-web support with the following options:

{
  loader: 'rust-native-wasm-loader',
  options: {
    cargoWeb: true,
    name: 'static/wasm/[name].[hash:8].wasm'
  }
}

The loader now uses cargo-web to build the project, and as a result needs to emit the wasm file separately. The loader now returns a normal Javascript module that can be loaded like so:

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

loadWasm.then(module => {
  console.log('return value was', module.add(2, 3));
});
Comments
  • Build dependencies with whitespace in their path are not properly handled

    Build dependencies with whitespace in their path are not properly handled

    Build dependencies are currently being parsed using the following line:

    https://github.com/dflemstr/rust-native-wasm-loader/blob/03a6e58fb23ca3e64904b647225e4b04af1ccb83/src/cargo.js#L77

    This will fail if a space exists anywhere in a dependency path. For example, if you have a dependency file that contains something like this:

    C:\Users\User\ Name\Documents\project\target\wasm32-unknown-unknown\debug\rust.wasm: C:\Users\User\ Name\Documents\project\src\mod.rs C:\Users\User\ Name\Documents\project\src\lib.rs
    

    You wind up trying to add each of the following lines as a dependency:

    C:\Users\User
    Name\Documents\project\src\mod.rs
    C:\Users\User
    Name\Documents\project\src\lib.rs
    

    Fixing this is a little tricky, since JavaScript regex doesn't support negative lookbehind. My current solution is to reverse the string, and use a negative lookahead instead:

    const reverseString = str => str.split('').reverse().join('');
    
    const parseDependencies = str =>
        reverseString(str.split(/:\s+/)[1].trim())
            .split(/(?:\s(?!\\))+/)
            .map(reverseString);
    

    which correctly parses the above example into

    C:\Users\User Name\Documents\project\src\mod.rs
    C:\Users\User Name\Documents\project\src\lib.rs
    

    Is that sufficient? Or am I missing a better solution?

    opened by grind086 5
  • ES6 style imports for bindgen Webpack 4

    ES6 style imports for bindgen Webpack 4

    I made a small tweak to the loader so bindgen-Rust can be imported using a standard ES6 style import instead of a dynamic import (the dynamic import is now generated by the loader). This is a bit more convenient and keeps the same style of imports everywhere. Similar to when using wasm2es6js, a promise, wasmBooted is exported. Once the promise resolves, the imported names are available for use.

    This currently doesn't have a test as the project pins webpack@3. Webpack 4 would also need to be included to test, which is tricky/not particularly possible with npm. I could probably mock some of this out and write a sanity test, at the least. I'm open to anything here.

    opened by cwheel 4
  • Add better error handling

    Add better error handling

    Previously, the loader would assume the compilation succeeded. When an error occured, it would fail when trying to parse the compiler's output and find that no files were emitted.

    This PR fixes this issue by making the loader emit errors so the developer could see the issues and correct them.

    opened by akatechis 4
  • Errors seem to not be correctly propagated

    Errors seem to not be correctly propagated

    I incorrectly moved my lib.rs file (for the "simple version" I was trying out), but when I ran it, rather than getting cargo's error (which turned out to be something to the effect of "Cannot parse manifest..." it gives the error below.

    Stack:

    ERROR in ./src/datastore/lib.rs
    Module build failed: TypeError: Cannot read property 'slice' of undefined
        at F:\workspace\project\node_modules\rust-native-wasm-loader\dist\index.js:253:30
        at Generator.next (<anonymous>)
        at step (F:\workspace\project\node_modules\rust-native-wasm-loader\dist\index.js:30:191)
        at F:\workspace\project\node_modules\rust-native-wasm-loader\dist\index.js:30:437
        at new Promise (<anonymous>)
        at F:\workspace\project\node_modules\rust-native-wasm-loader\dist\index.js:30:99
        at handleCargo (F:\workspace\project\node_modules\rust-native-wasm-loader\dist\index.js:267:18)
        at F:\workspace\project\node_modules\rust-native-wasm-loader\dist\index.js:156:40
        at Generator.next (<anonymous>)
        at step (F:\workspace\project\node_modules\rust-native-wasm-loader\dist\index.js:30:191)
        at F:\workspace\project\node_modules\rust-native-wasm-loader\dist\index.js:30:361
        at <anonymous>
        at process._tickCallback (internal/process/next_tick.js:118:7)
     @ ./src/index.js 1:0-41 3:0-7
    

    I'm on Windows 10, using the following:

    rustc 1.24.0 (4d90ac38c 2018-02-12) cargo 0.25.0 (8c93e0895 2018-02-01) node v9.7.1 npm v5.6.0

    And the following dependencies in package.json:

        "rust-native-wasm-loader": "^0.6.5",
        "wasm-loader": "^1.3.0",
        "webpack": "^4.0.1",
        "webpack-cli": "^2.0.10",
        "webpack-serve": "^0.1.4"
    
    opened by akatechis 4
  • Failed to build using npm, but looks ok using same command in CLI

    Failed to build using npm, but looks ok using same command in CLI

    I am try to use rust-native-wasm-loader with vue-cli. I am still new at webpack and vue adds a layer between webpack configuration and the development.

    First I have to add webpack configuration using chainWebpack. So my configuration looks like this

      chainWebpack: webpackConfig => {
        webpackConfig.module
         .rule('wasm')
           .test(/\.wasm$/)
           .use('wasm-loader')
           .loader('wasm-loader'),
        webpackConfig.module
         .rule('rust')
           .test(/\.rs$/)
           .use('rust-native-wasm-loader')
           .loader('rust-native-wasm-loader')
           .options({
             gc: true,
              release: true
           })
      },
    

    Then when I build using npm run serve I get this error """ 15% building modules 45/46 modules 1 active ...-19-0!/home/ubuntu/vuerust/src/l 94% asset optimization

    ERROR Failed to compile with 1 errors 13:10:14

    error in ./src/lib.rs

    Module parse failed: Unexpected character '' (1:0) You may need an appropriate loader to handle this file type. (Source code omitted for this binary file)

    @ ./src/main.js 7:0-28 @ multi (webpack)-dev-server/client?http://localhost:8080/ (webpack)/hot/dev-server.js ./src/main.js """ The artifacts are drwxrwxr-x 3 ubuntu ubuntu 4096 Feb 9 13:09 build drwxrwxr-x 2 ubuntu ubuntu 4096 Feb 9 13:10 deps drwxrwxr-x 2 ubuntu ubuntu 4096 Feb 9 13:09 examples drwxrwxr-x 2 ubuntu ubuntu 4096 Feb 9 13:09 incremental drwxrwxr-x 2 ubuntu ubuntu 4096 Feb 9 13:09 native -rw-rw-r-- 1 ubuntu ubuntu 137 Feb 9 13:10 vuerust.d -rw-rw-r-- 1 ubuntu ubuntu 39938 Feb 9 13:10 vuerust.gc.wasm -rw-rw-r-- 2 ubuntu ubuntu 57409 Feb 9 13:10 vuerust.wasm

    Now here is the interesting part. When I run the command

    cargo web build --message-format=json --target=wasm32-unknown-unknown --release > log
    

    I get a good build with artifact drwxrwxr-x 3 ubuntu ubuntu 4096 Feb 9 13:13 build drwxrwxr-x 2 ubuntu ubuntu 4096 Feb 9 13:14 deps drwxrwxr-x 2 ubuntu ubuntu 4096 Feb 9 13:13 examples drwxrwxr-x 2 ubuntu ubuntu 4096 Feb 9 13:13 incremental drwxrwxr-x 2 ubuntu ubuntu 4096 Feb 9 13:13 native -rw-rw-r-- 1 ubuntu ubuntu 137 Feb 9 13:14 vuerust.d -rw-rw-r-- 1 ubuntu ubuntu 17040 Feb 9 13:14 vuerust.js -rw-rw-r-- 2 ubuntu ubuntu 42167 Feb 9 13:14 vuerust.wasm

    If you tell me how to debug webpack I can do that, What I do not understand is the .js file is missing when using npm build and the sizes are different.

    opened by greenpdx 4
  • Update readme on setting the default toolchain

    Update readme on setting the default toolchain

    A small thing, but as somebody completely new to Rust, I had to dig quite deep to figure out why my build failed (especially since the latest release of rust-native-wasm-loader swallows the errors). I presume anyone who uses this loader wants to default to the nightly.

    opened by voneiden 3
  • Invalid Version with default config from README and wasm-bindgen

    Invalid Version with default config from README and wasm-bindgen

    I'm using wasm-bindgen to load a rust file into my react project. My webpack config for .rs files looks like this:

    {
            test: /\.rs$/,
            use: [
              {
                loader: 'babel-loader',
                options: {
                  compact: true,
                }
              },
              {
                loader: 'rust-native-wasm-loader',
                options: {
                  release: true,
                  wasmBindgen: {
                    wasm2es6js: true,
                  },
                }
              }
            ]
          }
    

    which is the default config from the README. But I'm getting this error. Any advice on how to fix this?

    ERROR in ./stutter/src/lib.rs
    Module build failed: TypeError: Invalid Version: (5f799e543)
        at new SemVer (/Users/jacob/Documents/stutter-ide/node_modules/semver/semver.js:305:11)
        at Range.test (/Users/jacob/Documents/stutter-ide/node_modules/semver/semver.js:1112:15)
        at Object.satisfies (/Users/jacob/Documents/stutter-ide/node_modules/semver/semver.js:1161:16)
        at /Users/jacob/Documents/stutter-ide/node_modules/rust-native-wasm-loader/dist/index.js:59:17
        at Generator.next (<anonymous>)
        at step (/Users/jacob/Documents/stutter-ide/node_modules/rust-native-wasm-loader/dist/index.js:38:191)
        at /Users/jacob/Documents/stutter-ide/node_modules/rust-native-wasm-loader/dist/index.js:38:361
     @ ./src/App.js 15:11-43
     @ ./src/index.js
     @ multi (webpack)-dev-server/client?http://localhost:8080 ./src/index.js
    
    opened by junewunder 2
  • fix tests; make tests reproducable

    fix tests; make tests reproducable

    PR contains the following

    • Two bug fixes when using wasm-bindgen with nodejs option.
    • Switching the projects internal package manager to npm as running yarn in examples directories caused yarn to recursivley cache project -> examples -> project -> ... until it had eaten up my ~ 70GB free space
    • Bumped jest timeouts to 10 mins
    • Locked down versions of all dependencies

    I might've missed something but hopefully we can have reliable ci moving forward

    opened by RobertBorg 2
  • Remove WASM builds after wasm2es6js processing

    Remove WASM builds after wasm2es6js processing

    This removes the generated WASM files (.wasm & _bg.wasm) after performing a wasm2es6js build.

    This prevents Webpack from resolving and trying to bundle these files instead of their equally named JS files, outputted from the transformation. If Webpack attempts to bundle these WASM files, it will fail, as they are not a WASM format it can import, and are imported synchronously, which is not supported at the time of this commit.

    This also increases the required version of wasm-bindgen to 0.2.0, which brings in new features and fixes.

    This also updates and fixes an error in the wasm-bindgen example, where the incorrect options were passed to the loader.

    opened by atkinchris 2
  • wasm2es6js looking for non-existent file

    wasm2es6js looking for non-existent file

    ERROR in ./src/main.rs
    Module build failed: Error: Command failed: wasm2es6js target\wasm32-unknown-unknown\release\garuda-wasm-mdns_wasm.wasm -o target\wasm32-unknown-unknown\release\garuda-wasm-mdns_wasm.js --base64
    thread 'main' panicked at 'failed to open input: Os { code: 2, kind: NotFound, message: "The system cannot find the file specified." }', libcore\result.rs:945:5
    note: Run with `RUST_BACKTRACE=1` for a backtrace.
    

    The wasm2es6js command is looking for garuda-wasm-mdns_wasm.wasm which is non-existent. The file that does exist is garuda-wasm-mdns.wasm. Somewhere there must be a descrepency between naming the release file and what wasm2es6js is looking for.

    rustc 1.26.0-nightly (2789b067d 2018-03-06) wasm-bindgen 0.1.1

    Webpack config

    rules: [
          {
            test: /\.rs$/,
            use: [{
              loader: 'wasm-loader',
            }, {
              loader: 'rust-native-wasm-loader',
              options: {
                release: true,
                gc: true,
                wasmBindgen: true,
                wasm2es6js: true,
              },
            }],
          }
        ],
    
    opened by mneil 2
  • Error building the

    Error building the "simple version"

    I'm trying to build the simple version from the README, and getting the following error. I get a similar error when I try running building the project in "watch" mode using webpack-serve.

    Stack:

    ERROR in ./src/lib.rs
    Module build failed: TypeError: (0 , _util.promisify) is not a function
        at Object.<anonymous> (F:\workspace\project\node_modules\rust-native-wasm-loader\dist\index.js:32:39)
        at Module._compile (F:\workspace\project\node_modules\v8-compile-cache\v8-compile-cache.js:178:30)
        at Object.Module._extensions..js (module.js:580:10)
        at Module.load (module.js:488:32)
        at tryModuleLoad (module.js:447:12)
        at Function.Module._load (module.js:439:3)
        at Module.require (module.js:498:17)
        at require (F:\workspace\project\node_modules\v8-compile-cache\v8-compile-cache.js:159:20)
        at loadLoader (F:\workspace\project\node_modules\loader-runner\lib\loadLoader.js:13:17)
        at iteratePitchingLoaders (F:\workspace\project\node_modules\loader-runner\lib\LoaderRunner.js:169:2)
        at iteratePitchingLoaders (F:\workspace\project\node_modules\loader-runner\lib\LoaderRunner.js:165:10)
        at F:\workspace\project\node_modules\loader-runner\lib\LoaderRunner.js:173:18
        at loadLoader (F:\workspace\project\node_modules\loader-runner\lib\loadLoader.js:36:3)
        at iteratePitchingLoaders (F:\workspace\project\node_modules\loader-runner\lib\LoaderRunner.js:169:2)
        at runLoaders (F:\workspace\project\node_modules\loader-runner\lib\LoaderRunner.js:362:2)
        at NormalModule.doBuild (F:\workspace\project\node_modules\webpack\lib\NormalModule.js:219:3)
        at NormalModule.build (F:\workspace\project\node_modules\webpack\lib\NormalModule.js:337:15)
        at Compilation.buildModule (F:\workspace\project\node_modules\webpack\lib\Compilation.js:346:10)
        at factory.create (F:\workspace\project\node_modules\webpack\lib\Compilation.js:572:15)
        at factory (F:\workspace\project\node_modules\webpack\lib\NormalModuleFactory.js:366:6)
        at hooks.afterResolve.callAsync (F:\workspace\project\node_modules\webpack\lib\NormalModuleFactory.js:143:13)
        at AsyncSeriesWaterfallHook.eval [as callAsync] (eval at create (F:\workspace\project\node_modules\tapable\lib\HookCodeFactory.js:24:12), <anonymous>:6:1)
        at resolver (F:\workspace\project\node_modules\webpack\lib\NormalModuleFactory.js:126:29)
        at process.nextTick (F:\workspace\project\node_modules\webpack\lib\NormalModuleFactory.js:304:9)
        at _combinedTickCallback (internal/process/next_tick.js:73:7)
        at process._tickCallback (internal/process/next_tick.js:104:9)
     @ ./src/index.js 1:0-31 3:0-7
    

    I'm on Windows 10, using the following:

    rustc 1.24.0 (4d90ac38c 2018-02-12) cargo 0.25.0 (8c93e0895 2018-02-01) node v7.9.0 npm v5.6.0

    And the following dependencies in package.json:

        "rust-native-wasm-loader": "^0.6.5",
        "wasm-loader": "^1.3.0",
        "webpack": "^4.0.1",
        "webpack-cli": "^2.0.10",
        "webpack-serve": "^0.1.4"
    
    opened by akatechis 2
  • Unable to chain webpack or Vue-cli to load .wasm

    Unable to chain webpack or Vue-cli to load .wasm

    Hi, I'm unable to build a project with .rs/wasm

    My demo repository: https://github.com/Zireael/wasm-rust

    The closest I'm getting is by using Vue-cli (try running vue-cli-service build on my project) with:

    > vue.config.js

        config.module
          .rule("Rust")
          .test(/\.rs$/)
          .use("wasm-loader")
          .loader("rust-native-wasm-loader")
          .options({
            cargoWeb: true,
            name: "/wasm/[name].[hash:8].wasm"
          });
    

    but the compiled .wasm does not get correctly copied into assets folder and instead is copied to build root folder as [hash].rs (it is compiled wasm inside, just with extension .rs) and browser complains that it's incorrect file type:

    Error loading Rust wasm module 'arithmetic': TypeError: Failed to execute 'compile' on 'WebAssembly': Incorrect response MIME type. Expected 'application/wasm'.
    :8081/#/:1 Uncaught (in promise) TypeError: Failed to execute 'compile' on 'WebAssembly': Incorrect response MIME type. Expected 'application/wasm'.
    

    For this I guess I need to figure out how to chain Vue/webpack to get it to copy the output .wasm to /assets folder and with .wasm extension. Would appreciate help.

    If I try using example from your git project using webpack (run webpack --mode development) on my project, I'm getting error message:

    ERROR in ./src/wasm/rust2/lib.rs
    Module build failed (from ./node_modules/rust-native-wasm-loader/dist/index.js):
    TypeError: Cannot read property 'slice' of undefined
        at C:\js\_templates\wasm-rust\node_modules\rust-native-wasm-loader\dist\cargo.js:105:30 [...]
    

    > webpack.config.js

              {
                test: /\.rs$/,
                use: [
                  { loader: "wasm-loader" },
                  {
                    loader: "rust-native-wasm-loader",
                    options: {
                      cargoWeb: true,
                      name: "/wasm/[name].[hash:8].wasm"
                    }
                  }
                ]
              }
    

    Have latest Node (12, altho tried 11 too), Vue, Webpack (4), cargo, rust-nightly, emscripten installed. Cargo is added to PATH (Windows 10).

    opened by Zireael 0
  • wasm-bindgen not found during webpack chaining

    wasm-bindgen not found during webpack chaining

    Hi I'm getting error (looks like it can't find wasm-bindgen):

    image

    I have wasm-bindgen installed on my system (can compile .rs into .wasm with [wasm-pack build]).

    I use Vue cli, not sure if that matters (it's just a wrapper for webpack). Would you have any ideas to solve this? I can use .wasm files built with wasm-pack, but can't .rs from webpack loader chaining.

    Vue Webpack chain config:

        config.module
          .rule("Rust")
          .test(/\.rs$/)
          .use("wasm-loader")
          .loader("rust-native-wasm-loader")
          .options({
            release: true
          });
    

    .rs import:

    import loadAdd from "@/js/wasm/hello_world/hello_world.rs";
    
    loadAdd().then(result => {
      const add = result.instance.exports["add"];
      console.log("return value was", add(2, 3));
    });
    

    I tried using the [wasm-bindgen experimental support] webpack config provided on your page a well, but getting same error.

    opened by Zireael 2
  • readme sample code -> new syntax to conform to object destructuring

    readme sample code -> new syntax to conform to object destructuring

    The readme sample code const add = result.instance.exports['add']; is throwing an error for projects using airbnb-eslint because it prefers object destructuring. Would it be possible to update for this in favor of a more modern syntax?

    opened by tysun 0
  • Hot Reload Support

    Hot Reload Support

    I would really like to see one of these new WASM compilers include Hot Reload Support. I tried this and it crashes. Is there anything that I can do to make this work with hot reload? I have some ideas for simpler programs...

    A trivial approach would be to simply strip the rusty types then transform it into more javascripty language...

      string
        .replace(/extern.*;/gm, '')
        .replace(/use.*;/gm, '')
        .replace(/#\[.*\]/gm, '')
        .replace(/eprintln!/gm, 'console.log')
        .replace(/extern (.|\n)[^}]*\}/gm, '')
        .replace(/pub fn (\w*)/gm, 'module.exports.$1 = function $1')
        .replace(/{.[^}]*}/gm, '%s')
        .replace(/\) -> \w* {/gm, '){')
        .replace(/: (i32|f32)/gm, '')
        .replace(/eprintln!/gm, 'console.log')
        .replace(/^(\s[^\n]*)\n}/gm, 'return $1; }')
        .replace(/(\s|\n)(\s*)/gm, ' ');
    

    Do you know if this is possible?!?!?

    I just wish we could sorta run things exactly the same in development as production without having to worry about comment things out in development.

    opened by couturecraigj 0
Owner
David Flemström
David Flemström
A simple tool to convert a WebAssembly module to a WASI component (component model, WASI-preview2).

A simple tool to convert a WebAssembly module (wasm32-wasi, wasm32-freestanding) to a WASI component (component model, WASI-preview2). Installation In

Frank Denis 5 Feb 18, 2024
Rust WebGL2 wrapper with a focus on making high-performance WebAssembly graphics code easier to write and maintain

Limelight Limelight is a WebGL2 wrapper with a focus on making high-performance WebAssembly graphics code easier to write and maintain. demo.mov live

drifting in space 27 Dec 30, 2022
Contains the source code to compile the drop'in language into WebAssembly files

drop'in compiler This repository contains the source code to compile the drop'in language into WebAssembly files. This source code is in an experiment

Blue Forest 2 Dec 17, 2022
Sealed boxes implementation for Rust/WebAssembly.

Sealed boxes for Rust/WebAssembly This Rust crate provides libsodium sealed boxes for WebAssembly. Usage: // Recipient: create a new key pair let reci

Frank Denis 16 Aug 28, 2022
WebAssembly on Rust is a bright future in making application runs at the Edge or on the Serverless technologies.

WebAssembly Tour WebAssembly on Rust is a bright future in making application runs at the Edge or on the Serverless technologies. We spend a lot of ti

Thang Chung 129 Dec 28, 2022
A console and web-based Gomoku written in Rust and WebAssembly

?? rust-gomoku A console and web-based Gomoku written in Rust and WebAssembly Getting started with cargo & npm Install required program, run # install

namkyu1999 2 Jan 4, 2022
darkforest is a console and web-based Roguelike written in Rust and WebAssembly.

darkforest darkforest is a console and web-based Roguelike written in Rust and WebAssembly. Key Features TBA Quick Start TBA How To Contribute Contrib

Chris Ohk 5 Oct 5, 2021
A Rust ESP stack trace decoder that can also runs in your browser thanks to WebAssembly

ESP Stack Trace Decoder A Rust ESP stack trace decoder that can also runs in your browser thanks to WebAssembly. It is composed of a ⌨️ Rust library,

Maxime BORGES 20 Oct 5, 2022
Simple file sharing with client-side encryption, powered by Rust and WebAssembly

Hako Simple file sharing with client-side encryption, powered by Rust and WebAssembly Not feature-packed, but basic functionalities are just working.

Jaehyeon Park 30 Nov 25, 2022
bn.js bindings for Rust & WebAssembly with primitive-types support

bn.rs bn.js bindings for Rust & WebAssembly with primitive-types support Write Rust code that uses BN use std::str::FromStr; use primitive_types::{H1

Alexey Shekhirin 23 Nov 22, 2022
A handy calculator, based on Rust and WebAssembly.

qubit ?? Visit Website To Use Calculator Example ?? Visit Website To Use Calculator 2 + 2

Abhimanyu Sharma 55 Dec 26, 2022
A simple compile-to-WebAssembly language rewritten in Rust

chasm A very simple compile-to-WebAssembly language You can play with chasm online. This is a rewrite in Rust of the compiler for the language chasm.

null 11 Nov 27, 2022
Stylist is a CSS-in-Rust styling solution for WebAssembly Applications.

Stylist Stylist is a CSS-in-Rust styling solution for WebAssembly Applications. This is a fork of css-in-rust. Install Add the following to your Cargo

Kaede Hoshikawa 190 Dec 30, 2022
WebAssembly serialization/deserialization in rust

parity-wasm Low-level WebAssembly format library. Documentation Rust WebAssembly format serializing/deserializing Add to Cargo.toml [dependencies] par

Parity Technologies 391 Nov 17, 2022
Zaplib is an open-source library for speeding up web applications using Rust and WebAssembly.

⚡ Zaplib Zaplib is an open-source library for speeding up web applications using Rust and WebAssembly. It lets you write high-performance code in Rust

Zaplib 1.2k Jan 5, 2023
A template for kick starting a Rust and WebAssembly project using wasm-pack.

A template for kick starting a Rust and WebAssembly project using wasm-pack.

Haoxi Tan 1 Feb 14, 2022
Client for integrating private analytics in fast and reliable libraries and apps using Rust and WebAssembly

TelemetryDeck Client Client for integrating private analytics in fast and reliable libraries and apps using Rust and WebAssembly The library provides

Konstantin 2 Apr 20, 2022
Rust-based WebAssembly bindings to read and write Apache Parquet files

parquet-wasm WebAssembly bindings to read and write the Parquet format to Apache Arrow. This is designed to be used alongside a JavaScript Arrow imple

Kyle Barron 103 Dec 25, 2022
A simple Rust and WebAssembly real-time implementation of the Vigénere Cipher utilizing the Sycamore reactive library.

WebAssembly Vigenère Cipher A simple Rust and WebAssembly real-time implementation of the Vigenère Cipher utilizing the Sycamore reactive library, Tru

Rodrigo Santiago 6 Oct 11, 2022