-
Notifications
You must be signed in to change notification settings - Fork 710
Pass *-options and -pgmc gcc 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
base: master
Are you sure you want to change the base?
Conversation
1bd501e
to
c3e68be
Compare
I probably need to think about tests, maybe something started working besides |
Ok, got it, we just need to separate the flags |
a439429
to
1b8e5bb
Compare
@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) |
There was a problem hiding this 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).
@@ -0,0 +1,3 @@ | |||
# ForeignOptsCapi | |||
|
|||
This test case asserts that cabal passes `cc-options` to the C compiler when use `foreign import capi`. |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I need to think about it, but I don't know yet. Maybe I need to read other issues to see if anything worked.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They worked as long as we manually transferred them to the source files, but they should also work if we pass them on to everyone. Since no errors were found, and the linking errors with the transfer of ccProgram are related to ghc, I don't know what else to add. 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you, at least, check that the test suite has tests for all the other-language options (ASM, JS, CXX, CMM, LD)? And if some of these options don't have tests, could you add something simple for them? I agree that it's not fun to do this exercise, but I think it's a big change and I want at least a minimal guarantee that we're not breaking things badly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a really good opinion, I'll check it out and come back with the results.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc-options
- cabal-testsuite/PackageTests/FFI/ForeignOptsC/README.md
cxx-options
- cabal-testsuite/PackageTests/FFI/ForeignOptsCxx/README.md
jspp-options
- cabal-testsuite/PackageTests/JS/JSPPOptions/README.md
asm-options
- none
cmm-options
- cabal-testsuite/PackageTests/Cmm/CmmSources/README.md
ld-options
- ParserTests
cpp-options
- ParserTests
-pgmc
- cabal-testsuite/PackageTests/ShowBuildInfo/Complex
-O1
and -O2
for C++ and C and Asm - cabal-testsuite/PackageTests/ShowBuildInfo/Complex
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if it still reproduces we should start tests for asm-options
and -pgmc
/-pgma
#6534
There was a problem hiding this 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.
Yes, it looks like so. I'd say the problem is rather that IMHO, it's wrong that there are separate EDIT: There might be situations where EDIT: So AFAICT, this is not the correct fix, not what I'd imagine seeing. |
0b74992
to
37417aa
Compare
ccbf2ce
to
75993c3
Compare
@zlonast: so are the CI failures expected? Some at least look intermittent (Internet is aging), so let me take the liberty of rebasing on master where some tests are marked flaky. Maybe it helps. Regardless, if anybody would like to help move this PR forward, in particular answer the last question about testing, that would be very helpful. Thank you! |
@mergify rebase |
✅ Branch has been successfully rebased |
75993c3
to
22d1f58
Compare
Bootstrap failure is unrelated: I've seen it several times today alone. The Windows failure does seem relevant. |
As I understand it, it would be right to solve this #4042 first, while I am not sure what solution should be proposed for versions below 9.4. anyone interested can look at what will happen if you pass the flag for versions below 9.4 https://github.com/haskell/cabal/actions/runs/15363053137/job/43232541759?pr=10969#step:17:952 |
8abdd39
to
9d73a34
Compare
@Mikolaj can we add |
9d73a34
to
3b8a89e
Compare
It's like GHCPATH just for gcc or clang, now I wrote 5 tests because of different paths in different windows versions :( |
Sounds good to me. Please go ahead. But just in case and let me ping @geekosaur, @ulysses4ever and @mpickering about this change and the review of the whole PR. |
@zlonast can you comment which suggestions were implemented and give an overview of what's done currently? |
In this pr I added: Removed all These options still need to be separated for older versions. The suggestion that gcc( I also took out the common part of the linking options. Written a test for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, what about possible option duplication? Are we sure we don't pass things twice? Even on older GHCs?
@@ -0,0 +1,3 @@ | |||
# ForeignOptsCapi | |||
|
|||
This test case asserts that cabal passes `cc-options` to the C compiler when use `foreign import capi`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you, at least, check that the test suite has tests for all the other-language options (ASM, JS, CXX, CMM, LD)? And if some of these options don't have tests, could you add something simple for them? I agree that it's not fun to do this exercise, but I think it's a big change and I want at least a minimal guarantee that we're not breaking things badly.
Also, great summary, thanks! Could you also change the PR title and description to better reflect the current state. For instance, the title shouldn't say what Cabal doesn't do, instead it should say what PR does. |
5bc91c4
to
ce977c6
Compare
What is the testing strategy for this patch? This is some of the most sensitive code in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain these comments a bit more, I don't understand what "separated" means.
`cc-options` and `cxx-options` still need to be separated (C/C++) for versions below 8.10.
gccProgram till need to be separated (C/C++) for versions below 9.4.
I can appreciate that this change is right direction of travel but also requires very much care since there's a high likelihood of either a bug or a change in the behaviour when a user program is compiled.
(mkVersion [8, 10]) | ||
(compiler lbi) | ||
(Internal.defaultGhcOptCcOptions lbi bi) | ||
, -- there are problems with linking with versions below 9.4, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What "problems with linking" and what exact issue does this solve? It's quite mysterious at the moment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree, these kinds of comments should include links to GHC issues
This is not https://gitlab.haskell.org/ghc/ghc/-/issues/17919, as that one is pre GHC-8.10
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if only i knew... i need to look at all pull requests for 9.4.7 and 9.4.8
fail cabal ci https://github.com/haskell/cabal/actions/runs/15363053137/job/43232541759?pr=10969#step:17:952
{ -- C++ compiler options: GHC >= 8.10 requires -optcxx, older requires -optc | ||
-- we want to be able to support cxx-options and cc-options separately | ||
-- see example in cabal-testsuite/PackageTests/FFI/ForeignOptsC | ||
ghcOptCxxOptions = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand what this code does either.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Older GHCs don't have optcxx
, and passed -optc
options also to C++ compiler too. (Well, people used c-sources
which GCC compiled even if they were C++ sources).
Technically, C++ support prior GHC-8.10 was quite accidental.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-optcxx
issue in GHC https://gitlab.haskell.org/ghc/ghc/-/issues/16477
defaultGhcOptCcProgram lbi = | ||
maybeToFlag $ programPath <$> lookupProgram gccProgram (withPrograms lbi) | ||
|
||
-- we want to be able to support C++ and C separately in older ghc |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain more what this comment means?
I compiled stackage with this branch and GHC-9.10.2 and all the packages compiled. |
Refactor componentGhcOptions for pass *-options to all invoking GHC. During the refactoring process we needed to add componentGhcOptions to all Haskell sources. It was also worth add linkGhcOptions to linkLibrary same as componentGhcOptions to linkExecutable, linkFLib. Add test for PackageTests/FFI/ForeignOptsCapi to pass cc-options flags to *.h. Add -pgmc gcc to componentGhcOptions for versions newer then 9.4. Add more tests like PackageTests/ShowBuildInfo/Complex for -pgmc gcc and -optc-O2,-optcxx-O2,-opta-O2. Move PackageTests/Cmm* to PackageTests/Cmm/*. Fixes haskell#9801 haskell#4435
ce977c6
to
6e4ba65
Compare
Will close issues #9801 #4435
Main idea #9801 (comment)
cc-options
,cxx-options
,jspp-options
,asm-options
,cmm-options
,ld-options
,cpp-options
,gccProgram(
-pgmc
) should be always passed when invoking GHC,similarly as
ghc-options
should be always used wheninvoking
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.
cc-options
andcxx-options
still need to be separated (C/C++) for versions below 8.10.https://gitlab.haskell.org/ghc/ghc/-/issues/16477
gccProgram till need to be separated (C/C++) for versions below 9.4.
I'm not sure what fixed this behavior in 9.4
Template Α: This PR modifies behaviour or interface
Include the following checklist in your PR:
significance: significant
in the changelog file.