Skip to content

Using a Rust function compiled to WebAssembly to show a fractal in the browser

Notifications You must be signed in to change notification settings

jdelafon/rust-webassembly-fractal

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rust to Web assembly experiment

Drawing a Mandelbrot fractal in the browser, importing a Rust function compiled to WebAssembly. Compare speed with raw JS.

See /docs/ to start the project.

Startup

source ../emsdk-portable/emsdk_env.sh
source $HOME/.cargo/env

Compile Rust files to Web Assembly

rustc --target=wasm32-unknown-emscripten src/mandelbrot.rs -o weba/mandelbrot.html

The build goes to /weba/. It produces a ".wasm", a ".js" and a ".html" file.

  • The .wasm is the WebAssembly binary file.
  • The .html is ready to load in a browser with a built-in console.
  • The .js is the file to load in a <script> tag in order to use wasm functions in JS.

Run in a web page

  • Go to /weba/

  • Run a web server at localhost:8000:

    ```
    python -m SimpleHTTPServer
    ```
    
  • Make sure web assembly is enabled in the browser

    • Chrome: chrome://flags -> "WebAssembly" stuff
    • Firefox: about:config -> "wasm" stuff
  • Go to localhost:8000/index.html in a browser.

About

Using a Rust function compiled to WebAssembly to show a fractal in the browser

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published