crossbind
GitHub

Quick start

Two paths lead to the same place: scaffold a fresh project, or add crossbind to an app you already have. Either way you end up with a bundler plugin, a crossbind.config.js, and a header you can import from JavaScript.

Rather try it first?
The tutorial runs in your browser with nothing to install: nine short steps from a first function to Rust and packages.

Prerequisites

The web, WASI and Android toolchains ship as Docker images, so crossbind needs very little installed on your machine:

  • Docker - runs the web image for WebAssembly and WASI and the android image for Android. Both are pulled automatically on the first build. Without Docker, Remote builds run the images on another machine.
  • Node.js 24+.
  • CMake 3.28+ - mobile only.
  • Xcode and CocoaPods - iOS only, macOS only.
  • A Rust toolchain (cargo plus the platform targets) - only to bind Rust for iOS or macOS, or with RUNNER=LOCAL; other builds run cargo in the image. See Rust.
  • wasmtime - only to run platform: 'wasi' output and the prebuilt -standalone-wasi tools.
shell
docker --version
node --version
docker pull ghcr.io/crossbind/web:1.0.20 # optional: the first build pulls it anyway
iOS
Xcode looks for Node.js in the system environment. If it is not there, link it once: ln -s $(which node) /usr/local/bin/node.

Set it up with a coding agent

Using Claude Code, Codex, Cursor, Copilot or similar? Paste this line into it: the agent installs the crossbind skill, adds crossbind to the project and checks one call from JavaScript, following these instructions.

prompt
Fetch and follow the instructions at https://crossbind.dev/agent/prompt.md to add crossbind to this project.

Prefer to do it yourself? Keep going.

A new project

The scaffolder wires the bundler, its plugin and a starter crossbind.config.js for you. Answer the prompts - if you are unsure, pick Web, React and Vite. For a desktop or mobile app of your own, pick Desktop and App, then follow Apps.

shell
npm create crossbind@beta
shell
? Project name › my-app
? Where should we create your project? › ./my-app
? What kind of project? › Web
? Choose framework / variant › React
? Choose bundler / ecosystem › Vite

Every prompt can be preselected positionally, which is how CI and scripted setups create a project:

shell
npm create crossbind@beta my-app Web React Vite

Then install and start the dev server - and skip to your first call.

shell
cd my-app
npm install
npm run dev

An existing project

Already have an app? Install the plugin for your bundler and register it. Vite is shown here; Webpack, Rspack and Rollup follow the same shape on the Bundler plugins page, Metro on React Native.

shell
npm install -D @crossbind/plugin-vite@beta
Versions on this page
Every install command here follows the npm beta tag. When this page was built it resolved to [email protected] (changelog), @crossbind/[email protected] (which requires crossbind ^2.0.0-beta.69) and [email protected]. Each package keeps its own version; for a setup you can reproduce later, pin those exact ones:
shell
npm create crossbind@2.0.0-beta.71 my-app Web React Vite
npm install -D @crossbind/plugin-vite@2.0.0-beta.69 crossbind@2.0.0-beta.69
vite.config.js
import { defineConfig } from 'vite';
import viteCrossbindPlugin from '@crossbind/plugin-vite';
 
export default defineConfig({
plugins: [viteCrossbindPlugin()],
});

The plugin reads a crossbind.config.js from your project root. The minimal one is two lines - paths.config anchors every other path to this file, so it is never optional:

crossbind.config.js
export default {
paths: {
config: import.meta.url,
},
};

Everything else this file can carry is in Configuration.

Your first call

C++ lives under src/native. Declare the class in a header - the public surface has to be in the header, because that is what the binder reads.

src/native/MySampleClass.h
#pragma once
#include <string>
 
class MySampleClass {
public:
static std::string sample() {
return "Hello World!";
}
};

Now import that header from your app code and call it. initNative() is exported by the header module itself; one call boots every native module you imported. In a browser the module runs in a Web Worker by default, so each call returns a promise.

src/main.js
import { initNative, MySampleClass } from './native/MySampleClass.h';
 
await initNative();
console.log(await MySampleClass.sample());
First build
The first npm run dev compiles the wasm inside Docker and can take a while. After that the cache makes rebuilds incremental, and editing the header hot-reloads the page.

Build for production

Nothing special: your bundler build triggers the release compile through the plugin.

shell
npm run build

Building for another platform? Each one has its own page: Node.js, Edge, Electron, Apps, React Native and Executables.

Where to next

  • C++ - what the auto-binder accepts, and the C++ ↔ JS type table.
  • crossbind ports - use a prebuilt library instead of compiling one.
  • Files - where files live in the browser, Node and on edge.
  • Troubleshooting - when the first build does not go to plan.
Type to search every guide page and section.
↑↓ navigate↵ openesc close