trunk-rs / trunk

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

trunk fails to find rust code when `build.target = "src/index.html"` #857

Open aslilac opened 2 weeks ago

aslilac commented 2 weeks ago

I would like my index.html to live in the src/ directory, because I consider it to be part of my source code. Trunk unfortunately doesn't seem to handle this well.

[build]
target = "src/index.html"

...results in Trunk saying...

WARN no rust project found

...even though the Cargo.toml and src/main.rs files are unmoved.

I poked around the trunk repo a bit to see if I could figure out a fix, but got lost pretty quickly. :(

mnemotic commented 2 weeks ago

See https://github.com/trunk-rs/trunk/issues/849#issuecomment-2283197282.

In your index.html you need to tell Trunk where to look for Cargo.toml.

aslilac commented 1 week ago

huh, interesting. I would've really expected this to be configurable from Trunk.toml. it feels really unintuitive to configure something like this inside the index.html, imho. kinda like a Box<Box<ThingIWantToConfigure>>.

ctron commented 1 week ago

I agree, it could be more intuitive. On the other side, trunk considers the index.html and or Trunk.toml the authoritative source of information. Cargo is "only" a sub-task.

If you have any ideas how to improve that, that would be great.

aslilac commented 1 week ago

as a fix for this specific issue, I think it'd be nice if Trunk checked for Cargo.toml..

..which would fix my case and other similar ones without any additional configuration

ctron commented 6 days ago

Sounds reasonable. Could you come up with a PR?

aslilac commented 6 days ago

if you could point me at what files I should look in I might be able to work on it tonight :)

ctron commented 3 days ago

Sorry for the late response. This could/should/might be a good introduction: https://github.com/trunk-rs/trunk/blob/14b972f7369cf4e9d1b098e3afb4bc0e0ecd54d9/src/config/mod.rs#L1-L60

Here is the code for loading the configuration: https://github.com/trunk-rs/trunk/blob/14b972f7369cf4e9d1b098e3afb4bc0e0ecd54d9/src/config/models/mod.rs#L119-L148