Building a Rust Project
What This Guide Covers #
For Language versions and other build-environment specific information visit our reference pages:
The rest of this guide covers configuring Rust projects in Travis CI. If you’re new to Travis CI please read our Tutorial and build configuration guides first.
Choosing a Rust version #
By default, we download and install the latest stable Rust release at the start
of the build (thanks to
minimal profile is used
and includes the following language tools
If you want additional language tools like
install them in
To test against specific Rust releases:
language: rust rust: - 1.0.0 - 1.1.0
Travis CI also supports all three Rust release channels:
The Rust team appreciates testing against the
even if you are only targeting
stable. A full configuration looks like this:
language: rust rust: - stable - beta - nightly jobs: allow_failures: - rust: nightly fast_finish: true
This will runs your tests against all three channels, but any breakage in
nightly will not fail the rest of build.
Dependency Management #
Travis CI uses Cargo to install your dependencies:
cargo build --verbose
You can cache your dependencies so they are only recompiled if they or the compiler were upgraded:
This adds the following directories to the cache:
In addition, it adds the following command to the
phase of the job in order to reduce cache size:
rm -rf "$TRAVIS_HOME/.cargo/registry/src"
This means that, if you override the
before_cache step for another reason, you should add the step above in order to reduce the cache size:
before_cache: - rm -rf "$TRAVIS_HOME/.cargo/registry/src" ⋮ # rest of your existing "before_cache"
Default Build Script #
Travis CI uses Cargo to run your build, the default commands are:
cargo test --verbose
You can always configure different commands if you need to. For example,
if your project is a
--workspace to the build commands to build and test all of the member
language: rust script: - cargo build --verbose --workspace - cargo test --verbose --workspace
Environment variables #
The Rust version that is specified in the
.travis.yml is available during the
build in the
TRAVIS_RUST_VERSION environment variable.
Build Config Reference #
You can find more information on the build config format for Rust in our Travis CI Build Config Reference.