Setup Travis CI for Rust Diesel project

Rust is supported on Travis CI
, there are three main channels of Rust you can use: stable
, beta
and nightly
. You can just follow their instruction to get your Rust project build smoothly.

But when it come to
, it will be a bit tricky.

The reason is, in order to build a diesel-based project, you will need to have:

  • A database on your build machine
  • A .env
    file with a configuration to connect to that database
  • diesel-cli
    installed to run migration

So, it will require some more configuration.

Let’s create a .travis.yml
file in your project’s root folder.

Step 1: Rust version

You can select any version of Rust in your Travis CI, put this to your config file:

language: rust
  - nightly
  // or
  - 1.22.0
  // or
  - stable

Step 2: PostgreSQL (or what ever database you use)

Next, we need to add PostgreSQL as an extra service:

  - postgresql

If you’re using a different database, just change it. For the complete list of supported database, please take a look at this document

Step 3: Init your database and migration

Now we need to do a lot of things, create a databse, install diesel-cli
, create a database and run migration, let create a before_script

  - psql -c 'create database build_db;' -U postgres
  - echo "DATABASE_URL=postgres://postgres@localhost/build_db" > .env
  - cargo install diesel_cli --no-default-features --features=postgres
  - diesel migration run

Step 4: Build and Test

Finally, build and test your project with cargo

  - cargo build --verbose --all
  - cargo test --verbose --all

That’s all you need!

If you are too lazy to follow the four steps, this is a gist
for you.

P/S:It’s worth to mention that due to a lot of cargo
run, the build time is so freaking slow, with the above gist, my project took approximately 8 to 9 mins per build.

You might want to add some caching for cargo
in your .travis.yml

cache: cargo

See more about dependencies caching here


Getting started with rust-toolset One of the new software collections we’ve introduced this fall is for Rust , the programming language that aims for memory and thread safety witho...
Announcing Rust 1.15 The Rust team is happy to announce the latest version of Rust, 1.15.0. Rust is a systems programming language focused on safety, speed, and concurrenc...
This Week in Rust 176 Hello and welcome to another issue of This Week in Rust ! Rust is a systems language pursuing the trifecta: safety, concurrency, and speed. Thi...
My journey with Rust in 2017 — The good, the bad, ... My journey with Rust in 2017 — The good, the bad, the weird Note: This post is not only about Rust, but rather my experiences, problems and solutio...
Rust performance: finishing the job Today I saw a story about profiling and optimising some Rust code . It's a nice little into to perf , but the author stops early and leaves qui...
The Practical Developer责编内容来自:The Practical Developer (源链) | 更多关于

本站遵循[CC BY-NC-SA 4.0]。如您有版权、意见投诉等问题,请通过eMail联系我们处理。
酷辣虫 » Setup Travis CI for Rust Diesel project

专业 x 专注 x 聚合 x 分享 CC BY-NC-SA 4.0

使用声明 | 英豪名录