-
Notifications
You must be signed in to change notification settings - Fork 710
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
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).
changelog.d/pr-10969.md
Outdated
prs: 10969 | ||
--- | ||
|
||
*-options should be always passed when invoking 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 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?
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 were only partially in componentGhcOptions
, after my changes, some cross-interaction became possible. This is currently only available for .c
and .h
or .cpp/.cxx/.c++
and .h
. I think so.
@@ -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.
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
37417aa
to
17df07a
Compare
Basically I just merged most of the options into one base one and added the separation in 8.10. |
9dae1ff
to
d7fec38
Compare
optimizationCFLags lbi = | ||
( case withOptimization lbi of | ||
NoOptimisation -> [] | ||
NormalOptimisation -> ["-O1"] -- _ -> ["-O2"] -- attention: needs-review toGhcOptimisation |
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'm not sure about this change, even though it seems logical.
@@ -17,13 +17,13 @@ Warning: [unknown-directory] 'hs-source-dirs: doesnt-exist' specifies a director | |||
Preprocessing executable 'Complex' for Complex-0.1.0.0... | |||
Building executable 'Complex' for Complex-0.1.0.0... | |||
# show-build-info Complex exe:Complex | |||
{"cabal-lib-version":"<CABALVER>","compiler":{"flavour":"ghc","compiler-id":"ghc-<GHCVER>","path":"<GHCPATH>"},"components":[{"type":"exe","name":"exe:Complex","unit-id":"Complex-0.1.0.0-inplace-Complex","compiler-args":["-fbuilding-cabal-package","-O","-outputdir","single.dist/work/./dist/build/<ARCH>/ghc-<GHCVER>/Complex-0.1.0.0/x/Complex/build","-odir","single.dist/work/./dist/build/<ARCH>/ghc-<GHCVER>/Complex-0.1.0.0/x/Complex/build","-hidir","single.dist/work/./dist/build/<ARCH>/ghc-<GHCVER>/Complex-0.1.0.0/x/Complex/build","-hiedir","single.dist/work/./dist/build/<ARCH>/ghc-<GHCVER>/Complex-0.1.0.0/x/Complex/build/extra-compilation-artifacts/hie","-stubdir","single.dist/work/./dist/build/<ARCH>/ghc-<GHCVER>/Complex-0.1.0.0/x/Complex/build","-i","-iapp","-isingle.dist/work/./dist/build/<ARCH>/ghc-<GHCVER>/Complex-0.1.0.0/x/Complex/build","-isingle.dist/work/./dist/build/<ARCH>/ghc-<GHCVER>/Complex-0.1.0.0/x/Complex/build/Complex/autogen","-isingle.dist/work/./dist/build/<ARCH>/ghc-<GHCVER>/Complex-0.1.0.0/x/Complex/build/global-autogen","-Isingle.dist/work/./dist/build/<ARCH>/ghc-<GHCVER>/Complex-0.1.0.0/x/Complex/build/Complex/autogen","-Isingle.dist/work/./dist/build/<ARCH>/ghc-<GHCVER>/Complex-0.1.0.0/x/Complex/build/global-autogen","-Isingle.dist/work/./dist/build/<ARCH>/ghc-<GHCVER>/Complex-0.1.0.0/x/Complex/build","-optP-include","-optPsingle.dist/work/./dist/build/<ARCH>/ghc-<GHCVER>/Complex-0.1.0.0/x/Complex/build/Complex/autogen/cabal_macros.h","-this-unit-id","Complex-0.1.0.0-inplace-Complex","-hide-all-packages","-Wmissing-home-modules","-no-user-package-db","-package-db","<ROOT>/single.dist/home/.cabal/store/ghc-<GHCVER>/package.db","-package-db","<ROOT>/single.dist/work/dist/packagedb/ghc-<GHCVER>","-package-id","<PACKAGEDEP>","-package-id","<PACKAGEDEP>","-XHaskell2010","-threaded","-rtsopts","-with-rtsopts=-N -T","-Wredundant-constraints"],"modules":["Other","Paths_Complex"],"src-files":["Main.lhs"],"hs-src-dirs":["app"],"src-dir":"<ROOT>/","cabal-file":"Complex.cabal"}]} | |||
{"cabal-lib-version":"<CABALVER>","compiler":{"flavour":"ghc","compiler-id":"ghc-<GHCVER>","path":"<GHCPATH>"},"components":[{"type":"exe","name":"exe:Complex","unit-id":"Complex-0.1.0.0-inplace-Complex","compiler-args":["-fbuilding-cabal-package","-O","-outputdir","single.dist/work/./dist/build/<ARCH>/ghc-<GHCVER>/Complex-0.1.0.0/x/Complex/build","-odir","single.dist/work/./dist/build/<ARCH>/ghc-<GHCVER>/Complex-0.1.0.0/x/Complex/build","-hidir","single.dist/work/./dist/build/<ARCH>/ghc-<GHCVER>/Complex-0.1.0.0/x/Complex/build","-hiedir","single.dist/work/./dist/build/<ARCH>/ghc-<GHCVER>/Complex-0.1.0.0/x/Complex/build/extra-compilation-artifacts/hie","-stubdir","single.dist/work/./dist/build/<ARCH>/ghc-<GHCVER>/Complex-0.1.0.0/x/Complex/build","-i","-iapp","-isingle.dist/work/./dist/build/<ARCH>/ghc-<GHCVER>/Complex-0.1.0.0/x/Complex/build","-isingle.dist/work/./dist/build/<ARCH>/ghc-<GHCVER>/Complex-0.1.0.0/x/Complex/build/Complex/autogen","-isingle.dist/work/./dist/build/<ARCH>/ghc-<GHCVER>/Complex-0.1.0.0/x/Complex/build/global-autogen","-Isingle.dist/work/./dist/build/<ARCH>/ghc-<GHCVER>/Complex-0.1.0.0/x/Complex/build/Complex/autogen","-Isingle.dist/work/./dist/build/<ARCH>/ghc-<GHCVER>/Complex-0.1.0.0/x/Complex/build/global-autogen","-Isingle.dist/work/./dist/build/<ARCH>/ghc-<GHCVER>/Complex-0.1.0.0/x/Complex/build","-optP-include","-optPsingle.dist/work/./dist/build/<ARCH>/ghc-<GHCVER>/Complex-0.1.0.0/x/Complex/build/Complex/autogen/cabal_macros.h","-optc-O1","-optcxx-O1","-opta-O1","-this-unit-id","Complex-0.1.0.0-inplace-Complex","-hide-all-packages","-Wmissing-home-modules","-no-user-package-db","-package-db","<ROOT>/single.dist/home/.cabal/store/ghc-<GHCVER>/package.db","-package-db","<ROOT>/single.dist/work/dist/packagedb/ghc-<GHCVER>","-package-id","<PACKAGEDEP>","-package-id","<PACKAGEDEP>","-XHaskell2010","-threaded","-rtsopts","-with-rtsopts=-N -T","-Wredundant-constraints"],"modules":["Other","Paths_Complex"],"src-files":["Main.lhs"],"hs-src-dirs":["app"],"src-dir":"<ROOT>/","cabal-file":"Complex.cabal"}]} |
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.
Just add "-optc-O1","-optcxx-O1","-opta-O1"
@ulysses4ever Yes, you're right, now I've fixed it.
@phadej correctly noted that
Because they were only transferred to
I think you're right, now I did it this way.
Yes, I separated them into
Looks like I'll have to think about how to break the
I hope you like the new version better. |
d7fec38
to
879010c
Compare
{ ghcOptCcOptions = | ||
( case compilerCompatVersion GHC (compiler lbi) of | ||
Just v | ||
| v >= mkVersion [8, 10] -> Internal.defaultGhcOptCcOptions lbi bi |
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.
why this (duplicated snippet) is not in sourcesGhcOptions
. It has access to lbi
?
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.
It does not completely match, there are different defaultGhcOptCcOptions
and defaultGhcOptCxxOptions
.
You are right, ghcOptCcOptions
and ghcOptCxxOptions
can be moved to sourcesGhcOptions
.
On the other hand, ghcOptCcProgram
should be left here, since not everywhere (it seems to me) there may be access to gccProgram
.
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 didn't quite understand about the access of lbi
...
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.
here may be access to gccProgram.
That's a bug on its own:
- If
--with-gcc
is given, it should always be passed to GHC (so GHC always consistently uses the same GCC).
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.
there are different defaultGhcOptCcOptions and defaultGhcOptCxxOptions
What are the differences? Why. I don't find that intuitive. If there is a reason, we should have a comment about that. But in that case we should work on removing that reason. I only see a downsides of using subtly different calls to GHC when compiling C or C++ 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.
if we do such refactoring in renderGhcOptions
from
, -- C++ compiler options: GHC >= 8.10 requires -optcxx, older requires -optc
let cxxflag = case compilerCompatVersion GHC comp of
Just v | v >= mkVersion [8, 10] -> "-optcxx"
_ -> "-optc"
in [cxxflag ++ opt | opt <- ghcOptCxxOptions opts]
to
, ["-optcxx" ++ opt | opt <- ghcOptCxxOptions opts]
and we will also make options in accordance with their appearance
-- C++ compiler options: GHC >= 8.10 requires -optcxx, older requires -optc
, ghcOptCxxOptions = case compilerCompatVersion GHC (compiler lbi) of
Just v
| v >= mkVersion [8, 10] -> optimizationCFlags lbi ++ cxxOptions bi
| otherwise -> []
Nothing -> []
, ghcOptCcOptions = case compilerCompatVersion GHC (compiler lbi) of
Just v
| v >= mkVersion [8, 10] -> optimizationCFlags lbi ++ ccOptions bi
| otherwise -> optimizationCFlags lbi ++ cxxOptions bi ++ ccOptions bi
Nothing -> []
we will fail on foreign-opts-cxx.cabal
test as it is tested on versions older than 8.10
cabal-version: 2.2
name: foreign-opts-cxx
version: 0.1
build-type: Simple
executable foreign-opts-cxx-exe
main-is: Main.hs
build-depends: base
default-language: Haskell2010
include-dirs: cxxbits
extra-libraries: stdc++
cxx-sources: cxxbits/cxxlib.cpp
-- The following options are shared in all ForeignOpts cases:
cc-options: -D__TESTOPT_C__=11
cxx-options: -D__TESTOPT_CXX__=22
#ifdef __TESTOPT_C__
#error "Got unexpected __TESTOPT_C__ from cc-options"
#endif
to avoid these subtleties we can skipUnlessGhcVersion ">= 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.
No. Am I explaining myself unclearly. Let's try again.
it looks like that
- You set C options and
ghcOptCcProgram
only inbuildCSources
- You set C++ options and
ghcOptCxxProgram
only inbuildCxxSources
That cannot be right. You should set these options always.
My comments weren't related to >=8.10 check.
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.
No, I always set after 8.10
and try to separate them in 8.8
for buildCSources
and buildCxxSources
, because otherwise the foreign-opts-cxx.cabal
test will fail. In order for foreign-opts-cxx.cabal
to pass on 8.8
they need to be separated or use skipUnlessGhcVersion ">= 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.
Ok, I see. The GHC-8.8 doesn't know about C++ compiler, so we have to deal with it separately, and in an ugly way.
Could you write a note, referencing the test. By looking at the code only, it looks wrong or at least suspicious.
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.
In the retrospective, cabal-install
could refused to support an accidental "but it did work before with older GHC, cc-options were passed to C compiler" when proper cxx-options
were added. Those accidents just make code base very spagetti.
490eb39
to
016e3ef
Compare
All resource options now use base options. Add test for FFI/ForeignOptsCapi. Update test ShowBuildInfo/Complex. Add ghcOptCcProgram to componentGhcOptions.
016e3ef
to
a4a1f41
Compare
Will close issues #9801 #4435
Main idea #9801 (comment)
Template Α: This PR modifies behaviour or interface
Include the following checklist in your PR:
significance: significant
in the changelog file.