Set up Docker for Building Cobalt

  • Docker image definitions are provided to manage build environments, simplifying the process.

  • The docker compose run <platform> command is used for the simplest build usage, defaulting to a debug build with cobalt as the target.

  • Build configurations can be customized using environment variables like CONFIG and TARGET to specify optimization levels and build targets.

  • Windows builds are supported through a separate docker-compose-windows.yml file, which can be specified using the -f flag.

  • The base operating system image used for builds can be customized by passing the BASE_OS argument to docker compose build, allowing for different Debian-based images.

We provide Docker image definitions to simplify managing Cobalt build environments on Linux.

Prerequisites

These instructions assume: - You have already set up your Cobalt repository workspace on the host machine. - Docker is installed and running on your host Linux machine. If you need to install Docker, refer to the official Docker installation guide for Linux.

1. Building the Linux Docker Image

To build the linux builder Docker image, run one of the following commands from your workspace root (the directory containing docker-compose.yaml):

Using docker compose:

docker compose build linux

Or using Docker directly:

docker build -t linux cobalt/docker/linux

2. Launching the Linux Container

To run build commands in the container environment, first launch the container:

docker run --rm \
  --user $(id -u):$(id -g) \
  -e HOME=/tmp \
  -v /path/to/workspace:/cobalt \
  -w /cobalt/src \
  -e PYTHONPATH="/cobalt/src" \
  -it linux /bin/bash

3. Building Cobalt inside the Container

Once inside the interactive container shell (at /cobalt/src), run the following commands sequentially to configure and build the Cobalt target:

  1. Set the environment PATH variable: Configure the search path to locate depot_tools and ninja correctly:

    export PATH="/cobalt/tools/depot_tools:/cobalt/src/third_party/ninja:/cobalt/src:$PATH"
    
  2. (Optional) Clean stale build locks: If a previous compilation attempt was interrupted, a stale lock file might block siso. Clean it by running:

    rm -f out/linux-x64x11_devel/.siso_lock
    
  3. Generate the build configuration files for the linux-x64x11 platform in the devel configuration with Remote Build Execution (RBE) disabled:

    python3 cobalt/build/gn.py -p linux-x64x11 -C devel --no-rbe
    
  4. Compile the Cobalt target using autoninja:

    autoninja -C out/linux-x64x11_devel cobalt
    

Completed builds are generated in the out/linux-x64x11_devel directory of your workspace.