Documentation Index
Fetch the complete documentation index at: https://mintlify.com/risc0/risc0/llms.txt
Use this file to discover all available pages before exploring further.
risc0-build
Therisc0-build crate provides build-time utilities for compiling RISC-V guest programs for the RISC Zero zkVM.
Installation
Overview
This crate is typically used inbuild.rs files to compile guest code written in Rust for the RISC Zero zkVM. It handles cross-compilation to the RISC-V target and generates metadata about the compiled guest programs.
Feature Flags
Enables building guest programs using Docker for reproducible builds.
Generates a list of all compiled guest programs with their metadata.
Enables unstable/experimental features.
Core Functions
embed_methods
Embeds compiled guest methods for use in host code.This function reads the
[package.metadata.risc0] section from Cargo.toml, builds the specified guest packages, and generates constants for accessing the compiled ELF binaries and image IDs.Returns: List of compiled guest programs with their metadata.Example in build.rs:embed_methods_with_options
Embeds methods with custom build options per guest package.Parameters:
guest_pkg_to_options: Map of guest package names to their build options
embed_method_metadata_with_options
Builds methods and embeds minimal metadata (name and path only).Use this when you want to load the ELF at runtime rather than embedding it in the binary, reducing compile times for large guest programs.
Types
GuestOptions
Configuration options for building guest programs.Built using GuestOptionsBuilder:
Options for building guests using Docker.Built using DockerOptionsBuilder:
GuestListEntry
Metadata for a compiled guest program.Fields:
name: Guest binary nameelf: Combined user + kernel ELF binaryimage_id: Computed image ID for verificationpath: Path to the ELF file
Minimal metadata for a compiled guest program.
Utility Functions
get_package
Returns the Cargo package from a manifest directory.
get_target_dir
Determines the build target directory from a Cargo manifest.
cargo_command
Creates a cargo command configured for building zkVM guests.Parameters:
subcmd: Cargo subcommand (e.g., “build”, “test”)rustc_flags: Additional rustc flags
Generated Code
After callingembed_methods() in your build.rs, include the generated code:
my-method becomes MY_METHOD_ELF).
Cargo.toml Configuration
Add guest packages to yourCargo.toml:
Environment Variables
Set to
1 to build guests in debug mode (faster compilation, slower execution).Set to skip building guests (useful for checking without rebuilding).
Set to pass
--locked to cargo when building guests.Path to Rust source for building std from source.