A proof-of-concept demonstrating how to build a sqlite3 Ruby binding using FFX, which transpiles Ruby FFI definitions into a C extension with embedded ZJIT type hints.
ext/sqliteffx/
extconf.rb # links -lsqlite3, then hands off to FFX
ffx.rb # copy of FFX (transpiler)
ffi.rb # empty stub so `require "ffi"` records definitions
sqliteffx.rb # FFI definitions (sqlite3_open, exec, close, ...)
lib/sqliteffx.rb # higher-level Database wrapper
test/ # minitest coverage
bundle install
bundle exec rake
require "sqliteffx"
puts Sqliteffx.sqlite3_libversion
Sqliteffx::Database.open(":memory:") do |db|
db.exec("CREATE TABLE t (x INTEGER)")
db.exec("INSERT INTO t VALUES (1), (2), (3)")
end- FFX's
:pointertype is a rawunsigned long longaddress, so Ruby code allocates out-pointer storage viamalloc(also attached through FFX) and reads the stored pointer withFiddle. extconf.rbcallshave_library("sqlite3")beforeFFX.create_makefilesohave_funccan find sqlite3 symbols on the link line.- Callback-taking functions (e.g. the full
sqlite3_execrow callback) are passed0here; FFX doesn't yet model function-pointer params.