rust-diplomat / diplomat

Experimental Rust tool for generating FFI definitions allowing many other languages to call Rust code
https://rust-diplomat.github.io/book/
Other
512 stars 48 forks source link

WASM Automatic Demo Generator Proof of Concept #500

Closed ambiguousname closed 2 months ago

ambiguousname commented 3 months ago

Rough implementation of the process described in https://docs.google.com/document/d/1xRTmK0YtOfuAe7ClN6kqDaHyv5HpdIRIYQW6Zc_KKFU/edit?usp=sharing

Proof of concept is live at https://ambiguous.name/diplomat/

sffc commented 3 months ago

Notes from 2024-06-20

Design doc: https://docs.google.com/document/d/1xRTmK0YtOfuAe7ClN6kqDaHyv5HpdIRIYQW6Zc_KKFU/edit#heading=h.b6hfjuxzqkmm

ambiguousname commented 3 months ago

Big issue right now is that build-test and gen throw errors. Pretty sure this is related to my modifications to attrs.rs in the core module. I have some ideas for fixing gen, but build-test requires testing against snapshots that I'm not entirely sure how to work with. Any help would be appreciated!

ambiguousname commented 3 months ago

Ah, I've found the insta crate, so I will run tests and verify that the snapshots look okay, then add them as a change to review. Still doesn't solve the gen errors, unfortunately.

ambiguousname commented 2 months ago

Mixed syntax for arguments, terminusArgs, and ...args. Cleaning up would be helpful, so using the argument names would be better than terminusArgs[3], say.

ambiguousname commented 2 months ago

Move rendering.mjs into templates, call it diplomatDefaultRendering.mjs (maybe with the base .html and index.js file too, if index.html is not detected?) and copy it over every time it's run.

ambiguousname commented 2 months ago

Some self notes:

ambiguousname commented 2 months ago

Currently going through the pain of setting up a proof of concept demo in the ICU4X repo.

Based on how many things I'm having to move around to make this work, I think I'm in favor of Manish's idea to make the demo-gen part a flag on the JS2 backend. This would remove capabilities like #[diplomat::attr(demo_gen, disable]), but I think that's small potatoes compared to making sure this works out of the box after running it once.

Edit: especially because renames (and disables!) that apply to JS2, do NOT apply to demo-gen.

sffc commented 2 months ago

but "opt out if it can't be constructed" is also fine i guess.

We're close to the WASM generator working out of the box with no annotations or configurations, and I'd like to keep it that way. I think the heuristic of "opt in if we know how to make a demo for this function signature" is good.

Manishearth commented 2 months ago

We're close to the WASM generator working out of the box with no annotations or configurations, and I'd like to keep it that way. I think the heuristic of "opt in if we know how to make a demo for this function signature" is good.

I believe the current heuristic is opt-out, not opt-in. Which is fine, but will potentially cause friction if the backend also produces errors when it's unable to do something, and might make it harder for ICU4X devs to add new FFI. I'm fine with that shift, but it's an angle of complexity we should definitely consider: not every terminus is going to be renderable.

ambiguousname commented 2 months ago

(Potentially) Non-blocking Issues List:

Manishearth commented 2 months ago

Fine to do all fixes in a followup.