22

How can I configure travis-ci such that my project builds with more than one version of a compiler?

Say, I want to build it with gcc-4.8, gcc-4.9, clang-3.4, clang-3.5 and clang-3.6.

I know how to build on both gcc and clang, but not on more than one version of them.

To give a little bit more context, my project is a C++ library and I want to ensure compatibility with those compilers.

1 Answer 1

37

It was (and still is) quite painful to figure out what is possible/allowed with Travis CI and what isn't. My current solution looks like this:

language: cpp
matrix:
  include:
    - os: linux
      compiler: gcc
      addons:
        apt:
          sources: ['ubuntu-toolchain-r-test']
          packages: ['g++-4.8']
      env: COMPILER=g++-4.8

    - os: linux
      compiler: gcc
      addons:
        apt:
          sources: ['ubuntu-toolchain-r-test']
          packages: ['g++-4.9']
      env: COMPILER=g++-4.9

    - os: linux
      compiler: gcc
      addons:
        apt:
          sources: ['ubuntu-toolchain-r-test']
          packages: ['g++-5']
      env: COMPILER=g++-5

    - os: linux
      compiler: clang
      env: COMPILER=clang++

    - os: linux
      compiler: clang
      addons:
        apt:
          sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-precise-3.5']
          packages: ['clang-3.5']
      env: COMPILER=clang++-3.5

    - os: linux
      compiler: clang
      addons:
        apt:
          sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-precise-3.6']
          packages: ['clang-3.6']
      env: COMPILER=clang++-3.6

# Activate when 3.7 is released and the repository is available
#    - os: linux
#      compiler: clang
#      addons:
#        apt:
#          sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-precise-3.7']
#          packages: ['clang-3.7']
#      env: COMPILER=clang++-3.7

# Activate when we are allowed to use MacOS X
#    - os: osx
#      compiler: clang
#      env: COMPILER=clang++

script:
  make CXX=$COMPILER -j3

Some remarks:

  • The above uses the container-based infrastructure
  • Only one compiler is installed per container - speeds up the build and avoids problems as you often can not install several packages/compilers in parallel
  • You can not set CXX directly as Travis CI will overwrite it. You need an intermediate variable like COMPILER
  • The clang++ without extension is currently Clang 3.4
  • Clang 3.7 is not yet available, but should be shortly
  • Clang 3.8 (the development version) from the llvm-toolchain-precise repository is currently black-listed

(Note that the above will change/improve over time, now (2016-01-11) Clang 3.7 is available, as is MacOS X. The above is meant as a starting point, adapt as needed)

Sign up to request clarification or add additional context in comments.

8 Comments

It's a nice thing to get something off the ground, but for serious projects you also need libc++ and Boost and stuff gets complicated quickly. Boost.Hana has a well-maintained .yaml file
@TemplateRex They seem to only use Clang, not GCC. Anyways, it is a good example once you've managed the basics. My answer was mostly meant for others to get started because I've seen so many version which are either overly complicated or they don't work or both. My hope is that knowledge spreads throughout as many other repositories as possible so that wherever a new user is looking he can find some good examples.
More as a side remark, half the pain is in knowing how to build the different stuff. I just wished that the gcc folks would put up a nightly build repo where one could download .rpm / .deb packages (just like Clang does). I'd also like to have the same for Boost/libc++, all that installing and compilation on a per user basis is just insane.
Thanks a bunch. That's precisely what I'm looking for.
@TemplateRex thanks so much for the pointer to Hana's .travis.yml
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.