Using cmake with haskell

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
18 messages Options
Reply | Threaded
Open this post in threaded view
|

Using cmake with haskell

Robert Clausecker
Hello readers of haskell-cafe!

I asked this question on Stackoverflow:

        http://stackoverflow.com/q/5969616/417501

Because I want to get a good answer, I cross post it here. It may be
interesting:

        Is it possible to use cmake for Haskell projects?
       
        I am planning a project written in Haskell, maybe there are some
        parts in C as well. For the buildsystem I decided against the
        common choice for Haskell programs cabal, mainly because I want
        to learn how building programs in other languages works.
       
        I heard about CMake and I think it is a pretty cool product.
        Although I have no knowledge in how to use it, I want use CMake
        for that project, just to find out how it works. Googleing did
        not reveal any facts about how to use cmake with haskell, and
        all tutorials I read were rather confusing. Is it possible, and
        if yes, how is it possible, to compile a projectwritten in
        Haskell using CMake?

Robert Clausecker


_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Using cmake with haskell

Bryan O'Sullivan
On Wed, May 11, 2011 at 12:54 PM, Robert Clausecker <[hidden email]> wrote:
       Is it possible to use cmake for Haskell projects?

Yes, but you shouldn't. Just use the cabal build system instead. It solves the same kinds of problems, but requires far less effort than dealing with CMake.
 
       I heard about CMake and I think it is a pretty cool product.

It is not. It's a fairly terrible piece of software. It has a grotesque macro language, lots of strange undocumented behaviours, and is generally a nightmare to work with. The only thing it's adequate for is managing the build and packaging of very complex cross-platform software packages. You certainly shouldn't use it for anything else. In fairness, the CMake developers are very nice and responsive, which is just as well given the number of times you'll have to ask them "why isn't this doing something sane?" if you use it for a real project.

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Using cmake with haskell

Marc Weber
In reply to this post by Robert Clausecker
Excerpts from Robert Clausecker's message of Wed May 11 21:54:32 +0200 2011:
> Because I want to get a good answer, I cross post it here. It may be
> interesting:
If you do this you should consider adding a reference to this thread on
stackoverflow as well .. You can read this mailinglist online
(haskell.org -> mailinglists or such)

why cmake?
+ maybe some paralell compiling possible (that's a make feature)
- ghc has to be run once for each file (slow down)

cabal is a standard. And we all like it for that.
It makes packaging all the libraries for nixos/gentoo/debian/... a *lot*
easier.

Not everything which can be done should be done as well.
Think alone about all the dependency handling done in cabal. There is no
need to duplicate this all.

So the interesting question would be discussing which parts of your
projects are in C for what reason. Then you should consider raising this
question again if cabal can't be made compiling those view files easily.

If you know what you need its also a good time to ask again for other
projects having already solved build tasks like this.

If you're looking for work to learn something new and to get your hands
dirty join darcs, yi, .. or such.
Sourceforge projects can even flag themselves as "need help at ...".

Marc Weber

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Using cmake with haskell

Gregory Crosswhite-2
In reply to this post by Bryan O'Sullivan
On 5/11/11 3:11 PM, Bryan O'Sullivan wrote:
> It's a fairly terrible piece of software.
My experience is that it is the only cross-platform build system I have
used to date that hasn't made my eyes bleed, though I only use it for
C/C++/Fortran.  I suppose that counts as a personal testimonial in favor
of it.  Put another way: it is definitely the worst of all build systems
--- except for all the rest.  :-)

Also, my most recent experience with Cabal is that it is a serious PITA
if you want to do any non-trivial cross-language stuff with it, since
essentially its only support for non-Haskell stuff is its hard-coded
support for C/C++.  It is true that you can add hooks to do arbitrary
stuff, but at that point you are basically bolting your own build system
on top of it and have to start from scratch --- or worse, *autotools*
(SHUDDER!)

