@@ -484,7 +484,24 @@ loadSessionWithOptions recorder SessionLoadingOptions{..} dir = do
484484 packageSetup (hieYaml, cfp, opts, libDir) = do
485485 -- Parse DynFlags for the newly discovered component
486486 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+
488505 let deps = componentDependencies opts ++ maybeToList hieYaml
489506 dep_info <- getDependencyInfo deps
490507 -- Now lookup to see whether we are combining with an existing HscEnv
@@ -499,6 +516,7 @@ loadSessionWithOptions recorder SessionLoadingOptions{..} dir = do
499516 -- We will modify the unitId and DynFlags used for
500517 -- compilation but these are the true source of
501518 -- information.
519+
502520 new_deps = RawComponentInfo (homeUnitId_ df) df targets cfp opts dep_info
503521 : maybe [] snd oldDeps
504522 -- Get all the unit-ids for things in this component
0 commit comments