jolt build command compiles Rust code into RISC-V binaries optimized for proving in the Jolt zkVM.
Usage
Build Modes
Build with Rust standard library support (std mode).
- Uses
riscv64imac-zero-linux-musltarget - Includes musl libc and gcc runtime libraries
- Automatically downloads and installs required toolchain
- Larger binary size but full std features
Build without standard library (no_std mode). This is the default.
- Uses
riscv64imac-unknown-none-elftarget - Minimal runtime, smaller binaries
- Requires
#![no_std]in guest code
Toolchain Options
Path to custom musl libc installation.If not specified, Jolt will automatically download or build musl. Use this to provide a pre-built musl library.
Path to custom GCC runtime libraries (libgcc).Used in std mode for exception handling and runtime support. If not specified, Jolt will build it automatically.
Force full toolchain build from source, even if binaries are available.Useful for:
- Reproducible builds
- Custom toolchain patches
- Verifying build from source
Debugging and Backtrace
Controls symbol preservation and frame pointer generation for debugging.Values:
auto- Preserve symbols in debug/dev profiles, strip in releaseenable- Always preserve symbols (skips-Cstrip=symbols)dwarf- Preserve symbols + enable frame pointers (-Cforce-frame-pointers=yes)frame-pointers- Enable frame pointers without DWARFdisable- Always strip symbols
The
JOLT_BACKTRACE=1 environment variable is often more convenient than --backtrace enable for ad-hoc debugging, as it doesn’t require rebuild flags.Cargo Integration
Additional arguments passed directly to
cargo build.All arguments after -- are forwarded to cargo:Environment Variables
Optimization Level
Controls optimization level for guest code via
-Copt-level.Valid values:0- No optimizations1- Basic optimizations2- Some optimizations3- All optimizations (default)s- Optimize for sizez- Optimize for size, more aggressive
Backtrace Control
Enables symbol preservation for debugging without modifying build flags.Unlike
1- Preserve symbols, enable tracer backtracesfull- Include register dumps and cycle counts
--backtrace enable, this triggers a guest rebuild automatically while keeping your existing cargo build flags intact.Target-Specific CFLAGS
The build system automatically sets:Rust Flags
Jolt automatically adds these rustflags to guest builds:-Cpasses=lower-atomic- Lower atomic operations to library calls-Cpanic=abort- Panic = abort (no unwinding)-Copt-level=<N>- Optimization level fromJOLT_GUEST_OPT-Cllvm-args=-enable-machine-outliner=never- Disable broken RISC-V outliner--cfg=getrandom_backend="custom"- Use custom entropy source-Cstrip=symbols- Strip symbols (unless backtrace enabled)-Cforce-frame-pointers=yes- Only with--backtrace dwarf/frame-pointers
Build Process
The build happens in several stages:- Workspace detection - Finds the Cargo workspace root
- Toolchain setup - Downloads/builds musl and gcc libs (std mode only)
- Target spec generation - Creates custom RISC-V target JSON
- Linker script - Generates memory layout from embedded template
- Cargo build - Compiles guest with custom rustflags
- Post-processing - Strips symbols if configured
Examples
Basic Build
Build with default settings (no_std, opt-level 3):Release Build
Build with cargo release profile:Std Mode Build
Build with standard library:Debug Build with Backtraces
Build with symbols for debugging:Optimize for Size
Minimize binary size:Custom Toolchain
Use pre-built toolchain components:Reproducible Build
Build toolchain from source:Output Location
Built binaries are placed in the standard cargo target directory: No-std mode:Troubleshooting
Toolchain Download Failures
If automatic toolchain installation fails:Optimization Errors
If you encounter “Invalid JOLT_GUEST_OPT value” errors:Linker Errors
For linker errors in std mode:Performance Considerations
Optimization Level
- Use
JOLT_GUEST_OPT=3(default) for best proving performance - Use
JOLT_GUEST_OPT=zorsonly if binary size is critical - Lower optimization levels (
0,1,2) increase trace length and proving time
Symbol Stripping
- Stripped binaries are smaller and faster to load
- Only preserve symbols when debugging is needed
JOLT_BACKTRACE=1is zero-cost at runtime (only affects build)
Frame Pointers
--backtrace dwarfadds frame pointer overhead (~500 cycles for std guests)- Only needed for DWARF unwinding or external tooling
JOLT_BACKTRACE=1provides backtraces without this cost
Related Commands
jolt run
Run the built binary on the emulator
jolt new
Create a new Jolt project