Skip to main content

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 in src/recipe.rs.

Recipe Structure

Source Types

Build Templates

Build Process

The Cookbook follows a multi-stage build process:

1. Recipe Discovery

The build system:
  1. Locates recipes/category/package-name/recipe.toml
  2. Parses the TOML into a Recipe struct
  3. Validates all required fields

2. Dependency Resolution

The Cookbook recursively resolves dependencies:
Algorithm:
  1. Parse recipe for target package
  2. Collect build.dependencies
  3. Recursively resolve dependencies of dependencies
  4. De-duplicate and topologically sort
  5. Return ordered list of packages to build
The Cookbook enforces a maximum recursion depth (defined by WALK_DEPTH) to prevent infinite dependency loops.

3. Source Fetching

Implemented in src/cook/fetch.rs and src/cook/fetch_repo.rs.

Git Repositories

Tar Archives

4. Build Execution

Implemented in src/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 in src/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:
  1. Build Dependencies - Required to compile
  2. Dev Dependencies - Additional build tools
  3. Package Dependencies - Required at runtime

Auto-Detection

The Cookbook can automatically detect runtime dependencies through dynamic linking analysis:
Process:
  1. Scan all ELF binaries in staging directory
  2. Extract DT_NEEDED entries from dynamic section
  3. Match libraries to packages
  4. 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:
Within recipes:

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 the pkg crate:

Error Handling

The Cookbook uses structured error types:
Errors include context about:
  • 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:
Host packages run on the build machine (e.g., build tools). Target packages run on Redox (e.g., user applications).

Optional Package Splitting

A single recipe can produce multiple packages:
Example: openssl produces:
  • openssl (runtime libraries)
  • openssl-dev (headers and static libraries)

Version Detection

The Cookbook can auto-detect versions from sources:

Debugging

Verbose Mode

Enables:
  • 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:
Or configure in repo.toml:

Integration Points

Package Manager

The Cookbook produces packages consumed by pkg (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