Why isn't Cabal hyperlinking my sources? - haskell

$ cabal --version
cabal-install version 1.22.2.0
using version 1.22.2.0 of the Cabal library
$ cabal install --haddock-hyperlink-source gloss-juicy
Warning: /home/theking/.cabal/config: Unrecognized field hyperlink-source on
line 91
I do have hyperlink-source: True on in my config. I added the flag just to be redundant. When I look for the docs, it is all colorized and everything, but the source code isn't linkified. What am I doing wrong?

Hopefully we're talking about the haddock command line option --hyperlinked-source (note hyperlinked).
Version 2.16.1 does not support the --hyperlinked-source option.
Version 2.16.2 does support the --hyperlinked-source option.
You might have to build 2.16.2 from the git repo:
https://github.com/haskell/haddock

Related

How do I match the right Cabal spec with each resolver in my Travis CI builds?

After updating my Haskell package's .cabal file to Cabal 2.2, most of my Travis CI builds with resolvers older than LTS 12.9 fail with:
This package description follows
version 2.2 of the Cabal specification. This tool only supports up to version XX.XX.XX.
where the version varies depending on the resolver specified in my .travis.yaml.
It seems that for each resolver I need to specify a different Cabal version In fact, because of Cabal spec changes, I appear to need a different .cabal file for each resolver. Is this the case? Is there a better way? How do I match the right Cabal spec with each resolver in my Travis CI builds?
To my knowledge, the Cabal spec version and Cabal library version always correspond, meaning that Cabal library version 2.0.C.D will support Cabal spec version 2.0 and earlier. You just need to check which version of the Cabal library ships with each LTS version, which depends on the GHC version. Some links that will help:
I put together a page correlating GHC, base, and Cabal versions: https://www.snoyman.com/base
The Stackage homepage lists the latest LTS for each GHC version in the bottom left column: https://www.stackage.org/
You can check the Cabal library version for a specific LTS by following a link like https://www.stackage.org/lts-9/package/Cabal, which in this case auto-redirects to https://www.stackage.org/lts-9.21/package/Cabal-1.24.2.0.

How to specify path to `llvm` for `ghc` and `cabal`?

I'm trying to add the new llvm path to cabal to build with -fllvm option because I receive the error that it can't see the newer version:
<no location info>: error:
Warning: Couldn't figure out LLVM version!
Make sure you have installed LLVM 5.0
I have LLVM 5 installed under this path: /usr/local/Cellar/llvm#5/5.0.2/bin/. I need to somehow tell this to cabal but I can't find where to do this. In stack there is settings file under the installed ghc, but what is the wright way to do this for cabal?
I would start with
export PATH=/usr/local/Cellar/llvm#5/5.0.2/bin/:$PATH
cabal install
and see if that works.
I don't see any mention of options to set the LLVM path in the GHC user guide or the --with-PROG section of cabal configure --help. It certainly seems like a reasonable flag to add to cabal. The GHC guide only mentions finding it on PATH.

How can configuration tools like sdl-config be used with a cabalized project?

I have a working SDL/Haskell application that I would like to build using Cabal instead of the current Makefile (because that is the "Haskell way"). The Makefile is itself very simple, and I was hoping that the default cabal build process could allow me to reconstruct a build command specified in my Makefile. The problem is that it makes use of "sdl-config", a utility that gives you all the necessary cc- compiler options:
wrapper.o: SDLWrapper_stub.h
ghc -no-hs-main `sdl-config --cflags` -Wall wrapper.c -c
Cabal does not seem to expand that into a shell call when calling GHC. How can I specify that sdl-config's options should be fed into GHC when compiling wrapper.o?
Using the configure style in Cabal, you can write a little configure script that substitutes a variable for the output of the sdl-config command. The values will then be replaced in a $foo.buildinfo.in file, yielding a $foo.buildinfo file, that Cabal will include in the build process.
General solution: the configure script
#!/bin/sh
SDLFLAGS=`sdl-config --cflags`
echo Found "$SDLFLAGS"
sed 's,#SDLFLAGS#,'"$SDLFLAGS"',' z.buildinfo.in > z.buildinfo
The $foo.builinfo.in file
cc-options: #SDLFLAGS#
The .cabal file
Build-type: Configure
When you run "cabal configure" the "cc-options" field in z.buildinfo will be created to hold:
cc-options: -I/usr/include/SDL -D_GNU_SOURCE=1 -D_REENTRANT
which cabal will include in the build.
Done.
Specific solution for pkg-config tools
For tools that support the pkg-config-style of configuration, such as sdl or cairo and others, Cabal has specific support already:
pkgconfig-depends: package list
A list of pkg-config packages, needed to build this package. They can be annotated with versions, e.g. gtk+-2.0 >= 2.10, cairo >= 1.0. If no version constraint is specified, any version is assumed to be acceptable. Cabal uses pkg-config to find if the packages are available on the system and to find the extra compilation and linker options needed to use the packages.
If you need to bind to a C library that supports pkg-config (use pkg-config --list-all to find out if it is supported) then it is much preferable to use this field rather than hard code options into the other fields.
So for sdl you just need:
pkgconfig-depends: sdl
Use the Configure build type in your $PROJ_NAME.cabal file and generate a $PROJ_NAME.buidinfo file from a $PROJ_NAME.buildinfo.in template with a configure script. Look at the source of the SDL library on Hackage for an example. This section of the Cabal user guide provides more details.
One tip: do not forget to mention $PROJ_NAME.buildinfo.in and configure in the extra-source-files field.

