Cabal rebuild all with enable-shared flag - haskell

I am having an issue with building a shared library with ghc and I think I need to rebuild my haskell packages with --enable-shared, is there an easy way to rebuild all of my packages with cabal with the flag --enable-shared?

If you have a ~/.cabal/world, cabal install --reinstall --enable-shared world could work, but test with the --dry-run flag first. That will, however only take care of cabal-installed packages. If you have packages installed with your distro's package manager, the distro might also provide shared versions for those (otherwise, you'd have to do it manually). Also, it would probably be helpful to set shared: True in ~/.cabal/config.

Related

For cabal, what does only-dependencies flag mean?

I'm fairly new to Haskell, and upon seeing this flag, e.g. in this dockerfile, I can't ever seem to find an explanation for what it does. "Install only the dependencies necessary to build the given packages," in the cabal help install doesn't say much to me.
If I'm not building inside a docker container, I use sandboxes. Is this flag applicable to either of these situations?
For cabal, what does only-dependencies flag mean?
It can be spelled as both --dependencies-only and --only-dependencies and it simply means that it will install all, and only, the dependencies the specific package requires (without installing or building the packages themselves). Note that by default tests and benchmark dependencies will not be installed; for them you need to add --enable-tests and --enable-benchmarks respectively.
Is this flag applicable to either of these situations?
Yes, this can be used just fine with cabal sandboxes as well as without.
What's then the difference between it and simply running cabal install, which has worked for me so far?
cabal install will install both those dependencies and the packages themselves. Same for cabal build. cabal install --only-dependencies will only install the dependencies those packages require.

Reinstall behavior of cabal-dev

The latest cabal-install that I've been using (0.13.3, from the darcs repo) is nice; it lets you know when you might break your GHC installation with reinstalls. What I want to know is this: suppose a cabal install foo would perform a reinstall that would break my GHC. What would happen if I cabal-dev install foo instead? Would I be able to avoid breaking GHC? Could I actually make use of the foo package in a cabal-dev sandbox, or would it just be a broken sandbox?
Example: yesod, GHC 7.4.1, cabal-dev 0.9 built from github source, Cabal 1.14.0 library.
Just to clarify, if I am understanding you right, you are not breaking GHC in either case. I believe you are referring to installing a package, which then reinstalls one of the underlying dependencies of another package, therefore breaking that other package's dependency chain and preventing it from properly working/compiling when used. Simply removing .ghc from your home folder and re-doing cabal installs typically resolves this problem, albeit in a really painful way.
When you use cabal-dev, all the cabal install steps and ghc-pkg register steps are done in a local sandbox environment. Your global/user ghc packages are not at all touched. Since you typically instantiate one cabal-dev sandbox per project, clashes like described above don't typically happen.
To get to your question - it depends entirely on what is already installed in that particular cabal-dev sandbox. If there are no conflicts, it wouldn't break anything. If you are forcing a --reinstall, you might have to --reinstall any packages in the local cabal-dev sandbox that depend on the package you just reinstalled.
In any case, your GHC installation itself would not break (or be altered in any way) and you can always rm -rf cabal-dev under your project folder and redo cabal-dev install.
Hope this helps.

Reinstall all depending packages with cabal manually [duplicate]

