Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
phadej opened this issue Mar 12, 2024 · 6 comments
Open

Comments

@phadej
Copy link
Collaborator

phadej commented Mar 12, 2024

... 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
Copy link
Collaborator Author

phadej commented May 15, 2025

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
Copy link
Collaborator Author

phadej commented May 15, 2025

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.

@ulysses4ever
Copy link
Collaborator

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

also, is this a dup of #4435?

@phadej
Copy link
Collaborator Author

phadej commented May 15, 2025

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

cc-options: -DMYDEF=1

@ulysses4ever
Copy link
Collaborator

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.

@zlonast
Copy link
Collaborator

zlonast commented May 18, 2025

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 👀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants