Enable --hyperlink-source for "cabal install" - haskell

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.

Related

Cabal install tidal ends with warning

I'm trying install tidal in command line this way:
cabal install tidal
but it ends with this message:
Warning: You asked to install executables, but there are no executables in
target: tidal. Perhaps you want to use --lib to install libraries instead.
Return of:
cabal install tidal --lib
is:
Resolving dependencies...
Up to date
If I check ghk-pkg list, there is no package tidal
...
Have somebody similar problem or what I'm doing wrong?
My environment is:
Windows 10 Education
Haskell 8.4.3
Cabal 3.2.0.0
Ghc 8.10.1
Thank you for help.
Like Stack for a longer time, Cabal-install does now (as of 3.2) not really install libraries anymore – in the sense of, change the computer's state so that GHC can access the library on it†. Both tools only install executables now. It used to do that for libraries too, but that was stopped with the now default Nix-style builds.
Now (and, really, also already before), the way to use a library is instead to just depend on it, and let Cabal figure out behind the scenes if it needs to be installed. I.e., you add a .cabal file to your .hs source file with build-depends: tidal in it. Then when you say cabal install ., it will first download and install the library before then using it for building your own executable.
†Of course both Stack and Cabal do technically speaking install libraries, just they don't globally register them. I.e., cabal knows where it has installed the library, but you're not really supposed to know about that. It's in the spirit of continuous integration: if your code builds now with the particular state of libraries you happen to have installed, that's not very reliable. If it builds with just those libraries that are explicitly listed in a project file, the chances are much better that future-you (or somebody else) will still be able to use your code on another computer without hours of figuring out what libraries to install first.
cabal install --lib tidal doesn't install the library binaries in a location managed by ghc-pkg. The binaries remain in the Cabal "store".
What it does is to create a plaintext GHC package environment file that is picked up by standalone invocations of ghc and ghci and tells them where to look for the extra libraries.
By default (as mentioned in the docs) this package environment file will be created at ~/.ghc/$ARCH-$OS-$GHCVER/environments/default and will be picked by ghc and ghci invocations made anywhere.
We can also supply an extra --package-env parameter to create the environment file in a local folder, which will only affect ghc and ghci invocations made in that folder. For example:
cabal install --lib --package-env . tidal
cabal projects themselves ignore environment files, as their package environments are constructed from the build-depends section of the cabal file for the sake of reproducibility. But environment files are useful for not having to create a cabal project in the first place, if you only need it for playing with the library in ghci, or if you are compiling simple programs using ghc only.

Why isn't Cabal hyperlinking my sources?

$ 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

Can cabal not un-install packages?

cabal help shows thers isnot "uninstall" option.
then what's the best way to uninstall the packages installed by cabal ?
% cabal update
% cabal install mighttpd2
mighttpd2 is installed successfully. However the ghc-pkg cannot find & unregister it:
% ghc-pkg list | grep -i might
% ghc-pkg unregister mighttpd2
ghc-pkg: cannot find package mighttpd2
Sincerely!
>find .cabal | grep -i mighttp
.cabal/share/doc/mighttpd2-2.3.3
.cabal/share/doc/mighttpd2-2.3.3/LICENSE
.cabal/share/mighttpd2-2.3.3
.cabal/share/mighttpd2-2.3.3/sample.conf
.cabal/share/mighttpd2-2.3.3/sample.route
.cabal/packages/hackage.haskell.org/mighttpd2
.cabal/packages/hackage.haskell.org/mighttpd2/2.3.3
.cabal/packages/hackage.haskell.org/mighttpd2/2.3.3/mighttpd2-2.3.3.tar.gz
>ghc-pkg list | grep -i package\.conf
/usr/local/lib/ghc-7.0.3/package.conf.d:
/home/sw2wolf/.ghc/i386-freebsd-7.0.3/package.conf.d:
So ".cabal/packages/hackage.haskell.org" cannot be seen by ghc-pkg.
you might not have the Cabal path as part of your GHC path.
step 1
First, try to find out what your GHC package path is,
ghc-pkg list
# displays stuff like "/home/username/.../package.conf.d"
then, make sure the one Cabal is writing to is active. For me, Cabal adds packages to
/home/username/.ghc/x86_64-linux-7.0.4/package.conf.d
step 2
If there is no such directory on your system, see what Cabal's writing.
strace -f -o trace.txt cabal install mighttpd2
grep "package\.cache" trace.txt
then add the package path to this system environment variable
export GHC_PACKAGE_PATH=NEWPATH:/usr/local/lib/ghc-7.0.3/package.conf.d
try again, if it doesn't work proceed to step 3
step 3
look in that directory and see if there's a file like
mighthttpd2-version-LONGHASHCODE.conf
if it's there, then you probably need to recache
ghc-pkg recache --user
The GHC package system is not used for executables, and the mighttpd2 package only builds executables. To uninstall it, simply remove the two executables (mighty and mkindex) and the two data files (sample.conf and sample.route) listed in the package's cabal file. You can find which directories these files were installed to by perusing cabal's config file in ~/.cabal/config.

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.

ghc can't find my cabal installed packages

I've installed ghc 6.12.3, and then the Haskell Platform. I'm trying to compile a test program:
$ ghc test.hs
test.hs:3:0:
Failed to load interface for `Bindings':
Use -v to see a list of the files searched for.
so, naturally, I do
cabal install Bindings
Which works fine, and places the package in ~/.cabal/lib/bindings-0.1.2 The problem is, that when I go to compile again with ghc, it still doesn't find the package I've installed with cabal.
compiling in verbose mode gives:
ghc -v test.hs
Using binary package database: /home/ludflu/ghc/lib/ghc-6.12.3/package.conf.d/package.cache
Using binary package database: /home/ludflu/.ghc/x86_64-linux 6.12.3/package.conf.d/package.cache
As suggested by another stackoverflow user, I tried:
ghc-pkg describe rts > rts.pkg
vi rts.pkg # add the /home/ludflu/.cabal/lib to `library-dirs` field
ghc-pkg update rts.pkg
But to no avail. How to I add the .cabal to the list of package directories to search?
Thank you!
You can check which packages are installed with ghc-pkg list. It may be that you need to either specify the packages to ghc with -package <pkgname> or I believe adding --make to will trigger a chasing down of dependencies, including packages.
Edit: the bindings package is obsolete indeed, see the hackage page. This isn't a package management problem, the only module available is Bindings.Deprecated, which you are perfectly able to load, even though it is an empty module. I believe the relevant parts have been broken out into bindings-<module>, so if you want the bindings functionality you should look to those packages.
http://www.haskell.org/haskellwiki/Cabal-install
One thing to be especially aware of, is that the packages are installed locally by default by cabal, whereas the commands
runhaskell Setup configure
runhaskell Setup build
runhaskell Setup install
install globally by default. If you install a package globally, the local packages are ignored. The default for cabal-install can be modified by editing the configuration file.
I was getting the same error with the runhaskell command. I used the cabal in the directory that had the .cabal file and was able to resolve the error.

Resources