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

Selecting library entrypoint over binary entrypoint #864

Open 9SMTM6 opened 2 weeks ago

9SMTM6 commented 2 weeks ago

I might be missing something, but it appears to me that we're unable to select the library entrypoint if there are any binary entrypoints.

I've tried to rename my binary entrypoint and use data-target-name to select the library, but to no avail. The moment there is a binary entrypoint, whether implicitly via an existing main.rs, or explicitly with a different name declared in Cargo.toml, it seems trunk wants to compile that entrypoint.

9SMTM6 commented 2 weeks ago

I have an issue with that since I want to use embassy-executor - yes, I'll likely have both that async executor and wasm_thread in my webpage in the end :sweat: - , which comes with the #[embassy_executor::main] macro, and I can't make that work on a binary entrypoint on wasm. I might be able to work around that, but frankly I'd prefer not to do it that way.

If I didnt overlook something, I could try and make a PR for that. I'm uncertain about the API you would prefer. I think an explicit data-lib attribute to select the library would make for the easiest discovery and best errors, but alternatively I could also try and fix the selection of the compilation target. However then, from my understanding, people will always have to have specifically named binary entrypoint when they also want to target native as well, because AFAIK both the library and default binary entrypoint take their name from package.name

9SMTM6 commented 2 weeks ago

My need for this is gone after all. Still happy to help, if you want this.