Getting started with Rust WebAssembly apps for the SAFE Browser

The main disadvantage is really the same as that of having many different programming languages for desktop/server apps. If everyone just used one single programming languages, certain things would be simpler, everyone just has that one language they need to learn and think about, but the advantages of having many programming languages, rather than just a single one, vastly outweigh this disadvantage.

You can call js code from webassembly and vice versa.

3 Likes

So cool! Thank you for posting.

I tweeted Beaker browser to confirm that web assembly is available for use.

Here I see a WebAssembly object in the Beaker console

Can’t wait to make time to play with this.

7 Likes

Any Windows users whom also want to play, it’s not quite a smooth process to install and utilise Emscripten.
Here’s a guide: https://github.com/hunterlester/rusty_safe_web#emscripten-setup

4 Likes

Take a look at the source code of stdweb.

Also there is this thing called cargo-web which will install emscripten (linux only right now) for you and make rust webdev easier, but there is one downside it only supports asm.js (the predecessor of wasm).

edit: just saw this on “this week in rust”: lord_io/blog/2017/wargo/ (“Sorry, new users can only put 2 links in a post.”)

3 Likes

I tested wargo on a simple bin app in rust, it worked, kinda. You do need to tell llvm to not go through main and complete. In any case it works a bit, but if you then have libs that are not no_std only then there are issues AFAIK. Anyhow wargo is a great try, I see the rust team looking at wasm and agreeing the compiler targets right now are not tier 1 ready at all. So a bit of work to do, but that team will get it, if anyone can.

Interesting to see the c++ emscripten projects have not yet got to create exciting stuff yet, I wish there were movement here, but its for sure very interesting.

4 Likes

native wasm support for rust(work in progress): https://github.com/rust-lang/rust/pull/45905

3 Likes
  1. wasm support got enable: https://github.com/rust-lang/rust/pull/46115
  2. there is a chance for stdweb to support the wasm target without emscripten: https://github.com/koute/stdweb/issues/36
4 Likes

Over the weekend I started playing with wasm-bindgen which,

allows JS/wasm to communicate with strings, JS objects, classes, etc, as opposed to purely integers and floats.

Notable features of this project includes:

Exposing Rust structs to JS as classes
Exposing Rust functions to JS
Managing arguments between JS/Rust (strings, numbers, classes, objects, etc)
Importing JS functions with richer types (strings, objects)
Importing JS classes and calling methods
Receiving arbitrary JS objects in Rust, passing them through to JS
Catching JS exceptions in imports

I began building a simple safe_app_wasm library but ran into compilation issues having to do with dependency crates that only support Windows or Linux target families, when my target is wasm32-unknown-unknown, summarised in this issue.

You’ll see that these two crates memmap and fs2 that we rely on need either a Windows or Linux target.

Even when rust-wasm decides how to treat wasm32-unknown-unknown target, it looks like 3rd party crates will still need to implement wasm support.

wasm-bindgen is much cleaner than my experiments using Neon and I think it would be worthwhile to spend time either opening issues in crates that we want supported or to open PR’s on those crates to implement wasm.

5 Likes
1 Like

An IDE that can be run in the browser for WebAssembly: https://hacks.mozilla.org/2018/04/sneak-peek-at-webassembly-studio/

5 Likes

For a higher-level library to complie wasm from Rust, might be relevant to consider yew: https://github.com/DenisKolodin/yew

2 Likes

Have you guys checked this book out?

2 Likes

What is the current state of using Rust, and a Rust-based web framework such as Dominator or Yew as @jonas mentioned, for SAFE apps via WebAssembly vis-a-vis SAFE Browser?

Safe Browser is chromium based, so whatevers working in the appropriate version should be working for the Safe Browser. I personally haven’t attempted anything beyond a couple basic wasm tutorials in my time (and not in SB). But there’s no reason it shouldn’t work AFAIK

2 Likes

What is the most recent example demonstrating loading an SPA as a wasm file with minimal JS bootstrapping it?

Also, would the JS and wasm files be first stored to SAFE and then referenced in the fetch with their xor-url?

Uploaded files all have an xor URL, but in a website they can be resolved in the normal way using a full domain based URL, or a relative URL. The browser will resolve these and perform the fetch if they are referred to in a web page.

1 Like

There’s no safe specific example. But if you get one setup would be great to have such a thing :slight_smile: :+1:

@anon78698497 have a look at the Name Resolution System (as @bochaco noted in the other thread), and you should be able to setup a site from a local folder in a few CLI commands :+1:

2 Likes

@joshuef

I’m building my first SAFE project with offering that in mind.

3 Likes

Done.

Hello SAFE

1 Like

See also:

2 Likes