System libraries
Platform guards
Keep OS-specific bindings safe in cross-platform projects.
System libraries only exist on their platform. Guard examples and tests before opening an OS-specific module.
if (process.platform !== 'darwin') {
console.log('This example uses Security.framework and only runs on macOS.')
process.exit(0)
}| Platform | process.platform |
|---|---|
| macOS | 'darwin' |
| Linux | 'linux' |
| Windows | 'win32' |
For tests, use a skip guard:
const run = process.platform === 'linux' ? test : test.skipRuntime requirements
- Bun and Deno ship native FFI.
- Node uses
node:ffiwhere available, otherwisekoffi. - Deno scripts that load libraries need
--allow-ffi; examples that read overrides also need--allow-env. - None of these bindings run in the browser.
Library path overrides
Every shipped module accepts a direct override and an environment override:
await using libc = await openLibc('/lib/x86_64-linux-gnu/libc.so.6')UNFFI_LIBC_PATH=/lib/x86_64-linux-gnu/libc.so.6 bun app.tsmacOS system libraries may live in the dyld shared cache. UnFFI accepts canonical framework paths such as /System/Library/Frameworks/CoreFoundation.framework/CoreFoundation even when they are not visible as ordinary files.