2

I have a project that requires GHC 7.10.2, so to use Travis CI I must install the required version of GHC myself in a pre-install step.

I currently have this working with

env:
 - CABALVER=1.22 GHCVER=7.10.2

before_install:
 - |
    travis_retry sudo add-apt-repository -y ppa:hvr/ghc
    travis_retry sudo apt-get update
    travis_retry sudo apt-get install cabal-install-$CABALVER ghc-$GHCVER
    export PATH=/opt/ghc/$GHCVER/bin:/opt/cabal/$CABALVER/bin:$PATH

in my .travis.yml; but am limited to using the "legacy" infrastructure because of my use of sudo.

I'd like to take advantage of the new container-based infrastructure, and have followed the migration docs as far as I can, resulting in

sudo: false

env:
 - CABALVER=1.22 GHCVER=7.10.2

addons:
  apt:
    sources:
    - hvr-ghc
    packages:
    - cabal-install-$CABALVER
    - ghc-$GHCVER

before_install:
 - |
    export PATH=/opt/ghc/$GHCVER/bin:/opt/cabal/$CABALVER/bin:$PATH

as what seems to me should be the equivalent of the above. But this proceeds to use the default (7.4) version of GHC, which results in a failed build.

How do I build for Haskell 7.10.2 in the container-based infrastructure? Specifically, what should I have in my .travis.yml?

dfeuer
  • 48,079
  • 5
  • 63
  • 167
orome
  • 45,163
  • 57
  • 202
  • 418

2 Answers2

1

There's an explanation of how to do this with Stack in the guide, you can see a full example at:

https://github.com/commercialhaskell/stack/blob/master/doc/GUIDE.md#travis-with-caching

Michael Snoyman
  • 31,100
  • 3
  • 48
  • 77
  • That approach (which I'll try next; just asking ahead now) looks like it would require me to build the whole Haskell stack manually. I'm not sure I know how to do that. – orome Sep 28 '15 at 20:10
  • 2
    @raxacoricofallapatorius It will just fetch all the packages you need from `stackage`. Installing `stack` is painless if you follow the tutorial. I would say this is the best approach specially in the container-base infrastructure because you will get caching for free. I have tried it and it works like a charm. – Pierre R Sep 28 '15 at 20:16
  • Is what's there in the example sufficient to build a full 7.10.2 stack, or do I need more? (Again, I'll check when I have access; just looking ahead.) – orome Sep 28 '15 at 20:28
  • 2
    The example handles everything you need for the full tool chain – Michael Snoyman Sep 28 '15 at 20:58
  • That fails [pretty spectacularly](https://travis-ci.org/orome/crypto-enigma/builds/82636563). What am I missing? – orome Sep 28 '15 at 21:41
  • I have no idea, you haven't told us anything that explains why it's failing. There are many examples in the wild of it succeeding (e.g., the yaml repo). – Michael Snoyman Sep 29 '15 at 03:33
  • @raxacoricofallapatorius You need to have a `stack.yaml` file for your project. The command is failing because you are missing this file. The clue is this output from your Travis build: `Run from outside a project, using implicit global config` – Gabriella Gonzalez Sep 29 '15 at 04:00
  • Was that always a link to the Travis output? If so, I missed it first time around. I could have sworn it was plain text. – Michael Snoyman Sep 29 '15 at 07:41
  • Ah. No idea about `stack`. Never used it. What would that look like for `7.10.2`? – orome Sep 29 '15 at 11:47
  • The page I linked to is the user's guide for Stack. The top of the page gives instructions on getting started. But tldr use stack init like the error message says – Michael Snoyman Sep 29 '15 at 15:05
  • I see — so I need to use Stack locally too. I don't yet. Will I encounter any issues with my local Haskell/GHC config if I install it and used it for this? Does installing it locally for (just) this purpose have side effects? – orome Sep 29 '15 at 17:11
  • No. And you don't need to use it locally. You just need a stack.yaml file. – Michael Snoyman Sep 29 '15 at 19:00
  • Cool. Works now (I'll make sure it continues to for a bit). I had to dig around to get [`pcre.h`](http://stackoverflow.com/a/27819983/656912), whatever that is, and install bunch of packages along with Stack, but so far so good. How do I confirm thought that it's doing what I expect? It no longer prints a GHC version to the log — where in `.travis.yml` should I add `ghc --version`? – orome Sep 29 '15 at 19:05
  • stack exec -- git --version. At this point, I'd recommend reading through the guide, it will cover most of these kinds of questions – Michael Snoyman Sep 29 '15 at 19:42
  • Now it fails. I've made no code changes at all, just changes to the one or two changes to a readme file, but [now my Travis builds fail](https://travis-ci.org/orome/crypto-enigma/jobs/82974788) with "No compiler found, expected minor version match with ghc-7.10.2 (x86_64) (based on resolver setting in /home/travis/build/orome/crypto-enigma/stack.yaml). Try running stack setup to locally install the correct GHC" – orome Sep 30 '15 at 17:47
  • 1
    That's because you're trying to use `ghc` before installing it. You just got lucky with the cache hit in the first few runs most likely. Use `--install-ghc` on the `stack ghc` call. Also, this is really getting too long for an SO comments section... – Michael Snoyman Sep 30 '15 at 17:57
  • This is [now tripping me up](http://stackoverflow.com/q/33437022/656912) (I think) when I try to use automatic deployment to Hackage. – orome Oct 30 '15 at 13:52
1

I suspect you are using language: haskell. Could you try with language: c.

My understanding is that travis does not really support ghc-7.10.x just yet (there are outstanding issues). The workaround is to bypass and install it manually (using the hvr-ghc ppa); hence the language: c instead of haskell.

Another tip. Start by removing env. I am pretty sure it won't work inside your addons. Simply use ghc-7.10.2 and cabal-1.22. Now youraddonsshould work fine. Check your travis log to be sure.

I can confirm the stack tutorial (link by Michael Snoyman) is quite good. But it should work with or without stack.

For reference here is a travis file where I try to minimize the usage of sudo to the strict minimum:

https://github.com/PierreR/language-puppet/blob/450ca249e23300351085d24fd58dcf9f429769d5/.travis.yml

As you see, I still use the old travis infra because I need Ruby2.x with the C header.

Here is kind of the same travis file but without using stack (stack is only useful with caching):

https://github.com/bartavelle/language-puppet/blob/master/.travis.yml

Pierre R
  • 216
  • 1
  • 7
  • Any ideas on how to get this to work without Stack? [This answer](http://stackoverflow.com/a/32830882/656912) assumes Stack, which I don't use. – orome Sep 29 '15 at 15:40
  • I said explicitly it should work with or without stash. It doesn't ? – Pierre R Sep 29 '15 at 18:31
  • By using `language: c` there will be no default `ghc` so at least you should see that you are now using the expected ghc-7.10.x. – Pierre R Sep 29 '15 at 18:38
  • I just get `"./configure && make && make test" exited with 127`. – orome Sep 29 '15 at 18:43
  • Ok I might know of one problem. Could you replace ` - ghc-$GHCVER` with `ghc-7.10.2` in `addons` ? Don't use `env` for now, you have only one version anyhow. – Pierre R Sep 29 '15 at 18:49