Skip to content

Commit f089b2e

Browse files
committed
Add -W ghc0
1 parent 367c5c6 commit f089b2e

File tree

30 files changed

+346
-167
lines changed

30 files changed

+346
-167
lines changed

Cabal/src/Distribution/Simple/Configure.hs

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ configure_setupHooks
465465
let verbosity = fromFlag (configVerbosity cfg)
466466
distPref = fromFlag $ configDistPref cfg
467467
mbWorkDir = flagToMaybe $ configWorkingDir cfg
468-
(lbc0, comp, platform, enabledComps) <- preConfigurePackage cfg g_pkg_descr
468+
(lbc0, comp, compNative, platform, enabledComps) <- preConfigurePackage cfg g_pkg_descr
469469

470470
-- Package-wide pre-configure hook
471471
lbc1 <-
@@ -547,7 +547,7 @@ configure_setupHooks
547547
preConfigurePackage
548548
:: ConfigFlags
549549
-> GenericPackageDescription
550-
-> IO (LBC.LocalBuildConfig, Compiler, Platform, ComponentRequestedSpec)
550+
-> IO (LBC.LocalBuildConfig, Compiler, Compiler, Platform, ComponentRequestedSpec)
551551
preConfigurePackage cfg g_pkg_descr = do
552552
let verbosity = fromFlag $ configVerbosity cfg
553553

@@ -615,12 +615,14 @@ preConfigurePackage cfg g_pkg_descr = do
615615
-- programDb: location and args of all programs we're
616616
-- building with
617617
( comp :: Compiler
618+
, compNative :: Compiler
618619
, compPlatform :: Platform
619620
, programDb00 :: ProgramDb
620621
) <-
621622
configCompilerEx
622623
(flagToMaybe (configHcFlavor cfg))
623624
(flagToMaybe (configHcPath cfg))
625+
(flagToMaybe (configHcNativePath cfg))
624626
(flagToMaybe (configHcPkg cfg))
625627
programDbPre
626628
(lessVerbose verbosity)
@@ -636,7 +638,7 @@ preConfigurePackage cfg g_pkg_descr = do
636638
interpretSymbolicPath mbWorkDir builddir
637639

638640
lbc <- computeLocalBuildConfig cfg comp programDb00
639-
return (lbc, comp, compPlatform, enabled)
641+
return (lbc, comp, compNative, compPlatform, enabled)
640642

641643
computeLocalBuildConfig
642644
:: ConfigFlags
@@ -2477,34 +2479,36 @@ ccLdOptionsBuildInfo cflags ldflags ldflags_static =
24772479

24782480
configCompilerAuxEx
24792481
:: ConfigFlags
2480-
-> IO (Compiler, Platform, ProgramDb)
2482+
-> IO (Compiler, Compiler, Platform, ProgramDb)
24812483
configCompilerAuxEx cfg = do
24822484
programDb <- mkProgramDb cfg defaultProgramDb
24832485
let common = configCommonFlags cfg
24842486
verbosity = fromFlag $ setupVerbosity common
24852487
configCompilerEx
24862488
(flagToMaybe $ configHcFlavor cfg)
24872489
(flagToMaybe $ configHcPath cfg)
2490+
(flagToMaybe $ configHcNativePath cfg)
24882491
(flagToMaybe $ configHcPkg cfg)
24892492
programDb
24902493
verbosity
24912494

24922495
configCompilerEx
24932496
:: Maybe CompilerFlavor
2494-
-> Maybe FilePath
2495-
-> Maybe FilePath
2497+
-> Maybe FilePath -- ^ given compiler location
2498+
-> Maybe FilePath -- ^ given native compiler location
2499+
-> Maybe FilePath -- ^ given compiler package location
24962500
-> ProgramDb
24972501
-> Verbosity
2498-
-> IO (Compiler, Platform, ProgramDb)
2499-
configCompilerEx Nothing _ _ _ verbosity = dieWithException verbosity UnknownCompilerException
2500-
configCompilerEx (Just hcFlavor) hcPath hcPkg progdb verbosity = do
2501-
(comp, maybePlatform, programDb) <- case hcFlavor of
2502-
GHC -> GHC.configure verbosity hcPath hcPkg progdb
2503-
GHCJS -> GHCJS.configure verbosity hcPath hcPkg progdb
2504-
UHC -> UHC.configure verbosity hcPath hcPkg progdb
2505-
HaskellSuite{} -> HaskellSuite.configure verbosity hcPath hcPkg progdb
2502+
-> IO (Compiler, Compiler, Platform, ProgramDb)
2503+
configCompilerEx Nothing _ _ _ _ verbosity = dieWithException verbosity UnknownCompilerException
2504+
configCompilerEx (Just hcFlavor) hcPath hcNativePath hcPkg progdb verbosity = do
2505+
(comp, nativeComp, maybePlatform, programDb) <- case hcFlavor of
2506+
GHC -> GHC.configure verbosity hcPath hcNativePath hcPkg progdb
2507+
-- GHCJS -> GHCJS.configure verbosity hcPath hcPkg progdb
2508+
-- UHC -> UHC.configure verbosity hcPath hcPkg progdb
2509+
-- HaskellSuite{} -> HaskellSuite.configure verbosity hcPath hcPkg progdb
25062510
_ -> dieWithException verbosity UnknownCompilerException
2507-
return (comp, fromMaybe buildPlatform maybePlatform, programDb)
2511+
return (comp, nativeComp, fromMaybe buildPlatform maybePlatform, programDb)
25082512

