Skip to content

Commit 727a26c

Browse files
9999yearsKleidukos
authored andcommitted
Always pass ghc-options (#8717)
* Always pass `ghc-options` The [documentation for `ghc-shared-options`][1] states that they are combined with `ghc-options`: > Additional options for GHC when the package is built as shared > library. The options specified via this field are combined with the > ones specified via `ghc-options`, and are passed to GHC during both > the compile and link phases. However, _only_ `ghc-shared-options` and not `ghc-options` are passed in many cases. This is an issue because it requires setting `ghc-shared-options` even if the shared (dynamic) parts of the build don't actually need different options; this has the unpleasant side-effect of causing modules to be compiled twice, effectively doubling compile time! See here, where any non-empty `ghc-shared-options` causes Cabal to not set `-dynamic-too`: https://github.com/haskell/cabal/blob/acbc0f3a5cc9faf0913ff3e270196693816cec41/Cabal/src/Distribution/Simple/GHC.hs#L1466-L1469 This issue was discovered while integrating the `mold` linker with a Haskell project. [1]: https://cabal.readthedocs.io/en/latest/cabal-package.html#pkg-field-ghc-shared-options * Add documentation * Also enhance profArgs and profDynArgs --------- Co-authored-by: Hécate Moonlight <[email protected]> Co-authored-by: Hécate <[email protected]> (cherry picked from commit 9c775f2)
1 parent 86f7f2c commit 727a26c

File tree

3 files changed

+32
-6
lines changed

3 files changed

+32
-6
lines changed

Cabal/src/Distribution/Simple/GHC.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,7 @@ libAbiHash verbosity _pkg_descr lbi lib clbi = do
689689
, ghcOptFPic = toFlag True
690690
, ghcOptHiSuffix = toFlag "dyn_hi"
691691
, ghcOptObjSuffix = toFlag "dyn_o"
692-
, ghcOptExtra = hcSharedOptions GHC libBi
692+
, ghcOptExtra = hcOptions GHC libBi ++ hcSharedOptions GHC libBi
693693
}
694694
profArgs =
695695
vanillaArgs
@@ -701,8 +701,9 @@ libAbiHash verbosity _pkg_descr lbi lib clbi = do
701701
(withProfLibDetail lbi)
702702
, ghcOptHiSuffix = toFlag "p_hi"
703703
, ghcOptObjSuffix = toFlag "p_o"
704-
, ghcOptExtra = hcProfOptions GHC libBi
704+
, ghcOptExtra = hcOptions GHC libBi ++ hcProfOptions GHC libBi
705705
}
706+
ghcArgs =
706707
ghcArgs
707708
| withVanillaLib lbi = vanillaArgs
708709
| withSharedLib lbi = sharedArgs

Cabal/src/Distribution/Simple/GHCJS.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ buildOrReplLib mReplFlags verbosity numJobs _pkg_descr lbi lib clbi = do
569569
, ghcOptFPic = toFlag True
570570
, -- ghcOptHiSuffix = toFlag "dyn_hi",
571571
-- ghcOptObjSuffix = toFlag "dyn_o",
572-
ghcOptExtra = hcSharedOptions GHC libBi
572+
ghcOptExtra = hcOptions GHC libBi ++ hcSharedOptions GHC libBi
573573
, ghcOptHPCDir = hpcdir Hpc.Dyn
574574
}
575575

@@ -758,7 +758,7 @@ buildOrReplLib mReplFlags verbosity numJobs _pkg_descr lbi lib clbi = do
758758
, ghcOptDynLinkMode = toFlag GhcDynamicOnly
759759
, ghcOptInputFiles = toNubListR dynamicObjectFiles
760760
, ghcOptOutputFile = toFlag sharedLibFilePath
761-
, ghcOptExtra = hcSharedOptions GHC libBi
761+
, ghcOptExtra = hcOptions GHC libBi ++ hcSharedOptions GHC libBi
762762
, -- For dynamic libs, Mac OS/X needs to know the install location
763763
-- at build time. This only applies to GHC < 7.8 - see the
764764
-- discussion in #1660.
@@ -1309,7 +1309,7 @@ gbuild verbosity numJobs pkg_descr lbi bm clbi = do
13091309
ghcOptFPic = toFlag True
13101310
, ghcOptHiSuffix = toFlag "dyn_hi"
13111311
, ghcOptObjSuffix = toFlag "dyn_o"
1312-
, ghcOptExtra = hcSharedOptions GHC bnfo
1312+
, ghcOptExtra = hcOptions GHC bnfo ++ hcSharedOptions GHC bnfo
13131313
, ghcOptHPCDir = hpcdir Hpc.Dyn
13141314
}
13151315
dynTooOpts =
@@ -1743,7 +1743,7 @@ libAbiHash verbosity _pkg_descr lbi lib clbi = do
17431743
, ghcOptFPic = toFlag True
17441744
, ghcOptHiSuffix = toFlag "js_dyn_hi"
17451745
, ghcOptObjSuffix = toFlag "js_dyn_o"
1746-
, ghcOptExtra = hcSharedOptions GHC libBi
1746+
, ghcOptExtra = hcOptions GHC libBi ++ hcSharedOptions GHC libBi
17471747
}
17481748
profArgs =
17491749
vanillaArgs

changelog.d/pr-8717

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
synopsis: Always pass `ghc-options` to GHC
2+
packages: Cabal
3+
prs: #8717
4+
issues:
5+
6+
description: {
7+
8+
Previously, options set in the package field `ghc-options` would not be passed
9+
to GHC during the link phase for shared objects (where multiple `.o` or
10+
`.dyn_o` files are merged into a single object file). This made it impossible
11+
to use `ghc-options` to use a different linker by setting (for example)
12+
`ghc-options: -optl-fuse-ld=mold -optlm-fuse-ld=mold`; the options would be
13+
dropped in the link phase, falling back to the default linker.
14+
15+
It was possible to work around this by duplicating the `ghc-options` to
16+
`ghc-shared-options`, which _are_ passed in the shared link phase, but that had
17+
the (undocumented and unfortunate) side-effect of disabling the GHC
18+
`-dynamic-too` flag, effectively doubling compilation times when
19+
`ghc-shared-options` are set.
20+
21+
Now, `ghc-options` are combined with `ghc-shared-options` (to accurately
22+
reflect the documentation on this feature) and the fact that
23+
`ghc-shared-options` disables `-dynamic-too` is documented.
24+
25+
}

0 commit comments

Comments
 (0)