Skip to content

Dual compiler support #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 82 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
f03ad8d
feat: add per-file options to extra source files
andreabedini Mar 6, 2025
db19c2f
feat(Cabal): include executables for simpleUserHooks and autoconfUser…
andreabedini Dec 2, 2024
8d61712
fix: don't build Setup programs with -threaded
hsyl20 Feb 21, 2025
fc017bd
fix: static linking on MacOS by preventing '-optl-static' flag
angerman Feb 23, 2025
438f94f
feat: no more vowel dropping on macOS
angerman Feb 23, 2025
e590584
feat: add pre and post build hooks
erikd Mar 6, 2025
d4c0c01
feat: support generated cmm-sources
andreabedini Mar 13, 2025
c44c4a9
refactor: jsem is irrelevant to fetching packages
andreabedini Mar 7, 2025
9b66d2c
refactor: introduce resolveProgramDb
andreabedini Mar 6, 2025
0516edb
wip: introduce build and host toolchains
andreabedini Mar 5, 2025
61f100f
wip: thread toolchains everywhere
andreabedini Mar 6, 2025
bb80d2a
wip: Thread HostHc into the proper places.
angerman Mar 6, 2025
b1a44bd
wip: log more details from the SolverInstallPlan
andreabedini Mar 7, 2025
c13273e
wip: pass qualified package name into the SolverInstallPlan
andreabedini Mar 7, 2025
8b90158
refactor(cabal-install-solver)!: remove QualifyOptions
andreabedini Mar 14, 2025
a696671
refactor(cabal-install-solver)!: remove deadcode
andreabedini Mar 14, 2025
d908ca3
wip move Toolchain into cabal-install-solver
andreabedini Mar 14, 2025
9a4f854
wip
andreabedini Mar 14, 2025
27a5f68
drop elaborationWarnings
andreabedini Mar 17, 2025
bf465c1
needsProfilingLib cannot per per compiler just yet
andreabedini Mar 17, 2025
da1abc6
Add CompilerId to IPI
angerman Mar 15, 2025
b3ae65d
Cleanup and Add the compilerId to the installedPackageIndex
angerman Mar 15, 2025
cca7205
Ensure dependency unit-ids are updated correctly.
angerman Mar 17, 2025
a68d450
Plan with build _and_ host package indices.
angerman Mar 17, 2025
ddbdd71
Add Stage = Host | Build
angerman Mar 14, 2025
08db0c1
Fixup pkgCompiler
angerman Mar 18, 2025
c83ed1c
Fixup cherry-pick
angerman Mar 18, 2025
5f7fbb8
Thread toolchains everywhere.
angerman Mar 18, 2025
20068b0
s/Host/Build/g
angerman Mar 18, 2025
672e511
Add WeightedPSQ.filterKey
angerman Mar 18, 2025
075b2a6
More toolchain threading
angerman Mar 18, 2025
9698a71
Stop `Stage`, which now lives in D.S.T.Stage
angerman Mar 18, 2025
7b27c1a
Add Ord Stage
angerman Mar 18, 2025
0b47c06
Add stage to SolverPackage, and use stage from elabStage
angerman Mar 18, 2025
17102ac
Make it work [somewhat]
angerman Mar 18, 2025
1677003
Make sure we are aware of BOTH build and host compilers.
angerman Mar 18, 2025
d449b91
Drop debugging
angerman Mar 18, 2025
a2144ec
Drop more debugging
angerman Mar 18, 2025
d183c9b
Fix build-depends also.
angerman Mar 18, 2025
184755d
it's build-compiler, not host-compiler for -W
angerman Mar 19, 2025
57fca26
Don't prune if buildIsHost
angerman Mar 19, 2025
8b3bd34
prune inRepo from build deps
angerman Mar 19, 2025
1c536a3
Add `--build-package-db`.
angerman Mar 20, 2025
675f086
Fixup: Really only filter HOST, not InRepo.
angerman Mar 20, 2025
6bfb13b
Fixup host/build package-db
angerman Mar 20, 2025
6ca784e
Cleaup
angerman Mar 20, 2025
418e8c5
Fix assert
angerman Mar 22, 2025
bb65785
fixup! Fixup host/build package-db
angerman Mar 23, 2025
674f2b2
Add cabal.project: build-packages
angerman Mar 23, 2025
79b31e1
Add compiler to PackageId
angerman Mar 24, 2025
328713a
Revert "Add compiler to PackageId"
angerman Mar 24, 2025
f860065
fixup! Add compiler to PackageId
angerman Mar 24, 2025
ad675ad
Revert "fixup! Add compiler to PackageId"
angerman Mar 24, 2025
1259214
fixup! Add compiler to PackageId
angerman Mar 24, 2025
02f17b1
Revert "fixup! Add compiler to PackageId"
angerman Mar 24, 2025
7c321e3
Add build package index
angerman Mar 24, 2025
409e01f
Prevent NonReinstallable Packages from Setup dependencies.
angerman Mar 25, 2025
bb2f2e1
Add compiler to PackageId
angerman Mar 24, 2025
fa6d6d1
fixup! Add compiler to PackageId
angerman Mar 24, 2025
6939af8
fixup! Add compiler to PackageId
angerman Mar 24, 2025
51d9f95
Absolutely hacked nonsense, but ... it works?!
angerman Mar 25, 2025
78afc12
Drop debug
angerman Mar 25, 2025
0532529
Set source-dir witout compiler
angerman Mar 25, 2025
5b81693
BUG: Parsect PackageIdentifier is broken
angerman Mar 26, 2025
062f69e
Revert "BUG: Parsect PackageIdentifier is broken"
angerman Mar 26, 2025
8aadca3
Add ScopeAnyBuildDepQualifier
angerman Mar 27, 2025
2554a52
Fix deleteSourcePackageId
angerman Mar 27, 2025
1a3a0a0
Use ScopeAnyBuildDepQualifier
angerman Mar 27, 2025
7f34ae9
If build is host, allow installing even for build.
angerman Mar 27, 2025
78342ee
Better packageid
angerman Mar 27, 2025
35e6455
Add support for Package Indices
angerman Mar 27, 2025
c520482
UGLY! Forcing pkgCompiler to Nothing across the codebasy :cry:
angerman Apr 1, 2025
6ed7441
Add build. constraint.
angerman Apr 1, 2025
9fe4d06
Drop erronous traces
angerman Apr 1, 2025
a1494a8
Revert "UGLY! Forcing pkgCompiler to Nothing across the codebasy :cry:"
angerman Apr 2, 2025
f140135
Update UnitId
angerman Apr 4, 2025
8a62993
Fixup AbiTag logic to deal with <build>_<host>-<abitag>.
angerman Apr 5, 2025
4e2e060
+HasCallStack
angerman Apr 5, 2025
6744f1a
+Debug
angerman Apr 5, 2025
3de93d0
+Debug: UnitId
angerman Apr 5, 2025
df70cef
Add "flags:" to ipi
angerman Apr 7, 2025
7e50837
Fixup compiler id in pkgid
angerman Apr 7, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cabal-syntax/Cabal-syntax.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ library
Distribution.Types.Executable
Distribution.Types.Executable.Lens
Distribution.Types.ExecutableScope
Distribution.Types.ExtraSource
Distribution.Types.ExposedModule
Distribution.Types.Flag
Distribution.Types.ForeignLib
Expand Down
10 changes: 6 additions & 4 deletions Cabal-syntax/src/Distribution/Backpack.hs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ import Distribution.Utils.Base62
import qualified Data.Map as Map
import qualified Data.Set as Set