25092513
-- -----------------------------------------------------------------------------
25102514
-- Testing C lib and header dependencies

Cabal/src/Distribution/Simple/GHC.hs

Lines changed: 133 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ import Distribution.Simple.PackageIndex (InstalledPackageIndex)
109109
import qualified Distribution.Simple.PackageIndex as PackageIndex
110110
import Distribution.Simple.PreProcess.Types
111111
import Distribution.Simple.Program
112-
import Distribution.Simple.Program.Builtin (runghcProgram)
112+
import Distribution.Simple.Program.Builtin (runghcProgram, ghcNativeProgram)
113113
import Distribution.Simple.Program.GHC
114114
import qualified Distribution.Simple.Program.HcPkg as HcPkg
115115
import qualified Distribution.Simple.Program.Strip as Strip
@@ -151,113 +151,139 @@ import Distribution.Simple.Setup.Build
151151

152152
configure
153153
:: Verbosity
154-
-> Maybe FilePath
155-
-> Maybe FilePath
154+
-> Maybe FilePath -- ^ given compiler location
155+
-> Maybe FilePath -- ^ given native compiler location
156+
-> Maybe FilePath -- ^ given compiler package location
156157
-> ProgramDb
157-
-> IO (Compiler, Maybe Platform, ProgramDb)
158-
configure verbosity hcPath hcPkgPath conf0 = do
159-
(ghcProg, ghcVersion, progdb1) <-
160-
requireProgramVersion
161-
verbosity
162-
ghcProgram
163-
(orLaterVersion (mkVersion [7, 0, 1]))
164-
(userMaybeSpecifyPath "ghc" hcPath conf0)
165-
let implInfo = ghcVersionImplInfo ghcVersion
166-
167-
-- Cabal currently supports ghc >= 7.0.1 && < 9.12
168-
-- ... and the following odd development version
169-
unless (ghcVersion < mkVersion [9, 12]) $
170-
warn verbosity $
171-
"Unknown/unsupported 'ghc' version detected "
172-
++ "(Cabal "
173-
++ prettyShow cabalVersion
174-
++ " supports 'ghc' version < 9.12): "
175-
++ programPath ghcProg
176-
++ " is version "
177-
++ prettyShow ghcVersion
178-
179-
-- This is slightly tricky, we have to configure ghc first, then we use the
180-
-- location of ghc to help find ghc-pkg in the case that the user did not
181-
-- specify the location of ghc-pkg directly:
182-
(ghcPkgProg, ghcPkgVersion, progdb2) <-
183-
requireProgramVersion
184-
verbosity
185-
ghcPkgProgram
186-
{ programFindLocation = guessGhcPkgFromGhcPath ghcProg
187-
}
188-
anyVersion
189-
(userMaybeSpecifyPath "ghc-pkg" hcPkgPath progdb1)
190-
191-
when (ghcVersion /= ghcPkgVersion) $
192-
dieWithException verbosity $
193-
VersionMismatchGHC (programPath ghcProg) ghcVersion (programPath ghcPkgProg) ghcPkgVersion
194-
-- Likewise we try to find the matching hsc2hs and haddock programs.
195-
let hsc2hsProgram' =
196-
hsc2hsProgram
197-
{ programFindLocation = guessHsc2hsFromGhcPath ghcProg
198-
}
199-
haddockProgram' =
200-
haddockProgram
201-
{ programFindLocation = guessHaddockFromGhcPath ghcProg
202-
}
203-
hpcProgram' =
204-
hpcProgram
205-
{ programFindLocation = guessHpcFromGhcPath ghcProg
206-
}
207-
runghcProgram' =
208-
runghcProgram
209-
{ programFindLocation = guessRunghcFromGhcPath ghcProg
210-
}
211-
progdb3 =
212-
addKnownProgram haddockProgram' $
213-
addKnownProgram hsc2hsProgram' $
214-
addKnownProgram hpcProgram' $
215-
addKnownProgram runghcProgram' progdb2
216-
217-
languages <- Internal.getLanguages verbosity implInfo ghcProg
218-
extensions0 <- Internal.getExtensions verbosity implInfo ghcProg
219-
220-
ghcInfo <- Internal.getGhcInfo verbosity implInfo ghcProg
221-
let ghcInfoMap = Map.fromList ghcInfo
222-
filterJS = if ghcVersion < mkVersion [9, 8] then filterExt JavaScriptFFI else id
223-
extensions =
224-
-- workaround https://gitlab.haskell.org/ghc/ghc/-/issues/11214
225-
filterJS $
226-
-- see 'filterExtTH' comment below
227-
filterExtTH $
228-
extensions0
229-
230-
-- starting with GHC 8.0, `TemplateHaskell` will be omitted from
231-
-- `--supported-extensions` when it's not available.
232-
-- for older GHCs we can use the "Have interpreter" property to
233-
-- filter out `TemplateHaskell`
234-
filterExtTH
235-
| ghcVersion < mkVersion [8]
236-
, Just "NO" <- Map.lookup "Have interpreter" ghcInfoMap =
237-
filterExt TemplateHaskell
238-
| otherwise = id
239-
240-
filterExt ext = filter ((/= EnableExtension ext) . fst)
241-
242-
compilerId :: CompilerId
243-
compilerId = CompilerId GHC ghcVersion
244-
245-
compilerAbiTag :: AbiTag
246-
compilerAbiTag = maybe NoAbiTag AbiTag (Map.lookup "Project Unit Id" ghcInfoMap >>= stripPrefix (prettyShow compilerId <> "-"))
247-
248-
let comp =
249-
Compiler
250-
{ compilerId
251-
, compilerAbiTag
252-
, compilerCompat = []
253-
, compilerLanguages = languages
254-
, compilerExtensions = extensions
255-
, compilerProperties = ghcInfoMap
256-
}
257-
compPlatform = Internal.targetPlatform ghcInfo
258-
-- configure gcc and ld
259-
progdb4 = Internal.configureToolchain implInfo ghcProg ghcInfoMap progdb3
260-
return (comp, compPlatform, progdb4)
158+
-> IO (Compiler, Compiler, Maybe Platform, ProgramDb)
159+
configure verbosity hcPath hcNativePath hcPkgPath conf0 = do
160+
conf verbosity hcPath hcNativePath hcPkgPath conf0
161+
where
162+
conf :: Verbosity -> Maybe FilePath -> Maybe FilePath -> Maybe FilePath -> ProgramDb
163+
-> IO (Compiler, Compiler, Maybe Platform, ProgramDb)
164+
conf verbosity hcPath hcNativePath hcPkgPath conf0 = do
165+
print ("conf", hcPath, hcNativePath, hcPkgPath)
166+
(ghcProg, ghcVersion, progdb0) <-
167+
requireProgramVersion
168+
verbosity
169+
ghcProgram
170+
(orLaterVersion (mkVersion [7, 0, 1]))
171+
(userMaybeSpecifyPath "ghc" hcPath conf0)
172+
173+
(ghcProg', ghcVersion', progdb1) <-
174+
requireProgramVersion
175+
verbosity
176+
ghcNativeProgram
177+
(orLaterVersion (mkVersion [7, 0, 1]))
178+
(userMaybeSpecifyPath "ghc0" hcNativePath progdb0)
179+
180+
-- Cabal currently supports ghc >= 7.0.1 && < 9.12
181+
-- ... and the following odd development version
182+
unless (ghcVersion < mkVersion [9, 12]) $
183+
warn verbosity $
184+
"Unknown/unsupported 'ghc' version detected "
185+
++ "(Cabal "
186+
++ prettyShow cabalVersion
187+
++ " supports 'ghc' version < 9.12): "
188+
++ programPath ghcProg
189+
++ " is version "
190+
++ prettyShow ghcVersion
191+
192+
-- This is slightly tricky, we have to configure ghc first, then we use the
193+
-- location of ghc to help find ghc-pkg in the case that the user did not
194+
-- specify the location of ghc-pkg directly:
195+
(ghcPkgProg, ghcPkgVersion, progdb2) <-
196+
requireProgramVersion
197+
verbosity
198+
ghcPkgProgram
199+
{ programFindLocation = guessGhcPkgFromGhcPath ghcProg
200+
}
201+
anyVersion
202+
(userMaybeSpecifyPath "ghc-pkg" hcPkgPath progdb1)
203+
204+
when (ghcVersion /= ghcPkgVersion) $
205+
dieWithException verbosity $
206+
VersionMismatchGHC (programPath ghcProg) ghcVersion (programPath ghcPkgProg) ghcPkgVersion
207+
-- Likewise we try to find the matching hsc2hs and haddock programs.
208+
let hsc2hsProgram' =
209+
hsc2hsProgram
210+
{ programFindLocation = guessHsc2hsFromGhcPath ghcProg
211+
}
212+
haddockProgram' =
213+
haddockProgram
214+
{ programFindLocation = guessHaddockFromGhcPath ghcProg
215+
}
216+
hpcProgram' =
217+
hpcProgram
218+
{ programFindLocation = guessHpcFromGhcPath ghcProg
219+
}
220+
runghcProgram' =
221+
runghcProgram
222+
{ programFindLocation = guessRunghcFromGhcPath ghcProg
223+
}
224+
progdb3 =
225+
addKnownProgram haddockProgram' $
226+
addKnownProgram hsc2hsProgram' $
227+
addKnownProgram hpcProgram' $
228+
addKnownProgram runghcProgram' progdb2
229+
230+
231+
(comp, compPlatform, progdb4) <- mkCompiler verbosity ghcProg ghcVersion progdb3
232+
(comp', compPlatform', progdb5) <- mkCompiler verbosity ghcProg' ghcVersion' progdb4
233+
234+
return (comp, comp', compPlatform, progdb5)
235+
236+
mkCompiler :: Verbosity -> ConfiguredProgram -> Version -> ProgramDb -> IO (Compiler, Maybe Platform, ProgramDb)
237+
mkCompiler verbosity ghcProg ghcVersion progdb = do
238+
-- vvvv
239+
-- > TODO <: do the same (ghcInfo, ... ) for the ghcNativeProg
240+
-- ^^^^
241+
let implInfo = ghcVersionImplInfo ghcVersion
242+
243+
languages <- Internal.getLanguages verbosity implInfo ghcProg
244+
extensions0 <- Internal.getExtensions verbosity implInfo ghcProg
245+
ghcInfo <- Internal.getGhcInfo verbosity implInfo ghcProg
246+
247+
let ghcInfoMap = Map.fromList ghcInfo
248+
filterJS = if ghcVersion < mkVersion [9, 8] then filterExt JavaScriptFFI else id
249+
extensions =
250+
-- workaround https://gitlab.haskell.org/ghc/ghc/-/issues/11214
251+
filterJS $
252+
-- see 'filterExtTH' comment below
253+
filterExtTH $
254+
extensions0
255+
256+
-- starting with GHC 8.0, `TemplateHaskell` will be omitted from
257+
-- `--supported-extensions` when it's not available.
258+
-- for older GHCs we can use the "Have interpreter" property to
259+
-- filter out `TemplateHaskell`
260+
filterExtTH
261+
| ghcVersion < mkVersion [8]
262+
, Just "NO" <- Map.lookup "Have interpreter" ghcInfoMap =
263+
filterExt TemplateHaskell
264+
| otherwise = id
265+
266+
filterExt ext = filter ((/= EnableExtension ext) . fst)
267+
268+
compilerId :: CompilerId
269+
compilerId = CompilerId GHC ghcVersion
270+
271+
compilerAbiTag :: AbiTag
272+
compilerAbiTag = maybe NoAbiTag AbiTag (Map.lookup "Project Unit Id" ghcInfoMap >>= stripPrefix (prettyShow compilerId <> "-"))
273+
274+
let comp =
275+
Compiler
276+
{ compilerId
277+
, compilerAbiTag
278+
, compilerCompat = []
279+
, compilerLanguages = languages
280+
, compilerExtensions = extensions
281+
, compilerProperties = ghcInfoMap
282+
}
283+
compPlatform = Internal.targetPlatform ghcInfo
284+
-- configure gcc and ld
285+
progdb' = Internal.configureToolchain implInfo ghcProg ghcInfoMap progdb
286+
return (comp, compPlatform, progdb')
261287

262288
-- | Given something like /usr/local/bin/ghc-6.6.1(.exe) we try and find
263289
-- the corresponding tool; e.g. if the tool is ghc-pkg, we try looking

Cabal/src/Distribution/Simple/Program.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ module Distribution.Simple.Program
108108

109109
-- * Programs that Cabal knows about
110110
, ghcProgram
111+
, ghcNativeProgram
111112
, ghcPkgProgram
112113
, ghcjsProgram
113114
, ghcjsPkgProgram

0 commit comments

Comments
 (0)