I really wanted to be able to use Travis to test my ndjson
package but the C++ library I'm using won't compile under gcc
4.6.
The ndjson
package is on CRAN and the CRAN builds are fine (except for 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'm using gcc
5 in the example below, but you can use any version available in the toolchain test builds. Ideally, one should mimic CRAN's gcc
version and this may be something the Travis folks might consider making default for R builds.
The .travis.yml
starts off the same:
language: r
warnings_are_errors: true
sudo: required
env:
global:
- CRAN: http://cran.rstudio.com
I added a matrix build configuration to add the new package source as well as specify the package(s) that needed to be installed. I left it in a matrix configuration since I'm going to try to (eventually) 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
Next, I made sure the auto default compiler is set to this newer gcc
and also made doubly sure that R would 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 equates to:
VER=-5
CC=gcc$(VER) -std=c11
CXX=g++$(VER)
SHLIB_CXXLD=g++$(VER)
FC=gfortran
F77=gfortran
and is just (IMO) cleaner this way.
In theory, all I would have had to do is create the Makevars
(i.e. not have to change the default gcc
with update-alternatives
) but it turned out that Travis used the Makevars
gcc
setting when installing the dependencies but not for the actual package build itself. So, the update-alternatives
is necessary. I also had to add the -std=c11
to ensure a few of the dependencies compiled (the build errored w/o it).
After these modifications to the .travis.yml
configuration, ndjson
built fine.