At one point I was working on my own build system Blueprint that was a
generalized build system where GHC was just one specific tool within the
system, but although I got it working just fine, at some point
implementing all of the of the crazy stuff that is needed for proper GHC
package support burned me out so I stopped short of finishing it since
it's not like I didn't have other things to do with my time.  :-)  You
might ask why I didn't just use the Cabal libraries to help myself out,
and while I was able to get some use out of them unfortunately most the
functionality in the Cabal libraries is simply not designed to be used
by third parties.  (For the curious, the sources are available at
www.github.com/gcross/blueprint;  look at the *blueprint* branch, not
the *master* branch which was a first attempt that has been superseded
by a complete rewrite.)

So anyway, what it comes down to in my experience is

1) Cabal is a tool that can only be used to build Haskell packages with
some supporting C/C++ code thrown in

and

2) Cabal is currently the only tool that can realistically be used to
properly build and install Haskell packages due to the great complexity
involved with getting all the details right

Cheers,
Greg

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Using cmake with haskell

Jason Dagit-3


On Wed, May 11, 2011 at 6:13 PM, Gregory Crosswhite <[hidden email]> wrote:
[snip] 
1) Cabal is a tool that can only be used to build Haskell packages with some supporting C/C++ code thrown in

and

2) Cabal is currently the only tool that can realistically be used to properly build and install Haskell packages due to the great complexity involved with getting all the details right

I agree with much of what you said.  I created this feature request for cabal, that I think would go quite aways towards addressing the problem, but someone marked it as wontfix:

In my opinion, the two most valuable things about cabal are its good dependency calculation and it allowed hackage to gain momentum.  Unfortunately, we are also forced to use it as a build system and it's quite inadequate for that task.  I say forced because there is no standard way to extract the dependency calculations from it.  You have to write a Setup.hs file to extract it and it's not trivial. If you succeed at that task, then you can't even reuse the code without copy&pasting it later.

In fact, I never invoke cabal-install directly anymore.  I've corrupted my package databases too many times.  I make sure to always use cabal-dev for everything.  I think that says something about cabal's efficacy as a build system.

Jason
ps. As soon as I figure out a way to get infinite free time I'll implement the translation to makefiles myself...

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Using cmake with haskell

Yves Parès
Talking about that, what are the differences between cabal-install and cabal-dev? Is cabal-dev (which I've never used nor installed) more suited for incremental development?


2011/5/12 Jason Dagit <[hidden email]>


On Wed, May 11, 2011 at 6:13 PM, Gregory Crosswhite <[hidden email]> wrote:
[snip] 
1) Cabal is a tool that can only be used to build Haskell packages with some supporting C/C++ code thrown in

and

2) Cabal is currently the only tool that can realistically be used to properly build and install Haskell packages due to the great complexity involved with getting all the details right

I agree with much of what you said.  I created this feature request for cabal, that I think would go quite aways towards addressing the problem, but someone marked it as wontfix:

In my opinion, the two most valuable things about cabal are its good dependency calculation and it allowed hackage to gain momentum.  Unfortunately, we are also forced to use it as a build system and it's quite inadequate for that task.  I say forced because there is no standard way to extract the dependency calculations from it.  You have to write a Setup.hs file to extract it and it's not trivial. If you succeed at that task, then you can't even reuse the code without copy&pasting it later.

In fact, I never invoke cabal-install directly anymore.  I've corrupted my package databases too many times.  I make sure to always use cabal-dev for everything.  I think that says something about cabal's efficacy as a build system.

Jason
ps. As soon as I figure out a way to get infinite free time I'll implement the translation to makefiles myself...

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe



_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Using cmake with haskell

Jason Dagit-3


