I really wanted to use Travis to test my ndjson package, but the C ++ library I use will not compile under gcc 4.6.
The ndjson package is on CRAN, and the CRAN builds are excellent (with the exception of r-oldrel on Windows, which doesn't bother me) a bit), so I needed a way to change the compiler that R uses on Travis.
I use gcc 5 in the example below, but you can use any version available in instrumental tests . Ideally, you need to emulate the CRAN gcc version, and this may be something that Travis people might consider creating a default for R-builds.
.travis.yml begins with the same:
language: r warnings_are_errors: true sudo: required env: global: - CRAN: http:
I added a matrix build configuration to add a new package source, as well as specify the packages (packages) that need to be installed. I left it in the matrix configuration, since I will try (in the end) to add clang .
matrix: include: - os: linux compiler: gcc addons: apt: sources: ['ubuntu-toolchain-r-test'] packages: ['g++-5'] env: - COMPILER=g++-5 - CC=gcc=5 - CXX=g++-5
Then I made sure that the auto default compiler is installed on this new gcc , and I am doubly sure that R will use it by creating a local Makevars :
before_install: - sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-5 100 - mkdir -p ~/.R - echo "VkVSPS01CkNDPWdjYyQoVkVSKSAtc3RkPWMxMSAKQ1hYPWcrKyQoVkVSKQpTSExJQl9DWFhMRD1nKyskKFZFUikKRkM9Z2ZvcnRyYW4KRjc3PWdmb3J0cmFuCg==" | base64 -d > ~/.R/Makevars - cat ~/.R/Makevars
The base64 string matches:
VER=-5 CC=gcc$(VER) -std=c11 CXX=g++$(VER) SHLIB_CXXLD=g++$(VER) FC=gfortran F77=gfortran
and is just (IMO) clean that way.
In theory, all I would have to do was create Makevars (i.e. do not change the default gcc value using update-alternatives ), but it turned out that Travis used the Makevars gcc setting when installing the dependencies, but not for the build itself package. Thus, update-alternatives is required. I also had to add -std=c11 to make sure some of the compiled dependencies (build error not indicated).
After these changes to the configuration .travis.yml , ndjson built perfectly.