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

Allow C++ compiler versions to be specified in yaml-file

Open jpauwels opened this issue 9 years ago • 13 comments

Using a specific compiler version required up to now to manually export $CC and $CXX (a hack that is very common in the wild, see linked issues). This changeset should solve this so you can simply do compiler: gcc-4.9. Closes #3871, partly implements #979, replaces PR#542 (which accurately describes the problem, but just makes the hack easier).

Additionally, this solves the minor problem that announce displays the given compiler: anystring without sanitising the string, such that it prints a different version (the specified anystring) than the one that is actually used (the system default if not either g++ or clang++ is specified). Finally, this changeset also sets the default OS X compiler to clang instead of gcc.

jpauwels avatar Feb 20 '16 15:02 jpauwels

Okay, seems like the spec needs to be updated for the CI check to pass, but I could use some help for that. I basically learned a bit of Ruby just to fix this issue and I'm not even 100% sure what a spec is :-) (some sort of Ruby testing/coverage framework is what I can deduce).

jpauwels avatar Feb 20 '16 16:02 jpauwels

Sorry for the delay.

The failure is coming from here: https://github.com/travis-ci/travis-build/blob/bbe7c12b6f2c8bdc6cd9a7d3e839a729048648ae/spec/build/script/cpp_spec.rb#L88

This is testing whether gcc --version should be run when compiler: gcc. And I think it should.

BanzaiMan avatar May 09 '16 06:05 BanzaiMan

Well, maybe it is legitimate to show g++ --version output when we have compiler: gcc. Then the spec should be changed.

BanzaiMan avatar May 09 '16 07:05 BanzaiMan

I would love it if we could go forward with this. https://github.com/travis-ci/travis-ci/issues/3871 is very annoying.

ldionne avatar Jun 16 '16 15:06 ldionne

@BanzaiMan I could use some more input on best Ruby/Travis practices, before starting to update the spec. Notably, how to set platform specific DEFAULTS.

jpauwels avatar Jun 18 '16 19:06 jpauwels

Actually, I don't understand why it's not possible to simply avoid modifying the compiler in the cxx and cc methods, i.e. instead of

def cxx
    case compiler
    when /^gcc/i, /^g\+\+/i then
        'g++'
    when /^clang/i, /^clang\+\+/i then
        'clang++'
    else
        'g++'
    end
end

just use

def cxx
    compiler
end

This way, whatever is being set in compiler: xxx in the script will be used as CXX, which I think is what we want.

ldionne avatar Jun 18 '16 20:06 ldionne

It seems like we don't need all the logic added in this PR (and the removal of the default compiler); we just need to stop overwriting the compiler set by the user.

ldionne avatar Jun 18 '16 20:06 ldionne

@ldionne It's more nice to have than strictly necessary. It's just some string sanitising to prevent users from making mistakes and to make matching pairs of C and C++ compilers. Anyway, I managed to make the spec pass now. I guess I should add some new test cases too and then wait for @BanzaiMan's input before I squash the commits to merge.

jpauwels avatar Jun 18 '16 20:06 jpauwels

@jpauwels Ok, I agree. For what it's worth, this LGTM. The only thing that I can imagine could break builds is the fact that you changed the default to clang++ on OS X, but that should be fine since Clang has been the default compiler on OS X for a while and g++ is even aliased to clang++.

ldionne avatar Jun 18 '16 20:06 ldionne

Is this pull request going anywhere?

brettwooldridge avatar Dec 19 '16 10:12 brettwooldridge

yeah, it would be nice if travis could automatically switch to whatever compiler version I want without manually having to do sudo apt-get install <insert compiler here> manually in my .travis.yml.

AraHaan avatar Feb 17 '17 23:02 AraHaan

Bump. This is becoming increasingly necessary for those of us who want to build only with the supported GCC versions (currently 6 and 7). My current workaround is to set language: c and export CXX in a before_install script based on the value of $CC... not ideal.

A possible alternative to consider would be giving access to the compiler field through some environment variable (${TRAVIS_COMPILER}?).

CJKay avatar Apr 15 '18 11:04 CJKay

I was thinking of this and well what if one wants gcc 8.x but travis has up to 7.x. This has so know if it should install gcc 8 on it’s own or whatever the current version is until travis provides that version too.

Also the end of hacking gcc 4.6 or so or clang 2/3 which are default with travis to whatever versions people preset in yml would help a lot to prevent useless or time consuming compiler installs or hacks for them.

AraHaan avatar May 02 '18 20:05 AraHaan