Article illustration 1

For JavaScript developers wrestling with native dependencies, the ritual of npm install often means waiting through lengthy compilation processes and wrestling with platform-specific build tools. A new project called ffilibs aims to eliminate this friction by delivering pre-compiled static builds of essential native libraries directly through npm.

The Native Dependency Pain Point

Working with powerful libraries like libgit2 (Git implementation) or libssh2 (SSH protocol) traditionally requires compiling C/C++ code during installation—a process that consumes time, demands build toolchains, and introduces cross-platform compatibility challenges. This friction contradicts JavaScript's reputation for rapid development cycles.

Enter ffilibs: Pre-compiled Power

ffilibs solves this by providing optimized static builds of popular open-source libraries:

Library Version Description Package
libgit2 1.9.1 Git implementation library @ffilibs/libgit2-beta
libssh2 1.9.0 SSH2 library @ffilibs/libssh2-beta
yogalayout.dev 3.2.1 Cross-platform layout engine @ffilibs/yogalayout.dev-beta
tree-sitter.dev 0.22.6 Incremental parsing library @ffilibs/tree-sitter.dev-beta

Key Advantages:

  • Zero-Compile Installs: npm install fetches pre-built binaries
  • 🔧 No External Dependencies: Statically linked for self-contained execution
  • 🌍 Cross-Platform: Supports macOS, Linux (x64/ARM64) and Windows (x64)
  • 🦀 Bun-Optimized: Leverages Bun's efficient FFI (bun:ffi) for near-native performance

Bun FFI: The Perfect Partner

ffilibs shines when combined with Bun's Foreign Function Interface (FFI), which allows direct calls to native code. The integration is remarkably straightforward:

import { dlopen } from 'bun:ffi';
import path from 'path';

const lib = dlopen(
  path.join(import.meta.dir, 'node_modules/@ffilibs/libgit2-beta/prebuilds/linux/arm/lib/libgit2.a'), 
  {
    git_libgit2_init: { args: [], returns: 'int' },
    git_libgit2_shutdown: { args: [], returns: 'int' }
  }
);

// Initialize and use libgit2 directly
lib.symbols.git_libgit2_init();
// ... perform Git operations ...
lib.symbols.git_libgit2_shutdown();

Engineering Rigor

Each library undergoes a standardized build process:
1. Static Linking: Eliminates runtime dependencies
2. Release Optimizations: Compiled with -O3 for peak performance
3. CI Verification: Built on GitHub Actions across all supported platforms
4. Configuration Consistency: Critical features (like SSH) enabled uniformly

"There needs to be a project that provides static builds of common libraries... Bun makes it stupid easy to call into these, it's just the packaging that is annoying"
@thdxr, Project Inspiration

The Ecosystem Impact

By abstracting away compilation complexities, ffilibs enables JavaScript developers to leverage high-performance native libraries without sacrificing the rapid iteration cycles they expect. This approach could significantly accelerate adoption of performance-critical functionality in areas like:
- Version control systems
- Secure communication protocols
- Layout engines
- Parser toolchains

The project actively welcomes contributions through library requests, build optimizations, and documentation improvements, with explicit support for Hacktoberfest participation.

The Roadmap

While currently in beta with four core libraries, ffilibs' vision extends to becoming a comprehensive repository for pre-compiled native assets. Windows ARM64 support remains a key gap, and community involvement will determine how quickly the library catalog expands. As JavaScript runtimes like Bun continue enhancing native interoperability, projects like ffilibs become crucial bridges between high-performance native code and the dynamic web ecosystem.