Registering multiple versions of packages with `ghc-pkg`?

I'm trying to install GHC and Cabal on FreeBSD 8.1.
I've installed GHC 7.0.1 (because it's current stable release) and now trying to install Cabal (to install cabal-install), but it fails with this error message.
%./Setup configure
Configuring Cabal-1.8.0.4...
Setup: At least the following dependencies are missing:
base >=4 && <3 && >=1 && <5, filepath >=1 && <1.2
%
Definitely I'm having too higher version of library.
%ghc-pkg list
/usr/local/lib/ghc-7.0.1/package.conf.d
Cabal-1.10.0.0
array-0.3.0.2
base-4.3.0.0
bin-package-db-0.0.0.0
bytestring-0.9.1.8
containers-0.4.0.0
directory-1.1.0.0
extensible-exceptions-0.1.1.2
ffi-1.0
filepath-1.2.0.0
ghc-7.0.1
ghc-binary-0.5.0.2
ghc-prim-0.2.0.0
haskell2010-1.0.0.0
haskell98-1.1.0.0
hpc-0.5.0.6
integer-gmp-0.2.0.2
old-locale-1.0.0.2
old-time-1.0.0.6
pretty-1.0.1.2
process-1.0.1.4
random-1.0.0.3
rts-1.0
template-haskell-2.5.0.0
time-1.2.0.3
unix-2.4.1.0
/home/eonil/.ghc/x86_64-freebsd-7.0.1/package.conf.d
network-2.2.1.5
parsec-2.1.0.1
%
Should I downgrade to GHC 6.x? Or can I install lower version of the packages? (or side-by-side install)
You've hit on what is known as Haskell's own DLL hell.
You can install previous versions of libraries just by appending the version number, e.g. cabal install base-3.0.3.2, although I don't know what restrictions there are with GHC 7.0.1.
You can also create little cabal sandboxes with cabal-dev or capri. These would sort of allow you to start from scratch, ignoring packages that would cause conflicts.
If none of this works and you do find you have to reinstall GHC, can I recommend you use Haskell Platform. It bundles GHC 6.12.3 with a number of useful libraries.
Update: Misread you were trying to actually install cabal install. I'd just use Haskell Platform. It comes with all this stuff already set up.
One solution would be to install ghc-6.12, which would provide Cabal-1.8. You could use that ghc to build cabal-install for the executable, then switch to ghc-7 for everything else once the cabal executable is built.
However I think you should be able to build Cabal-1.8 with ghc-7. It looks like the installer is getting confused over the base dependencies. Try doing ./Setup configure -fbase4 -f-base3 and see if that works.
Edit: if you have darcs installed, you can check out the cabal source tree. This is already set up for Cabal-1.10 and ghc-7, so it should build out of the box. You could wget the source too if you can't install darcs.
I had to downgrade GHC 6.x.
Originally I did this for Happstack. However Happstack needs at least 6.12.x of GHC and installing Cabal on FreeBSD 8.1 with GHC 7.x is too hard. (I couldn't succeed)
I just downloaded and installed GHC 6.12.3 from GHC website, and everything worked magically! Cabal, Happstack installed at once. I failed just only once because of insufficient swapping space.

Enable --hyperlink-source for "cabal install"

The command cabal haddock has very useful --hyperlink-source option.
I would like to have the source hyperlinked when building documentation with cabal install.
The ticket #517 seems to be just about it: http://hackage.haskell.org/trac/hackage/ticket/517
However, perhaps it is possible to set this flag via ~/.cabal/config file?
If not, how can I get working cabal-install build with the patch from #517 without installing Cabal-1.9, which is currently mandatory (due to one patch from December)?
Currently you cannot get the equivalent of the --hyperlink-source option when using the "all in one" cabal install command. The ticket you cite is exactly about this issue.
For me this worked:
cabal update
cabal install haddock
Edit config file ~/.cabal/config
Enable Documentation: True (removing "-- " at the beginning of the line is fine)
Cabal Library:
cd ...someNicePlace...
cabal unpack Cabal
Edit file Distribution/Simple/Setup.hs, therein find defaultHaddockFlags = ...
I switched some of them from False to True:
...
haddockHoogle = Flag True,
...
haddockHtml = Flag True,
...
haddockExecutables = Flag True,
...
haddockHscolour = Flag True,
...
having haddockHscolour the only important one (don't have to change the others if not want to).
Install updated Cabal Library:
sudo cabal install --global
cabal-install (cabal shell command)
To get the updated Cabal Libary working within cabal shell command, I reinstalled cabal-install also:
cd ...someNicePlace...
cabal unpack cabal-install
sudo cabal install --global
Since then the shell command cabal --version says to me:
cabal-install version 1.16.0.2
using version 1.16.0.3 of the Cabal library
And, as wanted, any new cabal install is now installing full haddock html documentation with source codes hyperlinked as default.
Ticket #517 is about passing haddock options via cabal, like if you have special needs like building a hoogle database or usa a different CSS
Most users will be happy with standard haddock and hyperlinked sources though, which is possible with Cabal-1.8. Ticket #517 is if you have bigger needs.
Simply calling cabal haddock --hyperlink-source should do the trick.
If you want this as the default, you can edit ~/.cabal/config as you mentioned.

Resources