cabal icon indicating copy to clipboard operation
cabal copied to clipboard

Cabal doesn't pass cc-options to GHC when compiling ordinary Haskell sources

Open phadej opened this issue 1 year ago • 6 comments

... however with CApiFFI, GHC will invoke C-compiler which may end up compile a large non-trivial amount of code (e.g. CApiFFI is a way to use header only libraries, without creating a dummy source for them).

phadej avatar Mar 12 '24 16:03 phadej

To reproduce, create a header with some definitions used for CApiFFI. The cc-options won't be passed when interpreting t that header.

example bits could be like

#ifndef MYDEF
#error "not defined"
#endif

static inline int myplus(int a, int b) { return a + b; }
foreign import capi "myheader.h myplus" myplus :: CInt -> CInt -> CInt
cc-options: -DMYDEF=1

My real case was related to compiling xxhash (which can be used as header-only library), and I wanted to write cc-options: -march=auto, which didn't get passed to C-compiler.

phadej avatar May 15 '25 15:05 phadej

IMHO, cc-options (and ld-options and cpp-options and ...) should be always passed when invoking GHC, similarly as ghc-options should be always used when invoking ghc - regardless of what is the intention of a particular GHC-call. GHC might use or not use the options, Cabal cannot know and should not guess.

phadej avatar May 15 '25 15:05 phadej

@phadej could you also sketch the cabal file that should be used with this?

also, is this a dup of #4435?

ulysses4ever avatar May 15 '25 15:05 ulysses4ever

could you also sketch the cabal file that should be used with this?

cc-options: -DMYDEF=1

phadej avatar May 15 '25 15:05 phadej

IMHO, cc-options (and ld-options and cpp-options and ...) should be always passed when invoking GHC

I agree. @zlonast, you recently did some work around passing of various options to various places. Would you be interested in taking a look at this issue? I imagine, having the context in your head might render this task trivial.

ulysses4ever avatar May 17 '25 21:05 ulysses4ever

Would you be interested in taking a look at this issue? I imagine, having the context in your head might render this task trivial.

Yes, let me try to solve the issue 👀

zlonast avatar May 18 '25 11:05 zlonast