crossbind
GitHub

智能体时代的应用平台

为 Web、移动端和桌面端构建并发布 JavaScript 应用。

按需加入 C++ 和 Rust。通过扩展连接第三方工具,并上架应用商店。

npm create crossbind@beta
开始使用

基于 MIT 许可证,免费开源。

在演练场中运行
import { initNative, greet } from './native/greet.h';
import { fibonacci } from './native/math.rs';
 
await initNative();
 
console.log(await greet('crossbind'));
console.log(await fibonacci(90));
#pragma once
#include <string>
 
inline std::string greet(std::string name) {
return "Hello, " + name + "!";
}
pub fn fibonacci(n: i32) -> u64 {
let (mut a, mut b) = (0, 1);
for _ in 0..n {
(a, b) = (b, a + b);
}
a
}
# For library projects
npx crossbind build
# For app projects
npx crossbind app upload app-store -p ios
  • 浏览器Chrome, Firefox, Safari
  • 移动端iOS, Android
    crossbind 应用 · React Native
  • 服务器与边缘Node.js, Cloudflare Workers
  • 桌面端macOS, Linux, Windows
    crossbind 应用 · Electron
  • WASIwasmtime 47+

用智能体设置

把这段话粘贴到 Claude Code、Codex、Cursor、Copilot 或任意编程智能体中:

阅读并按照 https://crossbind.dev/agent/prompt.md 上的说明,把 crossbind 添加到这个项目中。

它会安装 crossbind skill,把 crossbind 添加到项目中,并从 JavaScript 验证一次调用。 阅读说明

从原生源码到每个运行环境。

crossbind 从任何地方获取 C++ 和 Rust 代码,为每个目标构建,并把每个平台要加载的产物打包成 npm 包。

在 JavaScript 中使用 SQLite。

对 crossbind 的库目录执行 SQL 查询。SQLite 以 WebAssembly 的形式在你的浏览器中运行。

#pragma once
 
#include <sqlite3.h>
 
#include <stdexcept>
#include <string>
 
class Database {
public:
Database() {
if (sqlite3_open(":memory:", &handle) != SQLITE_OK) throw std::runtime_error("cannot open the database");
}
 
~Database() { sqlite3_close(handle); }
 
std::string version() { return sqlite3_libversion(); }
 
void exec(const std::string& sql) { run(sql); }
 
std::string query(const std::string& sql) {
rows = "[";
run(sql);
rows += "]";
return rows;
}
 
private:
void run(const std::string& sql) {
char* message = nullptr;
if (sqlite3_exec(handle, sql.c_str(), collect, this, &message) == SQLITE_OK) return;
const std::string reason = message ? message : "unknown error";
sqlite3_free(message);
throw std::runtime_error(reason);
}
 
static int collect(void* owner, int count, char** values, char** names) {
Database* self = static_cast<Database*>(owner);
if (self->rows.size() > 1) self->rows += ",";
self->rows += "{";
for (int column = 0; column < count; column += 1) {
if (column) self->rows += ",";
self->rows += quote(names[column]) + ":" + (values[column] ? quote(values[column]) : "null");
}
self->rows += "}";
return 0;
}
 
static std::string quote(const char* text) {
std::string out = "\"";
for (const char* character = text; *character; character += 1) {
if (*character == '"' || *character == '\\') out += '\\';
out += *character;
}
return out + "\"";
}
 
sqlite3* handle = nullptr;
std::string rows;
};
import { initNative, Database } from './native/database.h';
import { catalogAsSql } from './catalog.js';
 
await initNative();
const db = await new Database();
await db.exec(catalogAsSql);
 
const rows = await db.query(`
`);
首次运行会下载 1.5 MB 的 WebAssembly。在演练场中运行 →

直接引入预编译的 C 和 C++ 库。

全部 16 个库 →
输入关键词,搜索指南的所有页面和章节。
↑↓ 选择↵ 打开esc 关闭