travis-build icon indicating copy to clipboard operation
travis-build copied to clipboard

Dynamic compiler installation for Linux C/C++ builds

Open BanzaiMan opened this issue 7 years ago • 3 comments

This PR adds the ability to install gcc and clang on the fly for Linux builds.

How is compiler versions found?

In language: c and language: cpp builds, we detect gcc and clang versions using the following regular expressions:

C C++
gcc /^gcc(-\d+(\.\d+)*)?/i /^g(?:cc|\+\+)(-\d+(\.\d+)*)?/i
clang /^clang(-\d+(\.\d+)*)?/i /^clang(?:\+\+)?(-\d+(\.\d+)*)?/i

And use $1 in the match to drive package installations.

How do we decide to install new packages?

From the compiler value given in the config, we compute $CC value.

  • For C builds, it is identical to the compiler value
  • For C++ builds—for GCC, gcc or gcc-6; for clang, clang or clang-7

If this command is missing, we initiate package installation. For example, given:

language: c
compiler:
  - gcc-6

and the command gcc-6 is not available, we proceed to install APT packages.

Which packages are installed?

First, appropriate apt repository is added.

  • for GCC, ppa:ubuntu-toolchain-r/test
  • for clang, see https://apt.llvm.org/

Then, the following packages will be installed:

  • for C builds, value given by compiler
  • for C++ builds, value computed for CC (e.g., gcc-6 for gcc, clang-7 for clang), even when compiler looks different (e.g., g++-6 or clang++-7).

In all cases, libstdc++-6 is also installed (if necessary).

BanzaiMan avatar Nov 29 '18 02:11 BanzaiMan

Tests:

Trusty Xenial
C https://staging.travis-ci.org/BanzaiMan/travis_staging_test/builds/736324 (gcc-6 and clang-7 are installed on the fly.) https://staging.travis-ci.org/BanzaiMan/travis_staging_test/builds/736319 (only gcc-6 is installed on the fly.)
C++ https://staging.travis-ci.org/BanzaiMan/travis_staging_test/builds/736334 https://staging.travis-ci.org/BanzaiMan/travis_staging_test/jobs/736331
C++ (with g++-6, clang++-7) https://staging.travis-ci.org/BanzaiMan/travis_staging_test/builds/736339 (See g++-6 and clang++-7 jobs)

BanzaiMan avatar Nov 29 '18 02:11 BanzaiMan

Hmm. The assumption that the compiler value should equal the command name appears wrong for g++-6. https://staging.travis-ci.org/BanzaiMan/travis_staging_test/jobs/736342#L246

Maybe the CC value (gcc-6 for compiler: g++-6) is the command to seek for C++ builds.

BanzaiMan avatar Nov 29 '18 02:11 BanzaiMan

Currently, on C++ builds, we use the compiler value to announce the compiler version. We now accept compiler: g++-6, but this command is not available for gcc-6, which will be installed using this PR. I am inclined to use $CC value to announce the compiler version, but this could be confusing to some.

BanzaiMan avatar Nov 29 '18 02:11 BanzaiMan