复制安装命令
用 Codex 或 Claude 安装复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它先审查 Skill 页面再帮你安装。
复制前请先查看来源、License 和安全提示。
Rust in. Native bindings out.
用 Codex 或 Claude 安装复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它先审查 Skill 页面再帮你安装。
复制前请先查看来源、License 和安全提示。
来源文件:README.md
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
Extension trait; ship as linked binaries, dynamic libraries, or template-only declarations.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
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.
| Target | Backend / package style |
|---|---|
| Python | PyO3 bindings with Python type stubs |
| TypeScript / Node.js | NAPI-RS native addon with .d.ts output |
| WebAssembly | wasm-bindgen package for browser and JS runtimes |
| Ruby | Magnus native extension |
| PHP | Native PHP extension |
| Elixir | Rustler NIF package |
| R | extendr package |
| Go | cgo package over the generated C FFI layer |
| Java | JVM package over the generated native library |
| Kotlin | Kotlin/JVM package over generated native bindings |
| Kotlin Android | Android package with generated JNI shims |
| C# | .NET package using P/Invoke |
| Dart / Flutter | flutter_rust_bridge package |
| Swift | Swift package with Rust bridge support |
| Zig | Zig package over the generated C ABI |
| Gleam | Gleam package backed by Rustler |
| C FFI | C ABI, header, and shared-library glue |
| JNI | Rust 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.
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.
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.
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.
Load a compiled .so/.dylib/.dll declaring a C-ABI factory function. Works when you can't ship a Rust binary.
[[extensions.dylib]]
path = "target/release/libmy_extension.dylib"
extern "C" fn alef_extension_factory() -> Box<dyn alef::Extension> {
Box::new(MyExtension)
}
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.
| Command | Purpose |
|---|---|
alef init | Create alef.toml, generate initial bindings, and scaffold package files. |
alef extract | Extract Rust source into Alef IR JSON. |
alef generate | Generate bindings, service API wrappers, public API wrappers, and type stubs. |
alef stubs | Generate type stubs only. |
alef scaffold | Generate package manifests, native build files, and package scaffolding. |
alef readme | Generate per-language README files. |
alef docs | Generate Markdown API reference pages. |
alef setup | Install per-language development dependencies. |
alef fmt / alef lint | Run configured formatters, linters, and type checks. |
alef test | Run configured unit, integration, e2e, or coverage test commands. |
alef build | Build language bindings using native tools. |
alef verify | Check generated files and optional compile/lint state for CI. |
alef diff | Show what generation would change without writing files. |
alef e2e | Initialize, scaffold, validate, list, or generate local e2e suites. |
alef test-apps | Generate and run standalone registry-mode test applications. |
alef publish | Prepare, build, package, and validate release artifacts. |
alef all | Run the full generation workflow in one command. |
Run alef --help or alef <command> --help for the full option set.
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
MIT - see LICENSE for details.
name: alef
description: >-
Use Alef correctly for Rust-to-polyglot binding generation. Trigger when
configuring alef.toml, generating bindings, READMEs, API/CLI/MCP docs,
llms.txt, agent skills, e2e suites, or debugging stale/missing generated
output in Alef-powered repositories. Covers the safe command sequence,
config ownership, generated-output rules, snippet validation, downstream
smoke testing, and Alef development workflow.
license: MIT
metadata:
author: xberg-io
version: "1.0"
repository: https://github.com/xberg-io/alefAlef extracts a Rust public API surface and generates language-native bindings,
package scaffolding, type stubs, READMEs, docs, e2e tests, and release metadata
from alef.toml.
Use this skill when working in Alef itself or in a downstream repo that uses Alef.
alef.toml as the source of truth.alef.toml before proposing config or generation changes.CHANGELOG.md.From a repo that uses Alef:
alef generate --format
alef scaffold
alef readme
alef docs
alef verify --exit-code
Use the combined command when a full refresh is expected:
alef all --format
Use filters to keep iteration small:
alef generate --lang python,node
alef docs --output docs/reference
alef test --lang python
alef verify --exit-code
When testing an unreleased local Alef from a sibling repo, run the binary through Cargo instead of using the installed version:
cargo run -q --manifest-path ../alef/Cargo.toml -- docs
cargo run -q --manifest-path ../alef/Cargo.toml -- all --format
Current Alef configs use:
[workspace] for shared languages, tools, DTO defaults, docs defaults, and
pipeline defaults.[[crates]] for each generated package/API surface.[crates.<language>] or [workspace.<language>] for target-specific output,
package names, feature flags, excludes, and stubs.source_crates when a facade crate re-exports API from multiple Rust crates.features when cfg-gated public fields/types must be considered present.Use include for small curated APIs. Use exclude for large APIs where most
public items should bind except known internal, generic, trait, or unsupported
items.
Alef can generate docs in this order:
llms.txt.Important rules:
llms.txt and skills are template-owned. Missing templates are hard errors.llms.txt or skills.adopt_existing = true.Common docs config shape:
[workspace.docs]
reference_output = "docs/reference"
[workspace.docs.cli]
sources = ["crates/my-cli/src/main.rs"]
[workspace.docs.mcp]
sources = ["crates/my-lib/src/mcp/server.rs"]
[workspace.docs.llms]
template = "templates/docs/llms.txt.jinja"
output = "docs/llms.txt"
adopt_existing = true
[workspace.docs.skills]
template_dir = "templates/docs/skills"
outputs = [".codex/skills", ".agents/skills", ".claude/skills", ".github/skills"]
adopt_existing = true
[workspace.docs.snippets]
dirs = ["docs/snippets"]
docs_dirs = ["docs"]
required_languages = ["python", "rust"]
validation_level = "syntax"
Skill templates default to grouped api, cli, and mcp skills:
templates/docs/skills/
├── api/SKILL.md.jinja
├── cli/SKILL.md.jinja
└── mcp/SKILL.md.jinja
Use snippets as maintained examples, not generated filler. Configure validation instead of silently trusting examples:
dirs: snippet roots.docs_dirs: docs/template roots to scan for includes.required_languages: language variants every grouped snippet should have.validation_level: syntax, typecheck, compile, or run.include_base_paths: paths matching MkDocs snippet include roots.Unreferenced snippets should normally warn, not fail. Missing references, missing required language variants, unknown languages, and skip annotations without reasons should fail.
Missing type or function:
alef extract -o /tmp/api.json
jq '.types | keys' /tmp/api.json
Then check:
sources or source_crates?ffi) or explicit type mapping?Stale output:
alef verify --exit-code
alef diff
alef generate --clean --format
Cache issues:
rm -rf .alef
alef generate --clean --format
Docs generation issues:
adopt_existing = true.-v/RUST_LOG when a warning is expected but not visible.In the Alef repo, prefer focused checks while iterating:
cargo fmt
cargo check -q
cargo test -q docs:: -- --nocapture
cargo test -q <module_or_test_name>
Before committing behavior changes, run the highest-signal relevant tests. For docs/template work, also smoke test downstream repos with the local binary:
cargo run -q --manifest-path ../alef/Cargo.toml -- docs
git diff --check
Use the sibling repos that exercise Alef broadly:
../crawlberg../html-to-markdown../liter-llm../tree-sitter-language-packDo not include ../xberg unless explicitly asked.
CHANGELOG.md under [Unreleased] for user-visible changes.
评论 (0)
暂无评论,成为第一个评论者吧!