9 ms·
Rust to WebAssembly Made Easier
- flavio81 9y agoI am not a Rust fan nor user, but I must heartily applaud the sign that the times are changing -- for that we will finally free ourselves from being forced to have only one choice (Javascript) for delivering frontend code at the browser. Looking forward to many interesting stuff done by leveraging Webassembly to the max!
- milesokeefe 9y agoNot exactly, WebAssembly has no direct DOM access so if you want have your front end run in WebASM you’ll still need JavaScript to make anything work. Personally I think that’s a good thing, I don’t want front ends to get any more obfuscated than they have gotten.
- ozten 9y agoNot really, minimal bridge only has to be written once and is reusable across any language that compiles to Web Assembly.
- tyingq 9y agoThat minimal bridge is anywhere from 10x to 100x slower than pure JS right now. https://github.com/rust-webplatform/rust-webplatform/issues/20 https://github.com/rust-webplatform/rust-webplatform/issues/...
- adamnemecek 9y ago"Where we're going, we don't need a DOM."
- steveklabnik 9y agoYou can bridge it though. See https://github.com/rust-webplatform/rust-todomvc https://github.com/rust-webplatform/rust-todomvc , rendered at http://rust-webplatform.github.io/rust-todomvc/ http://rust-webplatform.github.io/rust-todomvc/ That said, I think there are better opportunities for wasm than trying to oust JavaScript; that's not really a stated goal of the wasm project.
- shams93 9y agoIts definitely meant to make javascript more capable. Currently while you can do some things with webaudio for example, with WASM you can use complex DSP, you can also build out valuable audio code that you want to keep locked down in binary format where someone getting your algorithm could do damage to your business but in the case of a webaudio DAW the code can't be run on the server.
- steveklabnik 9y agoI’d argue it’s intended to make the platform more capabale. JS is clearly part of the platform. Really though, the point is that wasm’s goals aren’t somehow eliminating JavaScript, but complimenting it.
- krapp 9y ago>the point is that wasm’s goals aren’t somehow eliminating JavaScript, but complimenting it That may not be the goal of WASM's creators, but it will certainly be the goal of many of its implementers.
- flavio81 9y ago>better opportunities for wasm than trying to oust JavaScript; that's not really a stated goal of the wasm project. Yes, that's what the wasm guys say, however, what I think is that it will effectively displace Javascript. Not only that, the labor market implications for the current JS full stack developers and front-end developers will be interesting.
- pjmlp 9y agoToday, canvas and WebGL are enough, we don't need DOM. Tomorrow, DOM access might actually exist.
- rickycook 9y agobut then we are kinda back in the realms of flash and why that was all so horrific
- jlebrech 9y agoditching html and css is not obfuscation :P
- hacker_9 9y agoWhy would you use Rust over JS for front end work though?
- supergreg 9y agoNot exactly rust, but there's benefits to running the same language both on the front and back end. You could reuse template systems and validation logic for example.
- Thaxll 9y agoLike Java did 15years ago.
- flavio81 9y agoBut it's not a fair comparison: 1. Java (apple) plugins were not built into the browser; and it was not an internationally agreed standard between browser vendors. You needed to install a big plugin to make it work. 2. Due to the computing capacity of the average PC on those times, startup was slow and it consumed lots of memory. 3. Java applets could only be written in Java. In comparison: 1. Webassembly is an standard, and its support is built into the browser. 2. Webassembly is very high performance, higher than what users come to accept as good (= Javascript under Google V8) 3. Startup should be quick.
- geofft 9y agoFor ... reasons ... I want to build a Chrome extension that implements USB-IP support as described in the Linux kernel https://www.kernel.org/doc/Documentation/usb/usbip_protocol.txt https://www.kernel.org/doc/Documentation/usb/usbip_protocol.... , with the Chrome USB API on one end and a websocket tunnel on the other, leading to websockify running on an EC2 instance. (Or, apparently, WebUSB is a thing these days and I don't need an extension?) I could do protocol parsing in JS, but Rust seems like a much more well-suited language for this. The frontend itself, as in the UI, I'll write in JS, but there are parts that need to be running client-side that aren't really "frontend". Someone I know built a thing which (for more complicated reasons) ends up speaking HTTPS tunneled over a websocket connection, with a need to terminate TLS within the local JavaScript context. There are a few pure-JS TLS libraries, but it'd be nicer to use an actual TLS library. Someone else I know literally built a Kerberos client in JS. Again, having the UI in JS seems good but the protocol bits probably shouldn't be in JS. (Also, it is possible that I keep weird company.) As a maybe more sympathetic example, consider noVNC or Guacamole, which are JavaScript clients for VNC. It would be a lot simpler to just hand an existing VNC implementation a <canvas> and let it do what it's been doing on desktop for years (drawing to a region of memory) than to reimplement VNC in JS.
- dualogy 9y ago> being forced to have only one choice (Javascript) When it comes to JS, you already have a gazillion prettier and more enthralling languages to choose from that transpile neatly to JS. Are {{TypeScript/Flow/ReasonML/PureScript/Elm/CoffeeScript/Haxe/Haste/GHCJS/Fay/Fable/WebSharper/Scala.js/GorillaScript/Roy/Idris/etc}} really not enough choice? While wasm is still busy being hatched and birthed, JS has already long become "the web's choice compilation target". That's not to say that projects compiling to wasm aren't worthwhile of course :D but I observed that the precursor "asm.js" paradigm didn't get widely adopted even though browsers already do optimize-for/precompile it. Unless the whole "EcmaScript + Browser APIs" (dom/xhr/string/array/etcpp) are readily-available from within wasm by default without bridging (ie "the modern web client runtime" exposed fully within wasm -- in a prim-op/pointer fashion I guess), I remain mildly skeptical that it'll take off as "a full JS replacement" rather than remain a pluggable niche component for specialized high-perf computations and such..
- justinpombrio 9y ago> that transpile neatly to JS As a PL researcher, I can assure you that there is nothing "neat" about transpiling to JS. JS is an awful compilation target.
- dualogy 9y agoHow so? Interested in your elaboration. I would have surmised it'd be very smooth and fun to target, given all the freedoms it gives you (free-form records, dynamically-sized arrays, no types). All the things that are "foot guns" when hand-writing it, should make codegen-ing it a lot easier. Because when a code-gen "shoots yourself in the foot", one can just fix the transpiler once instead of one's individual JS code-base(s) time-and-again
- TazeTSchnitzel 9y agoFor one thing, JS has no unstructured control-flow. So your compilation process involves breaking down ifs, loops and so on into branches, then… trying to messily reconstruct them.
- colde 9y agoHave you looked at Dart? https://webdev.dartlang.org/ https://webdev.dartlang.org/
- kibwen 9y agoIf anyone here has an experience report from attempting to use Rust with WebAssembly, the Rust team is currently seeking active feedback from users! https://internals.rust-lang.org/t/state-of-webassembly-and-rust/6077 https://internals.rust-lang.org/t/state-of-webassembly-and-r... In particular: 1. If you’re using wasm/asmjs and Rust today, how’s it going? Do things generally work well? Are there weird pain points? Is crates.io missing support for key functionality? Is key functionality missing from rustc? 2. If you looked at using wasm/asmjs and Rust historically, but decided not to do so, why not? What are the blockers for enabling your use case with wasm/asmjs and Rust? 3. In general do you have an idea for a use case with wasm/asmjs and Rust on the web? We’re wondering if there’s some sweet uses of wasm/asmjs which really showcase how Rust can shine on the web. (I'm not the author of that thread, please leave feedback there to keep it all collected in one place.)
- paulgdp 9y agoHi, I've been using Rust to WebAssembly very recently for a toy project [0] and posted about it very recently on HN [1]. So my answers: 1. I'm using both wasm and asm.js (installed using rustup) and it works for me extremely well, no weird bugs, very easy to set up. However I'm really missing a way to pass arguments to the linker, like "-s BINARYEN_METHOD='asmjs,native-wasm'" or "-s EMCC_DEBUG=1" or "-s DETERMINISTIC=1" or "-s SIMD=1" or "SIDE_MODULE=1" I think there is already a bug opened for this but I'm not able to find it on Google right now. From crate.io, I'm missing a N-dimensional array library (BLAS/LAPACK like) that compile to webassembly. There is ndarray[3], but its available BLAS dependencies are using fortran and therefore not compilable to wasm. Maybe thoses projects could help: emlapack[4], weblas[5] Also, I know it would be difficult to implement and would need some kind of better interaction with emscripten, but anything that makes it easier to pass and convert/cast object/arguments to and from javascript would be welcome. Right now, it requires a lot of boilerplate and unsafe code, mostly with structs [6]. 2. I'm using it and considers using it more, I love it, thank a lot to everyone working on it! 3. Right now I'm deep into deep learning and I'm thinking about writting an implementation in Rust (that's why it would be nice to have a BLAS/LAPACK library). It could then be used on the Tensorflow playground[6] to showcase the technology. [0] https://buddhabrot.paulg.fr https://buddhabrot.paulg.fr [1] https://news.ycombinator.com/item?id=15491781 https://news.ycombinator.com/item?id=15491781 [3] https://crates.io/crates/ndarray https://crates.io/crates/ndarray [4] https://github.com/likr/emlapack https://github.com/likr/emlapack [5] https://www.npmjs.com/package/weblas https://www.npmjs.com/package/weblas [6] https://github.com/PaulGrandperrin/rustybrot-web/blob/master/src/main.rs https://github.com/PaulGrandperrin/rustybrot-web/blob/master... [7] http://playground.tensorflow.org http://playground.tensorflow.org
- empath75 9y agoSeems like wasm would be a better platform for crypto mining in the browser than js is.
- ManagementBug 9y agoWhy would anyone mine in browser?
- mkl 9y agoI don't think any user would want to, but some unscrupulous websites and ads already do.
- mrdoops 9y agoI don't think mining is the best application of utilizing client side connections. But surely we can find profitable ways to distribute computation. I'd be willing to divert the resources of a small sandboxed vm of sorts to websites if it meant less/no ads. It'd be fascinating to see what people could come up with if there were a publicly distributed Lambda/Serverless sort of capability.
- stepik777 9y agoSomeone should write a WebGL miner already
- minxomat 9y agoWebgl has no benefits for mining. Coin hive already uses Wasm, but was falsy classified by every media outlet as "Javascript".
- xuejie 9y agoI'm surprised that no one has asked this yet even tho I noticed mentions of stdweb: any idea how this is different from cargo-web(https://github.com/koute/cargo-web https://github.com/koute/cargo-web)?
- qbaqbaqba 9y agoWhat does this mean to JavaScript? Google is pushing Dart, Mozilla Rust, Facebook have their own Reason. Is there any major player supporting JavaScript?
- steveklabnik 9y agowasm and JavaScript are complimentary, not at odds. Google and Mozilla are also investing heavily in the future of JavaScript as well as their work on wasm.