Testing with Docker - Rust Compiler Development Guide (original) (raw)

Rust Compiler Development Guide

Testing with Docker

The src/ci/docker directory includes Docker image definitions for Linux-based jobs executed on GitHub Actions (non-Linux jobs run outside Docker). You can run these jobs on your local development machine, which can be helpful to test environments different from your local system. You will need to install Docker on a Linux, Windows, or macOS system (typically Linux will be much faster than Windows or macOS because the latter use virtual machines to emulate a Linux environment).

Jobs running in CI are configured through a set of bash scripts, and it is not always trivial to reproduce their behavior locally. If you want to run a CI job locally in the simplest way possible, you can use a provided helper Python script that tries to replicate what happens on CI as closely as possible:

python3 src/ci/github-actions/ci.py run-local <job-name>
# For example:
python3 src/ci/github-actions/ci.py run-local dist-x86_64-linux-alt

If the above script does not work for you, you would like to have more control of the Docker image execution, or you want to understand what exactly happens during Docker job execution, then continue reading below.

The run.sh script

The src/ci/docker/run.sh script is used to build a specific Docker image, run it, build Rust within the image, and either run tests or prepare a set of archives designed for distribution. The script will mount your local Rust source tree in read-only mode, and an obj directory in read-write mode. All the compiler artifacts will be stored in the obj directory. The shell will start out in the objdirectory. From there, it will execute ../src/ci/run.sh which starts the build as defined by the Docker image.

You can run src/ci/docker/run.sh <image-name> directly. A few important notes regarding the run.sh script:

Interactive mode

Sometimes, it can be useful to build a specific Docker image, and then run custom commands inside it, so that you can experiment with how the given system behaves. You can do that using an interactive mode, which will start a bash shell in the container, using src/ci/docker/run.sh --dev <image-name>.

When inside the Docker container, you can run individual commands to do specific tasks. For example, you can run ../x test tests/ui to just run UI tests.

Some additional notes about using the interactive mode:

The approach described above is a relatively low-level interface for running the Docker images directly. If you want to run a full CI Linux job locally with Docker, in a way that is as close to CI as possible, you can use the following command:

cargo run --manifest-path src/ci/citool/Cargo.toml run-local <job-name>
# For example:
cargo run --manifest-path src/ci/citool/Cargo.toml run-local dist-x86_64-linux-alt