[Solved] What is the easiest way to add clippy to a Travis CI build?


#1

I’ve wanted to add clippy linting to a Rust project for a while, originally putting it off because I’ve been trying to do all development with stable Rust. But it looks like there are ways to use cargo to run it.

I’m unclear how this would interact with a build matrix that has stable and beta builds. Has anyone done this before and found a simple solution?

My current .travis.yml:

language: rust

rust:
  - stable
  - beta
  - nightly

install:
  # Steps copied from the rust-sdl2 project.
  - wget https://www.libsdl.org/release/SDL2-2.0.4.tar.gz -O sdl2.tar.gz
  - tar xzf sdl2.tar.gz
  - pushd SDL2-2.0.4 && ./configure && make && sudo make install && popd

  # Steps copied from rust-sdl2_mixer project.
  - wget https://www.libsdl.org/projects/SDL_mixer/release/SDL2_mixer-2.0.1.tar.gz -O sdl2_mixer.tar.gz
  - tar xzf sdl2_mixer.tar.gz
  - pushd SDL2_mixer-2.0.1 && ./configure && make && sudo make install && popd

matrix:
  allow_failures:
    - rust: nightly

os:
  - linux
  - osx

script:
  - cargo build --verbose

Thanks.


#2

You can inspect the TRAVIS_RUST_VERSION environment variable to conditionally run parts of the script block: https://github.com/sfackler/rust-phf/blob/master/.travis.yml#L10


#3

To add to that you can also use it to conditionally run before script steps to install clippy, which lets you run it in CI without having it referenced from your code anywhere. In roaring-rs I also hard code a nightly and clippy version to use to make sure they’re in sync.


#4

:tada: Thanks @Nemo157 an @sfackler, this is exactly what I needed.


#5

@Nemo157 I’m curious how do you know the correspondence of a particular clippy version and a functioning nightly? Is that documented somewhere?

For example, I recently ran into this issue with current clippy and nightly.


#6

Not that I know of, I just looked at the versions I had installed locally since I knew they were working.


#7

Is there a reason why you need to test all versions on all platforms on every change? That wastes a lot of resources on travis.

I can understand that cross-platform tests are important, but beta can be tested once on release, at least.

SDL is rather platform specific, I can understand, but I’m couldn’t at least OS X/nightly be completely cut without great impact?