@@ -484,7 +484,25 @@ 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
+ _ -> df'
502
+ #else
503
+ df'
504
+ #endif
505
+
488
506
let deps = componentDependencies opts ++ maybeToList hieYaml
489
507
dep_info <- getDependencyInfo deps
490
508
-- Now lookup to see whether we are combining with an existing HscEnv
@@ -499,6 +517,7 @@ loadSessionWithOptions recorder SessionLoadingOptions{..} dir = do
499
517
-- We will modify the unitId and DynFlags used for
500
518
-- compilation but these are the true source of
501
519
-- information.
520
+
502
521
new_deps = RawComponentInfo (homeUnitId_ df) df targets cfp opts dep_info
503
522
: maybe [] snd oldDeps
504
523
-- Get all the unit-ids for things in this component
0 commit comments