-
I was wondering if you would be happy to share a little about your overall process / recipe / any references you relied on while writing these bindings. I feel very fortunate to have stumbled upon this library - recently I've been attempting to create Go bindings for the Box2D library, and haven't quite known where to begin when it came to creating bindings via WASM. Any input would be greatly appreciated! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
First you need to compile the C/++ to Wasm. I use SQLite makes this “easy” by providing a single source file, I double down and use the C preprocessor concat my extra files. Box2D might need a build system (Autotools, CMake); can't really help you much there. My setup is “simple enough” that I just use a few bash scripts to download, patch, configure, build and optimize the Wasm. You can look at this for a simpler example. Then there's the actual wrapper. Probably this repo is not the best place to start, I'd start with wazero examples. SQLite mostly has a straight forward API in that it's not struct based: most functions take ints/floats, pointers to C strings (or ints/floats), or opaque pointers (which are just ints). OTOH implementation choices make the API callback heavy (including being reentrant - i.e. Go-calls-C-calls-Go-calls-C…) To make that performant I use a style which you won't need if you just have Go-calls-C (or even Go-calls-C-calls-Go). https://github.com/wasilibs also has other wrapped libraries, which you may find useful. |
Beta Was this translation helpful? Give feedback.
First you need to compile the C/++ to Wasm. I use
wasi-sdk
andbinaryen
.SQLite makes this “easy” by providing a single source file, I double down and use the C preprocessor concat my extra files. Box2D might need a build system (Autotools, CMake); can't really help you much there.
My setup is “simple enough” that I just use a few bash scripts to download, patch, configure, build and optimize the Wasm. You can look at this for a simpler example.
Then there's the actual wrapper. Probably this repo is not the best place to start, I'd start with wazero examples.
SQLite mostly has a straight forward API in that it's not struct based: most functions take ints/floats, pointers to C strings (or …