@@ -484,7 +484,22 @@ 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
495+ " main" ->
496+ let hash = B. unpack $ B16. encode $ H. finalize $ H. updates H. init (map B. pack $ componentOptions opts)
497+ hashed_uid = Compat. toUnitId (Compat. stringToUnit (" main-" ++ hash))
498+ in setHomeUnitId_ hashed_uid df'
499+ #else
500+ df'
501+ #endif
502+
488503 let deps = componentDependencies opts ++ maybeToList hieYaml
489504 dep_info <- getDependencyInfo deps
490505 -- Now lookup to see whether we are combining with an existing HscEnv
@@ -499,6 +514,7 @@ loadSessionWithOptions recorder SessionLoadingOptions{..} dir = do
499514 -- We will modify the unitId and DynFlags used for
500515 -- compilation but these are the true source of
501516 -- information.
517+
502518 new_deps = RawComponentInfo (homeUnitId_ df) df targets cfp opts dep_info
503519 : maybe [] snd oldDeps
504520 -- Get all the unit-ids for things in this component
0 commit comments