npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

rustport

v1.3.6

Published

A CLI tool that automatically generates TypeScript FFI bindings for Rust libraries, making it easy to call Rust functions from JavaScript/TypeScript in Bun projects

Downloads

12

Readme

🚀 RustPort

RustPort is an NPM package as well as a command-line tool that automates the creation of TypeScript Foreign Function Interface (FFI) bindings for Rust libraries created by Tahcin Ul Karim (Mycin). This means you can call blazing-fast Rust functions from your JavaScript or TypeScript projects effortlessly.

Perfect for Bun-powered apps, RustPort takes care of all the annoying binding work, so you don’t have to.


🧐 Why RustPort?

Because manually writing FFI bindings is like writing assembly—painful and unnecessary. RustPort offers:

Zero-Hassle Rust FFI Binding Generation – Just run a command, and boom, your Rust functions are ready in TypeScript.

Flawless Integration with Bun – If you’re using Bun, RustPort is your new best friend.

Effortless Type Mapping – Converts Rust types into TypeScript like magic.

Super Simple CLI – Generate and clean bindings in seconds with one command.


📦 Installation

RustPort can be installed globally via your favorite package manager:

# Using npm
npm install -g rustport

# Using yarn
yarn global add rustport

# Using bun
bun add -g rustport

🚀 Getting Started

Step 1: Set Up Your Project

Inside your project, create a lib/ directory where RustPort will generate its magic:

mkdir -p lib/rs

Step 2: Write Some Rust Code

Create a Rust file, say hello.rs, inside lib/rs/:

#[no_mangle]
pub extern "C" fn say_hello() {
    println!("Hello, Rustacean! 🦀");
}

Yes, that’s all you need. No weird macros, no painful setup.

Step 3: Generate the Bindings

Now, let RustPort do its thing:

rustport generate lib/

This will:

✅ Compile your Rust functions into dynamic libraries (.so / .dll / .dylib).
✅ Generate TypeScript FFI bindings.
✅ Create an index.ts file inside lib/.

Step 4: Use Rust Functions in TypeScript

Now, call Rust functions as if they were just another JavaScript function:

import { sayHello } from "./lib";

sayHello(); // Prints: Hello, Rustacean! 🦀

Step-5. Run it!

Note that for now it only supports Bun, but we’re working on supporting Deno and Node.js. For this, you'll need Bun installed on your machine. Install Bun using npm, yarn, or bun:

npm install -g bun

Now run the file.

bun run fileName.ts

That’s it! You just called Rust from TypeScript without touching a single binding manually. 🎉


🔥 CLI Commands

rustport generate <path>

Generates Rust FFI bindings and compiles Rust files to dynamic libraries.

rustport generate lib/

rustport clean

Wipes out all generated files and libraries, leaving no trace of your sins. 😈

rustport clean

rustport help

Displays the help menu.

rustport help

⚡ Advanced Usage

🏗️ Customizing Bindings

Want to rename functions or create wrappers? Just tweak the generated index.ts:

import { sayHello as rustSayHello } from "./lib";

export function sayHello() {
    rustSayHello();
}

🧮 Passing & Returning Numbers

Rust loves numbers. So do we. Let's make them talk:

Rust (math.rs):

#[no_mangle]
pub extern "C" fn add_numbers(a: i32, b: i32) -> i32 {
    a + b
}

Generate bindings:

rustport generate lib/

TypeScript:

import { addNumbers } from "./lib";

console.log("5 + 3 =", addNumbers(5, 3));

📝 Passing & Returning Strings

Rust can return strings too, but remember: memory management is a thing!

Rust (string_utils.rs):

use std::ffi::{CString, CStr};
use std::os::raw::c_char;

#[no_mangle]
pub extern "C" fn greet(name: *const c_char) -> *mut c_char {
    let c_str = unsafe { CStr::from_ptr(name) };
    let r_str = format!("Hello, {}!", c_str.to_str().unwrap());
    CString::new(r_str).unwrap().into_raw()
}

Generate bindings:

rustport generate lib/

TypeScript:

import { greet } from "./lib";

console.log(greet("Alice")); // Prints: Hello, Alice!

Yes, Rust just greeted Alice from TypeScript. Wild, huh? 😲


🛠️ Troubleshooting

1. RustPort fails to generate bindings

  • Make sure Rust and Cargo are installed.
  • Check if lib/rs/ contains valid Rust files.
  • Run cargo build inside lib/rs/ to debug compilation issues.

2. TypeScript FFI calls fail

  • Ensure that Rust functions are exported with #[no_mangle].
  • Verify the correct function signatures in TypeScript.

3. Dynamic libraries not loading?

  • On Windows, ensure .dll files are in the correct directory.
  • On macOS, use install_name_tool to set the correct paths.
  • On Linux, check LD_LIBRARY_PATH.

🏗️ Example Project

Here’s what a simple RustPort-powered Bun project might look like:

my-project/
├── lib/
│   ├── rs/
│   │   ├── hello.rs
│   │   ├── math.rs
│   │   ├── string_utils.rs
│   │   ├── Cargo.toml
├── src/
│   ├── main.ts
├── package.json

main.ts

import { sayHello, addNumbers, greet } from "../lib";

sayHello();
console.log(addNumbers(10, 20));
console.log(greet("Bob"));

💖 Contributing

If you love RustPort and want to make it even better, open an issue or send a PR on GitHub! If this tool saved you time, consider buying us a virtual coffee. ☕


📜 License

RustPort is licensed under MIT. See the LICENSE file for details.

Now go forth and build fast, Rust-powered Bun projects! 🚀

Note: Also check out ZigPort for a similar tool that generates TypeScript FFI bindings for Zig libraries.