On Fri, May 13, 2011 at 7:47 AM, Yves Parès <[hidden email]> wrote:
Talking about that, what are the differences between cabal-install and cabal-dev? Is cabal-dev (which I've never used nor installed) more suited for incremental development?

Cabal-dev is a wrapper around caba-install that primarily adds sandboxing but also adds support for loading your project into ghci.  The sandboxing makes it possible to install multiple versions without disrupting other things.  It gives you isolation so that if cabal-install overwrites a package it only affects your current build dir.  I've completely stopped getting the diamond of death in my dependencies since I started using it.

Someone made a great write up of how to get started with cabal-dev:

It's actually very easy to get started with but extra documentation never hurts :)

Jason

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Using cmake with haskell

Mats Rauhala
A little self-promotion, but I wrote this today:
http://users.utu.fi/machra//posts/2011-05-13-environment.html

A post about interfacing vim and cabal-dev.

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe

attachment0 (205 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Using cmake with haskell

Maciej Piechotka
In reply to this post by Gregory Crosswhite-2
On Wed, 2011-05-11 at 18:13 -0700, Gregory Crosswhite wrote:
> on top of it and have to start from scratch --- or worse, *autotools*
> (SHUDDER!)

While i don't have much experience autotools seems to be villainize.
Sure it's old and have it's quirks. It is hard to learn and many people
use it improperly. It have horrible libtool - but on the other hand it
have many features that others had not in any sane manner (to mention
one which is often neglected - parallel build).

Regards

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe

signature.asc (853 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Using cmake with haskell

Gregory Crosswhite-2
On 5/14/11 1:25 PM, Maciej Marcin Piechotka wrote:
> (to mention
> one which is often neglected - parallel build).

While I do appreciate you stepping in to defend autotools (if for no
other reason then because someone has to so that the discussion is
balanced :-) ), I think that you are wrong to say that autotools is
unusual in getting the idea of parallel builds right, since in my
experience the opposite is the case:  most systems support parallel
builds --- such as SCons, CMake, I think waf, etc. --- with Cabal being
an outlier here.

Cheers,
Greg

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Using cmake with haskell

Nathan Howell-2

Waf supports parallel builds and works with GHC without too much trouble. I use it in a mixed Haskell, C++, Scala and Python build. If there is interest I could conceivably clean up the ghc waf tool and release it.


On Sat, May 14, 2011 at 5:32 PM, Gregory Crosswhite <[hidden email]> wrote:
On 5/14/11 1:25 PM, Maciej Marcin Piechotka wrote:
(to mention
one which is often neglected - parallel build).

While I do appreciate you stepping in to defend autotools (if for no other reason then because someone has to so that the discussion is balanced :-) ), I think that you are wrong to say that autotools is unusual in getting the idea of parallel builds right, since in my experience the opposite is the case:  most systems support parallel builds --- such as SCons, CMake, I think waf, etc. --- with Cabal being an outlier here.


Cheers,
Greg

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe


_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Using cmake with haskell

Gregory Crosswhite-2
What on earth are you doing that mixes Haskell, C++, Scala, and Python?  I am very intrigued by the very idea of such a project.  :-)

I have to confess that don't care for waf myself because I had unpleasant experiences using it which stemmed in part from its design which I also didn't like.  For example, if you don't get the proper complex incantations correct then it will simply fail silently without giving you any hint as to what you might have gotten wrong, even for the most basic of tasks!  Also, the last time I looked into waf in depth a couple of years ago the basic task model was designed around a language like C++  where there is a build phase and then a link phase and everything within a phase can be built in any order, so to compile something like Haskell code you need to essentially put every file in its own phase, but the scheduler they used for phases was not optimized at all precisely because they were assuming a C++-like model where there were only a couple of phases;  they could have changed this since then, though.

But anyway, I am always willing to keep an open mind about tools if someone convinces me that my current negative impressions about them is wrong or outdated, so if you got waf to build a project with all four of those languages then that does definitely give it extra points in my book.  :-)

Cheers,
Greg

On 5/14/11 6:12 PM, Nathan Howell wrote:

Waf supports parallel builds and works with GHC without too much trouble. I use it in a mixed Haskell, C++, Scala and Python build. If there is interest I could conceivably clean up the ghc waf tool and release it.


