trunk icon indicating copy to clipboard operation
trunk copied to clipboard

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

Open aslilac opened this issue 1 year ago • 7 comments
trafficstars

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. :(

aslilac avatar Aug 24 '24 06:08 aslilac

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.

mnemotic avatar Aug 24 '24 10:08 mnemotic

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>>.

aslilac avatar Sep 03 '24 17:09 aslilac

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.

ctron avatar Sep 04 '24 06:09 ctron

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

  • Next to the index.html file (like it already does; this would take precedence to avoid any breakage)
  • Next to the Trunk.toml file

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

aslilac avatar Sep 04 '24 16:09 aslilac

Sounds reasonable. Could you come up with a PR?

ctron avatar Sep 06 '24 12:09 ctron

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

aslilac avatar Sep 06 '24 16:09 aslilac

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

ctron avatar Sep 10 '24 07:09 ctron