Stream: cargo-component

Topic: Integration of `cargo-component` and `cargo-leptos`


view this post on Zulip raskyld (Sep 21 2024 at 19:52):

Hello everyone, I am trying to contribute to Leptos to make it capable of compiling the server side down to a WebAssembly Component.

I had sparkles :sparkles: of happiness when I saw the commit promoting wasm32-wasip2 target to Tier 2 landing in 1.81, and then learned about the hard truth :tear:

So If I want to do that, for now, I need to target wasm32-wasip1 (so the toolchain comes with wasm-ld, IIUC) and then do the "componentisation".

My question may be a really stupid one since I am not familiar with cargo plugin systems, but can two cargo plugin integrates?

Basically, cargo leptos allows users to have a single codebase but compile two artifacts (one for the client side, one for the server), it seems to do so by spawning the cargo binary: https://github.com/leptos-rs/cargo-leptos/blob/main/src/compile/server.rs#L29

I feel like I have two choice:

The second approach seems the simpler but I don't know if it's "Idiomatic", do you have any recommendations? :pray:

This commit promotes the wasm32-wasip2 Rust target to tier 2 as proposed in rust-lang/compiler-team#760. There are two major changes in this PR: The dist-various-2 container, which already produce...
If this message does not go away, try reloading the page.
Build tool for Leptos (Rust). Contribute to leptos-rs/cargo-leptos development by creating an account on GitHub.

view this post on Zulip Yoshua Wuyts (Sep 23 2024 at 11:04):

raskyld said:

I feel like I have two choice:

The second is probably what I would start with. The commands in cargo are fairly stable, and since cargo component largely mirrors the API it probably also stay reasonably stable.

view this post on Zulip Yoshua Wuyts (Sep 23 2024 at 11:08):

If cargo-component is installed and available from your path, then yeah you should just be able to call it from a command.

view this post on Zulip Yoshua Wuyts (Sep 23 2024 at 11:09):

Though I guess: another option could be to use the wasm32-wasip2 target on beta by doing something like this

A sandboxed local task runner for Rust. Contribute to yoshuawuyts/cargo-task-wasm development by creating an account on GitHub.

view this post on Zulip Yoshua Wuyts (Sep 23 2024 at 11:10):

Rust 1.82 should be released in ~3 weeks, so depending on your needs that might potentially be the smoothest transition?

view this post on Zulip Yoshua Wuyts (Sep 23 2024 at 11:12):

Though I don't know whether you just want to compile for WASI 0.2, or whether you also need any other functionality from cargo-component. Using the beta toolchain directly with Cargo probably works best if you don't need any of the other cargo-component functionality.

view this post on Zulip raskyld (Sep 23 2024 at 20:27):

Thanks a lot for the answer!
I went with using cargo-component with the requirements that it should be in the users' PATH for now (it's just a PoC anyway).


Last updated: Nov 25 2024 at 19:03 UTC