Build a Rust Project
For Language versions and other build-environment specific information visit our reference pages:
This guide covers configuring Rust projects in Travis CI. If you’re new to Travis CI, please read our Onboarding and General Build configuration guides first.
Choose a Rust version #
By default, we download and install the latest stable Rust release at the start
of the build (thanks to rustup
). The minimal
profile is used
and includes the following language tools: cargo
, rustc
, and rustup
.
If you want additional language tools like rustfmt
or clippy
, please
install them in before_install
.
To test against specific Rust releases:
language: rust
rust:
- 1.0.0
- 1.1.0
Travis CI also supports all three Rust release channels: stable
,
beta
, and nightly
.
The Rust team appreciates testing against the beta
and nightly
channels,
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 run 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:
cache: cargo
This adds the following directories to the cache:
$TRAVIS_HOME/.cache/sccache
$TRAVIS_HOME/.cargo/
$TRAVIS_HOME/.rustup/
target
In addition, it adds the following command to the before_cache
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, you
should pass --workspace
to the build commands to build and test all of the member
crates:
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.