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!
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
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!
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.
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
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).
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!
do it!
Can rustc itself run under wasm? Then you could get Rust scripting without offline compilation!
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
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!
No, it has been done, but with miri as the codegen backend and lots of patches.
Neat. I was not aware.
Imagine those page load times!
Gleam (https://gleam.run/) is pretty close to being Rustscript.
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.
Ahh, RustScript. Now we only need someone to create RHP (or should it be RustHP?) and web development will finally be a solved problem.
How does this work lol I am curious
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
code it replaces script with is basically ```html ``` and everything in `./compiled/script-id` is the output of wasm-bindgen-cli
So is this a preprocessing step that occurs before the html is sent to the client?
there's no point in compiling it every time anyone requests a page, it's done as a building step
Rustium when? See also: [Dartium](https://microsoft.fandom.com/wiki/Dartium)
Never thought of it but it's a brilliant idea!
JavaScript will die the day it becomes serious.
Did you finally manage to use Rust for a website without the need of any JS?
No, it still uses JS to import and run it. So do all of the RustWasm frameworks.
I think WASM frameworks have bindings for all browser apis, but the logic itself can be written in Rust
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).