trunk-rs / trunk

Build, bundle & ship your Rust WASM application to the web.
https://trunkrs.dev/
Apache License 2.0
3.5k stars 251 forks source link

Support custom build command / other wasm targets #830

Open wooden-worm opened 3 months ago

wooden-worm commented 3 months ago

Problem

Trunk is currently hard coded to build for wasm32-unknown-unknown, making it hard to work with other wasm targets (wasm64, wasi targets)

Solution

A simple way to unblock other wasm targets is to provide an option to disable the default wasm32 build. I think a default_build = true entry in Trunk.toml would suffice. If the option is explicitly set to false, we just don't add the default wasm32 build here https://github.com/trunk-rs/trunk/blob/d61478448bd093449708b63dcb3e7baf286a191c/src/pipelines/html.rs#L150

See this discussion for more context.

If this is the right approach I can work on a PR.

ctron commented 3 months ago

I think all Rust based options would go here: https://github.com/trunk-rs/trunk/blob/d61478448bd093449708b63dcb3e7baf286a191c/src/pipelines/rust/mod.rs

Extracted by https://github.com/trunk-rs/trunk/blob/d61478448bd093449708b63dcb3e7baf286a191c/src/pipelines/rust/mod.rs#L123 from the link element for rust.

I think having the ability to request the default would be good. But it might also be good to have the ability to just specify that target. Maybe that can be combined with a magic value (like target=*) to fall back to the default (vs trunk's default of wasm32).

wooden-worm commented 3 months ago

Having a target config option sounds good to me. I think we can just have the default value of wasm32-unknown-unknown, which works as it does now. Adding support for others could come later. Until then, having a none option would also unblock other targets?

ctron commented 3 months ago

Might be tricky to have a default value and None at the same time. That's why I had the idea of * (or some other magic string).