Overview
The Cookbook is Redox OS’s package build system, implemented in Rust. It manages downloading sources, building packages, handling dependencies, and creating package archives.The Cookbook is located in the main redox repository and is built as part of the bootstrap process.
Architecture
The Cookbook system consists of several key components:Core Modules
Recipe Data Structures
The recipe system is built around strongly-typed Rust structures defined insrc/recipe.rs.
Recipe Structure
Source Types
Build Templates
Build Process
The Cookbook follows a multi-stage build process:1. Recipe Discovery
- Locates
recipes/category/package-name/recipe.toml - Parses the TOML into a
Recipestruct - Validates all required fields
2. Dependency Resolution
The Cookbook recursively resolves dependencies:- Parse recipe for target package
- Collect
build.dependencies - Recursively resolve dependencies of dependencies
- De-duplicate and topologically sort
- Return ordered list of packages to build
3. Source Fetching
Implemented insrc/cook/fetch.rs and src/cook/fetch_repo.rs.
Git Repositories
Tar Archives
4. Build Execution
Implemented insrc/cook/cook_build.rs.
Template Execution
Each template has a corresponding build function:Build Environment
The Cookbook sets up a complete build environment:5. Package Creation
Implemented insrc/cook/package.rs.
Staging Directory
All installed files go to a staging directory:Package Archive Format
The Cookbook creates.tar.gz and .pkgar archives:
Dependency Management
Dependency Types
The Cookbook distinguishes between three types of dependencies:- Build Dependencies - Required to compile
- Dev Dependencies - Additional build tools
- Package Dependencies - Required at runtime
Auto-Detection
The Cookbook can automatically detect runtime dependencies through dynamic linking analysis:- Scan all ELF binaries in staging directory
- Extract
DT_NEEDEDentries from dynamic section - Match libraries to packages
- Return set of required packages
Auto-detected dependencies are written to
target/${TARGET}/${PACKAGE}/auto_deps.toml.Configuration System
Recipes can be configured per-target in.config/${TARGET}/repo.toml:
Configuration Application
Parallel Builds
The Cookbook supports parallel compilation:Build Targets
The Makefile provides numerous targets:Recipe Targets
Package Operations
Batch Operations
Source Structure
The Cookbook source code organization:Recipe Lookup
Recipes are discovered through thepkg crate:
Error Handling
The Cookbook uses structured error types:- Which recipe failed
- Dependency chain leading to failure
- Specific build errors
Caching
The Cookbook caches multiple stages:Source Cache
Sources are cached across builds. Use
make u.RECIPE to update.Build Cache
Sysroot Cache
Dependencies are extracted to a shared sysroot:Advanced Features
Host vs Target Packages
The Cookbook can build packages for both host and target:Optional Package Splitting
A single recipe can produce multiple packages:openssl produces:
openssl(runtime libraries)openssl-dev(headers and static libraries)
Version Detection
The Cookbook can auto-detect versions from sources:Debugging
Verbose Mode
- Full command output
- Dependency resolution details
- Build environment variables
Build Logs
Logs are written to:Interactive Debugging
Enter the build environment:Performance Optimization
Parallel Fetching
The Cookbook can fetch multiple sources in parallel:Incremental Builds
Only rebuild when necessary:- Source changes detected via checksums
- Dependency updates trigger rebuilds
- Build artifacts cached
Binary Downloads
For faster builds, use pre-built binaries:repo.toml:
Integration Points
Package Manager
The Cookbook produces packages consumed bypkg (Redox’s package manager):
Installer
The system installer uses Cookbook packages:Build System
The main build system orchestrates Cookbook:Testing Recipes
Unit Tests
Recipe parsing has unit tests:Integration Tests
Test recipes in QEMU:Best Practices
Cache Friendly
Structure recipes to maximize cache reuse across builds.
Dependency Minimal
Only declare dependencies actually used - extras slow builds.
Reproducible
Pin versions, use checksums, specify revisions for reproducible builds.
Error Handling
Provide clear error messages in custom build scripts.
See Also
- Recipe Format Reference - Complete recipe TOML specification
- Application Porting Guide - How to port software
- Build System Reference - Full build system documentation
- Cookbook Repository - Source code