module

bun:ffi

The 'bun:ffi' module enables high-performance calls to native libraries from JavaScript. It works with languages that support the C ABI (Zig, Rust, C/C++, C#, Nim, Kotlin, etc).

Bun generates and just-in-time compiles C bindings that efficiently convert values between JavaScript types and native types, using embedded TinyCC (a small and fast C compiler). According to benchmarks, bun:ffi is roughly 2-6x faster than Node.js FFI via Node-API.

⚠️ Experimental — bun:ffi has known bugs and limitations, and should not be relied on in production. The most stable way to interact with native code from Bun is to write a Node-API module.

Functions 8

  • cc()

    **Experimental:** Compile ISO C11 source code using TinyCC, and make symbols available as functions to JavaScript.

  • CFunction()

    Turn a native library's function pointer into a JavaScript function

  • dlopen()

    Open a library using "bun:ffi"

  • linkSymbols()

    Link a map of symbols to JavaScript functions

  • ptr()

    Get the pointer backing a TypedArray or ArrayBuffer

  • toArrayBuffer()

    Read a pointer as an ArrayBuffer

  • toBuffer()

    Read a pointer as a Buffer

  • viewSource()

    View the generated C code for FFI bindings

Classes 2

Interfaces 5

Types 5

Variables 2

Enums 1

Namespaces 1