I want to compile my program with profiling, so I run:
$ cabal configure --enable-executable-profiling
...
$ cabal build
...
Could not find module 'Graphics.UI.GLUT':
Perhaps you havent installed the profiling libraries for package 'GLUT-2.2.2.0'?
...
$ # indeed I have not installed the prof libs for GLUT, so..
$ cabal install -p GLUT --reinstall
...
Could not find module 'Graphics.Rendering.OpenGL':
Perhaps you havent installed the profiling libraries for package 'OpenGL-2.4.0.1'?
...
So, the problem is, that unlike cabal's usual welcome behavior, cabal doesn't resolve the dependencies and install them when needing profiling libraries.
I can work around it by resolving the dependencies manually (by following errors that appear after a while of compiling):
$ cabal install -p OpenGLRaw --reinstall
$ cabal install -p StateVar --reinstall
$ cabal install -p Tensor --reinstall
$ cabal install -p ObjectName --reinstall
$ cabal install -p GLURaw --reinstall
$ cabal install -p OpenGL --reinstall
$ cabal install -p GLUT --reinstall
And then repeat for my next dependency..
Is there a better way to do this? i.e do make cabal do the work on its own as it does for normal libraries?
I've enabled library-profiling: True in my ~/.cabal/config file. From then on, any new installations will automatically enable profiling.
Unfortunately that still means I had to manually reinstall for the old packages already installed. Although, after a while of doing this manually, I now have most packages reinstalled with profiling enabled...
From a comment by Tom Lokhorst:
I do hope someone will come along with a better answer, one that would not require me to reinstall the complete Haskell Platform manually next time.
For future visitors:
The task of installing profiling versions of all installed libraries has become less of a chore, cabal (cabal-install) now keeps track of what was installed using it in the world file in the .cabal directory (on linux, that would be $HOME/.cabal, on Windows something like C:\Users\%YOU%\AppData\Roaming\cabal\, on OSX ??).
So after enabling profiling in the config file (in the same directory), and clearing GHC's package database (you can find the locations of the global and user db per ghc-pkg list nonexisting; remove the cabal-installed packages from the global database with ghc-pkg unregister packagename if you have any, rename or delete the entire user db - this is necessary because the world file only tracks explicitly installed packages, not their dependencies), installing everything with profiling support should work as follows:
$ cabal install --reinstall world --dry-run
First run with --dry-run to check for problems before actually reinstalling anything. If it would reinstall boot packages like process or directory, that's a bad sign, if you don't know how to handle it, ask on the #haskell IRC channel, one of the mailing lists, or here for guidance. If it fails to find a consistent install plan due to new versions on hackage of some packages which are incompatible with each other, that can usually be solved by editing the world file and constraining allowable versions of some packages.
Then, if you are optimistic that nothing will badly break,
$ cabal install --reinstall world
and have a nice pot of tea while GHC is busy compiling.
Daniel Fischer's answer looks good, but for some reason my ~/.cabal/world library only contained entries for libraries directly installed, and not their dependencies.
Instead, I dumped out a list of all installed libraries using
$ ghc-pkg list > list
This lists the libraries installed system-wide and locally. Therefore, I edited the list file to remove the first portion (containing libraries installed system-wide) leaving only the lines after /home/<user>/.ghc/.... Finally, I ran
$ cabal install --reinstall $(cat list)
This worked for me. You should maybe do --dry-run first. Then go make a pot of tea. Or bake a cake.
it appears there is no way right now: Ticket #282 - profiling versions of libraries not managed well "As usual the problem is lack of devevloper time to implement all these
nice features we all want."
For visitors 2016+: Just install ghc-prof
Debian Linux Systems:
sudo apt-get install ghc-prof
Arch Linux Systems:
sudo pacman -S ghc-prof

cabal-install and Debian

