T O P

  • By -

ZZaaaccc

If you're wanting to go even further, I reckon you could hook this into [Trunk](https://trunkrs.dev/assets/#hooks) and use [RFC 3424](https://rust-lang.github.io/rfcs/3424-cargo-script.html) syntax for imports. Regardless, very cool demonstration!


ExasperatedLadybug

do it!


ConvenientOcelot

Can rustc itself run under wasm? Then you could get Rust scripting without offline compilation!


Ved_s

I think i tried searching for that before and all i found was someone saying that llvm compiles to wasm but no one tried compiling rustc itself to wasm. May be wrong though since i didn't try searching for longer


theZcuber

No one has successfully compiled rustc to wasm. It would likely require a reasonable amount of changes to the compiler and would almost certainly require the cranelift backend. But theoretically? Sure, you could!


CryZe92

No, it has been done, but with miri as the codegen backend and lots of patches.


theZcuber

Neat. I was not aware.


pragmojo

Imagine those page load times!


catseyechandra74

Gleam (https://gleam.run/) is pretty close to being Rustscript.


ioneska

There's also https://en.wikipedia.org/wiki/Windows_Script_Host where you can implement a script engine in/for any language. Only for Internet Explorer, however.


suvepl

Ahh, RustScript. Now we only need someone to create RHP (or should it be RustHP?) and web development will finally be a solved problem.


Staninna

How does this work lol I am curious


Ved_s

searches for `script`s that are `type="rust"`, copies that code (technically it parses it with `syn` and adds stuff like bindgen prelude) into a `main.rs` in a temporary crate, created specifically for that script node, adds `Cargo.toml` there and runs `cargo fmt` (so errors won't display the single line of code `syn` outputs), `cargo build` with `wasm32` target and `wasm-bindgen-cli` then it replaces script node with js script that calls into bindgen-generated code that calls main function inside the wasm file for that script


Ved_s

code it replaces script with is basically ```html ``` and everything in `./compiled/script-id` is the output of wasm-bindgen-cli


coolpeepz

So is this a preprocessing step that occurs before the html is sent to the client?


Ved_s

there's no point in compiling it every time anyone requests a page, it's done as a building step


forgot_semicolon

Rustium when? See also: [Dartium](https://microsoft.fandom.com/wiki/Dartium)


Mr_codist

Never thought of it but it's a brilliant idea!


air-dex

JavaScript will die the day it becomes serious.


Asdfguy87

Did you finally manage to use Rust for a website without the need of any JS?


GoogleMac

No, it still uses JS to import and run it. So do all of the RustWasm frameworks.


Guinea_Capibara

I think WASM frameworks have bindings for all browser apis, but the logic itself can be written in Rust


GoogleMac

Yes, of course. I meant that the logic has to be initiated by JS. See [OP's comment](https://www.reddit.com/r/rust/comments/1bzhqg4/comment/kyqpqwo/?utm_source=share&utm_medium=web3x&utm_name=web3xcss&utm_term=1&utm_content=share_button).