On Sat, May 14, 2011 at 5:32 PM, Gregory Crosswhite <[hidden email]> wrote:
On 5/14/11 1:25 PM, Maciej Marcin Piechotka wrote:
(to mention
one which is often neglected - parallel build).

While I do appreciate you stepping in to defend autotools (if for no other reason then because someone has to so that the discussion is balanced :-) ), I think that you are wrong to say that autotools is unusual in getting the idea of parallel builds right, since in my experience the opposite is the case:  most systems support parallel builds --- such as SCons, CMake, I think waf, etc. --- with Cabal being an outlier here.


Cheers,
Greg

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe



_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Using cmake with haskell

Nathan Howell-2
For some projects, the overhead of building proper Haskell bindings is far greater than coding more in C++ and having a simple binding layer. The same goes for Scala and Python. We've been using Protocol Buffers as the common pickling engine, which alleviates us from porting everything (lots of libraries...) to Haskell. Similar enough to using JSON or XML to interop between Warp, Yesod, Happstack, etc... and a web client running javascript. I'm sure many of us would much rather code in Haskell everywhere but it's not practical all the time, at least not yet.

Waf supports building code in dependent order, providing it knows about the dependencies. A simple regex based Haskell scanner does the job for me, describing dependencies within a single package. Cross package dependencies need to be explicit (as with cabal) because of overlapping/conflicting module names across packages. Overall it comes out to about 200 lines of Python, and does enough that I don't use cabal-install for my own projects. Building Haskell code in parallel with C++ can save quite a bit of time, and I personally don't enjoy waiting for unnecessarily serialized builds regardless of language.

-n

On Sat, May 14, 2011 at 8:54 PM, Gregory Crosswhite <[hidden email]> wrote:
What on earth are you doing that mixes Haskell, C++, Scala, and Python?  I am very intrigued by the very idea of such a project.  :-)

I have to confess that don't care for waf myself because I had unpleasant experiences using it which stemmed in part from its design which I also didn't like.  For example, if you don't get the proper complex incantations correct then it will simply fail silently without giving you any hint as to what you might have gotten wrong, even for the most basic of tasks!  Also, the last time I looked into waf in depth a couple of years ago the basic task model was designed around a language like C++  where there is a build phase and then a link phase and everything within a phase can be built in any order, so to compile something like Haskell code you need to essentially put every file in its own phase, but the scheduler they used for phases was not optimized at all precisely because they were assuming a C++-like model where there were only a couple of phases;  they could have changed this since then, though.

But anyway, I am always willing to keep an open mind about tools if someone convinces me that my current negative impressions about them is wrong or outdated, so if you got waf to build a project with all four of those languages then that does definitely give it extra points in my book.  :-)

Cheers,
Greg


On 5/14/11 6:12 PM, Nathan Howell wrote:

Waf supports parallel builds and works with GHC without too much trouble. I use it in a mixed Haskell, C++, Scala and Python build. If there is interest I could conceivably clean up the ghc waf tool and release it.


On Sat, May 14, 2011 at 5:32 PM, Gregory Crosswhite <[hidden email]> wrote:
On 5/14/11 1:25 PM, Maciej Marcin Piechotka wrote:
(to mention
one which is often neglected - parallel build).

While I do appreciate you stepping in to defend autotools (if for no other reason then because someone has to so that the discussion is balanced :-) ), I think that you are wrong to say that autotools is unusual in getting the idea of parallel builds right, since in my experience the opposite is the case:  most systems support parallel builds --- such as SCons, CMake, I think waf, etc. --- with Cabal being an outlier here.


Cheers,
Greg

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe




_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Using cmake with haskell

Malcolm Wallace-2
> On 5/14/11 6:12 PM, Nathan Howell wrote:
>> Waf supports parallel builds and works with GHC without too much trouble.

I'm surprised no-one has yet mentioned Shake, a build tool/library written in Haskell.  It does parallel builds, multi-language working, accurate dependencies, etc etc.  I use it every day at work, and it is robust, scalable, and relatively easy to use.

Introductory video here:
    http://vimeo.com/15465133

