Open cartazio opened 11 years ago
Cabal compiles C sources with ghc
, which also happens to work for C++ and Objective-C because the files are just passed to gcc
. Perhaps it'd be better to add separate fields for specific languages and invoke the C/C++/... compiler directly. This will allow the user to specify which compiler to use in .cabal/config
.
To preserve backwards compatibility, we can pass those c-sources that have a non-standard extension to the appropriate compiler and print a warning telling the user to use c-sources
only for C files.
@23Skidoo I like that idea. I like that idea a lot. Its a lot more refined and sane than my fuzzy ideas.
so there'd be 3 flags / fields per language
@cartazio Yes, something like this. We'd have c++-sources
, obj-c-sources
etc in addition to c-sources
in the .cabal files and c-compiler
, c++-compiler
etc in .cabal/config
. I think that the file extension -> language mapping can be hardcoded since we only need to support the extensions that gcc
uses.
are we depending on gcc or is clang viable too?
It should be possible to use any compiler that is command-line compatible with gcc
(e.g. icc
or clang
). I'm not quite sure how best to support compilers with different command-line syntax, such as MSVC. Probably the easiest way is to have a list of statically known compiler types.
There may be some subtleties to this... it looks like on my mac, ghc is calling the apple gcc-llvm compiler (well, its cc1 "front end"), even though i have a different newer version visible on my path instead! (i only realized this because i had c i was ffing to that would compile fine with avx flags when i did it myself, but during a cabal build will barf and say it doesn't know anything about sse4 or avx, which makes sense if it was using gcc 4.2 rather than the 4.8 i built)
(ie... it seems that the c compiler you build ghc with gets baked in a bit... for )
this may or may not be relevant to the main aim of this ticket, or at least an obstacle to make this sort of feature work well. I'll open a ticket on the ghc trac / thread on ghc-devs lists to try and get some more information on that possibly related issue.
@cartazio
(ie... it seems that the c compiler you build ghc with gets baked in a bit... for )
It's a GHC issue.
yup! But its a really really gnarly one! :-)
(and yup, i'm finding out its quite a ghc issue )
Further head banging and exploring indicates that its actually a cabal issue.
see my new ticket #1348
You know, this would be awfully useful for something like MPI which has its own wrapper command for cc
, namely mpicc
(a rather questionable decision but I can't change that).
Using -pgmc
doesn't work because Cabal disregards the ghc-options
when compiling C source as @cartazio pointed out in the other ticket.
Was there ever any progress on this issue?
May I please repeat the need for fixing this?
We are facing serious troubles in a package manager which makes cabal broken/useless when using just "whatever gcc
happens to be" is not an option.
FWIW, @luite wanted that cabal
specifically uses the GHC's "C Compiler" as in
% ghc --info | grep "C compiler"
,("C compiler command","gcc")
,("C compiler flags"," -fno-stack-protector")
,("C compiler link flags"," -fuse-ld=gold")
,("C compiler supports -no-pie","YES")
as he has emscripten for GHCJS.
I don't even know how cabal-install
picks which c-compiler to use (is it still via GHC)?
A workaround is to specify --with-gcc
options.
It's nice if it uses the same C compiler as ghc by default, but one should still be able to specify an alternative one.
We'll try to play with --with-gcc
.
It would likely be valuable to many projects (not just my own) to make it easier to choose what C compiler Cabal uses.
http://stackoverflow.com/questions/2528887/c-compiler-selection-in-cabal-package is a related stack overflow exposition. But I think
What would be needed to simplify specifying / picking out the CC? (i'd be willing to do some of the foot work)
or is the fact that its per se scriptable already enough to rule out adding support in more directly?