So, this is a bit of a personal problem, but maybe people will have good advice or workarounds.
The problem is about installing cabal-install and haskell-platform under Debian.
When you apt-get install haskell-platform, it ships with cabal-install, and its command cabal is available.
Now this cabal-install is not up-to-date:
> which cabal
/usr/bin/cabal
> /usr/bin/cabal --version
cabal-install version 0.8.0
using version 1.8.0.2 of the Cabal library
But, my understanding of running cabal update is that it updates cabal, but since it is not a "Debian thingy", it puts it in ~/.cabal/bin/.
> ~/.cabal/bin/cabal --version
cabal-install version 0.8.2
using version 1.8.0.2 of the Cabal library
Now my system has 2 cabals, and the one I get by typing cabal is not the one I want to use... Because it'll keep updating the other one instead of itself, and is therefore ineffective.
So what I did was I aliased it in my ~/.bashrc:
alias cabal='~/.cabal/bin/cabal'
Now:
> cabal --version
cabal-install version 0.8.2
using version 1.8.0.2 of the Cabal library
So, my final questions:
Is there a deb repository that holds cabal 0.8.2?
Could my current solution lead to problems? (For instance, which cabal still points to my useless /usr/bin/cabal, so if scripts use this command they'll get fooled...)
Did someone come up with a better solution? (Mine is a bit ad-hoc but that's all I could come up to with my poor knowledge of what is happening behind the scenes...)
Please correct me if anything I say above is wrong or inaccurate.
What I do is installing cabal with the --global flag. This will install cabal into /usr/local/bin/cabal, thus it will always superseed the Debian packages cabal.
Another way, is to generally avoid the Debian packages and install the Haskell platform straight from its source. This approach is also better, if you always want to have the latest releases of the Haskell libs.
I keep my user-local $HOME/.cabal/bin in the front of the PATH.
I install only ghc6, ghc6-prof, ghc6-doc and cabal-install from the distribution packages. I don't use distribution cabal-install for anything more than to bootstrap the new ~/.cabal.
All the rest I install with cabal install, including the newer cabal itself.
When I want to use newer GHC, I deploy it in /usr/local/stow/ghcVERSION, and enable it with GNU stow (it adds symlinks in /usr/local which, again, has precedence in my PATH). When I want to switch back to the distribution GHC I just run stow -D to remove all symbolic links to it.
I consider using cabal-dev to have project-specific cabal installations, and avoid broken dependencies which happen with cabal from time to time.
As a matter of fact I don't use Haskell Platform at all because I don't need all of it and find it easier to be able to install individual libraries. I do not install distribution libraries, because not all of them are available or are exactly the versions I need; and it is much easier to control conflicts if all of them are installed in the same place (~/.cabal in my case). I do not install anything with --global, because I think it is wrong and difficult to rollback.
Of course this information gets out of date, but yes, Debian unstable and testing have, at the time of writing, cabal-install 0.10.2.
Generally, the Debian packaging of Haskell stuff is aimed at users who want a set of packages that is known to work together, i.e. no dependency hell, at the expense of not always having the latest and greatest. This includes cabal-install. I use cabal-install from the repositories, and only to install those libraries that have not been packaged for Debian yet.
Disclaimer: I am one of the guys that create those packages for Debian.
On Ubuntu I also tend to install GHC via stow, ignoring the system packages altogether.
One slight twist from jetxee's approach is that I do install the Haskell Platform (from source), lumping it in with the GHC stow directory. I suppose I ought to call the paths /usr/local/stow/haskell-platform-VERSION, but I tend to use /usr/local/stow/ghc-VERSION instead.

Cabal not installing dependencies when needing profiling libraries?

I want to compile my program with profiling, so I run:
$ cabal configure --enable-executable-profiling
...
$ cabal build
...
Could not find module 'Graphics.UI.GLUT':
Perhaps you havent installed the profiling libraries for package 'GLUT-2.2.2.0'?
...
$ # indeed I have not installed the prof libs for GLUT, so..
$ cabal install -p GLUT --reinstall
...
Could not find module 'Graphics.Rendering.OpenGL':
Perhaps you havent installed the profiling libraries for package 'OpenGL-2.4.0.1'?
...
So, the problem is, that unlike cabal's usual welcome behavior, cabal doesn't resolve the dependencies and install them when needing profiling libraries.
I can work around it by resolving the dependencies manually (by following errors that appear after a while of compiling):
$ cabal install -p OpenGLRaw --reinstall
$ cabal install -p StateVar --reinstall
$ cabal install -p Tensor --reinstall
$ cabal install -p ObjectName --reinstall
$ cabal install -p GLURaw --reinstall
$ cabal install -p OpenGL --reinstall
$ cabal install -p GLUT --reinstall
And then repeat for my next dependency..
Is there a better way to do this? i.e do make cabal do the work on its own as it does for normal libraries?
I've enabled library-profiling: True in my ~/.cabal/config file. From then on, any new installations will automatically enable profiling.
Unfortunately that still means I had to manually reinstall for the old packages already installed. Although, after a while of doing this manually, I now have most packages reinstalled with profiling enabled...
From a comment by Tom Lokhorst:
I do hope someone will come along with a better answer, one that would not require me to reinstall the complete Haskell Platform manually next time.
For future visitors:
The task of installing profiling versions of all installed libraries has become less of a chore, cabal (cabal-install) now keeps track of what was installed using it in the world file in the .cabal directory (on linux, that would be $HOME/.cabal, on Windows something like C:\Users\%YOU%\AppData\Roaming\cabal\, on OSX ??).
So after enabling profiling in the config file (in the same directory), and clearing GHC's package database (you can find the locations of the global and user db per ghc-pkg list nonexisting; remove the cabal-installed packages from the global database with ghc-pkg unregister packagename if you have any, rename or delete the entire user db - this is necessary because the world file only tracks explicitly installed packages, not their dependencies), installing everything with profiling support should work as follows:
$ cabal install --reinstall world --dry-run
First run with --dry-run to check for problems before actually reinstalling anything. If it would reinstall boot packages like process or directory, that's a bad sign, if you don't know how to handle it, ask on the #haskell IRC channel, one of the mailing lists, or here for guidance. If it fails to find a consistent install plan due to new versions on hackage of some packages which are incompatible with each other, that can usually be solved by editing the world file and constraining allowable versions of some packages.
Then, if you are optimistic that nothing will badly break,
$ cabal install --reinstall world
and have a nice pot of tea while GHC is busy compiling.
Daniel Fischer's answer looks good, but for some reason my ~/.cabal/world library only contained entries for libraries directly installed, and not their dependencies.
Instead, I dumped out a list of all installed libraries using
$ ghc-pkg list > list
This lists the libraries installed system-wide and locally. Therefore, I edited the list file to remove the first portion (containing libraries installed system-wide) leaving only the lines after /home/<user>/.ghc/.... Finally, I ran
$ cabal install --reinstall $(cat list)
This worked for me. You should maybe do --dry-run first. Then go make a pot of tea. Or bake a cake.
it appears there is no way right now: Ticket #282 - profiling versions of libraries not managed well "As usual the problem is lack of devevloper time to implement all these
nice features we all want."
For visitors 2016+: Just install ghc-prof
Debian Linux Systems:
sudo apt-get install ghc-prof
Arch Linux Systems:
sudo pacman -S ghc-prof

Resources