Sccache in Travis CI

Has anyone used sccache successfully in Travis?

I wonder how to install it quickly and portably. If I run cargo install sccache it takes way longer than any savings from the cache itself. I've tried to use a prebuilt binary using MUSL, but sccache depends on openssl which was too hard to compile portably.

I wonder how to install it quickly and portably. If I run cargo install sccache it takes way longer than any savings from the cache itself.

Not the greatest solution but you could rely on caches

env:
  SCCACHE_VERSION=0.2.6
...
install:
- cargo install sccache --version $SCCACHE_VERSION || echo "Reusing sccache from CI cache"

No need to --force to upgrade; Travis flushes its caches when environment variables change.

  • If the build takes too long, you could use travis_wait
  • You do need to keep your fresh builds under 50 minutes or so. From some past experience, somewhere around there is Travis' hard cutoff for all steps within a build.

EDIT: This is the approach I'm using for clippy

Is the install: phase special in regards to caching? I've tried relying on cache: cargo when building sccache as part of script: phase, but I'm getting very low cache hit ratio from Travis', which is why I was looking for some other trick.

Is the install: phase special in regards to caching?

It isn't as far as I'm aware.

I’m getting very low cache hit ratio from Travis’

Strange, I almost always get to use my cache. Whats the project? I'd be interested to look to see whats going on.

Thanks. I've figured it out -- the project I was working on was using Docker, and services: docker in .travis.yml disables cargo caching.

A possible approach is to download the release tarball from Github. The sccache binary will be cached in the Cargo cache so the download can be skipped if it is already there.

env:
  global:
    - RUSTC_WRAPPER=sccache
    - SCCACHE_VERSION=0.2.13

cache:
  - cargo

before_install:
  - which sccache || travis_retry curl -Lo /tmp/sccache.tar.gz https://github.com/mozilla/sccache/releases/download/${SCCACHE_VERSION}/sccache-${SCCACHE_VERSION}-x86_64-unknown-linux-musl.tar.gz
  - which sccache || tar -xzf /tmp/sccache.tar.gz --directory=/tmp/
  - which sccache || cp /tmp/sccache-${SCCACHE_VERSION}-x86_64-unknown-linux-musl/sccache ${TRAVIS_HOME}/.cargo/bin