Skip to content

Cabal doesn't pass *-options to GHC when compiling ordinary Haskell sources #10969

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
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

zlonast
Copy link
Collaborator

@zlonast zlonast commented May 22, 2025

Will close issues #9801 #4435
Main idea #9801 (comment)

*-options 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.


Template Α: This PR modifies behaviour or interface

Include the following checklist in your PR:

@zlonast zlonast force-pushed the options-invoking-ghc branch 2 times, most recently from 1bd501e to c3e68be Compare May 22, 2025 17:02
@zlonast zlonast marked this pull request as ready for review May 22, 2025 17:52
@zlonast
Copy link
Collaborator Author

zlonast commented May 22, 2025

I probably need to think about tests, maybe something started working besides CApiFFI 🤔

@zlonast
Copy link
Collaborator Author

zlonast commented May 22, 2025

Ok, this only works for things newer than 8.8
gcc: fatal error: cannot specify ‘-o’ with ‘-c’, ‘-S’ or ‘-E’ with multiple files

Ok, got it, we just need to separate the flags -optc and -optcxx
Pass -optcxx for GHC >= 8.10 #7072

@zlonast zlonast added this to the Considered for 3.16 milestone May 22, 2025
@zlonast zlonast force-pushed the options-invoking-ghc branch 9 times, most recently from 4d8e74a to a439429 Compare May 24, 2025 12:58
Add test for capi

Add #if for GHC >=810
@zlonast zlonast force-pushed the options-invoking-ghc branch from a439429 to 1b8e5bb Compare May 24, 2025 15:33
@zlonast
Copy link
Collaborator Author

zlonast commented May 24, 2025

@ulysses4ever @phadej It's not very easy to add flags to sources files due to backward compatibility, so for now I suggest considering the pull request as is ¯\_(ツ)_/¯ (Anyway, this solved the problem with macros in header files)

Copy link
Collaborator

@ulysses4ever ulysses4ever left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great start, thank you! Below are some inline questions.

One general question: did you check that this doesn't lead to duplicated options when cabal calls GHC? I assume other *-options are passed today sometimes. So, sometimes we'll get those options passed as today and through your change too. Is that right? It seems undesirable.

It's not very easy to add flags to sources files due to backward compatibility

Can you be more specific? Do you mean it's hard to test on older GHCs? This shouldn't be a problem because the tests can run for specific versions of GHC (e.g. starting from 8.10).

---
synopsis: Pass *-options to GHC when compiling ordinary Haskell sources
packages: [Cabal]
prs: 10969
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, also add the issues field

prs: 10969
---

*-options should be always passed when invoking GHC,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you specify exactly which *-options are meant currently? (ASM, LD, etc...) And explain what's the difference with how there handled now: I assume they're passed only under specific circumstances now. Which ones?

@@ -0,0 +1,3 @@
# ForeignOptsCapi

This test case asserts that cabal passes `cc-options` to the C compiler when use `foreign import capi`.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But the patch does something to other *-options too. Is it possible to test this change w.r.t. other *-options?

Copy link
Collaborator

@geekosaur geekosaur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same concerns as @ulysses4ever raised.

++ ["-optJSP" ++ opt | opt <- jsppOptions bi]
++ ["-optl" ++ opt | opt <- ldOptions bi]
++ ["-optc" ++ opt | opt <- ccOptions bi]
#if __GLASGOW_HASKELL__ >= 810
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is wrong. You should check for the configured compiler, not the one used to compile Cabal.

@phadej
Copy link
Collaborator

phadej commented May 24, 2025

did you check that this doesn't lead to duplicated options when cabal calls GHC?

Yes, it looks like so.

I'd say the problem is rather that GhcOptions is not used uniformly. There is e.g. componentCcGhcOptions which does set ghcOptCcOptions. Why these don't show up when compiling files CApiFFI headers?

IMHO, it's wrong that there are separate componentAsmGhcOptions, componentJsGhcOptions, componentGhcOptions. There should be just one componentGhcOptions with all the options, and then it's up to GHC which ones are relevant, and which aren't.

EDIT: There might be situations where ghcOptMode or something like that is different, and input files "obviously". But the bulk of options should be the same. Starting with verbosity. I'd imagine there is only single line in the codebase which does ghcOptVerbosity = toFlag (min verbosity normal). Currently there are six copies of that. Cannot be right. I suspect there are many subtle inconsistencies hiding because of that.

EDIT: So AFAICT, this is not the correct fix, not what I'd imagine seeing.

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

Successfully merging this pull request may close these issues.

Cabal doesn't pass cc-options to GHC when compiling ordinary Haskell sources cc-options do not get passed to GHC
4 participants