Cabal doesn't pass cc-options to GHC when compiling ordinary Haskell sources
... 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).
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.
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 could you also sketch the cabal file that should be used with this?
also, is this a dup of #4435?
could you also sketch the cabal file that should be used with this?
cc-options: -DMYDEF=1
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.
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 👀