Use of ffi in emscripten build
Opened this issue · 3 comments
I have native code on an amd64 machine where I am able to use SDL via Chez's excellent FFI. I am exploring options for making the same code working in the browser. I am able to compile Chez for emscripten using instructions provided in the BUILDING document. Separately I am able to compile SDL for the web. Would appreciate any pointers on whether I could load the SDL wasm at runtime in the browser and bind to it or alternatively if in the emscripten build I could include it in the boot image. If this isnt possible, knowing that would be helpful too.
I can imagine that linking SDL into an Emscripten build Chez Scheme could work, but only if the FFI shapes that you need fit into the subset that is supported directly by pb. Those shapes the ones enumerated by define-pb-prototypes
in cmacros.ss
: https://github.com/cisco/ChezScheme/blob/main/s/cmacros.ss#L3388. They're the shapes that Chez Scheme needs for itself to access kernel functionality.
If ithe supported set happens to be close and you just need to add one or two, then I think we could entertain the possibly of adding them. To try that yourself, you'd modify both s/cmacro.ss
and c/pb.c
at the pb_call
case.
Edit: You'd probably also need to create a little more C code to register SDL functions using Sforeign_symbol
, unless dlopen
for Emscripten works better than my guess.
Thanks for the pointers, let me dig a bit and will get back to you.
With the huge caveat the I haven't used it, apparently https://github.com/hoodmane/libffi-emscripten is an Emscripten port of libffi that works well enough to support Python.