[ANN] RepliBuild.jl - A full C/C++ interop toolkit for tiered FFI generation

RepliBuild.jl, a declarative compiler bridge designed to automatically generate hyper-optimized FFI bindings directly from C and C++ source code.
​Instead of relying on fragile header parsing, RepliBuild drives a local compilation pipeline and extracts structural DWARF debug metadata directly from the generated objects. It uses this pure structural data to automatically synthesize a tiered FFI boundary, generating the safest and fastest possible dispatch for every function.
​Tiered FFI Generation
​RepliBuild classifies and routes functions automatically based on their complexity:
​Zero-Cost Abstractions (Base.llvmcall): When cross-language Link-Time Optimization (LTO) is enabled, the compiler emits LLVM Bitcode (.bc). The generated Julia wrapper dynamically loads this bitcode at parse-time, routing execution entirely through Base.llvmcall instead of standard ccall. This allows Julia’s JIT to seamlessly inline C/C++ code directly into Julia hot loops.
​Tier 1 Safe ccall & GC Preservation: For standard FFI boundaries, it emits highly structured ccall bindings. It automatically generates idiomatic mutable struct wrappers equipped with GC-traced finalizers and Base.unsafe_convert methods to guarantee memory safety across the boundary.
​Tier 2 MLIR / AOT Thunks: For complex C++ paradigms (like virtual method dispatch, packed structs, and large struct returns), execution is routed transparently through an MLIR JIT or statically compiled Ahead-Of-Time (AOT) thunks.

Declarative Workflow & Caching
​There is zero manual wrapper boilerplate required. You define the project in a single TOML file:
​replibuild.toml

[dependencies.lua]
type = "git"
url = "https://github.com/lua/lua.git"
tag = "v5.4.6"

[compile]
aot_thunks = true

[link]
enable_lto = true

[wrap]
language = "c"

On the julia side

# Resolves dependencies, builds, wraps, and globally caches the artifacts
RepliBuild.register("replibuild.toml") 

# Instantly loads the cached module and LLVM bitcode
Lua = RepliBuild.use("lua_wrapper") 

RepliBuild features aggressive project-level content hashing. Successive calls to RepliBuild.use() load the cached payload instantly, completely bypassing the compilation tax and dropping Time-To-First-Plot (TTFP) to near zero.
​Current Status
​The architecture is heavily modularized into independent C and C++ generators:
​The C Pipeline is highly stable, defaults to LTO, and automatically falls back to Julia’s internal LLVM (Clang_unified_jll) to guarantee strict llvmcall compatibility.
​The C++ Pipeline natively handles deep layout constraints like bitfields, unions, and template instantiation. (Note: Advanced C++ bridging currently requires a local LLVM 21 toolchain).
​You can find the repository, documentation in the julia registry or the public repo.
​Feedback, edge-case testing, and issue reports are highly welcome! This isnt a half baked toy. I worked on this for a year now with prior experience with the mlir jit. Have fun.

3 Likes

Also started working on the rustc generator will commit the first skeleton of the generator, rust dwarf is alot cleaner and I think RepliBuild.jl and julia will eventually handle rust better overall.

1 Like