import GHC.Stack (HasCallStack)

import Unsafe.Coerce (unsafeCoerce)

-----------------------------------------------------------------------
-- OpenUnitId

Expand Down Expand Up @@ -147,9 +151,7 @@ mkOpenUnitId uid cid insts =
mkDefUnitId :: ComponentId -> Map ModuleName Module -> DefUnitId
mkDefUnitId cid insts =
unsafeMkDefUnitId
( mkUnitId
(unComponentId cid ++ maybe "" ("+" ++) (hashModuleSubst insts))
)
(addSuffixToUnitId (maybe "" ("+" ++) (hashModuleSubst insts)) (unsafeCoerce cid))

-- impose invariant!

Expand Down Expand Up @@ -254,7 +256,7 @@ openModuleSubstFreeHoles insts = Set.unions (map openModuleFreeHoles (Map.elems
-- | When typechecking, we don't demand that a freshly instantiated
-- 'IndefFullUnitId' be compiled; instead, we just depend on the
-- installed indefinite unit installed at the 'ComponentId'.
abstractUnitId :: OpenUnitId -> UnitId
abstractUnitId :: HasCallStack => OpenUnitId -> UnitId
abstractUnitId (DefiniteUnitId def_uid) = unDefUnitId def_uid
abstractUnitId (IndefFullUnitId cid _) = newSimpleUnitId cid

Expand Down
10 changes: 7 additions & 3 deletions Cabal-syntax/src/Distribution/Compat/Graph.hs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ import qualified Data.Set as Set
import qualified Data.Tree as Tree
import qualified Distribution.Compat.Prelude as Prelude

import GHC.Stack (HasCallStack)

-- | A graph of nodes @a@. The nodes are expected to have instance
-- of class 'IsNode'.
data Graph a = Graph
Expand Down Expand Up @@ -377,16 +379,18 @@ fromMap m =
bounds = (0, Map.size m - 1)

-- | /O(V log V)/. Convert a list of nodes (with distinct keys) into a graph.
fromDistinctList :: (IsNode a, Show (Key a)) => [a] -> Graph a
fromDistinctList =
fromDistinctList :: (HasCallStack, IsNode a, Show (Key a)) => [a] -> Graph a
fromDistinctList xs =
fromMap
. Map.fromListWith (\_ -> duplicateError)
. map (\n -> n `seq` (nodeKey n, n))
. map (\n -> n `seq` (nodeKey n, n)) $ xs
where
duplicateError n =
error $
"Graph.fromDistinctList: duplicate key: "
++ show (nodeKey n)
++ " in "
++ unlines (map (show . nodeKey) xs)

-- Map-like operations

Expand Down
15 changes: 13 additions & 2 deletions Cabal-syntax/src/Distribution/Compiler.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DeriveTraversable #-}
{-# LANGUAGE FlexibleInstances #-}

-----------------------------------------------------------------------------

Expand Down Expand Up @@ -173,7 +174,7 @@
-- ------------------------------------------------------------

data CompilerId = CompilerId CompilerFlavor Version
deriving (Eq, Generic, Ord, Read, Show)
deriving (Eq, Generic, Ord, Read, Show, Data)

instance Binary CompilerId
instance Structured CompilerId
Expand All @@ -184,12 +185,18 @@
| v == nullVersion = pretty f
| otherwise = pretty f <<>> Disp.char '-' <<>> pretty v

instance Pretty (Maybe CompilerId) where
pretty = maybe Disp.empty pretty

instance Parsec CompilerId where
parsec = do
flavour <- parsec
version <- (P.char '-' >> parsec) <|> return nullVersion
return (CompilerId flavour version)

instance Parsec (Maybe CompilerId) where
parsec = Just <$> parsec <|> return Nothing

Check warning on line 198 in Cabal-syntax/src/Distribution/Compiler.hs

View workflow job for this annotation

GitHub Actions / hlint

Warning in module Distribution.Compiler: Use optional ▫︎ Found: "Just <$> parsec <|> return Nothing" ▫︎ Perhaps: "optional parsec"

lowercase :: String -> String
lowercase = map toLower

Expand All @@ -216,17 +223,21 @@
, compilerInfoExtensions :: Maybe [Extension]
-- ^ Supported extensions, if known.
}
deriving (Generic, Show, Read)
deriving (Generic, Show, Read, Eq)

instance Binary CompilerInfo
instance Structured CompilerInfo
instance NFData CompilerInfo where rnf = genericRnf

-- | AbiTag logic
data AbiTag
= NoAbiTag
| AbiTag String
deriving (Eq, Generic, Show, Read)

instance Binary AbiTag
instance Structured AbiTag
instance NFData AbiTag where rnf = genericRnf

instance Pretty AbiTag where
pretty NoAbiTag = Disp.empty
Expand Down
44 changes: 23 additions & 21 deletions Cabal-syntax/src/Distribution/FieldGrammar/Class.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import Distribution.FieldGrammar.Newtypes
import Distribution.Fields.Field
import Distribution.Utils.ShortText

import GHC.Stack (HasCallStack)

-- | 'FieldGrammar' is parametrised by
--
-- * @s@ which is a structure we are parsing. We need this to provide prettyprinter
Expand All @@ -43,11 +45,11 @@ class
| g -> c
where
-- | Unfocus, zoom out, /blur/ 'FieldGrammar'.
blurFieldGrammar :: ALens' a b -> g b d -> g a d
blurFieldGrammar :: HasCallStack => ALens' a b -> g b d -> g a d

-- | Field which should be defined, exactly once.
uniqueFieldAla
:: (c b, Newtype a b)
:: (c b, Newtype a b, HasCallStack)
=> FieldName
-- ^ field name
-> (a -> b)
Expand All @@ -58,7 +60,7 @@ class

-- | Boolean field with a default value.
booleanFieldDef
:: FieldName
:: HasCallStack => FieldName
-- ^ field name
-> ALens' s Bool
-- ^ lens into the field
Expand All @@ -68,7 +70,7 @@ class

-- | Optional field.
optionalFieldAla
:: (c b, Newtype a b)
:: (c b, Newtype a b, HasCallStack)
=> FieldName
-- ^ field name
-> (a -> b)
Expand All @@ -79,7 +81,7 @@ class

-- | Optional field with default value.
optionalFieldDefAla
:: (c b, Newtype a b, Eq a)
:: (c b, Newtype a b, Eq a, HasCallStack)
=> FieldName
-- ^ field name
-> (a -> b)
Expand All @@ -95,7 +97,7 @@ class
--
-- @since 3.0.0.0
freeTextField
:: FieldName
:: HasCallStack => FieldName
-> ALens' s (Maybe String)
-- ^ lens into the field
-> g s (Maybe String)
Expand All @@ -105,14 +107,14 @@ class
--
-- @since 3.0.0.0
freeTextFieldDef
:: FieldName
:: HasCallStack => FieldName
-> ALens' s String
-- ^ lens into the field
-> g s String

-- | @since 3.2.0.0
freeTextFieldDefST
:: FieldName
:: HasCallStack => FieldName
-> ALens' s ShortText
-- ^ lens into the field
-> g s ShortText
Expand All @@ -123,7 +125,7 @@ class
--
-- /Note:/ 'optionalFieldAla' is a @monoidalField@ with 'Last' monoid.
monoidalFieldAla
:: (c b, Monoid a, Newtype a b)
:: (c b, Monoid a, Newtype a b, HasCallStack)
=> FieldName
-- ^ field name
-> (a -> b)
Expand All @@ -134,21 +136,21 @@ class

-- | Parser matching all fields with a name starting with a prefix.
prefixedFields
:: FieldName
:: HasCallStack => FieldName
-- ^ field name prefix
-> ALens' s [(String, String)]
-- ^ lens into the field
-> g s [(String, String)]

-- | Known field, which we don't parse, nor pretty print.
knownField :: FieldName -> g s ()
knownField :: HasCallStack => FieldName -> g s ()

-- | Field which is parsed but not pretty printed.
hiddenField :: g s a -> g s a
hiddenField :: HasCallStack => g s a -> g s a

-- | Deprecated since
deprecatedSince
:: CabalSpecVersion
:: HasCallStack => CabalSpecVersion
-- ^ version
-> String
-- ^ deprecation message
Expand All @@ -157,7 +159,7 @@ class

-- | Removed in. If we encounter removed field, parsing fails.
removedIn
:: CabalSpecVersion
:: HasCallStack => CabalSpecVersion
-- ^ version
-> String
-- ^ removal message
Expand All @@ -166,7 +168,7 @@ class

-- | Annotate field with since spec-version.
availableSince
:: CabalSpecVersion
:: HasCallStack => CabalSpecVersion
-- ^ spec version
-> a
-- ^ default value
Expand All @@ -181,15 +183,15 @@ class
--
-- @since 3.4.0.0
availableSinceWarn
:: CabalSpecVersion
:: HasCallStack => CabalSpecVersion
-- ^ spec version
-> g s a
-> g s a
availableSinceWarn _ = id

-- | Field which can be defined at most once.
uniqueField
:: (FieldGrammar c g, c (Identity a))
:: (FieldGrammar c g, c (Identity a), HasCallStack)
=> FieldName
-- ^ field name
-> ALens' s a
Expand All @@ -199,7 +201,7 @@ uniqueField fn l = uniqueFieldAla fn Identity l

-- | Field which can be defined at most once.
optionalField
:: (FieldGrammar c g, c (Identity a))
:: (FieldGrammar c g, c (Identity a), HasCallStack)
=> FieldName
-- ^ field name
-> ALens' s (Maybe a)
Expand All @@ -209,7 +211,7 @@ optionalField fn l = optionalFieldAla fn Identity l

-- | Optional field with default value.
optionalFieldDef
:: (FieldGrammar c g, Functor (g s), c (Identity a), Eq a)
:: (FieldGrammar c g, Functor (g s), c (Identity a), Eq a, HasCallStack)
=> FieldName
-- ^ field name
-> ALens' s a
Expand All @@ -221,7 +223,7 @@ optionalFieldDef fn l x = optionalFieldDefAla fn Identity l x

-- | Field which can be define multiple times, and the results are @mappend@ed.
monoidalField
:: (FieldGrammar c g, c (Identity a), Monoid a)
:: (FieldGrammar c g, c (Identity a), Monoid a, HasCallStack)
=> FieldName
-- ^ field name
-> ALens' s a
Expand All @@ -231,7 +233,7 @@ monoidalField fn l = monoidalFieldAla fn Identity l

-- | Default implementation for 'freeTextFieldDefST'.
defaultFreeTextFieldDefST
:: (Functor (g s), FieldGrammar c g)
:: (Functor (g s), FieldGrammar c g, HasCallStack)
=> FieldName
-> ALens' s ShortText
-- ^ lens into the field
Expand Down
20 changes: 12 additions & 8 deletions Cabal-syntax/src/Distribution/InstalledPackageInfo.hs
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,15 @@ import qualified Text.PrettyPrint as Disp
import Distribution.Types.InstalledPackageInfo
import Distribution.Types.InstalledPackageInfo.FieldGrammar

installedComponentId :: InstalledPackageInfo -> ComponentId
import GHC.Stack (HasCallStack)

import Unsafe.Coerce (unsafeCoerce)

installedComponentId :: HasCallStack => InstalledPackageInfo -> ComponentId
installedComponentId ipi =
case unComponentId (installedComponentId_ ipi) of
"" -> mkComponentId (unUnitId (installedUnitId ipi))
_ -> installedComponentId_ ipi
fromMaybe
(unsafeCoerce (installedUnitId ipi))
(installedComponentId_ ipi)

-- | Get the indefinite unit identity representing this package.
-- This IS NOT guaranteed to give you a substitution; for
Expand All @@ -93,7 +97,7 @@ sourceComponentName = CLibName . sourceLibName

-- | Return either errors, or IPI with list of warnings
parseInstalledPackageInfo
:: ByteString
:: HasCallStack => ByteString
-> Either (NonEmpty String) ([String], InstalledPackageInfo)
parseInstalledPackageInfo s = case P.readFields s of
Left err -> Left (show err :| [])
Expand All @@ -117,20 +121,20 @@ parseInstalledPackageInfo s = case P.readFields s of
-- | Pretty print 'InstalledPackageInfo'.
--
-- @pkgRoot@ isn't printed, as ghc-pkg prints it manually (as GHC-8.4).
showInstalledPackageInfo :: InstalledPackageInfo -> String
showInstalledPackageInfo :: HasCallStack => InstalledPackageInfo -> String
showInstalledPackageInfo ipi =
showFullInstalledPackageInfo ipi{pkgRoot = Nothing}

-- | The variant of 'showInstalledPackageInfo' which outputs @pkgroot@ field too.
showFullInstalledPackageInfo :: InstalledPackageInfo -> String
showFullInstalledPackageInfo :: HasCallStack => InstalledPackageInfo -> String
showFullInstalledPackageInfo = P.showFields (const NoComment) . prettyFieldGrammar cabalSpecLatest ipiFieldGrammar

-- |
--
-- >>> let ipi = emptyInstalledPackageInfo { maintainer = fromString "Tester" }
-- >>> fmap ($ ipi) $ showInstalledPackageInfoField "maintainer"
-- Just "maintainer: Tester"
showInstalledPackageInfoField :: String -> Maybe (InstalledPackageInfo -> String)
showInstalledPackageInfoField :: HasCallStack => String -> Maybe (InstalledPackageInfo -> String)
showInstalledPackageInfoField fn =
fmap (\g -> Disp.render . ppField fn . g) $ fieldDescrPretty ipiFieldGrammar (toUTF8BS fn)

Expand Down
4 changes: 4 additions & 0 deletions Cabal-syntax/src/Distribution/PackageDescription.hs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ module Distribution.PackageDescription
, module Distribution.Types.HookedBuildInfo
, module Distribution.Types.SetupBuildInfo

-- * Extra sources
, module Distribution.Types.ExtraSource

-- * Flags
, module Distribution.Types.Flag

Expand Down Expand Up @@ -95,6 +98,7 @@ import Distribution.Types.ComponentName
import Distribution.Types.CondTree
import Distribution.Types.Condition
import Distribution.Types.ConfVar
import Distribution.Types.ExtraSource
import Distribution.Types.Dependency
import Distribution.Types.ExeDependency
import Distribution.Types.Executable
Expand Down
Loading
Loading