@@ -109,7 +109,7 @@ import Distribution.Simple.PackageIndex (InstalledPackageIndex)
109109import qualified Distribution.Simple.PackageIndex as PackageIndex
110110import Distribution.Simple.PreProcess.Types
111111import Distribution.Simple.Program
112- import Distribution.Simple.Program.Builtin (runghcProgram )
112+ import Distribution.Simple.Program.Builtin (runghcProgram , ghcNativeProgram )
113113import Distribution.Simple.Program.GHC
114114import qualified Distribution.Simple.Program.HcPkg as HcPkg
115115import qualified Distribution.Simple.Program.Strip as Strip
@@ -151,113 +151,139 @@ import Distribution.Simple.Setup.Build
151151
152152configure
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
0 commit comments