Alef

June 27, 2026 · View on GitHub

Xberg

Alef

Crates.io docs.rs CI License Rust 1.85+ 18 targets
א
Rust in. Native bindings out.
GitHub Discord

Alef is the polyglot binding generator behind the Xberg.dev ecosystem. It extracts a Rust API surface and emits language-native bindings, package scaffolding, type stubs, README files, API docs, e2e tests, and release metadata from one alef.toml.

Installation | Quick Start | Supported Targets | CLI Reference

Key Features

  • One source of truth - Configure a Rust workspace once and generate every enabled language target from it.
  • Language-native bindings - Emit host-language types, docs, errors, async wrappers, callbacks, and package files.
  • Multi-crate workspaces - Drive multiple independently published binding packages from a shared workspace config.
  • End-to-end fixtures - Generate cross-language test suites and registry-mode test apps from shared JSON fixtures.
  • Release-aware packaging - Sync versions, generate registry metadata, build artifacts, and validate publication state.
  • Configurable pipelines - Run setup, update, format, lint, test, clean, build, and publish commands per language.
  • Pluggable extension surface - Author domain-specific codegen logic via the Extension trait; ship as linked binaries, dynamic libraries, or template-only declarations.
  • Staleness checks - Cache inputs, embed generation hashes, and verify whether generated files are up to date.

Installation

Alef requires Rust 1.85 or newer.

cargo install alef --locked

If you use cargo-binstall, Alef also publishes binary-install metadata:

cargo binstall alef

Quick Start

Create or edit alef.toml in your Rust workspace:

[workspace]
languages = ["python", "node", "ffi", "go"]
alef_version = "0.24.12"

[[crates]]
name = "sample_core"
sources = ["src/lib.rs"]
version_from = "Cargo.toml"

Then generate the language packages:

alef generate --format
alef scaffold
alef readme
alef docs --output docs/reference
alef verify --exit-code

For a new project, Alef can create the initial config and first generated files:

alef init --lang python,node,ffi

For the full local generation pass, use:

alef all --format

Use --lang python,node to restrict commands to selected targets and --crate <name> to restrict commands to one configured crate.

Supported Targets

TargetBackend / package style
PythonPyO3 bindings with Python type stubs
TypeScript / Node.jsNAPI-RS native addon with .d.ts output
WebAssemblywasm-bindgen package for browser and JS runtimes
RubyMagnus native extension
PHPNative PHP extension
ElixirRustler NIF package
Rextendr package
Gocgo package over the generated C FFI layer
JavaJVM package over the generated native library
KotlinKotlin/JVM package over generated native bindings
Kotlin AndroidAndroid package with generated JNI shims
C#.NET package using P/Invoke
Dart / Flutterflutter_rust_bridge package
SwiftSwift package with Rust bridge support
ZigZig package over the generated C ABI
GleamGleam package backed by Rustler
C FFIC ABI, header, and shared-library glue
JNIRust JNI shim crate exercised by both kotlin_android (Android AAR) and host-JVM tests

Canonical language slugs are python, node, wasm, ruby, php, elixir, r, go, java, csharp, kotlin, kotlin_android, swift, dart, gleam, zig, ffi, and jni.

Configuration Model

Alef uses the current multi-crate schema:

  • [workspace] stores shared target languages, tool preferences, and pipeline defaults.
  • [[crates]] describes each Rust API surface that should become one or more published packages.
  • [crates.<language>] sections customize module names, package names, feature flags, output paths, field naming, dependency extras, and language-specific generation behavior.
  • [[crates.adapters]], trait bridge config, service API config, and e2e config opt into higher-level generated wrappers when a target supports them.

Generated binding files carry Alef hashes and are overwritten by generation commands. Scaffolded package files are generated once unless the command explicitly opts into overwrite behavior; generated README and API doc files are owned by alef readme and alef docs.

Extending Alef

Alef is opinionated about codegen and neutral about domain. The Extension trait lets you ship domain-specific generation logic (HTTP service APIs, plugin registries, custom bindings) without bloat in alef.

Linked Extension

Consumer crate implements alef::Extension, ships a thin CLI binary:

fn main() {
    alef::run_with_extensions(vec![Box::new(MyDomainExtension)])
}

Full type safety. Recommended for frameworks that generate an HTTP service API.

Dynamic Extension

Load a compiled .so/.dylib/.dll declaring a C-ABI factory function. Works when you can't ship a Rust binary.

extern "C" fn alef_extension_factory() -> Box<dyn alef::Extension> {
    Box::new(MyExtension)
}

Template-only Extension

Declare [[extensions.template]] blocks in alef.toml pointing to Jinja templates. Alef's built-in TemplateExtension emits them — no Rust required.

The full extension walkthrough covers trait references and per-language emission patterns.

CLI Reference

CommandPurpose
alef initCreate alef.toml, generate initial bindings, and scaffold package files.
alef extractExtract Rust source into Alef IR JSON.
alef generateGenerate bindings, service API wrappers, public API wrappers, and type stubs.
alef stubsGenerate type stubs only.
alef scaffoldGenerate package manifests, native build files, and package scaffolding.
alef readmeGenerate per-language README files.
alef docsGenerate Markdown API reference pages.
alef setupInstall per-language development dependencies.
alef fmt / alef lintRun configured formatters, linters, and type checks.
alef testRun configured unit, integration, e2e, or coverage test commands.
alef buildBuild language bindings using native tools.
alef verifyCheck generated files and optional compile/lint state for CI.
alef diffShow what generation would change without writing files.
alef e2eInitialize, scaffold, validate, list, or generate local e2e suites.
alef test-appsGenerate and run standalone registry-mode test applications.
alef publishPrepare, build, package, and validate release artifacts.
alef allRun the full generation workflow in one command.

Run alef --help or alef <command> --help for the full option set.

Development

This repository uses task for common workflows:

task setup
task build
task test
task lint

The most useful targeted commands while working on Alef itself are:

cargo test <module_or_test_name>
cargo insta review
prek run --all-files

Part of Xberg.dev

  • Xberg — document intelligence: text, tables, metadata from 91+ formats with optional OCR.
  • Xberg Enterprise — managed extraction API with SDKs, dashboards, and observability.
  • crawlberg — web crawling and scraping with HTML→Markdown and headless-Chrome fallback.
  • html-to-markdown — fast, lossless HTML→Markdown engine.
  • liter-llm — universal LLM API client with native bindings for 14 languages and 143 providers.
  • tree-sitter-language-pack — tree-sitter grammars and code-intelligence primitives.
  • alef — the polyglot binding generator that produces every per-language binding across the 5 polyglot repos.
  • Discord — community, roadmap, and release discussion.

License

MIT - see LICENSE for details.