# 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+
从原生源码到每个运行环境。
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。在演练场中运行 →