@@ -484,7 +484,24 @@ loadSessionWithOptions recorder SessionLoadingOptions{..} dir = do
484
484
packageSetup (hieYaml, cfp, opts, libDir) = do
485
485
-- Parse DynFlags for the newly discovered component
486
486
hscEnv <- emptyHscEnv ideNc libDir
487
- (df, targets) <- evalGhcEnv hscEnv $ setOptions opts (hsc_dflags hscEnv)
487
+ (df', targets) <- evalGhcEnv hscEnv $ setOptions opts (hsc_dflags hscEnv)
488
+ let df =
489
+ #if MIN_VERSION_ghc(9,3,0)
490
+ case unitIdString (homeUnitId_ df) of
491
+ -- cabal uses main for the unit id of all executable packages
492
+ -- This makes multi-component sessions confused about what
493
+ -- options to use for that component.
494
+ -- Solution: hash the options and use that as part of the unit id
495
+ -- This works because there won't be any dependencies on the
496
+ -- executable unit.
497
+ " main" ->
498
+ let hash = B. unpack $ B16. encode $ H. finalize $ H. updates H. init (map B. pack $ componentOptions opts)
499
+ hashed_uid = Compat. toUnitId (Compat. stringToUnit (" main-" ++ hash))
500
+ in setHomeUnitId_ hashed_uid df'
501
+ #else
502
+ df'
503
+ #endif
504
+
488
505
let deps = componentDependencies opts ++ maybeToList hieYaml
489
506
dep_info <- getDependencyInfo deps
490
507
-- Now lookup to see whether we are combining with an existing HscEnv
@@ -499,6 +516,7 @@ loadSessionWithOptions recorder SessionLoadingOptions{..} dir = do
499
516
-- We will modify the unitId and DynFlags used for
500
517
-- compilation but these are the true source of
501
518
-- information.
519
+
502
520
new_deps = RawComponentInfo (homeUnitId_ df) df targets cfp opts dep_info
503
521
: maybe [] snd oldDeps
504
522
-- Get all the unit-ids for things in this component
0 commit comments