Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using different libc++ versions on travis for clang

Tags:

Travis uses Ubuntu Trusty and the default libc++ version there is svn199600.

However I would like to test with different (newer) versions as I already do with different clang versions.

My current .travis.yml looks as follows:

language: generic

dist: trusty
sudo: required

matrix:
    include:
    - env: CXX=g++-7 CC=gcc-7
      addons:
        apt:
          packages:
            - g++-7
          sources: &sources
            - ubuntu-toolchain-r-test
            - llvm-toolchain-precise
            - llvm-toolchain-precise-3.9
            - llvm-toolchain-precise-3.8
            - llvm-toolchain-precise-3.7
            - llvm-toolchain-precise-3.6
            - sourceline: 'deb http://apt.llvm.org/trusty/ llvm-toolchain-trusty-4.0 main'
              key_url: 'http://apt.llvm.org/llvm-snapshot.gpg.key'
    - env: CXX=g++-6 CC=gcc-6
      addons:
        apt:
          packages:
            - g++-6
          sources: *sources
    - env: CXX=g++-5 CC=gcc-5
      addons:
        apt:
          packages:
            - g++-5
          sources: *sources
    - env: CXX=g++-4.9 CC=gcc-4.9
      addons:
        apt:
          packages:
            - g++-4.9
          sources: *sources
    - env: CXX=clang++-4.0 CC=clang-4.0
      addons:
        apt:
          packages:
            - clang-4.0
            - libc++-dev
          sources: *sources
    - env: CXX=clang++-3.9 CC=clang-3.9
      addons:
        apt:
          packages:
            - clang-3.9
            - libc++-dev
          sources: *sources
    - env: CXX=clang++-3.8 CC=clang-3.8
      addons:
        apt:
          packages:
            - clang-3.8
            - libc++-dev
          sources: *sources
    - env: CXX=clang++-3.7 CC=clang-3.7
      addons:
        apt:
          packages:
            - clang-3.7
            - libc++-dev
          sources: *sources
    - env: CXX=clang++-3.6 CC=clang-3.6
      addons:
        apt:
          packages:
            - clang-3.6
            - libc++-dev
          sources: *sources

script:
    - ./build_and_test.sh

before_install:
    - ./before_install.sh

Replacing libc++-dev with libc++-dev-3.9 for example does not help (still uses old library version), even when adding the following line:

- sourceline: 'deb-src http://apt.llvm.org/trusty/ llvm-toolchain-trusty-3.9 main'

I also attempted to add the following to my before_install.sh without success (also still old library):

sudo apt-add-repository "deb http://llvm.org/apt/trusty/ llvm-toolchain-trusty-3.9 main"   
sudo apt-get update   
sudo apt-get install -y libc++-dev libc++-helpers libc++1 libc++abi-dev lldb-3.9

How is it done correctly without building from source?

like image 255
Tobias Hermann Avatar asked Aug 29 '17 18:08

Tobias Hermann


People also ask

Which LIBC does clang use?

One can also use clang with Microsoft Visual Studio C and C++ libraries.

Are GCC and Clang interchangeable?

TL;DR: Clang is highly compatible to GCC - just give it a go. In most cases, Clang could be used as a GCC drop in replacement ( clang and clang++ are "GCC compatible drivers").

Does Apple use Clang or GCC?

Apple uses a specialized version of GCC 4.0 and 4.2 in Leopard's Xcode 3.1 that supports compiling Objective-C/C/C++ code to both PowerPC and Intel targets on the desktop and uses GCC 4.0 to target ARM development on the iPhone.

What is clang13?

Clang is an LLVM native C/C++/Objective-C compiler, which aims to deliver amazingly fast compiles (e.g. about 3x faster than GCC when compiling Objective-C code in a debug configuration), extremely useful error and warning messages and to provide a platform for building great source level tools.


1 Answers

It looks like it is not possible to do it without building from source. The range-v3 library uses a script doing exactly this.

I adjusted my travis.yml to use it too:

language: generic

dist: trusty
sudo: required

matrix:
    include:
    - os: linux
      compiler: gcc
      env: GCC_VERSION=7
        - CC=gcc-7
        - CXX=g++-7
      addons:
        apt:
          sources: ['ubuntu-toolchain-r-test']
          packages: ['g++-7']

    - os: linux
      compiler: gcc
      env: GCC_VERSION=6
        - CC=gcc-6
        - CXX=g++-6
      addons:
        apt:
          sources: ['ubuntu-toolchain-r-test']
          packages: ['g++-6']

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

    - os: linux
      compiler: clang
      env: CLANG_VERSION=5.0 LIBCXX=On
        - CC=clang-5.0
        - CXX=clang++-5.0
      addons:
        apt:
          sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-trusty-5.0']
          packages: ['clang-5.0', 'g++-6']

    - os: linux
      compiler: clang
      env: CLANG_VERSION=4.0 LIBCXX=On
        - CC=clang-4.0
        - CXX=clang++-4.0
      addons:
        apt:
          sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-trusty-4.0']
          packages: ['clang-4.0', 'g++-6']

    - os: linux
      compiler: clang
      env: CLANG_VERSION=3.9 LIBCXX=On
        - CC=clang-3.9
        - CXX=clang++-3.9
      addons:
        apt:
          sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-trusty-3.9']
          packages: ['clang-3.9', 'g++-6']

    - os: linux
      compiler: clang
      env: CLANG_VERSION=3.8 LIBCXX=On
        - CC=clang-3.8
        - CXX=clang++-3.8
      addons:
        apt:
          sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-trusty-3.8']
          packages: ['clang-3.8', 'g++-6']

before_install:
  - wget https://raw.githubusercontent.com/onqtam/doctest/master/doctest/doctest.h
  - sudo mv ./doctest.h /usr/local/include/doctest.h
  - |
    if [ -n "$GCC_VERSION" ]; then
      export CXX="g++-${GCC_VERSION}" CC="gcc-${GCC_VERSION}"
    fi
    if [ -n "$CLANG_VERSION" ]; then
      export CXX="clang++-${CLANG_VERSION}" CC="clang-${CLANG_VERSION}"
    fi
    if [ "$LIBCXX" == "On" ]; then
      sudo apt-get purge cmake
      sudo apt-get install cmake3
      cmake --version
      sudo CXX="$CXX" CC="$CC"
      sudo ./cmake/install_libcxx.sh
      export CXXFLAGS="-stdlib=libc++"
    fi

install:
  - mkdir -p build && cd build
  - cmake .. -DUNITTEST=ON

script:
  - which $CXX
  - $CXX --version
  - cmake --build . --target unittest --config Release -- -j4
like image 68
Tobias Hermann Avatar answered Sep 30 '22 06:09

Tobias Hermann