I was interested in checking out the ability to build web based front ends using the cargo-web crate, but the project appears to be in an abandoned state.
For example:
cargo web install
Fails to build on linux.
Does anyone have any news about any currently active projects using rust in this way?
I'd appreciate any advice or information on this.
It's worth noting that the Packt book "Creative Projects for Rust Programmers" which I purchased has an entire Chapter dedicated to using the this technology. Written way way back in the year 2020, so perhaps the world has simply moved on!
I'm not a user of cargo-web, but it seems to me it isn't really required for developing a front-end. Since the title suggests you are interested in WebAssembly, I can tell you my own experience with wasm.
Rust WebAssembly support seems great in that the built-in cross-compiler targets Just Work™, and most crates in the ecosystem support it. For running in the browser, the wasm32-unknown-unknown target needs to be used (which is more barebones, without support for e.g. filesystem I/O), so you should definitely check that before using a crate.
One potential problem with wasm support is depending on C libraries. From what I can tell, this simply doesn't work currently (due to some fairly obscure problems with ABI compatibility), or rather, it works through the emscripten target, which appears to be deprecated.
Other than that, wasm-pack is all you need to have your WebAssembly packaged up into a convenient, directly importable pair of {.wasm,.js} files and off you go.
Ps.: one thing I found out quickly is that passing complex structures between wasm and Rust doesn't always work with wasm-bindgen (you'll get compile errors if you want anything more complicated than a Vec<f64> or similar). Again, this is an ABI problem that is being worked on, but in the meantime, if you run into this kind of situation, don't panic – serialize to JSON!
Assuming you're talking about tagetting regular DOM stuff (gamedev/WebGL/webgpu would be a different approach...)
A large example of essentially full-stack Rust is under development here.. I plan to do a larger write-up about the tech stack when the project is ready for release: GitHub - ji-devs/ji-cloud (it's a bit disingenuous to say "full stack" since we bail out to lit-element for encapsulating CSS.. but that's a larger discussion that would take this on a tangent)
Btw this was my first Rust project, and I'd say it's the absolute worst way to learn Rust, hehe... doing it in the browser forces a lot of tough things early on that could be avoided by starting with cli tools or whatever (async everywhere, trying to pass data across FFI boundary, mis-match between application state and UI state, etc.)
(also just noticed the demo build is failing in CI, and the view source links are outdated... I run the demo locally whenever I make tweaks to the crate, and there's more than what's visible in the live link)
cargo generate is not a built-in command. They even write at the top of that page that you have to follow the setup instructions, which include installing cargo-generate.
% wasm-pack build
[INFO]: Checking for the Wasm target...
[INFO]: Compiling to Wasm...
warning: function is never used: `set_panic_hook`
--> src/utils.rs:1:8
|
1 | pub fn set_panic_hook() {
| ^^^^^^^^^^^^^^
|
= note: `#[warn(dead_code)]` on by default
warning: `wasm-game-of-life` (lib) generated 1 warning
Finished release [optimized] target(s) in 0.01s
[INFO]: Installing wasm-bindgen...
Error: no prebuilt wasm-opt binaries are available for this platform: Unrecognized target!
To disable `wasm-opt`, add `wasm-opt = false` to your package metadata in your `Cargo.toml`.
Anyway, maybe I wasn't doing everything right. I might retry when I have some more time to thoroughly test it.
P.S.: Does someone happen to know if Rust + WASM work on FreeBSD?
Thank you very the detailed reply. I am fairly new to rust, and love the language. I've been around the block a couple of times with Angular, and frankly not happy with the overall nature of that experience. It's cool stuff, but the idea of 100% rust code, is extremely appealing to me.
As I stated in my initial post, I'm largely going on what appears to be the quite outdated chapter in the "Creative Projects for Rust Programmers". It was quite reliable for the chahpter on serde and the Nom parser combinator crate, but the Web assembly is clearly out of date, or leaves much to be desired in either case.
For example, it simply says to run "cargo install cargo-web" in order to load the rust ability to generate Web assembly code. Are you saying that this step is not even required?
The chapter goes on to have you use the Yew framework to build the application example.
I see that Yew has more recent updates, so perhaps my best step would be to follow the advise they have there for getting started in Yew.
Okay. So I'm confused by what I read in that "Creative Projects for Rust Programmers", PackT book.
They say that you need to do cargo install cargo-web in order to pull down what's necessary for rust to generate Web assembly code.
Your comment suggests there are multiple choices, and you have found the best in your experience. Is that the one with a current and healthy community committed (for now at least) to pushing it forward?