Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wasm bindings #241

Open
arcanis opened this issue Nov 13, 2022 · 7 comments · May be fixed by #394
Open

Wasm bindings #241

arcanis opened this issue Nov 13, 2022 · 7 comments · May be fixed by #394
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@arcanis
Copy link

arcanis commented Nov 13, 2022

What problem does this solve or what need does it fill?

It seems that the wasm bindings don't exist anymore, so it's difficult to use this library from JS-land. I made a JS terminal library many years ago using Yoga and I'd like to rebuild it, evaluating new tech options.

What solution would you like?

Ideally a basic wasm API would be great. If not possible, it'd be useful to at least annotate FlexboxLayout & its enums with the wasm-bindgen attributes (cf second part of this answer here: https://stackoverflow.com/a/65336309), as there's a lot of them and duplicating them would be very painful.

What alternative(s) have you considered?

Keep using Yoga, but I'm interested to follow a bit the development here.

@arcanis arcanis added the enhancement New feature or request label Nov 13, 2022
@nicoburns
Copy link
Collaborator

I've been looking into this, and it looks like wasm support might not be too difficult:

  • The predecessor to this library stretch had wasm bindings (source here and docs here)
  • The setup seems to be a vanilla wasm-pack setup
  • The meat of the bindings aren't all that long (650 lines with quite a bit of boilerplate). And it looks like some of the boilerplate could be cut down on by adding #[wasm_bindgen] directly to taffy types (behind a feature flag) rather than duplicating them (if we are willing to bring in another dependency then num-derive and/or serde-wasm-bindgen could further cut down on boilerplate)

@alice-i-cecile
Copy link
Collaborator

Awesome! I'd be happy to review that.

@theetherGit
Copy link

I've been looking into this, and it looks like wasm support might not be too difficult:

  • The predecessor to this library stretch had wasm bindings (source here and docs here)
  • The setup seems to be a vanilla wasm-pack setup
  • The meat of the bindings aren't all that long (650 lines with quite a bit of boilerplate). And it looks like some of the boilerplate could be cut down on by adding #[wasm_bindgen] directly to taffy types (behind a feature flag) rather than duplicating them (if we are willing to bring in another dependency then num-derive and/or serde-wasm-bindgen could further cut down on boilerplate)

I found napi-rs used by resvg-js and it's pretty good binding with node too.

@nicoburns
Copy link
Collaborator

I found napi-rs used by resvg-js and it's pretty good binding with node too.

napi-rs does indeed look like a good option for node bindings (which yoga also has), however I don't think that would give us wasm support. So I would consider that a separate feature request.

@xavierzwirtz
Copy link

xavierzwirtz commented Dec 15, 2022

For what its worth, I have ported the C bindings from stretch to taffy. Pretty minor API changes overall, which makes me think porting the old WASM bindings would be very straightforward.

@nicoburns
Copy link
Collaborator

@xavierzwirtz Yeah, when I looked into this recently, it looked like C and WASM would be both be quite straightforward. But stretch's Swift and especially it's Kotlin bindings looked quite a bit more involved. Perhaps we ought to create a new meta issue for language bindings. It would be good to determine which languages have the most interest, and perhaps come up with a strategy that can allow us to re-add the bindings while keeping the maintenance burden manageable.

I suspect focussing on C and WASM first might be a good strategy. WASM effectively gives us Node support too (albeit with a performance penalty), and I suspect a good C API would make it easier for other people to write their own bindings for other languages, which generally support C FFI.

@nicoburns nicoburns added the good first issue Good for newcomers label Dec 30, 2022
@nicoburns
Copy link
Collaborator

Some WASM bindings for Taffy based on the Stretch bindings are now available here https://github.com/load1n9/gelatin

@nicoburns nicoburns linked a pull request Mar 12, 2023 that will close this issue
8 tasks
@nicoburns nicoburns mentioned this issue Mar 22, 2023
38 tasks
@nicoburns nicoburns removed this from the 0.4 "Make taffy easier to embed" milestone Apr 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
Status: In Progress
Development

Successfully merging a pull request may close this issue.

5 participants