-
Notifications
You must be signed in to change notification settings - Fork 161
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
Add wasm-bindgen feature #554
base: main
Are you sure you want to change the base?
Conversation
The code looks simple enough but I'm not very familiar with bindgen so I have a few questions
Is there any benefit to enabling this for other architectures?
Does this mean none of the
This doesn't appear to be consistent, I see that it's true for matrices but it looked like sse2 implementations of Quat, Vec3A and Vec4 still have bindgen enabled. Why did it need to be excluded on matrices?
It has been asked for before so it seems reasonable to consider it. I don't really have a good grasp on how it works though, how is this used in your project? In addition to gaining some understanding of a new feature to accept a PR, I also need to be able to test it, so I'll know if I managed to break it through other changes. Is there a way this can be tested? |
Almost certainly no. But while
Correct. But... shims can be enabled when the feature is active that expose those functions to JS, just as I did with
That's entirely possible, I just fused off things until the compiler was happy.
My project allows you to paint N and P type silicon on an infinite substrate. The core of it is written in Rust and compiled to WASM. It uses WebGL (soon to be WebGPU) to do rendering. I'm building a website around it now, and need to generate binding in-depth to minipulate things. For example, my camera type leans heavily on
I don't think testing makes any logical sense beyond 'does it compile' 🤷 Anything worth testing would be a bug in If you're happy with the direction of this PR I'll finish off the SSE stuff, clean things up and fix the lint errors? |
Also totally unrelated, thank you for Glam! You rock. I used a lot of nalgebra back in the Amethyst days, and when Bevy chose Glam I never looked back. Nalgebra might the the right pick for mathematicians, but the generics were pure hell. Glam is a joy to work with, it's my go-to on so many projects. |
I think having it on a feature makes sense, but perhaps it would be better to constrain it to wasm32 as well for now if that is sufficient for your needs? E.g.
OK, so you effectively need to expose the types to JS but don't actually use them from there? That makes sense then.
In that case perhaps compiling with the feature enabled in wasm32 would probably be sufficient to know it's not broken? Perhaps adding a step to build with this enabled to You project looks pretty interesting btw, I'll definitely try it out once the website is ready! |
For the lint failure, in this case it's fine to add a |
Close. I do actually use the types from JS. The editor controls are implemented in TypeScript, because I want to allow for people making new tools as plugins. Even if those are written in a WASM language, until WASI ships you still need a JS bridge to get from WASM to WASM module.
Yep! Let me poke around your tests a bit today, and see what I can come up with. Wasm bindgen can generate TypeScript types, so an 'example usage' TS file could be checked with |
Chiming in here because I recently added support for wasmtime's WIT components in glamour. I'm not sure I see the benefit to exposing host glam functions to a WASM guest. The overhead of calling back and forth makes it a not-great solution. But what does make sense is to support passing values, so that glam can potentially be used by both the host and the guest with zero overhead (modulo potentially some alignment adjustment). This is trivial to support because glam already supports (The WIT component support in glamour does not actually leverage this, but just hooks into wasmtime's |
I was going to argue that it lent some ergonomics to the calling JS code (I don't need to find a JS lib to do common ops, even if the performance is terrible) but I don't actually have a single use case for doing so. Every glam Also: sorry for the lack of progress. I had my first kiddo, and free-time... well it doesn't really exist right now lol. |
Ah congrats! |
See issue #292 and discussion #277
This adds a
wasm-bindgen
feature that decorates structs for wasm/JS bindings, and adds a wasm-only constructor.There are a couple points worth discussing/considering before merging this:
target_arch = "wasm32"
because not everyone compiling for WASM needs to access the types from JSconst fn
cannot be bound inwasm_bindgen
, so I crated a separatenew
(calledwasm_bindgen_ctor
) function just for the wasm constructornew
non-const, as other const factory functions use it transitivelywasm-bindgen
feature is active, it won't pollute auto-complete et. al#[wasm_bindgen(skip)]
decoratorswasm_bindgen
I need this for my project, but I can use my own fork if this PR doesn't fit well with your direction. No worries.