This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
# Build library
cargo build
cargo build --release
# Build eq CLI
cargo build --bin eq --features cli --release
# Test
cargo test
cargo test test_detect_v # Run a single test by name
# Lint / Format — always run cargo fmt before committing
cargo fmt # Auto-fix formatting
cargo fmt -- --check # Check formatting (CI gate)
cargo clippy -- -D warnings # Lint (warnings as errors)
# Docs
cargo doc --all-features --no-deps
# Run example
cargo run --example using_equilibrium
# Polyglot demo (TUI works everywhere; GUI needs GPU)
cd examples/polyglot-gui
cargo build --bin polyglot-tui
cargo build --bin polyglot-guiEquilibrium is a Rust library that auto-generates C FFI bindings for foreign-language source files. It implements a three-stage pipeline:
-
Language Detection (
src/detector.rs) — Maps file extensions to one of 10 supported languages (V, Zig, C, C++, C#, Rust, D, Nim, Odin, Hare).find_compiler()useswhichto locate installed compiler binaries. EachLanguagevariant knows its extensions, primary/fallback compiler commands, and the CLI flags needed to emit C-compatible output. -
Compilation to C (
src/compiler.rs) — Invokes the detected compiler with the appropriate flags to produce a.cor preprocessed intermediate file plus an optional.hheader.compile_to_c()auto-detects the language;compile_batch()handles multiple files;generate_header()produces headers for languages with cbindgen/native support (Rust, V). -
Binding Generation (
src/bindings.rs) — Parses a C header (functions, typedefs, structs) and emits Rustextern "C"declarations.BindingOptionscontrols the module name, include paths, symbol allowlists, and#[derive]attributes.c_type_to_rust()handles the type mapping (e.g.int→c_int,char*→*mut c_char).
src/lib.rs re-exports the public surface: detect_language, compile_to_c, generate_bindings, find_compiler.
The eq binary (feature-gated behind cli) provides four subcommands:
eq check— detects all supported compilers and shows versions/pathseq install [names…]— installs missing compilers via the best available package manager; multiple compilers install in parallel. Install order: wax → brew/linuxbrew → apt/dnf/pacman on Linux/macOS, wax → winget → scoop on Windows.eq build [args…]— runscargo buildwith all known compiler bin dirs prepended to PATH (linuxbrew, homebrew,/usr/local/sbin, etc.)eq generate <header> [-o file]— emits Rustextern "C"bindings from a C header viaequilibrium_ffi::generate_bindings
Language-specific ergonomic crates live in sibling directories:
equilibrium-rust/— proc macro#[ffi]attributeequilibrium-nim/— Nim type conversion helpersequilibrium-d/— D@ffiUDA andextern(C)helpersequilibrium-zig/— Zig comptime FFI helpers
examples/using_equilibrium.rs— demonstrates all three pipeline stages (detect, compile, generate bindings, scan_directory)equilibrium::load()is the primary one-call entry point; prefer it in docs and demos when the goal is to load a single C source and use generated bindingsexamples/demo-app/— minimal end-to-end demo:build.rscompilesmath.cviaccand generates bindings with equilibrium-ffi;main.rscalls C functions through the generatedinclude!()d bindingsexamples/full-demo/— full demo calling a C calculator library from Rustexamples/polyglot-gui/— interactive polyglot dashboard with a ratatui TUI (polyglot-tui) and a GPUI GUI (polyglot-gui). Calls live FFI into C, C++, Zig, Nim, V, D, Odin, and Rust.build.rsusesfind_bin()with hardcoded linuxbrew fallbacks so compilers are found regardless of the shell PATH that cargo inherits.
Zig objects must be compiled with -fPIC -OReleaseFast to link cleanly into Rust's PIE binary. ReleaseFast removes safety checks that otherwise pull in Zig's stdlib panic infrastructure, which conflicts with the linker. See examples/polyglot-gui/build.rs.
V's runtime cannot link directly into Rust's PIE binary. The polyglot-gui uses a C shim (v_module_shim.c) that implements the same exported symbols with identical semantics.
The polyglot-gui binary targets D3D11 (no Vulkan needed). Build from Windows PowerShell:
cargo build --release --bin polyglot-guiThe TUI binary works cross-platform. The eq CLI on Windows uses %TEMP% as the working directory when invoking winget/scoop to avoid UNC path errors from WSL2 filesystem paths.