RepliBuild Internals
This section documents the internal modules that power RepliBuild. These are generally not needed for standard usage but are valuable for contributors, advanced integration, or understanding the system's behavior. For the high-level architecture see Architecture.
Wrapper
Source: src/Wrapper.jl, src/Wrapper/
The Wrapper package generates Julia FFI modules from DWARF metadata and binary symbol tables. It is structured as a two-track system: a C generator and a C++ generator, selected automatically via config.wrap.language.
Module layout
| Module | Source | Role |
|---|---|---|
Wrapper.Generator | src/Wrapper/Generator.jl | Top-level wrap_library() entry point; dispatches to C or C++ generator |
Wrapper.TypeRegistry | src/Wrapper/TypeRegistry.jl | TypeRegistry and TypeStrictness — shared type-resolution context |
Wrapper.Symbols | src/Wrapper/Symbols.jl | ParamInfo / SymbolInfo structs for structured symbol data |
Wrapper.FunctionPointers | src/Wrapper/FunctionPointers.jl | DWARF function_ptr(...) signature to Julia @cfunction type string |
Wrapper.Utils | src/Wrapper/Utils.jl | Keyword escaping, identifier sanitization shared between generators |
Wrapper.C.GeneratorC | src/Wrapper/C/GeneratorC.jl | Full C wrapper generator (structs, enums, functions, LTO, thunks) |
Wrapper.C.TypesC | src/Wrapper/C/TypesC.jl | C type heuristics and base type map |
Wrapper.Cpp.GeneratorCpp | src/Wrapper/Cpp/GeneratorCpp.jl | Full C++ wrapper generator (same feature set + virtual dispatch) |
Wrapper.Cpp.TypesCpp | src/Wrapper/Cpp/TypesCpp.jl | C++ type map including STL, templates, references |
Wrapper.Cpp.IdentifiersCpp | src/Wrapper/Cpp/IdentifiersCpp.jl | Namespace stripping, operator sanitization |
Language selection
wrap.language is an extensible dispatch key — "c" and "cpp" are the first two targets, with additional language generators planned:
[wrap]
language = "c" # selects C generator + clang toolchain
language = "cpp" # selects C++ generator + clang++ toolchain (default)discover() sets this automatically based on the scanned source files. Adding a new language means adding a generator under src/Wrapper/<Lang>/ and registering it in Wrapper/Generator.jl.
Tier selection logic
The function is_ccall_safe() in src/Wrapper.jl is the core dispatch decision. It inspects each function's DWARF metadata and returns true (Tier 1 / ccall) or false (Tier 2 / MLIR).
Checks performed:
- STL container types — Any STL type in parameters or return forces Tier 2
- Return type safety:
- Template returns (contains
<) → Tier 2 (unpredictable ABI) - Struct return by value > 16 bytes → Tier 2 (too large for
ccallsret) - Non-POD class return → Tier 2
- Packed struct return (DWARF size != Julia aligned size) → Tier 2
- Template returns (contains
- Parameter type safety:
- Union parameters → Tier 2
- Packed struct parameters → Tier 2
Functions routed to Tier 2 are further divided between JIT dispatch (JITManager.invoke()) and AOT thunks (ccall to _thunks.so), controlled by the aot_thunks config flag.
Idiomatic wrapper generation
Beyond raw ccall bindings, the wrapper generator clusters related C++ functions by class name to produce idiomatic Julia types:
- Factory detection: Functions matching
create_X,new_X,make_X,alloc_X,init_X, or returningX*are identified as constructors. - Destructor detection: Functions matching
delete_X,destroy_X,free_X,dealloc_X, orX_destroyare identified as destructors. - Method clustering: Functions taking
X*as their first parameter and associated with the same DWARF class are grouped as instance methods.
The result is a mutable struct ManagedX with a raw Ptr{Cvoid} handle, a registered finalizer calling the C++ destructor, and multiple-dispatch method proxies that pass the pointer via Base.unsafe_convert.
RepliBuild.Wrapper.extract_symbols — Method
extract_symbols(binary_path::String, registry::TypeRegistry; demangle::Bool=true, method::Symbol=:nm)Extract symbols from compiled binary using specified method.
Methods
:nm- Fast, basic symbol extraction:objdump- Detailed with debug info (TODO):all- Try all methods and merge (TODO)
Returns vector of SymbolInfo objects.
RepliBuild.Wrapper.is_enum_like — Method
is_enum_like(cpp_type::String)::BoolCheck if a C++ type looks like an enum based on naming conventions. Returns false — enum detection is unreliable by name alone (uppercase names are more likely structs/classes). Real enum identification uses DWARF metadata via _is_enum_type() in DispatchLogic.jl which checks __enum__ prefixed keys.
RepliBuild.Wrapper.is_function_pointer_like — Method
is_function_pointer_like(cpp_type::String)::BoolCheck if a C++ type contains function pointer syntax. Looks for patterns: (name), ()(args), (^name) (blocks)
RepliBuild.Wrapper.is_struct_like — Method
is_struct_like(cpp_type::String)::BoolCheck if a C++ type looks like a struct/class based on naming conventions. Structs typically: start with uppercase, contain only alphanumeric + underscore.
RepliBuild.Wrapper.wrap_basic — Method
wrap_basic(config::RepliBuildConfig, library_path::String; generate_docs::Bool=true)Generate basic Julia wrapper from binary symbols only (no headers required).
Quality: ~40% - Conservative types, placeholder signatures, requires manual refinement. Use when: Headers not available, quick prototyping, binary-only distribution.
RepliBuild.Wrapper.wrap_library — Method
wrap_library(config::RepliBuildConfig, library_path::String;
headers::Vector{String}=String[],
generate_tests::Bool=false,
generate_docs::Bool=true)Generate Julia wrapper for compiled library.
Always uses introspective (DWARF metadata) wrapping when metadata is available, otherwise falls back to basic symbol-only extraction with conservative types.
Arguments
config: RepliBuildConfig with wrapper settingslibrary_path: Path to compiled library (.so, .dylib, .dll)headers: Optional header files (currently unused, reserved for future)generate_tests: Generate test file (default: false, TODO)generate_docs: Include comprehensive documentation (default: true)
Returns
Path to generated Julia wrapper file
RepliBuild.Wrapper.ParamInfo — Type
ParamInfoInformation about a function parameter.
RepliBuild.Wrapper.SymbolInfo — Type
SymbolInfoComprehensive information about a symbol extracted from binary/headers.
RepliBuild.Wrapper.TypeRegistry — Type
TypeRegistryRepliBuild.Wrapper.TypeStrictness — Type
TypeStrictnessCompiler
Source: src/Compiler.jl
The Compiler module handles the translation of C/C++ source code into LLVM IR and shared libraries. It oversees the entire build pipeline from dependency management down to IR optimization.
Build pipeline
- Auto-discovery and dependency resolution: Scans the project directory, resolving file paths and external git/local dependencies to merge into the build graph.
- Pre-processing (shims and templates): Dynamically generates C/C++ shim files for configured macros and explicitly instantiates templates based on
replibuild.tomlsettings. This allows normally invisible constructs to manifest in the final binary and DWARF metadata. - Compilation to LLVM IR: Translates source code into
.lltext format viaclang/clang++. - IR transformation and sanitization: Strips LLVM 19+ attributes incompatible with Julia's internal LLVM JIT, removes
va_start/va_endintrinsics from varargs function bodies (varargs are routed entirely throughccallwrapper generation), and cleans mismatched debug metadata. - Bitcode assembly: The sanitized IR is converted into
.bcbinary format for zero-cost LTO loading. UsesClang_unified_jllto guarantee LLVM version compatibility with Julia. - Linking: Object files are linked into the target shared library.
Language-aware compilation
.c files are compiled with clang; .cpp files with clang++. For C projects, create_library() and create_executable() also use clang as the linker driver.
Bitcode assembly
Compiler.assemble_bitcode(ll_path, bc_path) converts sanitized LLVM IR text (.ll) to binary bitcode (.bc). It prefers Clang_unified_jll.clang -emit-llvm so the resulting bitcode exactly matches the LLVM version bundled with Julia, maximizing Base.llvmcall compatibility. Falls back to system llvm-as if the JLL is unavailable.
This function is called by both the main LTO pipeline (link_optimize_ir) and the AOT thunks path (_build_aot_thunks).
RepliBuild.Compiler.assemble_bitcode — Method
Assemble LLVM IR text (.ll) to bitcode (.bc). Uses Julia's own libLLVM via the C API (LLVMParseIRInContext + LLVMWriteBitcodeToFile) to guarantee bitcode version compatibility with Base.llvmcall. Falls back to Clangunifiedjll, then system llvm-as.
RepliBuild.Compiler.build_type_registry — Method
Build type registry from functions. Collects all unique types used in the codebase.
RepliBuild.Compiler.compile_project — Method
Complete compilation workflow: discover sources, compile, link, create binary. This is the main entry point for building a project.
RepliBuild.Compiler.compile_single_to_ir — Method
Compile a single C++ file to LLVM IR. Returns (irfilepath, success, exitcode).
RepliBuild.Compiler.compile_to_ir — Method
Compile multiple C++ files to LLVM IR (with parallel support). Returns vector of IR file paths.
RepliBuild.Compiler.compute_project_hash — Method
Compute a content hash for the entire project: replibuild.toml + source files + git HEAD. Returns a hex string that changes when anything relevant changes.
RepliBuild.Compiler.cpp_to_julia_type — Function
Convert C++ type to Julia type. Basic type mapping - can be enhanced with type registry.
Arguments
cpp_type: C++ type stringstruct_names: Set of known struct/class names from DWARFenum_names: Set of known enum names from DWARF
RepliBuild.Compiler.create_executable — Function
Create executable from LLVM IR. Returns path to executable file.
RepliBuild.Compiler.create_library — Function
Create shared library from LLVM IR. Returns path to library file.
RepliBuild.Compiler.dwarf_type_to_julia — Method
Comprehensive C/C++ type to Julia type mapping. Handles all standard C/C++ types including sized integers, pointers, and qualifiers.
RepliBuild.Compiler.extract_class_name — Method
Extract class name from method signature (only considers '::' in the function-name prefix). Example: "Calculator::compute(int, int)" -> "Calculator" Example: "sum_vector(std::vector<int> const&)" -> "" (free function)
RepliBuild.Compiler.extract_compilation_metadata — Method
Extract compilation metadata from source files and binary. This is the core of automatic wrapper generation!
RepliBuild.Compiler.extract_dwarf_return_types — Method
Extract return types and struct definitions from DWARF debug info. Returns: (returntypesdict, structdefsdict)
- returntypes: Dict{mangledname => {ctype, juliatype, size}}
- structdefs: Dict{structname => {members: [{name, type, offset}]}}
RepliBuild.Compiler.extract_function_name — Method
Extract function name from demangled signature. Example: "Calculator::compute(int, int, char)" -> "compute" Example: "sumvector(std::vector<int, std::allocator<int> > const&)" -> "sumvector"
RepliBuild.Compiler.extract_mangled_name — Method
Extract mangled symbol name from nm output.
RepliBuild.Compiler.extract_stl_method_symbols — Method
Extract STL method symbols from the compiled binary. Uses nm to find mangled names of template-instantiated STL methods. Returns Dict mapping normalized container type -> vector of method info dicts.
RepliBuild.Compiler.extract_symbols_from_binary — Method
Extract symbol information from compiled binary using nm. Returns vector of symbol dictionaries with mangled/demangled names.
RepliBuild.Compiler.generate_macro_shims — Method
Generate a C/C++ shim file to instantiate requested macros as typed functions so they appear in the DWARF metadata and can be wrapped.
RepliBuild.Compiler.generate_template_instantiations — Method
Generate a dummy C++ file to explicitly instantiate requested templates so they appear in the DWARF metadata.
RepliBuild.Compiler.get_type_size — Method
Get type size in bytes from C/C++ type name.
RepliBuild.Compiler.infer_return_type — Method
Infer return type from demangled function signature using pattern matching. This is a fallback when DWARF debug info is unavailable for a given function.
RepliBuild.Compiler.is_project_cache_valid — Method
Check if the project-level cache is valid. Returns true if all artifacts exist and the content hash matches, meaning the build can be skipped entirely.
RepliBuild.Compiler.link_optimize_ir — Method
Link multiple LLVM IR files and optimize. Returns linked IR path (String) or original IR files (Vector{String}) on llvm-link failure.
RepliBuild.Compiler.needs_recompile — Method
Check if source file needs recompilation (based on mtime).
RepliBuild.Compiler.parse_function_signatures — Function
Parse function signatures from symbol information. Infers parameter types and return types from demangled names.
RepliBuild.Compiler.parse_parameters — Function
Parse parameter types from demangled signature. Example: "add(int, int)" -> [{"type": "int", "julia_type": "Cint"}, ...]
RepliBuild.Compiler.sanitize_ir_for_julia — Method
sanitize_ir_for_julia(ir_text::String) -> StringSanitize LLVM IR text for compatibility with Julia's internal LLVM (18). Strips LLVM 19–22 attributes/instructions, debug metadata, and converts varargs function bodies to extern declarations (vastart/vaend can't be JIT-compiled). Uses inlinehint (not alwaysinline) to avoid recursive inliner explosion on large modules.
Coverage by LLVM version: 19: GEP nuw, #dbg* records, inrange(), captures(), deadonunwind, initializes(), allocptr, icmp samesign, range(), trunc nuw/nsw, zext/uitofp nneg 20: GEP nusw, or disjoint, fptrunc/fpext fast-math flags, ptrtoaddr→ptrtoint 21: (covered by 19 patterns — captures/deadon_unwind/allocptr landed here) 22: ptrtoaddr instruction
This is the single source of truth for IR compatibility — used by both the C source LTO pipeline and the MLIR AOT thunks pipeline.
RepliBuild.Compiler.save_compilation_metadata — Method
Save compilation metadata to JSON file next to binary. This enables automatic wrapper generation!
RepliBuild.Compiler.save_project_hash — Method
Save the project hash after a successful build.
Configuration Manager
Source: src/ConfigurationManager.jl
The single source of truth for all build settings. Handles TOML parsing, validation, and merging into a typed RepliBuildConfig struct.
RepliBuild.ConfigurationManager.create_default_config — Function
Create a default configuration and save to file.
RepliBuild.ConfigurationManager.get_build_path — Method
Get full build path (project_root + paths.build)
RepliBuild.ConfigurationManager.get_cache_path — Method
Get full cache path (project_root + cache.directory)
RepliBuild.ConfigurationManager.get_compile_flags — Method
Get compiler flags
RepliBuild.ConfigurationManager.get_include_dirs — Method
Get all include directories (from config)
RepliBuild.ConfigurationManager.get_library_name — Method
Get library output name (uses config or auto-generates)
RepliBuild.ConfigurationManager.get_module_name — Method
Get wrapper module name (uses config or auto-generates)
RepliBuild.ConfigurationManager.get_output_path — Method
Get full output path (project_root + paths.output)
RepliBuild.ConfigurationManager.get_source_files — Method
Get all C++ source files (from config)
RepliBuild.ConfigurationManager.is_cache_enabled — Method
Should use cache?
RepliBuild.ConfigurationManager.is_parallel_enabled — Method
Should run parallel compilation?
RepliBuild.ConfigurationManager.is_stage_enabled — Method
Check if a stage is in the workflow
RepliBuild.ConfigurationManager.load_config — Function
Load RepliBuildConfig from TOML file. This is the ONLY function that parses TOML - all other modules use this.
RepliBuild.ConfigurationManager.merge_compile_flags — Method
Merge compile flags into config (creates new config). Used for runtime overrides like: compile(sources, flags=["-O3"])
RepliBuild.ConfigurationManager.print_config — Method
Print configuration summary
RepliBuild.ConfigurationManager.save_config — Method
Save configuration to TOML file. Only saves user-configurable settings (not runtime data).
RepliBuild.ConfigurationManager.validate_config! — Method
Validate config and throw error if invalid.
RepliBuild.ConfigurationManager.validate_config — Method
Validate configuration and return list of errors (empty if valid).
RepliBuild.ConfigurationManager.with_discovery_results — Method
Update both source files and include dirs (creates new config). Used after discovery completes.
RepliBuild.ConfigurationManager.with_include_dirs — Method
Update include directories in config (creates new config). Used after discovery finds include paths.
RepliBuild.ConfigurationManager.with_source_files — Method
Update source files in config (creates new config). Used after discovery finds C++ sources.
RepliBuild.ConfigurationManager.BinaryConfig — Type
Nested struct for [binary] section
RepliBuild.ConfigurationManager.CacheConfig — Type
Nested struct for [cache] section
RepliBuild.ConfigurationManager.CompileConfig — Type
Nested struct for [compile] section
RepliBuild.ConfigurationManager.DependenciesConfig — Type
Nested struct for [dependencies] section
RepliBuild.ConfigurationManager.DependencyItem — Type
Nested struct for a single dependency
RepliBuild.ConfigurationManager.DiscoveryConfig — Type
Nested struct for [discovery] section
RepliBuild.ConfigurationManager.LLVMConfig — Type
Nested struct for [llvm] section
RepliBuild.ConfigurationManager.LinkConfig — Type
Nested struct for [link] section
RepliBuild.ConfigurationManager.PathsConfig — Type
Nested struct for [paths] section
RepliBuild.ConfigurationManager.ProjectConfig — Type
Nested struct for [project] section
RepliBuild.ConfigurationManager.RepliBuildConfig — Type
Main immutable configuration structure. All modules receive this struct - it's the single source of truth.
RepliBuild.ConfigurationManager.TypesConfig — Type
Nested struct for [types] section - Type validation settings
RepliBuild.ConfigurationManager.WorkflowConfig — Type
Nested struct for [workflow] section
RepliBuild.ConfigurationManager.WrapConfig — Type
Nested struct for [wrap] section
Discovery
Source: src/Discovery.jl
Scans the filesystem to identify C/C++ source files, headers, and dependencies. Auto-detects project language (:c vs :cpp) from the scanned source extensions and sets wrap.language accordingly in the generated replibuild.toml.
RepliBuild.Discovery.discover — Function
discover(target_dir::String=pwd(); force::Bool=false, unsafe::Bool=false, build::Bool=false, wrap::Bool=false) -> StringMain discovery pipeline - scans project and generates configuration.
Process:
- Check for existing replibuild.toml (project identified by presence of replibuild.toml)
- Scan all files and categorize
- Detect and analyze binaries
- Walk AST dependencies using clang
- Generate or update replibuild.toml with discovered data
- Optionally run build and wrap pipeline
Arguments
target_dir: Project directory (default: current directory)force: Force rediscovery even if replibuild.toml existsunsafe: Bypass safety checks (use with extreme caution)build: Automatically run build() after discovery (default: false)wrap: Automatically run wrap() after build (requires build=true, default: false)
Safety Features
- Discovery is scoped ONLY to target_dir and subdirectories
- Will not scan outside the project root
- Skips .git, build, node_modules, .cache directories
Returns
- Path to generated
replibuild.tomlfile
Examples
# Discover only
toml_path = RepliBuild.Discovery.discover()
# Discover and build
toml_path = RepliBuild.Discovery.discover(build=true)
# Full pipeline: discover → build → wrap
toml_path = RepliBuild.Discovery.discover(build=true, wrap=true)
# Then use the TOML path:
RepliBuild.build(toml_path)
RepliBuild.wrap(toml_path)DWARFParser
Source: src/DWARFParser.jl
Parses llvm-dwarfdump output to extract structured type information from compiled binaries. This is the bridge between C++ debug metadata and Julia wrapper generation.
Data structures
| Type | Fields | Role |
|---|---|---|
ClassInfo | name, vtable_ptr_offset, base_classes, virtual_methods, members, size | Complete class/struct description with byte-level layout |
VtableInfo | classes, vtable_addresses, method_addresses | Aggregate metadata for all classes in a binary |
VirtualMethod | name, mangled_name, slot, return_type, parameters | Single virtual method with vtable slot index |
MemberInfo | name, type_name, offset | Struct field with byte offset from struct base |
Extraction targets
| DWARF Tag | Extracted Data |
|---|---|
DW_TAG_class_type / DW_TAG_structure_type | Class/struct name, byte size, members, virtual methods, inheritance |
DW_TAG_member | Field name, type, DW_AT_data_member_location (byte offset) |
DW_TAG_subprogram (with virtual flag) | Virtual method name, mangled name, vtable slot |
DW_TAG_inheritance | Base class references |
DW_TAG_enumeration_type | Enum definitions |
DW_TAG_union_type | Union layout |
DW_TAG_variable | Global variables |
DW_TAG_typedef | Type aliases |
RepliBuild.DWARFParser.export_vtable_json — Method
export_vtable_json(vtinfo::VtableInfo, output_path::String)Export vtable information to JSON for inspection or use by other tools.
RepliBuild.DWARFParser.parse_dwarf_output — Method
parse_dwarf_output(dwarf_text::String) -> Dict{String, ClassInfo}Parse llvm-dwarfdump output to extract class and vtable information.
RepliBuild.DWARFParser.parse_symbol_table — Method
parse_symbol_table(nm_output::String) -> Tuple{Dict{String, UInt64}, Dict{String, UInt64}}Parse nm output to extract vtable and method addresses. Returns (vtableaddresses, methodaddresses).
RepliBuild.DWARFParser.parse_vtables — Method
parse_vtables(binary_path::String) -> VtableInfoExtract complete vtable information from a binary using DWARF and symbol table.
Arguments
binary_path: Path to compiled binary with debug info
Returns
VtableInfocontaining classes, vtable addresses, and method addresses
RepliBuild.DWARFParser.read_vtable_data — Method
read_vtable_data(binary_path::String, vtable_addr::UInt64, num_entries::Int) -> Vector{UInt64}Read actual vtable function pointers from binary at given address.
RepliBuild.DWARFParser.ClassInfo — Type
Information about a C++ class with virtual methods
RepliBuild.DWARFParser.MemberInfo — Type
Information about a data member (field)
RepliBuild.DWARFParser.VirtualMethod — Type
Information about a virtual method
RepliBuild.DWARFParser.VtableInfo — Type
Complete vtable information from binary
JLCSIRGenerator
Source: src/JLCSIRGenerator.jl, src/ir_gen/
Transforms parsed DWARF metadata (VtableInfo) into MLIR source text in the JLCS dialect. The generated IR is then parsed and JIT-compiled by MLIRNative.
Submodules
| Module | Source | Input | Output |
|---|---|---|---|
TypeUtils | src/ir_gen/TypeUtils.jl | C++ type string | MLIR type string (f64, i32, !llvm.ptr, etc.) |
StructGen | src/ir_gen/StructGen.jl | ClassInfo + members | jlcs.type_info operation with field types and offsets |
FunctionGen | src/ir_gen/FunctionGen.jl | VirtualMethod | func.func @thunk_... wrapper function |
STLContainerGen | src/ir_gen/STLContainerGen.jl | STL method metadata | Accessor thunks for size(), data(), etc. |
Generation flow
generate_jlcs_ir(vtinfo::VtableInfo) produces a complete MLIR module:
- External dispatch declarations:
llvm.func @mangled_name(...)for each method with a resolved address - Type info operations:
jlcs.type_infofor each class with non-empty members (topological sort for inheritance) - Virtual method thunks:
func.func @thunk_...for each virtual method - Function thunks: Thunks for regular functions from compilation metadata
- STL container thunks: Accessor thunks for detected STL containers
MLIRNative
Source: src/MLIRNative.jl
Low-level ccall bindings to libJLCS.so, the compiled JLCS MLIR dialect shared library. Provides context management, module parsing, JIT engine creation, LLVM lowering, and symbol lookup.
See the MLIR / JLCS Dialect page for the full API reference.
JITManager
Source: src/JITManager.jl
Singleton runtime (GLOBAL_JIT) for Tier 2 function dispatch. Manages the MLIR context, JIT execution engine, and compiled symbol cache.
Key design points
- Lock-free hot path: The
_lookup_cached()function uses a double-check pattern — cached symbols are read from aDictwithout locking. Only first-call misses acquire the lock. - Arity specialization: Hand-specialized
invokemethods for 0-4 arguments avoid heap allocation ofAny[]. Stack-allocatedRefs and fixed-sizePtr{Cvoid}[]keep the hot path allocation-free. @generatedreturn dispatch:_invoke_calluses@generatedto resolve at compile time whether the return type is a primitive (directccallreturn) or a struct (sretbuffer allocation).- Variadic fallback: 5+ argument calls use dynamic allocation as a fallback.
Calling convention
All Tier 2 functions use a unified ciface calling convention:
| Return | Signature |
|---|---|
| Scalar | T ciface(void** args_ptr) |
| Struct | void ciface(T* sret, void** args_ptr) |
| Void | void ciface(void** args_ptr) |
BuildBridge
Source: src/BuildBridge.jl
Low-level compiler driver that shells out to clang, clang++, llvm-link, llvm-opt, llvm-as, and nm. All subprocess invocations go through this module, providing a single point of control for toolchain interaction.
LLVMEnvironment
Source: src/LLVMEnvironment.jl
Detects the system LLVM/Clang toolchain by searching standard paths and version-suffixed binaries. Falls back to LLVM_full_jll when no system toolchain is found. Caches results in ~/.replibuild/toolchain.toml with a 24-hour TTL.
EnvironmentDoctor
Source: src/EnvironmentDoctor.jl
check_environment() validates the complete toolchain: LLVM 21+, Clang, mlir-tblgen, CMake 3.20+, and libJLCS.so. Returns a ToolchainStatus struct indicating which tiers are available. Provides OS-specific install instructions for missing components.
DependencyResolver
Source: src/DependencyResolver.jl
Processes the [dependencies] table from replibuild.toml. Supports three dependency types:
| Type | Mechanism |
|---|---|
git | Shallow clone (--depth 1) into .replibuild_cache/deps/<name>/; re-fetches on tag change |
local | Scanned in-place; no copying |
system | pkg-config --cflags to inject include paths |
The exclude list is applied after scanning. Resolved source files merge into the compilation graph before the compile step.
PackageRegistry
Source: src/PackageRegistry.jl
Global package registry at ~/.replibuild/registry/. Provides:
register()— Store a project's build configurationuse()— Build + wrap + load, with artifact caching in~/.replibuild/builds/<hash>/list_registry()— Print all registered packages with hash, source, and build statusunregister()— Remove a package and clean cached builds
The REPLIBUILD_HOME environment variable can override the default registry location.
STLWrappers
Source: src/STLWrappers.jl
Detects STL container types (std::vector, std::string, std::map, etc.) in DWARF metadata and generates accessor functions. These are used by the MLIR IR generator (ir_gen/STLContainerGen.jl) to produce JIT thunks for STL container methods.
ASTWalker
Source: src/ASTWalker.jl
Clang.jl-based AST walker for enum extraction. Handles enum class, hex values, namespaces, and other constructs that are difficult to extract reliably from DWARF alone. Replaces the earlier regex-based approach.
ClangJLBridge
Source: src/ClangJLBridge.jl
Integration module for Clang.jl header parsing. Used by the wrapper generator when use_clang_jl = true to supplement DWARF metadata with AST-level information.
Scaffold
Source: src/Scaffold.jl
Generates a distributable Julia package from a registered RepliBuild project. The scaffolded package includes the compiled shared library, generated wrapper module, and a standard Julia Project.toml — ready for Pkg.add().
Introspect
Source: src/Introspect.jl, src/Introspect/
Umbrella module for binary analysis, Julia IR inspection, LLVM pass tooling, benchmarking, and data export. See Introspection Tools for the full API reference.
| Submodule | Source | Role |
|---|---|---|
Binary | src/Introspect/Binary.jl | symbols(), dwarf_info(), dwarf_dump(), disassemble(), headers() |
Julia | src/Introspect/Julia.jl | code_lowered(), code_typed(), code_llvm(), code_native(), code_warntype(), analysis functions |
LLVM | src/Introspect/LLVM.jl | llvm_ir(), optimize_ir(), compare_optimization(), run_passes(), compile_to_asm() |
Benchmarking | src/Introspect/Benchmarking.jl | benchmark(), benchmark_suite(), track_allocations() |
DataExport | src/Introspect/DataExport.jl | export_json(), export_csv(), export_dataset() |
Types | src/Introspect/Types.jl | Shared type definitions for the introspection subsystem |