Open source implementation here:
    https://github.com/batterseapower/openshake

Regards,
    Malcolm

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Using cmake with haskell

Rogan Creswick
On Sun, May 15, 2011 at 8:21 AM, Malcolm Wallace <[hidden email]> wrote:
>> On 5/14/11 6:12 PM, Nathan Howell wrote:
>>> Waf supports parallel builds and works with GHC without too much trouble.
>
> I'm surprised no-one has yet mentioned Shake, a build tool/library written in Haskell.  It does parallel builds, multi-language working, accurate dependencies, etc etc.  I use it every day at work, and it is robust, scalable, and relatively easy to use.

I didn't realize Shake had been released! Thanks for pointing that out!

--Rogan

>
> Introductory video here:
>    http://vimeo.com/15465133
>
> Open source implementation here:
>    https://github.com/batterseapower/openshake
>
> Regards,
>    Malcolm
>
> _______________________________________________
> Haskell-Cafe mailing list
> [hidden email]
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Using cmake with haskell

Max Bolingbroke-2
On 15 May 2011 18:46, Rogan Creswick <[hidden email]> wrote:
> On Sun, May 15, 2011 at 8:21 AM, Malcolm Wallace <[hidden email]> wrote:
>>> On 5/14/11 6:12 PM, Nathan Howell wrote:
>>>> Waf supports parallel builds and works with GHC without too much trouble.
>>
>> I'm surprised no-one has yet mentioned Shake, a build tool/library written in Haskell.  It does parallel builds, multi-language working, accurate dependencies, etc etc.  I use it every day at work, and it is robust, scalable, and relatively easy to use.
>
> I didn't realize Shake had been released! Thanks for pointing that out!

The version Malcolm uses is closed source - he has pointed you to my
poorly-documented open-source reimplementation. Any bugs+infelicities
you find are my fault rather than problems with the Shake concept :-)

Max

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Using cmake with haskell

Maciej Piechotka
In reply to this post by Gregory Crosswhite-2
On Sat, 2011-05-14 at 17:32 -0700, Gregory Crosswhite wrote:

> On 5/14/11 1:25 PM, Maciej Marcin Piechotka wrote:
> > (to mention
> > one which is often neglected - parallel build).
>
> While I do appreciate you stepping in to defend autotools (if for no
> other reason then because someone has to so that the discussion is
> balanced :-) ), I think that you are wrong to say that autotools is
> unusual in getting the idea of parallel builds right, since in my
> experience the opposite is the case:  most systems support parallel
> builds --- such as SCons, CMake, I think waf, etc. --- with Cabal being
> an outlier here.
>
> Cheers,
> Greg
Hmm. I could bet I have read it somewhere but I cannot find it right
now. Assume I haven't said it.

Regards

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe

signature.asc (853 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Using cmake with haskell

Evan Laforge
In reply to this post by Malcolm Wallace-2
On Sun, May 15, 2011 at 8:21 AM, Malcolm Wallace <[hidden email]> wrote:
>> On 5/14/11 6:12 PM, Nathan Howell wrote:
>>> Waf supports parallel builds and works with GHC without too much trouble.
>
> I'm surprised no-one has yet mentioned Shake, a build tool/library written in Haskell.  It does parallel builds, multi-language working, accurate dependencies, etc etc.  I use it every day at work, and it is robust, scalable, and relatively easy to use.

It's not surprising if it's not public.  No one is surprised that no
one has mentioned the internal Google build system, for instance.

> Open source implementation here:
>    https://github.com/batterseapower/openshake

It's good to see this, but is it usable yet?  I was assuming from the
fact that it's not on hackage yet that it's still experimental.  If
Shake is still "hopefully" going to be released then maybe there's not
a lot of motivation to work on a replacement, but if it's in "no one
knows" limbo then that could stall a replacement too.  I don't really
care so much about build systems that I'd write one from scratch or
bootstrap an experiment, but if there were something that was already
usable that would be a different story...

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe