evo-lua / evo-luvi

[Obsolete] Experimental Lua runtime environment built on Luvi (libuv + LuaJIT)
https://evo-lua.github.io
Apache License 2.0
1 stars 0 forks source link

Add a FFI-CDEF generator for the llhttp API #130

Closed Duckwhale closed 1 year ago

Duckwhale commented 1 year ago

Goals:

A quick prototype suggests the following approach may be viable:

  1. Resolve enum macros in llhttp.h via https://github.com/facebookresearch/CParser
  2. Read in the output file that lcpp produces
  3. Ignore all existing preprocessor macros (lines starting with "#")
  4. Load the rest as C definitions for llhttp (via ffi.cdef())
  5. Additionally, add the static exports table from Bindings/llhttp_ffi.h

This should work since the llhttp headers don't use any other fancy stuff that lcpp couldn't handle.

I'm a bit worried since the entire thing relies on an experimental tool that may or may not continue to function in the future, but if nothing major changes it might still be worth the risk. Having the definitions auto-generated would save a lot of maintenance work, and avoid difficult-to-debug SEGFAULT errors in FFI code.

Duckwhale commented 1 year ago

Since automatic updates as part of the build process seem a bit tricky (with bootstrapping and luajit-only APIs), I'll leave it as a manual step for now. It's probably not worth spending time on automating as it only takes a few seconds to copy/paste the generated headers into the cdef field. The update frequency would have to be fairly high for that investment to pay off.