diff --git a/.github/dependabot.yml b/.github/dependabot.yml
new file mode 100644
index 0000000000000000000000000000000000000000..b3b2315d90908ba3631046974eddd62649636613
--- /dev/null
+++ b/.github/dependabot.yml
@@ -0,0 +1,15 @@
+# From:
+# - https://github.com/haskell/hackage-server
+# - https://github.com/rhysd/actionlint/issues/228#issuecomment-1272493095
+# - https://docs.github.com/en/code-security/dependabot/working-with-dependabot/keeping-your-actions-up-to-date-with-dependabot
+
+# Set update schedule for GitHub Actions
+
+version: 2
+updates:
+
+  - package-ecosystem: "github-actions"
+    directory: "/"
+    schedule:
+      # Check for updates to GitHub Actions every week
+      interval: "weekly"
diff --git a/.github/workflows/bootstrap.yml b/.github/workflows/bootstrap.yml
index 5b0b2d452cc864a92bb5fb2f0508540f4ce96047..885b1916bc8d37c91d56eba2e3d745fb9fe58f53 100644
--- a/.github/workflows/bootstrap.yml
+++ b/.github/workflows/bootstrap.yml
@@ -26,7 +26,15 @@ jobs:
     name: Bootstrap ${{ matrix.os }} ghc-${{ matrix.ghc }}
     runs-on: ${{ matrix.os }}
     steps:
-      - uses: actions/checkout@v2
+      - uses: actions/cache@v3
+        name: Cache the downloads
+        id: bootstrap-cache
+        with:
+          path: "/home/runner/work/cabal/cabal/_build"
+          key: bootstrap-${{ runner.os }}-${{ matrix.ghc }}-20221115-${{ github.sha }}
+          restore-keys: bootstrap-${{ runner.os }}-${{ matrix.ghc }}-20221115-
+
+      - uses: actions/checkout@v3
       - name: bootstrap.py
         run: |
           GHC_VERSION=${{ matrix.ghc }}
@@ -43,7 +51,7 @@ jobs:
         run: |
           _build/bin/cabal --version
 
-      - uses: actions/upload-artifact@v2
+      - uses: actions/upload-artifact@v3
         with:
           name: cabal-${{ matrix.os }}-${{ matrix.ghc }}-bootstrapped
           path: _build/artifacts/*
diff --git a/.github/workflows/changelogs.yml b/.github/workflows/changelogs.yml
index daf2c5c01525b41fb62a4080e85ddb33a0e85a60..9c1e2ef70e8345af653d6461e1fb6722537cfae6 100644
--- a/.github/workflows/changelogs.yml
+++ b/.github/workflows/changelogs.yml
@@ -36,16 +36,15 @@ jobs:
       - name: ghcup
         run: |
           ghcup config set cache true
-          ghcup install ghc 8.10.7
-          ghcup set ghc 8.10.7
-      # GHC 8.10.7 needed due to https://github.com/phadej/changelog-d/pull/2
+          ghcup install ghc recommended
+          ghcup set ghc recommended
       - name: Update Hackage index
         run: cabal v2-update
       # Cannot install it from tarball due to
       # https://github.com/haskell/cabal/issues/7360
       - uses: actions/checkout@v3
         with:
-          repository: "phadej/changelog-d"
+          repository: "fgaz/changelog-d"
           path: "changelog-d"
       - name: Install changelog-d
         run: |
diff --git a/.github/workflows/quick-jobs.yml b/.github/workflows/quick-jobs.yml
index 3def7fd66f344ce84d5bd3ab2fb1d0d925e6b021..2f9d42666fcdca7ab73b55cacd53b0d0092b8b2f 100644
--- a/.github/workflows/quick-jobs.yml
+++ b/.github/workflows/quick-jobs.yml
@@ -37,7 +37,7 @@ jobs:
         run: cabal v2-update
       - name: Install alex
         run: cabal v2-install alex --constraint='alex ==3.2.6'
-      - uses: actions/checkout@v2
+      - uses: actions/checkout@v3
       - name: Regenerate files
         run: |
           make -B lexer
@@ -80,6 +80,6 @@ jobs:
           cabal-env --transitive QuickCheck
           cabal-env array bytestring containers deepseq directory filepath pretty process time binary unix text parsec mtl
           cat $HOME/.ghc/*/environments/default
-      - uses: actions/checkout@v2
+      - uses: actions/checkout@v3
       - name: Doctest
         run: make doctest
diff --git a/.github/workflows/users-guide.yml b/.github/workflows/users-guide.yml
index 2d16715b7d75f309cd7ca37635482235cb6ceadd..5b56c25266bfc257cb5b915dce2cf8beb0968f7d 100644
--- a/.github/workflows/users-guide.yml
+++ b/.github/workflows/users-guide.yml
@@ -49,12 +49,12 @@ jobs:
         python-version: [3.7]
 
     steps:
-    - uses: actions/checkout@v2
+    - uses: actions/checkout@v3
       with:
         submodules: recursive
 
     - name: Set up Python ${{ matrix.python-version }}
-      uses: actions/setup-python@v2
+      uses: actions/setup-python@v4
       with:
         python-version: ${{ matrix.python-version }}
 
@@ -67,7 +67,7 @@ jobs:
       run: |
         make SPHINX_HTML_OUTDIR=html users-guide
 
-    - uses: actions/upload-artifact@v2
+    - uses: actions/upload-artifact@v3
       with:
         name: users-guide-html
         path: html/
diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml
index 65a676c528beaa19be11d37d606eb8926274fa12..9c9ac2f4a3e58517599e40b42ae3b82ddee0ad06 100644
--- a/.github/workflows/validate.yml
+++ b/.github/workflows/validate.yml
@@ -37,7 +37,7 @@ jobs:
       GHC_FOR_RELEASE: ${{ format('["{0}"]', env.GHC_FOR_RELEASE) }}
     strategy:
       matrix:
-        os: ["ubuntu-latest", "macos-latest", "windows-latest"]
+        os: ["ubuntu-20.04", "macos-latest", "windows-latest"]
         ghc: ["9.4.2", "9.2.3", "9.0.2", "8.10.7", "8.8.4", "8.6.5", "8.4.4"]
         exclude:
           # corrupts GHA cache or the fabric of reality itself, see https://github.com/haskell/cabal/issues/8356
@@ -55,9 +55,9 @@ jobs:
 
     steps:
 
-      - uses: actions/checkout@v2
+      - uses: actions/checkout@v3
 
-      - uses: haskell/actions/setup@v1
+      - uses: haskell/actions/setup@v2
         id: setup-haskell
         with:
           ghc-version: ${{ matrix.ghc }}
@@ -151,7 +151,7 @@ jobs:
       # - Make it available in the workflow to make easier testing it locally
       - name: Upload cabal-install executable to workflow artifacts
         if: matrix.cli != 'false' && matrix.ghc == env.GHC_FOR_RELEASE
-        uses: actions/upload-artifact@v2
+        uses: actions/upload-artifact@v3
         with:
           name: cabal-${{ runner.os }}-${{ matrix.ghc }}
           path: ${{ env.CABAL_EXEC_TAR }}
@@ -176,7 +176,7 @@ jobs:
 
   validate-old-ghcs:
     name: Validate old ghcs ${{ matrix.extra-ghc }}
-    runs-on: ubuntu-latest
+    runs-on: ubuntu-20.04
     needs: validate
     # This job needs an older ubuntu (16.04) cause
     # the required old ghcs using the `-dyn` flavour
@@ -199,7 +199,7 @@ jobs:
       # cause it does not work with the git version included in it, see:
       # https://github.com/actions/checkout/issues/170
       # https://github.com/actions/checkout/issues/295
-      # - uses: actions/checkout@v2
+      # - uses: actions/checkout@v3
       - name: Checkout
         run: |
           echo $GITHUB_REF $GITHUB_SHA
@@ -212,7 +212,7 @@ jobs:
           apt-get update
           apt-get install -y ghc-${{ matrix.extra-ghc }}-dyn
 
-      - uses: haskell/actions/setup@v1
+      - uses: haskell/actions/setup@v2
         id: setup-haskell
         with:
           ghc-version: ${{ matrix.ghc }}
@@ -252,16 +252,16 @@ jobs:
     needs: validate
     strategy:
       matrix:
-        os: ["ubuntu-latest", "macos-latest", "windows-latest"]
+        os: ["ubuntu-20.04", "macos-latest", "windows-latest"]
         # We only use one ghc version the used one for the next release (defined at top of the workflow)
         # We need to build an array dynamically to inject the appropiate env var in a previous job,
         # see https://docs.github.com/en/actions/learn-github-actions/expressions#fromjson
         ghc: ${{ fromJSON (needs.validate.outputs.GHC_FOR_RELEASE) }}
 
     steps:
-      - uses: actions/checkout@v2
+      - uses: actions/checkout@v3
 
-      - uses: haskell/actions/setup@v1
+      - uses: haskell/actions/setup@v2
         id: setup-haskell
         with:
           ghc-version: ${{ matrix.ghc }}
@@ -274,7 +274,7 @@ jobs:
           echo "$HOME/.cabal/bin" >> $GITHUB_PATH
 
       - name: Download cabal executable from workflow artifacts
-        uses: actions/download-artifact@v2
+        uses: actions/download-artifact@v3
         with:
           name: cabal-${{ runner.os }}-${{ matrix.ghc }}
           path: cabal-head
@@ -297,7 +297,7 @@ jobs:
   validate-post-job:
     if: always()
     name: Validate post job
-    runs-on: ubuntu-latest
+    runs-on: ubuntu-20.04
     # IMPORTANT! Any job added to the workflow should be added here too
     needs: [validate, validate-old-ghcs, dogfooding]
 
diff --git a/.github/workflows/whitespace.yml b/.github/workflows/whitespace.yml
index 1c6d884e253d42bafae760f76f3ef30f4768786d..0eddc2f730712902f7c7b400be91eac8f0fefc4d 100644
--- a/.github/workflows/whitespace.yml
+++ b/.github/workflows/whitespace.yml
@@ -31,7 +31,7 @@ jobs:
         path: "~/.local/bin"
         key: fix-whitespace-${{ env.fix-whitespace-ver }}
 
-    - uses: haskell/actions/setup@v1
+    - uses: haskell/actions/setup@v2
       if: ${{ !steps.cache.outputs.cache-hit }}
       with:
         ghc-version: '9.2'
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index b0491d8868f4727ea9af3c411b1eb037a5dae7fa..b105e0a6d1375ed33ef26f533781b3ff7453506a 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -282,7 +282,7 @@ You can find a large number of real-world examples of changelog files
 [here](https://github.com/haskell/cabal/tree/bc83de27569fda22dbe1e10be1a921bebf4d3430/changelog.d).
 
 At release time, the entries will be merged with
-[this tool](https://github.com/phadej/changelog-d).
+[this tool](https://github.com/fgaz/changelog-d).
 
 In addition, if you're changing the .cabal file format specification you should
 add an entry in `doc/file-format-changelog.rst`.
diff --git a/Cabal-syntax/Cabal-syntax.cabal b/Cabal-syntax/Cabal-syntax.cabal
index b4143b6cbf807bb288fec02acff9ddaf3005cee6..b0c7244764823909fbbe76ec926974ed17c355a3 100644
--- a/Cabal-syntax/Cabal-syntax.cabal
+++ b/Cabal-syntax/Cabal-syntax.cabal
@@ -36,14 +36,14 @@ library
     deepseq    >= 1.3.0.1  && < 1.5,
     directory  >= 1.2      && < 1.4,
     filepath   >= 1.3.0.1  && < 1.5,
-    mtl        >= 2.1      && < 2.3,
+    mtl        >= 2.1      && < 2.4,
     parsec     >= 3.1.13.0 && < 3.2,
     pretty     >= 1.1.1    && < 1.2,
     text       (>= 1.2.3.0 && < 1.3) || (>= 2.0 && < 2.1),
     time       >= 1.4.0.1  && < 1.13,
     -- transformers-0.4.0.0 doesn't have record syntax e.g. for Identity
     -- See also https://github.com/ekmett/transformers-compat/issues/35
-    transformers (>= 0.3      && < 0.4) || (>=0.4.1.0 && <0.6)
+    transformers (>= 0.3      && < 0.4) || (>=0.4.1.0 && <0.7)
 
   if os(windows)
     build-depends: Win32 >= 2.3.0.0 && < 2.14
diff --git a/Cabal-syntax/src/Distribution/PackageDescription/Quirks.hs b/Cabal-syntax/src/Distribution/PackageDescription/Quirks.hs
index a1103c777332eda9864259b0f5c68388dab8447e..f2edfb3a387ebd8f93834f8de4ccfe130d9357f4 100644
--- a/Cabal-syntax/src/Distribution/PackageDescription/Quirks.hs
+++ b/Cabal-syntax/src/Distribution/PackageDescription/Quirks.hs
@@ -37,7 +37,7 @@ patches = Map.fromList
     [ mk "-- This file has been generated from package.yaml by hpack version 0.17.0.\n--\n-- see: https://github.com/sol/hpack\n\nname:                unicode-transforms\nversion:             0.3.3\nsynopsis:            Unicode normalization\ndescription:         Fast Unic"
          (Fingerprint 15958160436627155571 10318709190730872881)
          (Fingerprint 11008465475756725834 13815629925116264363)
-         (bsRemove "  other-modules:\n      .\n") -- TODO: remove traling \n to test structural-diff
+         (bsRemove "  other-modules:\n      .\n") -- TODO: remove trailing \n to test structural-diff
     -- http://hackage.haskell.org/package/DSTM-0.1.2
     -- http://hackage.haskell.org/package/DSTM-0.1.1
     -- http://hackage.haskell.org/package/DSTM-0.1
diff --git a/Cabal-syntax/src/Distribution/Types/BenchmarkInterface.hs b/Cabal-syntax/src/Distribution/Types/BenchmarkInterface.hs
index 8fe0738956bc9fea4a50f5e4334ea6c60de59357..d9e741fd7b1a3c554d028bdc07985fc908ac74d4 100644
--- a/Cabal-syntax/src/Distribution/Types/BenchmarkInterface.hs
+++ b/Cabal-syntax/src/Distribution/Types/BenchmarkInterface.hs
@@ -21,8 +21,8 @@ data BenchmarkInterface =
      -- | Benchmark interface \"exitcode-stdio-1.0\". The benchmark
      -- takes the form of an executable. It returns a zero exit code
      -- for success, non-zero for failure. The stdout and stderr
-     -- channels may be logged. It takes no command line parameters
-     -- and nothing on stdin.
+     -- channels may be logged. Test tooling may pass command line
+     -- arguments and/or connect the stdin channel to the test.
      --
      BenchmarkExeV10 Version FilePath
 
diff --git a/Cabal-syntax/src/Distribution/Types/Condition.hs b/Cabal-syntax/src/Distribution/Types/Condition.hs
index 8a36bd487a241b59484ec3213f5667cfcb1f4c62..0c89cb910dac2c15c152e4a9b0de6c042806483b 100644
--- a/Cabal-syntax/src/Distribution/Types/Condition.hs
+++ b/Cabal-syntax/src/Distribution/Types/Condition.hs
@@ -26,7 +26,7 @@ cNot (Lit b)  = Lit (not b)
 cNot (CNot c) = c
 cNot c        = CNot c
 
--- | Boolean AND of two 'Condtion' values.
+-- | Boolean AND of two 'Condition' values.
 cAnd :: Condition a -> Condition a -> Condition a
 cAnd (Lit False) _           = Lit False
 cAnd _           (Lit False) = Lit False
diff --git a/Cabal-syntax/src/Distribution/Types/Flag.hs b/Cabal-syntax/src/Distribution/Types/Flag.hs
index d3453219317041a57222dd70c80f4e21c2f43093..83cff4e06398e3b993e6e5b1c4c9a17883aad22c 100644
--- a/Cabal-syntax/src/Distribution/Types/Flag.hs
+++ b/Cabal-syntax/src/Distribution/Types/Flag.hs
@@ -193,7 +193,7 @@ lookupFlagAssignment fn = fmap snd . Map.lookup fn . getFlagAssignment
 
 -- | Insert or update the boolean value of a flag.
 --
--- If the flag is already present in the 'FlagAssigment', the
+-- If the flag is already present in the 'FlagAssignment', the
 -- value will be updated and the fact that multiple values have
 -- been provided for that flag will be recorded so that a
 -- warning can be generated later on.
diff --git a/Cabal-syntax/src/Distribution/Types/Library.hs b/Cabal-syntax/src/Distribution/Types/Library.hs
index e7bc00f5b8983524ce029e3cd298b831c8ff99ac..4ac153bc0b069229228c856a5cfc0add49befb85 100644
--- a/Cabal-syntax/src/Distribution/Types/Library.hs
+++ b/Cabal-syntax/src/Distribution/Types/Library.hs
@@ -25,7 +25,7 @@ data Library = Library
     , reexportedModules :: [ModuleReexport]
     , signatures        :: [ModuleName]       -- ^ What sigs need implementations?
     , libExposed        :: Bool               -- ^ Is the lib to be exposed by default? (i.e. whether its modules available in GHCi for example)
-    , libVisibility     :: LibraryVisibility  -- ^ Whether this multilib can be dependent from outside.
+    , libVisibility     :: LibraryVisibility  -- ^ Whether this multilib can be used as a dependency for other packages.
     , libBuildInfo      :: BuildInfo
     }
     deriving (Generic, Show, Eq, Ord, Read, Typeable, Data)
diff --git a/Cabal-syntax/src/Distribution/Types/LibraryVisibility.hs b/Cabal-syntax/src/Distribution/Types/LibraryVisibility.hs
index 3e6e760002125802f14cbc39b7ef5bf61a72a576..7ef160ace4dbf66c5953b5c1334b908c2d28f745 100644
--- a/Cabal-syntax/src/Distribution/Types/LibraryVisibility.hs
+++ b/Cabal-syntax/src/Distribution/Types/LibraryVisibility.hs
@@ -20,7 +20,7 @@ import qualified Text.PrettyPrint                as Disp
 -- @since 3.0.0.0
 --
 data LibraryVisibility
-      -- | Can be depenendent from other packages
+      -- | Can be used as a dependency for other packages
     = LibraryVisibilityPublic
       -- | Internal library, default
     | LibraryVisibilityPrivate
diff --git a/Cabal-syntax/src/Distribution/Types/PkgconfigVersion.hs b/Cabal-syntax/src/Distribution/Types/PkgconfigVersion.hs
index fc042d773ba9566b57878f756304ee3fea5f21b3..8779f328a665015fd41732ed6c30a8f390b4bac6 100644
--- a/Cabal-syntax/src/Distribution/Types/PkgconfigVersion.hs
+++ b/Cabal-syntax/src/Distribution/Types/PkgconfigVersion.hs
@@ -53,7 +53,7 @@ instance Parsec PkgconfigVersion where
         predicate c = isAsciiAlphaNum c || c == '.' || c == '-'
 
 -------------------------------------------------------------------------------
--- rmpvercmp - pure Haskell implementation
+-- rpmvercmp - pure Haskell implementation
 -------------------------------------------------------------------------------
 
 -- | Compare two version strings as @pkg-config@ would compare them.
diff --git a/Cabal-syntax/src/Distribution/Types/TestSuiteInterface.hs b/Cabal-syntax/src/Distribution/Types/TestSuiteInterface.hs
index 67048db1fabe3ab105b1a7adef29a1faa9893f84..7bbf2a142652add3422570d55e8ec85de9cadc41 100644
--- a/Cabal-syntax/src/Distribution/Types/TestSuiteInterface.hs
+++ b/Cabal-syntax/src/Distribution/Types/TestSuiteInterface.hs
@@ -21,8 +21,8 @@ data TestSuiteInterface =
 
      -- | Test interface \"exitcode-stdio-1.0\". The test-suite takes the form
      -- of an executable. It returns a zero exit code for success, non-zero for
-     -- failure. The stdout and stderr channels may be logged. It takes no
-     -- command line parameters and nothing on stdin.
+     -- failure. The stdout and stderr channels may be logged. Test tooling may
+     -- pass command line arguments and/or connect the stdin channel to the test.
      --
      TestSuiteExeV10 Version FilePath
 
diff --git a/Cabal-syntax/src/Distribution/Utils/ShortText.hs b/Cabal-syntax/src/Distribution/Utils/ShortText.hs
index bcabdb4c1e3d0a97b8df4a19d87a2c3bd79cca5e..8279b4af6feaff1aaa4e9ce56fbe5adcda2b21aa 100644
--- a/Cabal-syntax/src/Distribution/Utils/ShortText.hs
+++ b/Cabal-syntax/src/Distribution/Utils/ShortText.hs
@@ -4,7 +4,7 @@
 
 -- | Compact representation of short 'Strings'
 --
--- This module is designed to be import qualifeid
+-- This module is designed to be import qualified
 --
 -- @
 -- import Distribution.Utils.ShortText (ShortText)
diff --git a/Cabal-syntax/src/Distribution/Utils/Structured.hs b/Cabal-syntax/src/Distribution/Utils/Structured.hs
index 16bc9561f49d7941502a9334efe1b2501760903d..5327ed6a4270b363c317cf46529248bab1727268 100644
--- a/Cabal-syntax/src/Distribution/Utils/Structured.hs
+++ b/Cabal-syntax/src/Distribution/Utils/Structured.hs
@@ -321,7 +321,7 @@ containerStructure _ = Nominal faTypeRep 0 (show fTypeRep)
 -- Generic
 -------------------------------------------------------------------------------
 
--- | Derive 'structure' genrically.
+-- | Derive 'structure' generically.
 genericStructure :: forall a. (Typeable a, Generic a, GStructured (Rep a)) => Proxy a -> Structure
 genericStructure _ = gstructured (typeRep (Proxy :: Proxy a)) (Proxy :: Proxy (Rep a)) 0
 
diff --git a/Cabal-syntax/src/Language/Haskell/Extension.hs b/Cabal-syntax/src/Language/Haskell/Extension.hs
index 1365398cd1f508043c34c325031c726f8cf2beee..b7adc1c7e7e103ba74bb0ce8f72b983d5d5f7efc 100644
--- a/Cabal-syntax/src/Language/Haskell/Extension.hs
+++ b/Cabal-syntax/src/Language/Haskell/Extension.hs
@@ -25,7 +25,6 @@ module Language.Haskell.Extension (
         knownExtensions
   ) where
 
-import qualified Prelude (head)
 import Distribution.Compat.Prelude
 
 import Data.Array (Array, accumArray, bounds, Ix(inRange), (!))
@@ -752,9 +751,9 @@ classifyKnownExtension string@(c : _)
 knownExtensionTable :: Array Char [(String, KnownExtension)]
 knownExtensionTable =
   accumArray (flip (:)) [] ('A', 'Z')
-    [ (Prelude.head str, (str, extension)) -- assume KnownExtension's Show returns a non-empty string
-    | extension <- [toEnum 0 ..]
-    , let str = show extension ]
+    [ (hd, (str, extension)) -- assume KnownExtension's Show returns a non-empty string
+    | (extension, str@(hd : _)) <- map (\e -> (e, show e)) [toEnum 0 ..]
+    ]
 
 knownExtensions :: [KnownExtension]
 knownExtensions = [minBound .. maxBound]
diff --git a/Cabal-tests/tests/CheckTests.hs b/Cabal-tests/tests/CheckTests.hs
index b9b5d6d94f27d3828230cf0bbd4ee2f11b1004d6..603827e108e78fc1010498b531a4e7cb6fff4817 100644
--- a/Cabal-tests/tests/CheckTests.hs
+++ b/Cabal-tests/tests/CheckTests.hs
@@ -45,6 +45,7 @@ checkTests = testGroup "regressions"
     , checkTest "assoc-cpp-options.cabal"
     , checkTest "public-multilib-1.cabal"
     , checkTest "public-multilib-2.cabal"
+    , checkTest "all-upper-bound.cabal"
     , checkTest "issue-6288-a.cabal"
     , checkTest "issue-6288-b.cabal"
     , checkTest "issue-6288-c.cabal"
diff --git a/Cabal-tests/tests/ParserTests/regressions/all-upper-bound.cabal b/Cabal-tests/tests/ParserTests/regressions/all-upper-bound.cabal
new file mode 100644
index 0000000000000000000000000000000000000000..2b12c477fcf628ca20e09d8cd9aceb66a44cef12
--- /dev/null
+++ b/Cabal-tests/tests/ParserTests/regressions/all-upper-bound.cabal
@@ -0,0 +1,19 @@
+cabal-version: 3.0
+name:          all-upper-bound
+version:       0
+synopsis:      all-upper-bound
+category:      Tests
+license:       MIT
+maintainer:    someone@example.com
+description:   all-upper-bound test package.
+
+library
+  default-language: Haskell2010
+  build-depends:
+    , base     ^>=4.14
+    , somelib
+    , alphalib
+    , betalib
+    , deltalib
+
+  exposed-modules:  Foo
diff --git a/Cabal-tests/tests/ParserTests/regressions/all-upper-bound.check b/Cabal-tests/tests/ParserTests/regressions/all-upper-bound.check
new file mode 100644
index 0000000000000000000000000000000000000000..0da0e871ebb4377a3e8e850c68c5c8e113dce81c
--- /dev/null
+++ b/Cabal-tests/tests/ParserTests/regressions/all-upper-bound.check
@@ -0,0 +1,6 @@
+These packages miss upper bounds:
+  - alphalib
+  - betalib
+  - deltalib
+  - somelib
+Please add them, using `cabal gen-bounds` for suggestions. For more information see:  https://pvp.haskell.org/
diff --git a/Cabal-tests/tests/ParserTests/regressions/public-multilib-2.cabal b/Cabal-tests/tests/ParserTests/regressions/public-multilib-2.cabal
index fe0d60a561cc4546905d2f5cb35eb491b2912ed1..13d6c72f2de6657a86f57ad70c98261e18757768 100644
--- a/Cabal-tests/tests/ParserTests/regressions/public-multilib-2.cabal
+++ b/Cabal-tests/tests/ParserTests/regressions/public-multilib-2.cabal
@@ -9,6 +9,6 @@ library
   default-language: Haskell2010
   build-depends:
     , base     ^>=4.14
-    , somelib:internal
+    , somelib:internal ^>=1.0
 
   exposed-modules:  Foo
diff --git a/Cabal/Cabal.cabal b/Cabal/Cabal.cabal
index eff421130b4c18da02ebe826c41eb42349809c8c..c75d24df96763b3fb1a2325eaceb154d825cf3af 100644
--- a/Cabal/Cabal.cabal
+++ b/Cabal/Cabal.cabal
@@ -89,6 +89,7 @@ library
     Distribution.Simple.Bench
     Distribution.Simple.Build
     Distribution.Simple.Build.Macros
+    Distribution.Simple.Build.PackageInfoModule
     Distribution.Simple.Build.PathsModule
     Distribution.Simple.BuildPaths
     Distribution.Simple.BuildTarget
@@ -299,8 +300,8 @@ library
   build-depends:
     -- transformers-0.4.0.0 doesn't have record syntax e.g. for Identity
     -- See also https://github.com/ekmett/transformers-compat/issues/35
-    transformers (>= 0.3      && < 0.4) || (>=0.4.1.0 && <0.6),
-    mtl           >= 2.1      && < 2.3,
+    transformers (>= 0.3      && < 0.4) || (>=0.4.1.0 && <0.7),
+    mtl           >= 2.1      && < 2.4,
     text         (>= 1.2.3.0  && < 1.3) || (>= 2.0 && < 2.1),
     parsec        >= 3.1.13.0 && < 3.2
 
@@ -319,10 +320,12 @@ library
     Distribution.GetOpt
     Distribution.Lex
     Distribution.Simple.Build.Macros.Z
+    Distribution.Simple.Build.PackageInfoModule.Z
     Distribution.Simple.Build.PathsModule.Z
     Distribution.Simple.GHC.EnvironmentParser
     Distribution.Simple.GHC.Internal
     Distribution.Simple.GHC.ImplInfo
+    Distribution.Simple.ConfigureScript
     Distribution.ZinzaPrelude
     Paths_Cabal
 
diff --git a/Cabal/src/Distribution/Backpack/LinkedComponent.hs b/Cabal/src/Distribution/Backpack/LinkedComponent.hs
index dd5bc0bba3d1555deb28cfc204649a5bec888393..797fef251ac3568c1ab73c87555a6a7ee91ba581 100644
--- a/Cabal/src/Distribution/Backpack/LinkedComponent.hs
+++ b/Cabal/src/Distribution/Backpack/LinkedComponent.hs
@@ -210,12 +210,14 @@ toLinkedComponent verbosity db this_pid pkg_map ConfiguredComponent {
         -- Read out all the final results by converting back
         -- into a pure representation.
         let convertIncludeU (ComponentInclude dep_aid rns i) = do
-                uid <- convertUnitIdU (ann_id dep_aid)
+                let component_name = pretty $ ann_cname dep_aid
+                uid <- convertUnitIdU (ann_id dep_aid) component_name
                 return (ComponentInclude {
-                            ci_ann_id = dep_aid { ann_id = uid },
-                            ci_renaming = rns,
-                            ci_implicit = i
-                        })
+                        ci_ann_id = dep_aid { ann_id = uid },
+                        ci_renaming = rns,
+                        ci_implicit = i
+                    })
+
         shape <- convertModuleScopeU shape_u
         let (includes_u, sig_includes_u) = partitionEithers all_includes_u
         incls <- traverse convertIncludeU includes_u
diff --git a/Cabal/src/Distribution/Backpack/UnifyM.hs b/Cabal/src/Distribution/Backpack/UnifyM.hs
index 6256e82f4fb083805b26db9798abe1f0e74f0356..6b18a9d363a3f6bbe2c973581b264f553915c8ec 100644
--- a/Cabal/src/Distribution/Backpack/UnifyM.hs
+++ b/Cabal/src/Distribution/Backpack/UnifyM.hs
@@ -386,19 +386,21 @@ lookupMooEnv (m, i) k =
 
 -- The workhorse functions
 
-convertUnitIdU' :: MooEnv -> UnitIdU s -> UnifyM s OpenUnitId
-convertUnitIdU' stk uid_u = do
+-- | Returns `OpenUnitId` if there is no a mutually recursive unit.
+-- | Otherwise returns a list of signatures instantiated by given `UnitIdU`.
+convertUnitIdU' :: MooEnv -> UnitIdU s -> Doc -> UnifyM s OpenUnitId
+convertUnitIdU' stk uid_u required_mod_name = do
     x <- liftST $ UnionFind.find uid_u
     case x of
-        UnitIdThunkU uid -> return (DefiniteUnitId uid)
+        UnitIdThunkU uid -> return $ DefiniteUnitId uid
         UnitIdU u cid insts_u ->
             case lookupMooEnv stk u of
-                Just _i ->
-                    failWith (text "Unsupported mutually recursive unit identifier")
-                    -- return (UnitIdVar i)
+                Just _ ->
+                    let mod_names = Map.keys insts_u
+                    in failWithMutuallyRecursiveUnitsError required_mod_name mod_names
                 Nothing -> do
                     insts <- for insts_u $ convertModuleU' (extendMooEnv stk u)
-                    return (IndefFullUnitId cid insts)
+                    return $ IndefFullUnitId cid insts
 
 convertModuleU' :: MooEnv -> ModuleU s -> UnifyM s OpenModule
 convertModuleU' stk mod_u = do
@@ -406,12 +408,20 @@ convertModuleU' stk mod_u = do
     case mod of
         ModuleVarU mod_name -> return (OpenModuleVar mod_name)
         ModuleU uid_u mod_name -> do
-            uid <- convertUnitIdU' stk uid_u
+            uid <- convertUnitIdU' stk uid_u (pretty mod_name)
             return (OpenModule uid mod_name)
 
+failWithMutuallyRecursiveUnitsError :: Doc -> [ModuleName] -> UnifyM s a
+failWithMutuallyRecursiveUnitsError required_mod_name mod_names =
+    let sigsList = hcat $ punctuate (text ", ") $ map (quotes . pretty) mod_names in
+    failWith $
+        text "Cannot instantiate requirement" <+> quotes required_mod_name $$
+        text "Ensure \"build-depends:\" doesn't include any library with signatures:" <+> sigsList $$
+        text "as this creates a cyclic dependency, which GHC does not support."
+
 -- Helper functions
 
-convertUnitIdU :: UnitIdU s -> UnifyM s OpenUnitId
+convertUnitIdU :: UnitIdU s -> Doc -> UnifyM s OpenUnitId
 convertUnitIdU = convertUnitIdU' emptyMooEnv
 
 convertModuleU :: ModuleU s -> UnifyM s OpenModule
diff --git a/Cabal/src/Distribution/PackageDescription/Check.hs b/Cabal/src/Distribution/PackageDescription/Check.hs
index b364979bd20951d93a67e9883874e3a1eabcd4de..c4944bd0a96587911f0302e8a5559882d2072d0c 100644
--- a/Cabal/src/Distribution/PackageDescription/Check.hs
+++ b/Cabal/src/Distribution/PackageDescription/Check.hs
@@ -50,7 +50,7 @@ import Distribution.PackageDescription
 import Distribution.PackageDescription.Configuration
 import Distribution.Parsec.Warning                   (PWarning, showPWarning)
 import Distribution.Pretty                           (prettyShow)
-import Distribution.Simple.BuildPaths                (autogenPathsModuleName)
+import Distribution.Simple.BuildPaths                (autogenPackageInfoModuleName, autogenPathsModuleName)
 import Distribution.Simple.BuildToolDepends
 import Distribution.Simple.CCompiler
 import Distribution.Simple.Glob
@@ -220,6 +220,7 @@ data CheckExplanation =
         | CVCustomSetup
         | CVExpliticDepsCustomSetup
         | CVAutogenPaths
+        | CVAutogenPackageInfo
         | GlobNoMatch String String
         | GlobExactMatch String String FilePath
         | GlobNoDir String String FilePath
@@ -227,10 +228,12 @@ data CheckExplanation =
         | UnknownArch [String]
         | UnknownCompiler [String]
         | BaseNoUpperBounds
+        | MissingUpperBounds [PackageName]
         | SuspiciousFlagName [String]
         | DeclaredUsedFlags (Set FlagName) (Set FlagName)
         | NonASCIICustomField [String]
-        | RebindableClash
+        | RebindableClashPaths
+        | RebindableClashPackageInfo
         | WErrorUnneeded String
         | JUnneeded String
         | FDeferTypeErrorsUnneeded String
@@ -647,6 +650,13 @@ ppExplanation CVAutogenPaths =
       ++ "the module does not come with the package and is generated on "
       ++ "setup. Modules built with a custom Setup.hs script also go here "
       ++ "to ensure that commands like sdist don't fail."
+ppExplanation CVAutogenPackageInfo =
+    "Packages using 'cabal-version: 2.0' and the autogenerated "
+      ++ "module PackageInfo_* must include it in 'autogen-modules' as well as"
+      ++ " 'exposed-modules' and 'other-modules'. This specifies that "
+      ++ "the module does not come with the package and is generated on "
+      ++ "setup. Modules built with a custom Setup.hs script also go here "
+      ++ "to ensure that commands like sdist don't fail."
 ppExplanation (GlobNoMatch field glob) =
     "In '" ++ field ++ "': the pattern '" ++ glob ++ "' does not"
       ++ " match any files."
@@ -666,6 +676,14 @@ ppExplanation (UnknownArch unknownArches) =
     "Unknown architecture name " ++ commaSep (map quote unknownArches)
 ppExplanation (UnknownCompiler unknownImpls) =
     "Unknown compiler name " ++ commaSep (map quote unknownImpls)
+ppExplanation (MissingUpperBounds names) =
+    let separator = "\n  - "
+    in
+    "These packages miss upper bounds:" ++ separator
+      ++ (intercalate separator (unPackageName <$> names)) ++ "\n"
+      ++  "Please add them, using `cabal gen-bounds` for suggestions."
+      ++ " For more information see: "
+      ++ " https://pvp.haskell.org/"
 ppExplanation BaseNoUpperBounds =
     "The dependency 'build-depends: base' does not specify an upper "
       ++ "bound on the version number. Each major release of the 'base' "
@@ -691,12 +709,18 @@ ppExplanation (NonASCIICustomField nonAsciiXFields) =
     "Non ascii custom fields: " ++ unwords nonAsciiXFields ++ ". "
       ++ "For better compatibility, custom field names "
       ++ "shouldn't contain non-ascii characters."
-ppExplanation RebindableClash =
+ppExplanation RebindableClashPaths =
     "Packages using RebindableSyntax with OverloadedStrings or"
       ++ " OverloadedLists in default-extensions, in conjunction with the"
       ++ " autogenerated module Paths_*, are known to cause compile failures"
       ++ " with Cabal < 2.2. To use these default-extensions with a Paths_*"
       ++ " autogen module, specify at least 'cabal-version: 2.2'."
+ppExplanation RebindableClashPackageInfo =
+    "Packages using RebindableSyntax with OverloadedStrings or"
+      ++ " OverloadedLists in default-extensions, in conjunction with the"
+      ++ " autogenerated module PackageInfo_*, are known to cause compile failures"
+      ++ " with Cabal < 2.2. To use these default-extensions with a PackageInfo_*"
+      ++ " autogen module, specify at least 'cabal-version: 2.2'."
 ppExplanation (WErrorUnneeded fieldName) = addConditionalExp $
     "'" ++ fieldName ++ ": -Werror' makes the package easy to "
       ++ "break with future GHC versions because new GHC versions often "
@@ -842,6 +866,7 @@ checkPackage gpkg mpkg =
   ++ checkUnusedFlags gpkg
   ++ checkUnicodeXFields gpkg
   ++ checkPathsModuleExtensions pkg
+  ++ checkPackageInfoModuleExtensions pkg
   ++ checkSetupVersions gpkg
   ++ checkDuplicateModules gpkg
   where
@@ -1740,6 +1765,11 @@ checkCabalVersion pkg =
            && not (elem (autogenPathsModuleName pkg) allModuleNamesAutogen) ) $
       PackageDistInexcusable CVAutogenPaths
 
+  , check (specVersion pkg >= CabalSpecV2_0
+           && elem (autogenPackageInfoModuleName pkg) allModuleNames
+           && not (elem (autogenPackageInfoModuleName pkg) allModuleNamesAutogen) ) $
+      PackageDistInexcusable CVAutogenPackageInfo
+
   ]
   where
     -- Perform a check on packages that use a version of the spec less than
@@ -1813,29 +1843,23 @@ checkCabalVersion pkg =
 --
 checkPackageVersions :: GenericPackageDescription -> [PackageCheck]
 checkPackageVersions pkg =
-  catMaybes [
-
-    -- Check that the version of base is bounded above.
-    -- For example this bans "build-depends: base >= 3".
-    -- It should probably be "build-depends: base >= 3 && < 4"
-    -- which is the same as  "build-depends: base == 3.*"
-    check (not (hasUpperBound baseDependency)) $
-      PackageDistInexcusable BaseNoUpperBounds
-
-  ]
+  -- if others is empty,
+  -- the error will still fire but listing no dependencies.
+  -- so we have to check
+  if length others > 0
+  then
+    PackageDistSuspiciousWarn (MissingUpperBounds others) : baseErrors
+  else
+    baseErrors
   where
-    baseDependency = case typicalPkg pkg of
-      Right (pkg', _) | not (null baseDeps) ->
-          foldr intersectVersionRanges anyVersion baseDeps
-        where
-          baseDeps =
-            [ vr | Dependency pname vr _ <- allBuildDepends pkg'
-                 , pname == mkPackageName "base" ]
-
-      -- Just in case finalizePD fails for any reason,
-      -- or if the package doesn't depend on the base package at all,
-      -- then we will just skip the check, since hasUpperBound noVersion = True
-      _          -> noVersion
+    baseErrors = PackageDistInexcusable BaseNoUpperBounds <$ bases
+    deps = toDependencyVersionsMap allBuildDepends pkg
+    -- base gets special treatment (it's more critical)
+    (bases, others) = partition (("base" ==) . unPackageName) $
+      [ name
+      | (name, vr) <- Map.toList deps
+      , not (hasUpperBound vr)
+      ]
 
 checkConditionals :: GenericPackageDescription -> [PackageCheck]
 checkConditionals pkg =
@@ -1922,13 +1946,25 @@ checkUnicodeXFields gpd
 
 -- | cabal-version <2.2 + Paths_module + default-extensions: doesn't build.
 checkPathsModuleExtensions :: PackageDescription -> [PackageCheck]
-checkPathsModuleExtensions pd
+checkPathsModuleExtensions = checkAutogenModuleExtensions autogenPathsModuleName RebindableClashPaths
+
+-- | cabal-version <2.2 + PackageInfo_module + default-extensions: doesn't build.
+checkPackageInfoModuleExtensions :: PackageDescription -> [PackageCheck]
+checkPackageInfoModuleExtensions = checkAutogenModuleExtensions autogenPackageInfoModuleName RebindableClashPackageInfo
+
+-- | cabal-version <2.2 + *_module + default-extensions: doesn't build.
+checkAutogenModuleExtensions ::
+  (PackageDescription -> ModuleName) ->
+  CheckExplanation ->
+  PackageDescription ->
+  [PackageCheck]
+checkAutogenModuleExtensions autogenModuleName rebindableClashExplanation pd
     | specVersion pd >= CabalSpecV2_2 = []
     | any checkBI (allBuildInfo pd) || any checkLib (allLibraries pd)
-        = return (PackageBuildImpossible RebindableClash)
+        = return (PackageBuildImpossible rebindableClashExplanation)
     | otherwise = []
   where
-    mn = autogenPathsModuleName pd
+    mn = autogenModuleName pd
 
     checkLib :: Library -> Bool
     checkLib l = mn `elem` exposedModules l && checkExts (l ^. L.defaultExtensions)
@@ -2409,14 +2445,7 @@ checkSetupVersions pkg =
     ]
   where
     criticalPkgs = ["Cabal", "base"]
-    deps = case typicalPkg pkg of
-      Right (pkgs', _) ->
-        Map.fromListWith intersectVersionRanges
-          [ (pname, vr)
-          | sbi <- maybeToList $ setupBuildInfo pkgs'
-          , Dependency pname vr _ <- setupDepends sbi
-          ]
-      _ -> Map.empty
+    deps = toDependencyVersionsMap (foldMap setupDepends . setupBuildInfo) pkg
     emitError nm =
       PackageDistInexcusable (UpperBoundSetup nm)
 
@@ -2455,6 +2484,24 @@ checkDuplicateModules pkg =
 -- * Utils
 -- ------------------------------------------------------------
 
+toDependencyVersionsMap :: (PackageDescription -> [Dependency]) -> GenericPackageDescription -> Map PackageName VersionRange
+toDependencyVersionsMap selectDependencies pkg = case typicalPkg pkg of
+      Right (pkgs', _) ->
+        let
+          self :: PackageName
+          self = pkgName $ package pkgs'
+        in
+        Map.fromListWith intersectVersionRanges $
+          [ (pname, vr)
+          | Dependency pname vr _ <- selectDependencies pkgs'
+          , pname /= self
+          ]
+      -- Just in case finalizePD fails for any reason,
+      -- or if the package doesn't depend on the base package at all,
+      -- no deps is no checks.
+      _ -> Map.empty
+
+
 quote :: String -> String
 quote s = "'" ++ s ++ "'"
 
diff --git a/Cabal/src/Distribution/Simple.hs b/Cabal/src/Distribution/Simple.hs
index be2d71d564fda92103200c1787fe3a9447fbe21b..77ba089fa982b9eab09b4302a6e8d1cda930b667 100644
--- a/Cabal/src/Distribution/Simple.hs
+++ b/Cabal/src/Distribution/Simple.hs
@@ -1,7 +1,7 @@
 {-# LANGUAGE FlexibleContexts #-}
+{-# LANGUAGE ScopedTypeVariables #-}
 {-# LANGUAGE RankNTypes #-}
 {-# LANGUAGE LambdaCase #-}
-{-# LANGUAGE CPP #-}
 -----------------------------------------------------------------------------
 -- |
 -- Module      :  Distribution.Simple
@@ -69,7 +69,6 @@ import Distribution.PackageDescription
 import Distribution.PackageDescription.Configuration
 import Distribution.Simple.PackageDescription
 import Distribution.Simple.Program
-import Distribution.Simple.Program.Db
 import Distribution.Simple.PreProcess
 import Distribution.Simple.Setup
 import Distribution.Simple.Command
@@ -80,6 +79,7 @@ import Distribution.Simple.Register
 
 import Distribution.Simple.Configure
 
+import Distribution.Simple.ConfigureScript
 import Distribution.Simple.LocalBuildInfo
 import Distribution.Simple.Bench
 import Distribution.Simple.BuildPaths
@@ -87,31 +87,21 @@ import Distribution.Simple.Test
 import Distribution.Simple.Install
 import Distribution.Simple.Haddock
 import Distribution.Simple.Utils
-import Distribution.Utils.NubList
 import Distribution.Verbosity
 import Language.Haskell.Extension
 import Distribution.Version
 import Distribution.License
 import Distribution.Pretty
-import Distribution.System (buildPlatform)
 
 -- Base
 import System.Environment (getArgs, getProgName)
 import System.Directory   (removeFile, doesFileExist
                           ,doesDirectoryExist, removeDirectoryRecursive)
-import System.FilePath    (searchPathSeparator, takeDirectory, (</>),
-                           splitDirectories, dropDrive)
-#ifdef mingw32_HOST_OS
-import System.FilePath    (normalise, splitDrive)
-#endif
+import System.FilePath    (takeDirectory, (</>))
 import Distribution.Compat.ResponseFile (expandResponse)
-import Distribution.Compat.Directory        (makeAbsolute)
-import Distribution.Compat.Environment      (getEnvironment)
-import Distribution.Compat.GetShortPathName (getShortPathName)
 
 import Data.List       (unionBy, (\\))
 
-
 -- | A simple implementation of @main@ for a Cabal setup script.
 -- It reads the package description file using IO, and performs the
 -- action specified on the command line.
@@ -616,7 +606,7 @@ autoconfUserHooks
                    confExists <- doesFileExist $ (baseDir lbi) </> "configure"
                    if confExists
                      then runConfigureScript verbosity
-                            backwardsCompatHack flags lbi
+                            flags lbi
                      else die' verbosity "configure script not found."
 
                    pbi <- getHookedBuildInfo verbosity (buildDir lbi)
@@ -625,8 +615,6 @@ autoconfUserHooks
                        lbi' = lbi { localPkgDescr = pkg_descr' }
                    postConf simpleUserHooks args flags pkg_descr' lbi'
 
-          backwardsCompatHack = False
-
           readHookWithArgs :: (a -> Flag Verbosity)
                            -> (a -> Flag FilePath)
                            -> Args -> a
@@ -647,112 +635,6 @@ autoconfUserHooks
             where
               verbosity = fromFlag (get_verbosity flags)
 
-runConfigureScript :: Verbosity -> Bool -> ConfigFlags -> LocalBuildInfo
-                   -> IO ()
-runConfigureScript verbosity backwardsCompatHack flags lbi = do
-  env <- getEnvironment
-  let programDb = withPrograms lbi
-  (ccProg, ccFlags) <- configureCCompiler verbosity programDb
-  ccProgShort <- getShortPathName ccProg
-  -- The C compiler's compilation and linker flags (e.g.
-  -- "C compiler flags" and "Gcc Linker flags" from GHC) have already
-  -- been merged into ccFlags, so we set both CFLAGS and LDFLAGS
-  -- to ccFlags
-  -- We don't try and tell configure which ld to use, as we don't have
-  -- a way to pass its flags too
-  configureFile <- makeAbsolute $
-    fromMaybe "." (takeDirectory <$> cabalFilePath lbi) </> "configure"
-  -- autoconf is fussy about filenames, and has a set of forbidden
-  -- characters that can't appear in the build directory, etc:
-  -- https://www.gnu.org/software/autoconf/manual/autoconf.html#File-System-Conventions
-  --
-  -- This has caused hard-to-debug failures in the past (#5368), so we
-  -- detect some cases early and warn with a clear message. Windows's
-  -- use of backslashes is problematic here, so we'll switch to
-  -- slashes, but we do still want to fail on backslashes in POSIX
-  -- paths.
-  --
-  -- TODO: We don't check for colons, tildes or leading dashes. We
-  -- also should check the builddir's path, destdir, and all other
-  -- paths as well.
-  let configureFile' = toUnix configureFile
-  for_ badAutoconfCharacters $ \(c, cname) ->
-    when (c `elem` dropDrive configureFile') $
-      warn verbosity $ concat
-        [ "The path to the './configure' script, '", configureFile'
-        , "', contains the character '", [c], "' (", cname, ")."
-        , " This may cause the script to fail with an obscure error, or for"
-        , " building the package to fail later."
-        ]
-
-  let extraPath = fromNubList $ configProgramPathExtra flags
-  let cflagsEnv = maybe (unwords ccFlags) (++ (" " ++ unwords ccFlags))
-                  $ lookup "CFLAGS" env
-      spSep = [searchPathSeparator]
-      pathEnv = maybe (intercalate spSep extraPath)
-                ((intercalate spSep extraPath ++ spSep)++) $ lookup "PATH" env
-      overEnv = ("CFLAGS", Just cflagsEnv) :
-                [("PATH", Just pathEnv) | not (null extraPath)]
-      hp = hostPlatform lbi
-      maybeHostFlag = if hp == buildPlatform then [] else ["--host=" ++ show (pretty hp)]
-      args' = configureFile':args ++ ["CC=" ++ ccProgShort] ++ maybeHostFlag
-      shProg = simpleProgram "sh"
-      progDb = modifyProgramSearchPath
-               (\p -> map ProgramSearchPathDir extraPath ++ p) emptyProgramDb
-  shConfiguredProg <- lookupProgram shProg
-                      `fmap` configureProgram  verbosity shProg progDb
-  case shConfiguredProg of
-      Just sh -> runProgramInvocation verbosity $
-                 (programInvocation (sh {programOverrideEnv = overEnv}) args')
-                 { progInvokeCwd = Just (buildDir lbi) }
-      Nothing -> die' verbosity notFoundMsg
-  where
-    args = configureArgs backwardsCompatHack flags
-
-    notFoundMsg = "The package has a './configure' script. "
-               ++ "If you are on Windows, This requires a "
-               ++ "Unix compatibility toolchain such as MinGW+MSYS or Cygwin. "
-               ++ "If you are not on Windows, ensure that an 'sh' command "
-               ++ "is discoverable in your path."
-
--- | Convert Windows path to Unix ones
-toUnix :: String -> String
-#ifdef mingw32_HOST_OS
-toUnix s = let tmp = normalise s
-               (l, rest) = case splitDrive tmp of
-                             ([],  x) -> ("/"      , x)
-                             (h:_, x) -> ('/':h:"/", x)
-               parts = splitDirectories rest
-           in  l ++ intercalate "/" parts
-#else
-toUnix s = intercalate "/" $ splitDirectories s
-#endif
-
-badAutoconfCharacters :: [(Char, String)]
-badAutoconfCharacters =
-  [ (' ', "space")
-  , ('\t', "tab")
-  , ('\n', "newline")
-  , ('\0', "null")
-  , ('"', "double quote")
-  , ('#', "hash")
-  , ('$', "dollar sign")
-  , ('&', "ampersand")
-  , ('\'', "single quote")
-  , ('(', "left bracket")
-  , (')', "right bracket")
-  , ('*', "star")
-  , (';', "semicolon")
-  , ('<', "less-than sign")
-  , ('=', "equals sign")
-  , ('>', "greater-than sign")
-  , ('?', "question mark")
-  , ('[', "left square bracket")
-  , ('\\', "backslash")
-  , ('`', "backtick")
-  , ('|', "pipe")
-  ]
-
 getHookedBuildInfo :: Verbosity -> FilePath -> IO HookedBuildInfo
 getHookedBuildInfo verbosity build_dir = do
   maybe_infoFile <- findHookedPackageDesc verbosity build_dir
diff --git a/Cabal/src/Distribution/Simple/Build.hs b/Cabal/src/Distribution/Simple/Build.hs
index ad1161155d36b9642a8f6bdb0c208c7670d4bb05..b4f1c2d7f126916c2fa03d420c3b10675a9fe592 100644
--- a/Cabal/src/Distribution/Simple/Build.hs
+++ b/Cabal/src/Distribution/Simple/Build.hs
@@ -55,6 +55,7 @@ import qualified Distribution.Simple.HaskellSuite as HaskellSuite
 import qualified Distribution.Simple.PackageIndex as Index
 
 import Distribution.Simple.Build.Macros      (generateCabalMacrosHeader)
+import Distribution.Simple.Build.PackageInfoModule (generatePackageInfoModule)
 import Distribution.Simple.Build.PathsModule (generatePathsModule)
 import qualified Distribution.Simple.Program.HcPkg as HcPkg
 
@@ -773,7 +774,7 @@ componentInitialBuildSteps _distPref pkg_descr lbi clbi verbosity = do
 
   writeAutogenFiles verbosity pkg_descr lbi clbi
 
--- | Generate and write out the Paths_<pkg>.hs and cabal_macros.h files
+-- | Generate and write out the Paths_<pkg>.hs, PackageInfo_<pkg>.hs, and cabal_macros.h files
 --
 writeAutogenFiles :: Verbosity
                   -> PackageDescription
@@ -790,6 +791,13 @@ writeAutogenFiles verbosity pkg lbi clbi = do
   createDirectoryIfMissingVerbose verbosity True pathsModuleDir
   rewriteFileEx verbosity pathsModulePath (generatePathsModule pkg lbi clbi)
 
+  let packageInfoModulePath = autogenComponentModulesDir lbi clbi
+                 </> ModuleName.toFilePath (autogenPackageInfoModuleName pkg) <.> "hs"
+      packageInfoModuleDir = takeDirectory packageInfoModulePath
+  -- Ensure that the directory exists!
+  createDirectoryIfMissingVerbose verbosity True packageInfoModuleDir
+  rewriteFileEx verbosity packageInfoModulePath (generatePackageInfoModule pkg lbi)
+
   --TODO: document what we're doing here, and move it to its own function
   case clbi of
     LibComponentLocalBuildInfo { componentInstantiatedWith = insts } ->
diff --git a/Cabal/src/Distribution/Simple/Build/PackageInfoModule.hs b/Cabal/src/Distribution/Simple/Build/PackageInfoModule.hs
new file mode 100644
index 0000000000000000000000000000000000000000..6b33c0c84c0f6417c50595c784b468e9b6c6cac4
--- /dev/null
+++ b/Cabal/src/Distribution/Simple/Build/PackageInfoModule.hs
@@ -0,0 +1,56 @@
+-----------------------------------------------------------------------------
+-- |
+-- Module      :  Distribution.Simple.Build.PackageInfoModule
+-- Copyright   :
+--
+-- Maintainer  :  cabal-devel@haskell.org
+-- Portability :  portable
+--
+-- Generating the PackageInfo_pkgname module.
+--
+-- This is a module that Cabal generates for the benefit of packages. It
+-- enables them to find their package informations.
+--
+module Distribution.Simple.Build.PackageInfoModule (
+    generatePackageInfoModule
+  ) where
+
+import Distribution.Compat.Prelude
+import Prelude ()
+
+import Distribution.Package
+import Distribution.PackageDescription
+import Distribution.Simple.Compiler
+import Distribution.Simple.LocalBuildInfo
+import Distribution.Utils.ShortText
+import Distribution.Version
+
+import qualified Distribution.Simple.Build.PackageInfoModule.Z as Z
+
+-- ------------------------------------------------------------
+-- * Building Paths_<pkg>.hs
+-- ------------------------------------------------------------
+
+generatePackageInfoModule :: PackageDescription -> LocalBuildInfo -> String
+generatePackageInfoModule pkg_descr lbi = Z.render Z.Z
+    { Z.zPackageName   = showPkgName $ packageName pkg_descr
+    , Z.zVersionDigits = show $ versionNumbers $ packageVersion pkg_descr
+    , Z.zSynopsis        = fromShortText $ synopsis pkg_descr
+    , Z.zCopyright       = fromShortText $ copyright pkg_descr
+    , Z.zHomepage        = fromShortText $ homepage pkg_descr
+    , Z.zSupportsNoRebindableSyntax = supports_rebindable_syntax
+    }
+  where
+    supports_rebindable_syntax   = ghc_newer_than (mkVersion [7,0,1])
+
+    ghc_newer_than minVersion =
+        case compilerCompatVersion GHC (compiler lbi) of
+            Nothing      -> False
+            Just version -> version `withinRange` orLaterVersion minVersion
+
+showPkgName :: PackageName -> String
+showPkgName = map fixchar . unPackageName
+
+fixchar :: Char -> Char
+fixchar '-' = '_'
+fixchar c   = c
diff --git a/Cabal/src/Distribution/Simple/Build/PackageInfoModule/Z.hs b/Cabal/src/Distribution/Simple/Build/PackageInfoModule/Z.hs
new file mode 100644
index 0000000000000000000000000000000000000000..e96ed923045cb1dfc782c79637a2c58c7b8e371d
--- /dev/null
+++ b/Cabal/src/Distribution/Simple/Build/PackageInfoModule/Z.hs
@@ -0,0 +1,60 @@
+{-# LANGUAGE DeriveGeneric #-}
+
+module Distribution.Simple.Build.PackageInfoModule.Z (render, Z (..)) where
+
+import Distribution.ZinzaPrelude
+
+data Z = Z
+  { zPackageName :: String,
+    zVersionDigits :: String,
+    zSynopsis :: String,
+    zCopyright :: String,
+    zHomepage :: String,
+    zSupportsNoRebindableSyntax :: Bool
+  }
+  deriving (Generic)
+
+render :: Z -> String
+render z_root = execWriter $ do
+  if (zSupportsNoRebindableSyntax z_root)
+  then do
+    tell "{-# LANGUAGE NoRebindableSyntax #-}\n"
+    return ()
+  else do
+    return ()
+  tell "{-# OPTIONS_GHC -fno-warn-missing-import-lists #-}\n"
+  tell "{-# OPTIONS_GHC -w #-}\n"
+  tell "module PackageInfo_"
+  tell (zPackageName z_root)
+  tell " (\n"
+  tell "    name,\n"
+  tell "    version,\n"
+  tell "    synopsis,\n"
+  tell "    copyright,\n"
+  tell "    homepage,\n"
+  tell "  ) where\n"
+  tell "\n"
+  tell "import Data.Version (Version(..))\n"
+  tell "import Prelude\n"
+  tell "\n"
+  tell "name :: String\n"
+  tell "name = "
+  tell (show $ zPackageName z_root)
+  tell "\n"
+  tell "version :: Version\n"
+  tell "version = Version "
+  tell (zVersionDigits z_root)
+  tell " []\n"
+  tell "\n"
+  tell "synopsis :: String\n"
+  tell "synopsis = "
+  tell (show $ zSynopsis z_root)
+  tell "\n"
+  tell "copyright :: String\n"
+  tell "copyright = "
+  tell (show $ zCopyright z_root)
+  tell "\n"
+  tell "homepage :: String\n"
+  tell "homepage = "
+  tell (show $ zHomepage z_root)
+  tell "\n"
diff --git a/Cabal/src/Distribution/Simple/BuildPaths.hs b/Cabal/src/Distribution/Simple/BuildPaths.hs
index 733953747c80e3d89f7d4bc4b9de0ebed8bd742d..189de54785f3d0ba5873631866469dced0641f71 100644
--- a/Cabal/src/Distribution/Simple/BuildPaths.hs
+++ b/Cabal/src/Distribution/Simple/BuildPaths.hs
@@ -20,6 +20,7 @@ module Distribution.Simple.BuildPaths (
     autogenComponentModulesDir,
 
     autogenPathsModuleName,
+    autogenPackageInfoModuleName,
     cppHeaderName,
     haddockName,
 
@@ -105,6 +106,14 @@ autogenPathsModuleName pkg_descr =
   where fixchar '-' = '_'
         fixchar c   = c
 
+-- | The name of the auto-generated PackageInfo_* module associated with a package
+autogenPackageInfoModuleName :: PackageDescription -> ModuleName
+autogenPackageInfoModuleName pkg_descr =
+  ModuleName.fromString $
+    "PackageInfo_" ++ map fixchar (prettyShow (packageName pkg_descr))
+  where fixchar '-' = '_'
+        fixchar c   = c
+
 haddockName :: PackageDescription -> FilePath
 haddockName pkg_descr = prettyShow (packageName pkg_descr) <.> "haddock"
 
@@ -235,8 +244,9 @@ mkGenericSharedBundledLibName platform comp lib
 -- | Default extension for executable files on the current platform.
 -- (typically @\"\"@ on Unix and @\"exe\"@ on Windows or OS\/2)
 exeExtension :: Platform -> String
-exeExtension (Platform _arch os) = case os of
-                   Windows -> "exe"
+exeExtension platform = case platform of
+                   Platform _ Windows -> "exe"
+                   Platform Wasm32 _  -> "wasm"
                    _       -> ""
 
 -- | Extension for object files. For GHC the extension is @\"o\"@.
diff --git a/Cabal/src/Distribution/Simple/Command.hs b/Cabal/src/Distribution/Simple/Command.hs
index 69e0a1976598966ad1e071c27a4c554523c485ac..5602e3796800d1c849438ec365112a4452562909 100644
--- a/Cabal/src/Distribution/Simple/Command.hs
+++ b/Cabal/src/Distribution/Simple/Command.hs
@@ -574,7 +574,7 @@ helpCommandUI =
     commandNotes = Just $ \pname ->
        "Examples:\n"
     ++ "  " ++ pname ++ " help help\n"
-    ++ "    Oh, appararently you already know this.\n"
+    ++ "    Oh, apparently you already know this.\n"
   }
 
 -- | wraps a @CommandUI@ together with a function that turns it into a @Command@.
diff --git a/Cabal/src/Distribution/Simple/Configure.hs b/Cabal/src/Distribution/Simple/Configure.hs
index 26022b9aa0b509c0ece19e39ddf5b03e165e426e..d8d2aecb80418efa3370007a7b3f7728a04b9a00 100644
--- a/Cabal/src/Distribution/Simple/Configure.hs
+++ b/Cabal/src/Distribution/Simple/Configure.hs
@@ -54,7 +54,7 @@ module Distribution.Simple.Configure
   , platformDefines,
   ) where
 
-import qualified Prelude as Unsafe (tail)
+import Prelude ()
 import Distribution.Compat.Prelude
 
 import Distribution.Compiler
@@ -106,7 +106,8 @@ import Data.ByteString.Lazy          ( ByteString )
 import qualified Data.ByteString            as BS
 import qualified Data.ByteString.Lazy.Char8 as BLC8
 import Data.List
-    ( (\\), inits, stripPrefix, intersect)
+    ( (\\), stripPrefix, intersect)
+import qualified Data.List.NonEmpty as NEL
 import qualified Data.Map as Map
 import System.Directory
     ( canonicalizePath, createDirectoryIfMissing, doesFileExist
@@ -1784,7 +1785,7 @@ checkForeignDeps pkg lbi verbosity =
         findOffendingHdr =
             ifBuildsWith allHeaders ccArgs
                          (return Nothing)
-                         (go . Unsafe.tail . inits $ allHeaders) -- inits always contains at least []
+                         (go . tail . NEL.inits $ allHeaders)
             where
               go [] = return Nothing       -- cannot happen
               go (hdrs:hdrsInits) =
@@ -2066,7 +2067,7 @@ checkForeignLibSupported comp platform flib = go (compilerFlavor comp)
     go :: CompilerFlavor -> Maybe String
     go GHC
       | compilerVersion comp < mkVersion [7,8] = unsupported [
-        "Building foreign libraires is only supported with GHC >= 7.8"
+        "Building foreign libraries is only supported with GHC >= 7.8"
       ]
       | otherwise = goGhcPlatform platform
     go _   = unsupported [
diff --git a/Cabal/src/Distribution/Simple/ConfigureScript.hs b/Cabal/src/Distribution/Simple/ConfigureScript.hs
new file mode 100644
index 0000000000000000000000000000000000000000..9c3e5c8874b2a993f1525d1b292a46dfb7f286aa
--- /dev/null
+++ b/Cabal/src/Distribution/Simple/ConfigureScript.hs
@@ -0,0 +1,195 @@
+{-# LANGUAGE FlexibleContexts #-}
+{-# LANGUAGE ScopedTypeVariables #-}
+{-# LANGUAGE RankNTypes #-}
+{-# LANGUAGE LambdaCase #-}
+{-# LANGUAGE CPP #-}
+-----------------------------------------------------------------------------
+-- |
+-- Module      :  Distribution.Simple.ConfigureScript
+-- Copyright   :  Isaac Jones 2003-2005
+-- License     :  BSD3
+--
+-- Maintainer  :  cabal-devel@haskell.org
+-- Portability :  portable
+--
+{-# OPTIONS_GHC -fno-warn-deprecations #-}
+
+module Distribution.Simple.ConfigureScript (
+    runConfigureScript
+  ) where
+
+import Prelude ()
+import Distribution.Compat.Prelude
+
+-- local
+import Distribution.PackageDescription
+import Distribution.Simple.Program
+import Distribution.Simple.Program.Db
+import Distribution.Simple.Setup
+
+import Distribution.Simple.LocalBuildInfo
+import Distribution.Simple.Utils
+import Distribution.Utils.NubList
+import Distribution.Verbosity
+import Distribution.Pretty
+import Distribution.System (buildPlatform)
+
+-- Base
+import System.FilePath    (searchPathSeparator, takeDirectory, (</>),
+                           splitDirectories, dropDrive)
+#ifdef mingw32_HOST_OS
+import System.FilePath    (normalise, splitDrive)
+#endif
+import Distribution.Compat.Directory        (makeAbsolute)
+import Distribution.Compat.Environment      (getEnvironment)
+import Distribution.Compat.GetShortPathName (getShortPathName)
+
+import qualified Data.List.NonEmpty as NonEmpty
+import qualified Data.Map as Map
+
+runConfigureScript :: Verbosity -> ConfigFlags -> LocalBuildInfo
+                   -> IO ()
+runConfigureScript verbosity flags lbi = do
+  env <- getEnvironment
+  let programDb = withPrograms lbi
+  (ccProg, ccFlags) <- configureCCompiler verbosity programDb
+  ccProgShort <- getShortPathName ccProg
+  -- The C compiler's compilation and linker flags (e.g.
+  -- "C compiler flags" and "Gcc Linker flags" from GHC) have already
+  -- been merged into ccFlags, so we set both CFLAGS and LDFLAGS
+  -- to ccFlags
+  -- We don't try and tell configure which ld to use, as we don't have
+  -- a way to pass its flags too
+  configureFile <- makeAbsolute $
+    fromMaybe "." (takeDirectory <$> cabalFilePath lbi) </> "configure"
+  -- autoconf is fussy about filenames, and has a set of forbidden
+  -- characters that can't appear in the build directory, etc:
+  -- https://www.gnu.org/software/autoconf/manual/autoconf.html#File-System-Conventions
+  --
+  -- This has caused hard-to-debug failures in the past (#5368), so we
+  -- detect some cases early and warn with a clear message. Windows's
+  -- use of backslashes is problematic here, so we'll switch to
+  -- slashes, but we do still want to fail on backslashes in POSIX
+  -- paths.
+  --
+  -- TODO: We don't check for colons, tildes or leading dashes. We
+  -- also should check the builddir's path, destdir, and all other
+  -- paths as well.
+  let configureFile' = toUnix configureFile
+  for_ badAutoconfCharacters $ \(c, cname) ->
+    when (c `elem` dropDrive configureFile') $
+      warn verbosity $ concat
+        [ "The path to the './configure' script, '", configureFile'
+        , "', contains the character '", [c], "' (", cname, ")."
+        , " This may cause the script to fail with an obscure error, or for"
+        , " building the package to fail later."
+        ]
+
+  let -- Convert a flag name to name of environment variable to represent its
+      -- value for the configure script.
+      flagEnvVar :: FlagName -> String
+      flagEnvVar flag = "CABAL_FLAG_" ++ map f (unFlagName flag)
+        where f c
+                | isAlphaNum c = c
+                | otherwise    = '_'
+      -- A map from such env vars to every flag name and value where the name
+      -- name maps to that that env var.
+      cabalFlagMap :: Map String (NonEmpty (FlagName, Bool))
+      cabalFlagMap = Map.fromListWith (<>)
+                     [ (flagEnvVar flag, (flag, bool) :| [])
+                     | (flag, bool) <- unFlagAssignment $ flagAssignment lbi
+                     ]
+  -- A map from env vars to flag names to the single flag we will go with
+  cabalFlagMapDeconflicted :: Map String (FlagName, Bool) <-
+    flip Map.traverseWithKey cabalFlagMap $ \ envVar -> \case
+      -- No conflict: no problem
+      singleFlag :| [] -> pure singleFlag
+      -- Conflict: warn and discard all but first
+      collidingFlags@(firstFlag :| _ : _) -> do
+        let quote s = "'" ++ s ++ "'"
+            toName = quote . unFlagName . fst
+            renderedList = intercalate ", " $ NonEmpty.toList $ toName <$> collidingFlags
+        warn verbosity $ unwords
+          [ "Flags", renderedList, "all map to the same environment variable"
+          , quote envVar, "causing a collision."
+          , "The value first flag", toName firstFlag, "will be used."
+          ]
+        pure firstFlag
+
+  let cabalFlagEnv = [ (envVar, Just val)
+                     | (envVar, (_, bool)) <- Map.toList cabalFlagMapDeconflicted
+                     , let val = if bool then "1" else "0"
+                     ] ++
+                     [ ( "CABAL_FLAGS"
+                       , Just $ unwords [ showFlagValue fv | fv <- unFlagAssignment $ flagAssignment lbi ]
+                       )
+                     ]
+  let extraPath = fromNubList $ configProgramPathExtra flags
+  let cflagsEnv = maybe (unwords ccFlags) (++ (" " ++ unwords ccFlags))
+                  $ lookup "CFLAGS" env
+      spSep = [searchPathSeparator]
+      pathEnv = maybe (intercalate spSep extraPath)
+                ((intercalate spSep extraPath ++ spSep)++) $ lookup "PATH" env
+      overEnv = ("CFLAGS", Just cflagsEnv) :
+                [("PATH", Just pathEnv) | not (null extraPath)] ++
+                cabalFlagEnv
+      hp = hostPlatform lbi
+      maybeHostFlag = if hp == buildPlatform then [] else ["--host=" ++ show (pretty hp)]
+      args' = configureFile':args ++ ["CC=" ++ ccProgShort] ++ maybeHostFlag
+      shProg = simpleProgram "sh"
+      progDb = modifyProgramSearchPath
+               (\p -> map ProgramSearchPathDir extraPath ++ p) emptyProgramDb
+  shConfiguredProg <- lookupProgram shProg
+                      `fmap` configureProgram  verbosity shProg progDb
+  case shConfiguredProg of
+      Just sh -> runProgramInvocation verbosity $
+                 (programInvocation (sh {programOverrideEnv = overEnv}) args')
+                 { progInvokeCwd = Just (buildDir lbi) }
+      Nothing -> die' verbosity notFoundMsg
+  where
+    args = configureArgs backwardsCompatHack flags
+    backwardsCompatHack = False
+
+    notFoundMsg = "The package has a './configure' script. "
+               ++ "If you are on Windows, This requires a "
+               ++ "Unix compatibility toolchain such as MinGW+MSYS or Cygwin. "
+               ++ "If you are not on Windows, ensure that an 'sh' command "
+               ++ "is discoverable in your path."
+
+-- | Convert Windows path to Unix ones
+toUnix :: String -> String
+#ifdef mingw32_HOST_OS
+toUnix s = let tmp = normalise s
+               (l, rest) = case splitDrive tmp of
+                             ([],  x) -> ("/"      , x)
+                             (h:_, x) -> ('/':h:"/", x)
+               parts = splitDirectories rest
+           in  l ++ intercalate "/" parts
+#else
+toUnix s = intercalate "/" $ splitDirectories s
+#endif
+
+badAutoconfCharacters :: [(Char, String)]
+badAutoconfCharacters =
+  [ (' ', "space")
+  , ('\t', "tab")
+  , ('\n', "newline")
+  , ('\0', "null")
+  , ('"', "double quote")
+  , ('#', "hash")
+  , ('$', "dollar sign")
+  , ('&', "ampersand")
+  , ('\'', "single quote")
+  , ('(', "left bracket")
+  , (')', "right bracket")
+  , ('*', "star")
+  , (';', "semicolon")
+  , ('<', "less-than sign")
+  , ('=', "equals sign")
+  , ('>', "greater-than sign")
+  , ('?', "question mark")
+  , ('[', "left square bracket")
+  , ('\\', "backslash")
+  , ('`', "backtick")
+  , ('|', "pipe")
+  ]
diff --git a/Cabal/src/Distribution/Simple/SrcDist.hs b/Cabal/src/Distribution/Simple/SrcDist.hs
index 3bba81bed94020588cbfc14262c39089b288c377..1cb2b84106393fe9d966fb0652520e5b7f9c6fff 100644
--- a/Cabal/src/Distribution/Simple/SrcDist.hs
+++ b/Cabal/src/Distribution/Simple/SrcDist.hs
@@ -361,8 +361,10 @@ filterAutogenModules pkg_descr0 = mapLib filterAutogenModuleLib $
       otherModules   = filter (filterFunction bi) (otherModules bi)
     }
     pathsModule = autogenPathsModuleName pkg_descr0
+    packageInfoModule = autogenPackageInfoModuleName pkg_descr0
     filterFunction bi = \mn ->
                                    mn /= pathsModule
+                                && mn /= packageInfoModule
                                 && not (mn `elem` autogenModules bi)
 
 -- | Prepare a directory tree of source files for a snapshot version.
diff --git a/Cabal/src/Distribution/Simple/Utils.hs b/Cabal/src/Distribution/Simple/Utils.hs
index 6bf0729410a53c08396d940124fd1192f8fd70d9..3fb6f56c7381cf4680940cbce49f6b85496be6c5 100644
--- a/Cabal/src/Distribution/Simple/Utils.hs
+++ b/Cabal/src/Distribution/Simple/Utils.hs
@@ -1535,12 +1535,13 @@ dropExeExtension filepath =
 -- | List of possible executable file extensions on the current build
 -- platform.
 exeExtensions :: [String]
-exeExtensions = case buildOS of
+exeExtensions = case (buildArch, buildOS) of
   -- Possible improvement: on Windows, read the list of extensions from the
   -- PATHEXT environment variable. By default PATHEXT is ".com; .exe; .bat;
   -- .cmd".
-  Windows -> ["", "exe"]
-  Ghcjs   -> ["", "exe"]
+  (_, Windows) -> ["", "exe"]
+  (_, Ghcjs)   -> ["", "exe"]
+  (Wasm32, _)  -> ["", "wasm"]
   _       -> [""]
 
 -- ------------------------------------------------------------
diff --git a/Cabal/src/Distribution/Types/LocalBuildInfo.hs b/Cabal/src/Distribution/Types/LocalBuildInfo.hs
index bef07444444ad88768faa5c186d1054b358c066b..bc9f6bc45d3a07b1679e08a432ec07fceb2f91e0 100644
--- a/Cabal/src/Distribution/Types/LocalBuildInfo.hs
+++ b/Cabal/src/Distribution/Types/LocalBuildInfo.hs
@@ -283,7 +283,7 @@ testCoverage lbi = exeCoverage lbi && libCoverage lbi
 -------------------------------------------------------------------------------
 -- Stub functions to prevent someone from accidentally defining them
 
-{-# WARNING componentNameTargets, unitIdTarget, allTargetsInBuildOrder, withAllTargetsInBuildOrder, neededTargetsInBuildOrder, withNeededTargetsInBuildOrder "By using this function, you may be introducing a bug where you retrieve a 'Component' which does not have 'HookedBuildInfo' applied to it.  See the documentation for 'HookedBuildInfo' for an explanation of the issue.  If you have a 'PakcageDescription' handy (NOT from the 'LocalBuildInfo'), try using the primed version of the function, which takes it as an extra argument." #-}
+{-# WARNING componentNameTargets, unitIdTarget, allTargetsInBuildOrder, withAllTargetsInBuildOrder, neededTargetsInBuildOrder, withNeededTargetsInBuildOrder "By using this function, you may be introducing a bug where you retrieve a 'Component' which does not have 'HookedBuildInfo' applied to it.  See the documentation for 'HookedBuildInfo' for an explanation of the issue.  If you have a 'PackageDescription' handy (NOT from the 'LocalBuildInfo'), try using the primed version of the function, which takes it as an extra argument." #-}
 
 componentNameTargets :: LocalBuildInfo -> ComponentName -> [TargetInfo]
 componentNameTargets lbi = componentNameTargets' (localPkgDescr lbi) lbi
diff --git a/Makefile b/Makefile
index 39ca47756ca7326457f6faed76f2fdcb382f7d9a..63654e831670cfe8be829be876cf0bc5d1a4575c 100644
--- a/Makefile
+++ b/Makefile
@@ -137,7 +137,6 @@ validate-dockerfiles : .docker/validate-8.8.4.dockerfile
 validate-dockerfiles : .docker/validate-8.6.5.dockerfile
 validate-dockerfiles : .docker/validate-8.4.4.dockerfile
 validate-dockerfiles : .docker/validate-8.2.2.dockerfile
-validate-dockerfiles : .docker/validate-8.6.5.dockerfile
 
 .docker/validate-%.dockerfile : .docker/validate.dockerfile.zinza cabal-dev-scripts/src/GenValidateDockerfile.hs
 	cabal v2-run --builddir=dist-newstyle-meta --project-file=cabal.project.meta gen-validate-dockerfile -- $* $< $@
diff --git a/bootstrap/bootstrap.py b/bootstrap/bootstrap.py
index 82b792e1e461be750db2405b207fab6cfe42da54..8efcbbae1168b9bb62ee5744f2bd2e8b38132ee8 100755
--- a/bootstrap/bootstrap.py
+++ b/bootstrap/bootstrap.py
@@ -331,7 +331,7 @@ def fetch_from_plan(plan : FetchPlan, output_dir : Path):
     sha = plan[path].sha256
     if not output_path.exists():
       print(f'Fetching {url}...')
-      with urllib.request.urlopen(url) as resp:
+      with urllib.request.urlopen(url, timeout = 10) as resp:
         shutil.copyfileobj(resp, output_path.open('wb'))
     verify_sha256(sha, output_path)
 
diff --git a/cabal-install-solver/cabal-install-solver.cabal b/cabal-install-solver/cabal-install-solver.cabal
index 69f7042a32bc953e00ac7159a6d6d0c80082203b..1b03d228a688c5f3995675e65b3996265b7246d1 100644
--- a/cabal-install-solver/cabal-install-solver.cabal
+++ b/cabal-install-solver/cabal-install-solver.cabal
@@ -112,9 +112,9 @@ library
     , containers    >=0.5.6.2  && <0.7
     , edit-distance ^>= 0.2.2
     , filepath      ^>=1.4.0.0
-    , mtl           >=2.0      && <2.3
+    , mtl           >=2.0      && <2.4
     , pretty        ^>=1.1
-    , transformers  >=0.4.2.0  && <0.6
+    , transformers  >=0.4.2.0  && <0.7
 
   if flag(debug-expensive-assertions)
     cpp-options: -DDEBUG_EXPENSIVE_ASSERTIONS
diff --git a/cabal-install-solver/src/Distribution/Solver/Modular/Linking.hs b/cabal-install-solver/src/Distribution/Solver/Modular/Linking.hs
index a348aa247b60e59d0d6cf74a3e94982e5d4218f5..eb3c98a8aca57ebd96969cbe7786abc4ac1ae014 100644
--- a/cabal-install-solver/src/Distribution/Solver/Modular/Linking.hs
+++ b/cabal-install-solver/src/Distribution/Solver/Modular/Linking.hs
@@ -11,8 +11,10 @@ import Prelude ()
 import Distribution.Solver.Compat.Prelude hiding (get,put)
 
 import Control.Exception (assert)
-import Control.Monad.Reader
-import Control.Monad.State
+import Control.Monad (forM_, zipWithM_)
+import Control.Monad.Reader (Reader, runReader, local, ask)
+import Control.Monad.State (MonadState, StateT, get, put, modify, execStateT)
+import Control.Monad.Trans (lift)
 import Data.Map ((!))
 import qualified Data.Map         as M
 import qualified Data.Set         as S
diff --git a/cabal-install-solver/src/Distribution/Solver/Modular/Solver.hs b/cabal-install-solver/src/Distribution/Solver/Modular/Solver.hs
index da5fa56963374a01d063952f72159712f6f4a8a6..467a743c1dae8b0614f1dd00d3a373feff3ad1d7 100644
--- a/cabal-install-solver/src/Distribution/Solver/Modular/Solver.hs
+++ b/cabal-install-solver/src/Distribution/Solver/Modular/Solver.hs
@@ -162,7 +162,11 @@ solve sc cinfo idx pkgConfigDB userPrefs userConstraints userGoals =
     nonInstallable =
         L.map mkPackageName
              [ "base"
+             , "ghc-bignum"
              , "ghc-prim"
+             , "ghc-boot"
+             , "ghc"
+             , "ghci"
              , "integer-gmp"
              , "integer-simple"
              , "template-haskell"
diff --git a/cabal-install-solver/src/Distribution/Solver/Modular/Validate.hs b/cabal-install-solver/src/Distribution/Solver/Modular/Validate.hs
index 41a170f1429cfe0e3fab124651c34351cb46751f..54911f2c367b3ac59c11b49761073b60609e2b12 100644
--- a/cabal-install-solver/src/Distribution/Solver/Modular/Validate.hs
+++ b/cabal-install-solver/src/Distribution/Solver/Modular/Validate.hs
@@ -12,7 +12,8 @@ module Distribution.Solver.Modular.Validate (validateTree) where
 -- assignment returned by exploration of the tree should be a complete valid
 -- assignment, i.e., actually constitute a solution.
 
-import Control.Monad.Reader
+import Control.Monad (foldM, mzero, liftM2)
+import Control.Monad.Reader (MonadReader, Reader, runReader, local, asks)
 import Data.Either (lefts)
 import Data.Function (on)
 
diff --git a/cabal-install-solver/src/Distribution/Solver/Types/PkgConfigDb.hs b/cabal-install-solver/src/Distribution/Solver/Types/PkgConfigDb.hs
index 14140104ffd8e192858920bb45cc27bd90bb07a3..11e6da847f024760d4cab3ea9a868c59e81d8443 100644
--- a/cabal-install-solver/src/Distribution/Solver/Types/PkgConfigDb.hs
+++ b/cabal-install-solver/src/Distribution/Solver/Types/PkgConfigDb.hs
@@ -24,6 +24,7 @@ import Distribution.Solver.Compat.Prelude
 import Prelude ()
 
 import           Control.Exception (handle)
+import           Control.Monad     (mapM)
 import qualified Data.Map          as M
 import           System.FilePath   (splitSearchPath)
 
@@ -31,7 +32,8 @@ import Distribution.Compat.Environment          (lookupEnv)
 import Distribution.Package                     (PkgconfigName, mkPkgconfigName)
 import Distribution.Parsec
 import Distribution.Simple.Program
-       (ProgramDb, getProgramOutput, pkgConfigProgram, needProgram)
+       (ProgramDb, getProgramOutput, pkgConfigProgram, needProgram, ConfiguredProgram)
+import Distribution.Simple.Program.Run          (getProgramInvocationOutputAndErrors, programInvocation)
 import Distribution.Simple.Utils                (info)
 import Distribution.Types.PkgconfigVersion
 import Distribution.Types.PkgconfigVersionRange
@@ -65,9 +67,15 @@ readPkgConfigDb verbosity progdb = handle ioErrorHandler $ do
         -- The output of @pkg-config --list-all@ also includes a description
         -- for each package, which we do not need.
         let pkgNames = map (takeWhile (not . isSpace)) pkgList
-        pkgVersions <- lines <$> getProgramOutput verbosity pkgConfig
-                                   ("--modversion" : pkgNames)
-        (return . pkgConfigDbFromList . zip pkgNames) pkgVersions
+        (pkgVersions, _errs, exitCode) <-
+                     getProgramInvocationOutputAndErrors verbosity
+                       (programInvocation pkgConfig ("--modversion" : pkgNames))
+        case exitCode of
+          ExitSuccess -> (return . pkgConfigDbFromList . zip pkgNames) (lines pkgVersions)
+          -- if there's a single broken pc file the above fails, so we fall back into calling it individually
+          _ -> do
+             info verbosity ("call to pkg-config --modversion on all packages failed. Falling back to querying pkg-config individually on each package")
+             pkgConfigDbFromList . catMaybes <$> mapM (getIndividualVersion pkgConfig) pkgNames
   where
     -- For when pkg-config invocation fails (possibly because of a
     -- too long command line).
@@ -80,6 +88,15 @@ readPkgConfigDb verbosity progdb = handle ioErrorHandler $ do
     ioErrorHandler :: IOException -> IO PkgConfigDb
     ioErrorHandler e = noPkgConfig (show e)
 
+    getIndividualVersion :: ConfiguredProgram -> String -> IO (Maybe (String, String))
+    getIndividualVersion pkgConfig pkg = do
+       (pkgVersion, _errs, exitCode) <-
+               getProgramInvocationOutputAndErrors verbosity
+                 (programInvocation pkgConfig ["--modversion",pkg])
+       return $ case exitCode of
+         ExitSuccess -> Just (pkg, pkgVersion)
+         _ -> Nothing
+
 -- | Create a `PkgConfigDb` from a list of @(packageName, version)@ pairs.
 pkgConfigDbFromList :: [(String, String)] -> PkgConfigDb
 pkgConfigDbFromList pairs = (PkgConfigDb . M.fromList . map convert) pairs
diff --git a/cabal-install/cabal-install.cabal b/cabal-install/cabal-install.cabal
index b02800e2ce4a2e1809db30ea52d71c4b804d0cc4..747d353276b3ffdc42339b4a657e76bd09abfa1b 100644
--- a/cabal-install/cabal-install.cabal
+++ b/cabal-install/cabal-install.cabal
@@ -215,7 +215,7 @@ library
         filepath   >= 1.4.0.0  && < 1.5,
         hashable   >= 1.0      && < 1.5,
         HTTP       >= 4000.1.5 && < 4000.5,
-        mtl        >= 2.0      && < 2.3,
+        mtl        >= 2.0      && < 2.4,
         network-uri >= 2.6.0.2 && < 2.7,
         pretty     >= 1.1      && < 1.2,
         process    >= 1.2.3.0  && < 1.7,
diff --git a/cabal-install/changelog b/cabal-install/changelog
index 48be043315b97d94871eb7769593e81338e680d6..dc75160a18655d4f49e3ac506f7ad7e60cef61c9 100644
--- a/cabal-install/changelog
+++ b/cabal-install/changelog
@@ -169,7 +169,7 @@
 	* Default changelog generated by 'cabal init' is now named
 	  'CHANGELOG.md' (#5441).
 	* Align output of 'new-build' command phases (#4040).
-	* Add suport for specifying remote VCS dependencies via new
+	* Add support for specifying remote VCS dependencies via new
 	  'source-repository-package' stanzas in 'cabal.project' files
 	  (#5351).
 
@@ -206,7 +206,7 @@
 	* Use [lfxtb] letters to differentiate component kind instead of
 	opaque "c" in dist-dir layout.
 	* 'cabal configure' now supports '--enable-static', which can be
-	used to build static libaries with GHC via GHC's `-staticlib`
+	used to build static libraries with GHC via GHC's `-staticlib`
 	flag.
 	* 'cabal user-config now supports '--augment' which can append
 	additional lines to a new or updated cabal config file.
@@ -226,7 +226,7 @@
 	when it wasn't necessary (#4444).
 	* Packages installed in sandboxes via 'add-source' now have
 	their timestamps updated correctly and so will not be reinstalled
-	unncecessarily if the main install command fails (#1375).
+	unnecessarily if the main install command fails (#1375).
 	* Add Windows device path support for copyFile, renameFile. Allows cabal
 	new-build to use temporary store path of up to 32k length
 	(#3972, #4914, #4515).
@@ -577,9 +577,9 @@
 	* Improved bootstrap.sh
 
 0.5.2 Duncan Coutts <duncan@haskell.org> Aug 2008
-	* Suport building haddock documentaion
+	* Support building haddock documentation
 	* Self-reinstall now works on Windows
-	* Allow adding symlinks to excutables into a separate bindir
+	* Allow adding symlinks to executables into a separate bindir
 	* New self-documenting config file
 	* New install --reinstall flag
 	* More helpful status messages in a couple places
diff --git a/cabal-install/src/Distribution/Client/CmdFreeze.hs b/cabal-install/src/Distribution/Client/CmdFreeze.hs
index 6ae404115a0617ad364d14bde849182c9c070fc3..273e90468330deb1417a6178a840d472f33bccd2 100644
--- a/cabal-install/src/Distribution/Client/CmdFreeze.hs
+++ b/cabal-install/src/Distribution/Client/CmdFreeze.hs
@@ -115,6 +115,7 @@ freezeAction flags@NixStyleFlags {..} extraArgs globalFlags = do
                          distDirLayout cabalDirLayout
                          projectConfig
                          localPackages
+                         Nothing
 
     let freezeConfig = projectFreezeConfig elaboratedPlan totalIndexState activeRepos
         dryRun = buildSettingDryRun buildSettings
@@ -233,4 +234,3 @@ projectFreezeConstraints plan =
         | InstallPlan.Configured elab <- InstallPlan.toList plan
         , elabLocalToProject elab
         ]
-
diff --git a/cabal-install/src/Distribution/Client/CmdInstall.hs b/cabal-install/src/Distribution/Client/CmdInstall.hs
index 64af0a7b046027b79f3ad9d75349260cbda069b6..bd6567cf49a601626476d7a47d130555e8644d8d 100644
--- a/cabal-install/src/Distribution/Client/CmdInstall.hs
+++ b/cabal-install/src/Distribution/Client/CmdInstall.hs
@@ -33,13 +33,13 @@ import Distribution.Client.CmdInstall.ClientInstallFlags
 import Distribution.Client.CmdInstall.ClientInstallTargetSelector
 
 import Distribution.Client.Setup
-         ( GlobalFlags(..), ConfigFlags(..) )
+         ( GlobalFlags(..), ConfigFlags(..), InstallFlags(..) )
 import Distribution.Client.Types
          ( PackageSpecifier(..), PackageLocation(..), UnresolvedSourcePackage
          , SourcePackageDb(..) )
 import qualified Distribution.Client.InstallPlan as InstallPlan
 import Distribution.Package
-         ( Package(..), PackageName, mkPackageName, unPackageName )
+         ( Package(..), PackageName, unPackageName )
 import Distribution.Types.PackageId
          ( PackageIdentifier(..) )
 import Distribution.Client.ProjectConfig
@@ -58,7 +58,7 @@ import Distribution.Client.ProjectConfig.Types
          , projectConfigConfigFile )
 import Distribution.Simple.Program.Db
          ( userSpecifyPaths, userSpecifyArgss, defaultProgramDb
-         , modifyProgramSearchPath, ProgramDb )
+         , modifyProgramSearchPath )
 import Distribution.Simple.BuildPaths
          ( exeExtension )
 import Distribution.Simple.Program.Find
@@ -124,12 +124,11 @@ import Distribution.Simple.Utils
          , withTempDirectory, createDirectoryIfMissingVerbose
          , ordNub )
 import Distribution.Utils.Generic
-         ( safeHead, writeFileAtomic )
+         ( writeFileAtomic )
 
 import qualified Data.ByteString.Lazy.Char8 as BS
-import Data.Ord
-         ( Down(..) )
 import qualified Data.Map as Map
+import qualified Data.Set as S
 import qualified Data.List.NonEmpty as NE
 import Distribution.Utils.NubList
          ( fromNubList )
@@ -372,14 +371,37 @@ installAction flags@NixStyleFlags { extraFlags = clientInstallFlags', .. } targe
       (projectConfigBuildOnly config)
       [ ProjectPackageRemoteTarball uri | uri <- uris ]
 
+    -- check for targets already in env
+    let getPackageName :: PackageSpecifier UnresolvedSourcePackage -> PackageName
+        getPackageName (NamedPackage pn _) = pn
+        getPackageName (SpecificSourcePackage (SourcePackage pkgId _ _ _)) = pkgName pkgId
+        targetNames = S.fromList $ map getPackageName (specs ++ uriSpecs)
+        envNames = S.fromList $ map getPackageName envSpecs
+        forceInstall = fromFlagOrDefault False $ installOverrideReinstall installFlags
+        nameIntersection = S.intersection targetNames envNames
+
+    -- we check for intersections in targets with the existing env
+    (envSpecs', nonGlobalEnvEntries') <- if null nameIntersection
+      then pure (envSpecs, map snd nonGlobalEnvEntries)
+      else if forceInstall
+             then let es = filter (\e -> not $ getPackageName e `S.member` nameIntersection) envSpecs
+                      nge = map snd . filter (\e -> not $ fst e `S.member` nameIntersection) $ nonGlobalEnvEntries
+                  in pure (es, nge)
+             else die' verbosity $ "Packages requested to install already exist in environment file at " ++ envFile ++ ". Overwriting them may break other packages. Use --force-reinstalls to proceed anyway. Packages: " ++ intercalate ", " (map prettyShow $ S.toList nameIntersection)
+
+    -- we construct an installed index of files in the cleaned target environment (absent overwrites) so that we can solve with regards to packages installed locally but not in the upstream repo
+    let installedPacks = PI.allPackagesByName installedIndex
+        newEnvNames = S.fromList $ map getPackageName envSpecs'
+        installedIndex' = PI.fromList . concatMap snd . filter (\p -> fst p `S.member` newEnvNames) $ installedPacks
+
     baseCtx <- establishDummyProjectBaseContext
                  verbosity
                  config
                  distDirLayout
-                 (envSpecs ++ specs ++ uriSpecs)
+                 (envSpecs' ++ specs ++ uriSpecs)
                  InstallCommand
 
-    buildCtx <- constructProjectBuildContext verbosity baseCtx targetSelectors
+    buildCtx <- constructProjectBuildContext verbosity (baseCtx {installedPackages = Just installedIndex'}) targetSelectors
 
     printPlan verbosity baseCtx buildCtx
 
@@ -396,7 +418,7 @@ installAction flags@NixStyleFlags { extraFlags = clientInstallFlags', .. } targe
     unless dryRun $
       if installLibs
       then installLibraries verbosity
-           buildCtx compiler packageDbs progDb envFile nonGlobalEnvEntries
+           buildCtx compiler packageDbs envFile nonGlobalEnvEntries'
       else installExes verbosity
            baseCtx buildCtx platform compiler configFlags clientInstallFlags
   where
@@ -649,29 +671,18 @@ installLibraries
   -> ProjectBuildContext
   -> Compiler
   -> PackageDBStack
-  -> ProgramDb
   -> FilePath -- ^ Environment file
   -> [GhcEnvironmentFileEntry]
   -> IO ()
 installLibraries verbosity buildCtx compiler
-                 packageDbs programDb envFile envEntries = do
-  -- Why do we get it again? If we updated a globalPackage then we need
-  -- the new version.
-  installedIndex <- getInstalledPackages verbosity compiler packageDbs programDb
+                 packageDbs envFile envEntries = do
   if supportsPkgEnvFiles $ getImplInfo compiler
     then do
       let
-        getLatest :: PackageName -> [InstalledPackageInfo]
-        getLatest = (=<<) (maybeToList . safeHead . snd) . take 1 . sortBy (comparing (Down . fst))
-                  . PI.lookupPackageName installedIndex
-        globalLatest = concat (getLatest <$> globalPackages)
-
         baseEntries =
           GhcEnvFileClearPackageDbStack : fmap GhcEnvFilePackageDb packageDbs
-        globalEntries = GhcEnvFilePackageId . installedUnitId <$> globalLatest
         pkgEntries = ordNub $
-              globalEntries
-          ++ envEntries
+             envEntries
           ++ entriesForLibraryComponents (targetsMap buildCtx)
         contents' = renderGhcEnvironmentFile (baseEntries ++ pkgEntries)
       createDirectoryIfMissing True (takeDirectory envFile)
@@ -709,21 +720,12 @@ warnIfNoExes verbosity buildCtx =
     exeMaybe (ComponentTarget (CExeName exe) _) = Just exe
     exeMaybe _                                  = Nothing
 
-globalPackages :: [PackageName]
-globalPackages = mkPackageName <$>
-  [ "ghc", "hoopl", "bytestring", "unix", "base", "time", "hpc", "filepath"
-  , "process", "array", "integer-gmp", "containers", "ghc-boot", "binary"
-  , "ghc-prim", "ghci", "rts", "terminfo", "transformers", "deepseq"
-  , "ghc-boot-th", "pretty", "template-haskell", "directory", "text"
-  , "bin-package-db"
-  ]
-
 -- | Return the package specifiers and non-global environment file entries.
 getEnvSpecsAndNonGlobalEntries
   :: PI.InstalledPackageIndex
   -> [GhcEnvironmentFileEntry]
   -> Bool
-  -> ([PackageSpecifier a], [GhcEnvironmentFileEntry])
+  -> ([PackageSpecifier a], [(PackageName, GhcEnvironmentFileEntry)])
 getEnvSpecsAndNonGlobalEntries installedIndex entries installLibs =
   if installLibs
   then (envSpecs, envEntries')
@@ -733,7 +735,7 @@ getEnvSpecsAndNonGlobalEntries installedIndex entries installLibs =
 
 environmentFileToSpecifiers
   :: PI.InstalledPackageIndex -> [GhcEnvironmentFileEntry]
-  -> ([PackageSpecifier a], [GhcEnvironmentFileEntry])
+  -> ([PackageSpecifier a], [(PackageName, GhcEnvironmentFileEntry)])
 environmentFileToSpecifiers ipi = foldMap $ \case
     (GhcEnvFilePackageId unitId)
         | Just InstalledPackageInfo
@@ -741,9 +743,7 @@ environmentFileToSpecifiers ipi = foldMap $ \case
           <- PI.lookupUnitId ipi unitId
         , let pkgSpec = NamedPackage pkgName
                         [PackagePropertyVersion (thisVersion pkgVersion)]
-        -> if pkgName `elem` globalPackages
-          then ([pkgSpec], [])
-          else ([pkgSpec], [GhcEnvFilePackageId installedUnitId])
+        -> ([pkgSpec], [(pkgName, GhcEnvFilePackageId installedUnitId)])
     _ -> ([], [])
 
 
diff --git a/cabal-install/src/Distribution/Client/CmdListBin.hs b/cabal-install/src/Distribution/Client/CmdListBin.hs
index cde9c8605159a16324b5821cb36f597fcd8d06db..d0d699d9aea6aa958fbe22a1e4c9cc73896cd9b0 100644
--- a/cabal-install/src/Distribution/Client/CmdListBin.hs
+++ b/cabal-install/src/Distribution/Client/CmdListBin.hs
@@ -34,12 +34,12 @@ import Distribution.Client.TargetProblem         (TargetProblem (..))
 import Distribution.Simple.BuildPaths            (dllExtension, exeExtension)
 import Distribution.Simple.Command               (CommandUI (..))
 import Distribution.Simple.Setup                 (configVerbosity, fromFlagOrDefault)
-import Distribution.Simple.Utils                 (die', wrapText)
+import Distribution.Simple.Utils                 (die', info, wrapText)
 import Distribution.System                       (Platform)
 import Distribution.Types.ComponentName          (showComponentName)
 import Distribution.Types.UnitId                 (UnitId)
 import Distribution.Types.UnqualComponentName    (UnqualComponentName)
-import Distribution.Verbosity                    (silent, verboseStderr)
+import Distribution.Verbosity                    (normal, silent, verboseStderr)
 import System.FilePath                           ((<.>), (</>))
 
 import qualified Data.Map                                as Map
@@ -133,7 +133,7 @@ listbinAction flags@NixStyleFlags{..} args globalFlags = do
 
     case binfiles of
         []     -> die' verbosity "No target found"
-        [exe] -> putStrLn exe
+        [exe] -> info normal exe
         _ -> die' verbosity "Multiple targets found"
   where
     defaultVerbosity = verboseStderr silent
diff --git a/cabal-install/src/Distribution/Client/Configure.hs b/cabal-install/src/Distribution/Client/Configure.hs
index 2cbe16096a456e7d1c89be2fae4fea793356f05b..554785ff847fe8aea35e13859a929cde04d9b6b1 100644
--- a/cabal-install/src/Distribution/Client/Configure.hs
+++ b/cabal-install/src/Distribution/Client/Configure.hs
@@ -154,6 +154,9 @@ configure verbosity packageDBs repoCtxt comp platform progdb
         (fromFlagOrDefault
            (useDistPref defaultSetupScriptOptions)
            (configDistPref configFlags))
+        (fromFlagOrDefault
+            (setupConfigDynamic defaultSetupScriptOptions)
+            (configDynExe configFlags))
         (chooseCabalVersion
            configExFlags
            (flagToMaybe (configCabalVersion configExFlags)))
@@ -167,6 +170,7 @@ configureSetupScript :: PackageDBStack
                      -> Platform
                      -> ProgramDb
                      -> FilePath
+                     -> Bool
                      -> VersionRange
                      -> Maybe Lock
                      -> Bool
@@ -178,6 +182,7 @@ configureSetupScript packageDBs
                      platform
                      progdb
                      distPref
+                     dynExe
                      cabalVersion
                      lock
                      forceExternal
@@ -209,6 +214,7 @@ configureSetupScript packageDBs
     , useDependenciesExclusive = not defaultSetupDeps && isJust explicitSetupDeps
     , useVersionMacros         = not defaultSetupDeps && isJust explicitSetupDeps
     , isInteractive            = False
+    , setupConfigDynamic       = dynExe
     }
   where
     -- When we are compiling a legacy setup script without an explicit
diff --git a/cabal-install/src/Distribution/Client/Dependency.hs b/cabal-install/src/Distribution/Client/Dependency.hs
index affa5bd57aa8bde72a4fce8306551155d65d5428..c5cbba8d48ebe2f7772e9e18816edde24533162a 100644
--- a/cabal-install/src/Distribution/Client/Dependency.hs
+++ b/cabal-install/src/Distribution/Client/Dependency.hs
@@ -400,6 +400,9 @@ dontUpgradeNonUpgradeablePackages params =
       , pkgname <- [ mkPackageName "base"
                    , mkPackageName "ghc-bignum"
                    , mkPackageName "ghc-prim"
+                   , mkPackageName "ghc-boot"
+                   , mkPackageName "ghc"
+                   , mkPackageName "ghci"
                    , mkPackageName "integer-gmp"
                    , mkPackageName "integer-simple"
                    , mkPackageName "template-haskell"
diff --git a/cabal-install/src/Distribution/Client/FetchUtils.hs b/cabal-install/src/Distribution/Client/FetchUtils.hs
index a4f5a95f792723e2b08685ad7b0e6fef2837108a..963a94c1aeccc6f19b10c3b6e8189ead1a250841 100644
--- a/cabal-install/src/Distribution/Client/FetchUtils.hs
+++ b/cabal-install/src/Distribution/Client/FetchUtils.hs
@@ -11,7 +11,7 @@
 --
 -- Functions for fetching packages
 -----------------------------------------------------------------------------
-{-# LANGUAGE RecordWildCards #-}
+{-# LANGUAGE RecordWildCards, ScopedTypeVariables #-}
 module Distribution.Client.FetchUtils (
 
     -- * fetching packages
@@ -22,6 +22,7 @@ module Distribution.Client.FetchUtils (
     -- ** specifically for repo packages
     checkRepoTarballFetched,
     fetchRepoTarball,
+    verifyFetchedTarball,
 
     -- ** fetching packages asynchronously
     asyncFetchPackages,
@@ -43,7 +44,7 @@ import Distribution.Client.HttpUtils
 import Distribution.Package
          ( PackageId, packageName, packageVersion )
 import Distribution.Simple.Utils
-         ( notice, info, debug, die' )
+         ( notice, info, debug, warn, die' )
 import Distribution.Verbosity
          ( verboseUnmarkOutput )
 import Distribution.Client.GlobalFlags
@@ -56,7 +57,8 @@ import qualified Control.Exception.Safe as Safe
 import Control.Concurrent.Async
 import Control.Concurrent.MVar
 import System.Directory
-         ( doesFileExist, createDirectoryIfMissing, getTemporaryDirectory )
+         ( doesFileExist, createDirectoryIfMissing, getTemporaryDirectory
+         , getFileSize )
 import System.IO
          ( openTempFile, hClose )
 import System.FilePath
@@ -67,6 +69,8 @@ import Network.URI
          ( URI(uriPath) )
 
 import qualified Hackage.Security.Client as Sec
+import qualified Hackage.Security.Util.Path as Sec
+import qualified Hackage.Security.Util.Checked as Sec
 
 -- ------------------------------------------------------------
 -- * Actually fetch things
@@ -118,6 +122,34 @@ checkRepoTarballFetched repo pkgid = do
       then return (Just file)
       else return Nothing
 
+verifyFetchedTarball :: Verbosity -> RepoContext -> Repo -> PackageId -> IO Bool
+verifyFetchedTarball verbosity repoCtxt repo pkgid =
+   let file = packageFile repo pkgid
+       handleError :: IO Bool -> IO Bool
+       handleError act = do
+         res <- Safe.try act
+         case res of
+           Left e -> warn verbosity ("Error verifying fetched tarball " ++ file ++ ", will redownload: " ++ show (e :: SomeException)) >> pure False
+           Right b -> pure b
+   in handleError $ case repo of
+           -- a secure repo has hashes we can compare against to confirm this is the correct file.
+           RepoSecure{} ->
+             repoContextWithSecureRepo repoCtxt repo $ \repoSecure ->
+                  Sec.withIndex repoSecure $ \callbacks ->
+                    let warnAndFail s = warn verbosity ("Fetched tarball " ++ file ++ " does not match server, will redownload: " ++ s) >> return False
+                    -- the do block in parens is due to dealing with the checked exceptions mechanism.
+                    in (do fileInfo <- Sec.indexLookupFileInfo callbacks pkgid
+                           sz <- Sec.FileLength . fromInteger <$> getFileSize file
+                           if sz /= Sec.fileInfoLength (Sec.trusted fileInfo)
+                             then warnAndFail "file length mismatch"
+                             else do
+                               res <- Sec.compareTrustedFileInfo (Sec.trusted fileInfo) <$> Sec.computeFileInfo (Sec.Path file :: Sec.Path Sec.Absolute)
+                               if res
+                                 then pure True
+                                 else warnAndFail "file hash mismatch")
+                       `Sec.catchChecked` (\(e :: Sec.InvalidPackageException) -> warnAndFail (show e))
+                       `Sec.catchChecked` (\(e :: Sec.VerificationError) -> warnAndFail (show e))
+           _ -> pure True
 
 -- | Fetch a package if we don't have it already.
 --
@@ -290,7 +322,7 @@ waitAsyncFetchPackage verbosity downloadMap srcloc =
 -- ------------------------------------------------------------
 
 -- | Generate the full path to the locally cached copy of
--- the tarball for a given @PackageIdentifer@.
+-- the tarball for a given @PackageIdentifier@.
 --
 packageFile :: Repo -> PackageId -> FilePath
 packageFile repo pkgid = packageDir repo pkgid
@@ -298,7 +330,7 @@ packageFile repo pkgid = packageDir repo pkgid
                      <.> "tar.gz"
 
 -- | Generate the full path to the directory where the local cached copy of
--- the tarball for a given @PackageIdentifer@ is stored.
+-- the tarball for a given @PackageIdentifier@ is stored.
 --
 packageDir :: Repo -> PackageId -> FilePath
 packageDir (RepoLocalNoIndex (LocalRepo _ dir _) _) _pkgid = dir
diff --git a/cabal-install/src/Distribution/Client/Init/Interactive/Command.hs b/cabal-install/src/Distribution/Client/Init/Interactive/Command.hs
index 5322f7a6fdacfa10b8de3fe92ef6eb507e0b1ace..ca63d80ad37ae89da18675933462736c9c93c220 100644
--- a/cabal-install/src/Distribution/Client/Init/Interactive/Command.hs
+++ b/cabal-install/src/Distribution/Client/Init/Interactive/Command.hs
@@ -297,7 +297,7 @@ cabalVersionPrompt flags = getCabalVersion flags $ do
 packageNamePrompt :: Interactive m => SourcePackageDb -> InitFlags -> m PackageName
 packageNamePrompt srcDb flags = getPackageName flags $ do
     defName <- case packageDir flags of
-        Flag b -> return $ filePathToPkgName b
+        Flag b -> filePathToPkgName b
         NoFlag -> currentDirPkgName
 
     go $ DefaultPrompt defName
diff --git a/cabal-install/src/Distribution/Client/Init/NonInteractive/Heuristics.hs b/cabal-install/src/Distribution/Client/Init/NonInteractive/Heuristics.hs
index 79b3f61a906c0c17a4548d28199df71f32c3ce5f..ad947ec7ed23483a777faf423eeaf1b48e2cd774 100644
--- a/cabal-install/src/Distribution/Client/Init/NonInteractive/Heuristics.hs
+++ b/cabal-install/src/Distribution/Client/Init/NonInteractive/Heuristics.hs
@@ -27,7 +27,6 @@ module Distribution.Client.Init.NonInteractive.Heuristics
   ) where
 
 import Distribution.Client.Compat.Prelude hiding (readFile, (<|>), many)
-import Distribution.Utils.Generic (safeLast)
 
 import Distribution.Simple.Setup (fromFlagOrDefault)
 
@@ -40,7 +39,7 @@ import System.FilePath
 import Distribution.CabalSpecVersion
 import Language.Haskell.Extension
 import Distribution.Version
-import Distribution.Types.PackageName (PackageName, mkPackageName)
+import Distribution.Types.PackageName (PackageName)
 import Distribution.Simple.Compiler
 import qualified Data.Set as Set
 import Distribution.FieldGrammar.Newtypes
@@ -82,24 +81,7 @@ guessLanguage _ = return defaultLanguage
 
 -- | Guess the package name based on the given root directory.
 guessPackageName :: Interactive m => FilePath -> m PackageName
-guessPackageName = fmap (mkPackageName . repair . fromMaybe "" . safeLast . splitDirectories)
-                 . canonicalizePathNoThrow
-  where
-    -- Treat each span of non-alphanumeric characters as a hyphen. Each
-    -- hyphenated component of a package name must contain at least one
-    -- alphabetic character. An arbitrary character ('x') will be prepended if
-    -- this is not the case for the first component, and subsequent components
-    -- will simply be run together. For example, "1+2_foo-3" will become
-    -- "x12-foo3".
-    repair = repair' ('x' :) id
-    repair' invalid valid x = case dropWhile (not . isAlphaNum) x of
-        "" -> repairComponent ""
-        x' -> let (c, r) = first repairComponent $ span isAlphaNum x'
-              in c ++ repairRest r
-      where
-        repairComponent c | all isDigit c = invalid c
-                          | otherwise     = valid c
-    repairRest = repair' id ('-' :)
+guessPackageName = filePathToPkgName
 
 -- | Try to guess the license from an already existing @LICENSE@ file in
 --   the package directory, comparing the file contents with the ones
diff --git a/cabal-install/src/Distribution/Client/Init/Utils.hs b/cabal-install/src/Distribution/Client/Init/Utils.hs
index 4e59e55164b449cb1180f38bdc82a3a1e81e8e48..91d887e4e4674d362ebd2ff11d81cbbf0f7eaaf1 100644
--- a/cabal-install/src/Distribution/Client/Init/Utils.hs
+++ b/cabal-install/src/Distribution/Client/Init/Utils.hs
@@ -23,9 +23,9 @@ module Distribution.Client.Init.Utils
 ) where
 
 
-import qualified Prelude
+import qualified Prelude ()
 import Distribution.Client.Compat.Prelude hiding (putStrLn, empty, readFile, Parsec, many)
-import Distribution.Utils.Generic (isInfixOf)
+import Distribution.Utils.Generic (isInfixOf, safeLast)
 
 import Control.Monad (forM)
 
@@ -38,7 +38,6 @@ import Distribution.CabalSpecVersion (CabalSpecVersion(..))
 import Distribution.ModuleName (ModuleName)
 import Distribution.InstalledPackageInfo (InstalledPackageInfo, exposed)
 import qualified Distribution.Package as P
-import qualified Distribution.Types.PackageName as PN
 import Distribution.Simple.PackageIndex (InstalledPackageIndex, moduleNameIndex)
 import Distribution.Simple.Setup (Flag(..))
 import Distribution.Utils.String (trim)
@@ -277,11 +276,28 @@ chooseDep v flags (importer, m, mipi) = case mipi of
       Flag x -> x                   < CabalSpecV2_0
       NoFlag -> defaultCabalVersion < CabalSpecV2_0
 
-filePathToPkgName :: FilePath -> P.PackageName
-filePathToPkgName = PN.mkPackageName . Prelude.last . splitDirectories
+filePathToPkgName :: Interactive m => FilePath -> m P.PackageName
+filePathToPkgName = fmap (mkPackageName . repair . fromMaybe "" . safeLast . splitDirectories)
+                 . canonicalizePathNoThrow
+  where
+    -- Treat each span of non-alphanumeric characters as a hyphen. Each
+    -- hyphenated component of a package name must contain at least one
+    -- alphabetic character. An arbitrary character ('x') will be prepended if
+    -- this is not the case for the first component, and subsequent components
+    -- will simply be run together. For example, "1+2_foo-3" will become
+    -- "x12-foo3".
+    repair = repair' ('x' :) id
+    repair' invalid valid x = case dropWhile (not . isAlphaNum) x of
+        "" -> repairComponent ""
+        x' -> let (c, r) = first repairComponent $ span isAlphaNum x'
+              in c ++ repairRest r
+      where
+        repairComponent c | all isDigit c = invalid c
+                          | otherwise     = valid c
+    repairRest = repair' id ('-' :)
 
 currentDirPkgName :: Interactive m => m P.PackageName
-currentDirPkgName = filePathToPkgName <$> getCurrentDirectory
+currentDirPkgName = filePathToPkgName =<< getCurrentDirectory
 
 mkPackageNameDep :: PackageName -> Dependency
 mkPackageNameDep pkg = mkDependency pkg anyVersion (NES.singleton LMainLibName)
diff --git a/cabal-install/src/Distribution/Client/Install.hs b/cabal-install/src/Distribution/Client/Install.hs
index 2baa8af9e49c01f70fe834f5819209bcf11f42d7..a53c7ded1aa046c1273aa3bf8ebf6d6259eb0167 100644
--- a/cabal-install/src/Distribution/Client/Install.hs
+++ b/cabal-install/src/Distribution/Client/Install.hs
@@ -1059,6 +1059,7 @@ performInstallations verbosity
         platform
         progdb
         distPref
+        (fromFlagOrDefault (setupConfigDynamic defaultSetupScriptOptions) $ configDynExe configFlags)
         (chooseCabalVersion configExFlags (libVersion miscOptions))
         (Just lock)
         parallelInstall
diff --git a/cabal-install/src/Distribution/Client/PackageHash.hs b/cabal-install/src/Distribution/Client/PackageHash.hs
index 067027db5412897d1c249b0dce7ac624717c24d1..30e495dbdf34ee29ee227cf9d00c1ddace410915 100644
--- a/cabal-install/src/Distribution/Client/PackageHash.hs
+++ b/cabal-install/src/Distribution/Client/PackageHash.hs
@@ -196,6 +196,7 @@ data PackageHashConfigInputs = PackageHashConfigInputs {
        pkgHashDebugInfo           :: DebugInfoLevel,
        pkgHashProgramArgs         :: Map String [String],
        pkgHashExtraLibDirs        :: [FilePath],
+       pkgHashExtraLibDirsStatic  :: [FilePath],
        pkgHashExtraFrameworkDirs  :: [FilePath],
        pkgHashExtraIncludeDirs    :: [FilePath],
        pkgHashProgPrefix          :: Maybe PathTemplate,
@@ -293,6 +294,7 @@ renderPackageHashInputs PackageHashInputs{
       , opt   "stripped-exe" True  prettyShow pkgHashStripExes
       , opt   "debug-info"   NormalDebugInfo (show . fromEnum) pkgHashDebugInfo
       , opt   "extra-lib-dirs"     [] unwords pkgHashExtraLibDirs
+      , opt   "extra-lib-dirs-static" [] unwords pkgHashExtraLibDirsStatic
       , opt   "extra-framework-dirs" [] unwords pkgHashExtraFrameworkDirs
       , opt   "extra-include-dirs" [] unwords pkgHashExtraIncludeDirs
       , opt   "prog-prefix" Nothing (maybe "" fromPathTemplate) pkgHashProgPrefix
diff --git a/cabal-install/src/Distribution/Client/ProjectConfig.hs b/cabal-install/src/Distribution/Client/ProjectConfig.hs
index 645ebe6f621bb90f044934b563eb28ddfed091e2..83184d5902ce6015ec0e8ba24b78110c34acd393 100644
--- a/cabal-install/src/Distribution/Client/ProjectConfig.hs
+++ b/cabal-install/src/Distribution/Client/ProjectConfig.hs
@@ -467,7 +467,7 @@ withProjectOrGlobalConfig
     -> Flag Bool                  -- ^ whether to ignore local project (--ignore-project flag)
     -> Flag FilePath              -- ^ @--cabal-config@
     -> IO a                       -- ^ with project
-    -> (ProjectConfig -> IO a)    -- ^ without projet
+    -> (ProjectConfig -> IO a)    -- ^ without project
     -> IO a
 withProjectOrGlobalConfig verbosity (Flag True) gcf _with without = do
     globalConfig <- runRebuild "" $ readGlobalConfig verbosity gcf
diff --git a/cabal-install/src/Distribution/Client/ProjectOrchestration.hs b/cabal-install/src/Distribution/Client/ProjectOrchestration.hs
index 3d93b0db1153c7bd1eff5b3c1f9a9b655dbc9ab0..da67b8a3ef4cff57534275488c8bbc9dfce6cb80 100644
--- a/cabal-install/src/Distribution/Client/ProjectOrchestration.hs
+++ b/cabal-install/src/Distribution/Client/ProjectOrchestration.hs
@@ -161,7 +161,7 @@ import           Distribution.Simple.Flag
 import qualified Distribution.Simple.Setup as Setup
 import           Distribution.Simple.Command (commandShowOptions)
 import           Distribution.Simple.Configure (computeEffectiveProfiling)
-
+import           Distribution.Simple.PackageIndex (InstalledPackageIndex)
 import           Distribution.Simple.Utils
                    ( die', warn, notice, noticeNoWrap, debugNoWrap, createDirectoryIfMissingVerbose, ordNub )
 import           Distribution.Verbosity
@@ -198,7 +198,8 @@ data ProjectBaseContext = ProjectBaseContext {
        projectConfig  :: ProjectConfig,
        localPackages  :: [PackageSpecifier UnresolvedSourcePackage],
        buildSettings  :: BuildTimeSettings,
-       currentCommand :: CurrentCommand
+       currentCommand :: CurrentCommand,
+       installedPackages :: Maybe InstalledPackageIndex
      }
 
 establishProjectBaseContext
@@ -260,11 +261,13 @@ establishProjectBaseContextWithRoot verbosity cliConfig projectRoot currentComma
       projectConfig,
       localPackages,
       buildSettings,
-      currentCommand
+      currentCommand,
+      installedPackages
     }
   where
     mdistDirectory = Setup.flagToMaybe projectConfigDistDir
     ProjectConfigShared { projectConfigDistDir } = projectConfigShared cliConfig
+    installedPackages = Nothing
 
 
 -- | This holds the context between the pre-build, build and post-build phases.
@@ -309,7 +312,8 @@ withInstallPlan
       distDirLayout,
       cabalDirLayout,
       projectConfig,
-      localPackages
+      localPackages,
+      installedPackages
     }
     action = do
     -- Take the project configuration and make a plan for how to build
@@ -321,6 +325,7 @@ withInstallPlan
                          distDirLayout cabalDirLayout
                          projectConfig
                          localPackages
+                         installedPackages
     action elaboratedPlan elaboratedShared
 
 runProjectPreBuildPhase
@@ -334,7 +339,8 @@ runProjectPreBuildPhase
       distDirLayout,
       cabalDirLayout,
       projectConfig,
-      localPackages
+      localPackages,
+      installedPackages
     }
     selectPlanSubset = do
     -- Take the project configuration and make a plan for how to build
@@ -346,6 +352,7 @@ runProjectPreBuildPhase
                          distDirLayout cabalDirLayout
                          projectConfig
                          localPackages
+                         installedPackages
 
     -- The plan for what to do is represented by an 'ElaboratedInstallPlan'
 
@@ -863,24 +870,22 @@ printPlan verbosity
                   PackageConfig {packageConfigOptimization = globalOptimization},
               projectConfigLocalPackages =
                   PackageConfig {packageConfigOptimization = localOptimization}
-            }
+            },
+            currentCommand
           }
           ProjectBuildContext {
             elaboratedPlanToExecute = elaboratedPlan,
             elaboratedShared,
             pkgsBuildStatus
           }
-
-  | null pkgs
-  = notice verbosity "Up to date"
-
-  | otherwise
-  = noticeNoWrap verbosity $ unlines $
+  | null pkgs && currentCommand == BuildCommand
+    = notice verbosity "Up to date"
+  | not (null pkgs) = noticeNoWrap verbosity $ unlines $
       (showBuildProfile ++ "In order, the following "
        ++ wouldWill ++ " be built"
        ++ ifNormal " (use -v for more details)" ++ ":")
     : map showPkgAndReason pkgs
-
+  | otherwise = return ()
   where
     pkgs = InstallPlan.executionOrder elaboratedPlan
 
@@ -1335,6 +1340,7 @@ establishDummyProjectBaseContext verbosity projectConfig distDirLayout localPack
         buildSettings = resolveBuildTimeSettings
                           verbosity cabalDirLayout
                           projectConfig
+        installedPackages = Nothing
 
     return ProjectBaseContext {
       distDirLayout,
@@ -1342,7 +1348,8 @@ establishDummyProjectBaseContext verbosity projectConfig distDirLayout localPack
       projectConfig,
       localPackages,
       buildSettings,
-      currentCommand
+      currentCommand,
+      installedPackages
     }
 
 establishDummyDistDirLayout :: Verbosity -> ProjectConfig -> FilePath -> IO DistDirLayout
diff --git a/cabal-install/src/Distribution/Client/ProjectPlanOutput.hs b/cabal-install/src/Distribution/Client/ProjectPlanOutput.hs
index c9243c310e0c53d846fa015d4d44c8aa37327ead..fde7ea8b97a99a30aa5d319bf45be93eac34399a 100644
--- a/cabal-install/src/Distribution/Client/ProjectPlanOutput.hs
+++ b/cabal-install/src/Distribution/Client/ProjectPlanOutput.hs
@@ -272,9 +272,9 @@ encodePlanAsJson distDirLayout elaboratedInstallPlan elaboratedSharedConfig =
     comp2str = prettyShow
 
     style2str :: Bool -> BuildStyle -> String
+    style2str _     BuildAndInstall  = "global"
     style2str True  _                = "local"
     style2str False BuildInplaceOnly = "inplace"
-    style2str False BuildAndInstall  = "global"
 
     jdisplay :: Pretty a => a -> J.Value
     jdisplay = J.String . prettyShow
diff --git a/cabal-install/src/Distribution/Client/ProjectPlanning.hs b/cabal-install/src/Distribution/Client/ProjectPlanning.hs
index 07ac42e4ec01af8d25abf999d7d3699cc92d41f2..7bb79457c9d1d21010648d78c87de13e9bb63dcf 100644
--- a/cabal-install/src/Distribution/Client/ProjectPlanning.hs
+++ b/cabal-install/src/Distribution/Client/ProjectPlanning.hs
@@ -170,7 +170,9 @@ import           Text.PrettyPrint (text, hang, quotes, colon, vcat, ($$), fsep,
 import qualified Text.PrettyPrint as Disp
 import qualified Data.Map as Map
 import qualified Data.Set as Set
-import           Control.Monad.State as State
+import           Control.Monad (sequence, forM)
+import           Control.Monad.IO.Class (liftIO)
+import           Control.Monad.State as State (State, execState, runState, state)
 import           Control.Exception (assert)
 import           Data.List (groupBy, deleteBy)
 import qualified Data.List.NonEmpty as NE
@@ -466,6 +468,7 @@ rebuildInstallPlan :: Verbosity
                    -> DistDirLayout -> CabalDirLayout
                    -> ProjectConfig
                    -> [PackageSpecifier UnresolvedSourcePackage]
+                   -> Maybe InstalledPackageIndex
                    -> IO ( ElaboratedInstallPlan  -- with store packages
                          , ElaboratedInstallPlan  -- with source packages
                          , ElaboratedSharedConfig
@@ -480,7 +483,7 @@ rebuildInstallPlan verbosity
                    }
                    CabalDirLayout {
                      cabalStoreDirLayout
-                   } = \projectConfig localPackages ->
+                   } = \projectConfig localPackages mbInstalledPackages ->
     runRebuild distProjectRootDirectory $ do
     progsearchpath <- liftIO $ getSystemSearchPath
     let projectConfigMonitored = projectConfig { projectConfigBuildOnly = mempty }
@@ -503,6 +506,7 @@ rebuildInstallPlan verbosity
                         <- phaseRunSolver         projectConfig
                                                   compilerEtc
                                                   localPackages
+                                                  (fromMaybe mempty mbInstalledPackages)
           (elaboratedPlan,
            elaboratedShared) <- phaseElaboratePlan projectConfig
                                                    compilerEtc pkgConfigDB
@@ -576,13 +580,15 @@ rebuildInstallPlan verbosity
         :: ProjectConfig
         -> (Compiler, Platform, ProgramDb)
         -> [PackageSpecifier UnresolvedSourcePackage]
+        -> InstalledPackageIndex
         -> Rebuild (SolverInstallPlan, PkgConfigDb, IndexUtils.TotalIndexState, IndexUtils.ActiveRepos)
     phaseRunSolver projectConfig@ProjectConfig {
                      projectConfigShared,
                      projectConfigBuildOnly
                    }
                    (compiler, platform, progdb)
-                   localPackages =
+                   localPackages
+                   installedPackages =
         rerunIfChanged verbosity fileMonitorSolverPlan
                        (solverSettings,
                         localPackages, localPackagesEnabledStanzas,
@@ -609,7 +615,7 @@ rebuildInstallPlan verbosity
             notice verbosity "Resolving dependencies..."
             planOrError <- foldProgress logMsg (pure . Left) (pure . Right) $
               planPackages verbosity compiler platform solver solverSettings
-                           installedPkgIndex sourcePkgDb pkgConfigDB
+                           (installedPackages <> installedPkgIndex) sourcePkgDb pkgConfigDB
                            localPackages localPackagesEnabledStanzas
             case planOrError of
               Left msg -> do reportPlanningFailure projectConfig compiler platform localPackages
@@ -666,6 +672,7 @@ rebuildInstallPlan verbosity
                          projectConfigAllPackages,
                          projectConfigLocalPackages,
                          projectConfigSpecificPackage,
+                         projectPackagesNamed,
                          projectConfigBuildOnly
                        }
                        (compiler, platform, progdb) pkgConfigDB
@@ -690,6 +697,7 @@ rebuildInstallPlan verbosity
                 localPackages
                 sourcePackageHashes
                 defaultInstallDirs
+                projectPackagesNamed
                 projectConfigShared
                 projectConfigAllPackages
                 projectConfigLocalPackages
@@ -916,9 +924,9 @@ getPackageSourceHashes verbosity withRepoCtx solverPlan = do
         -- Tarballs from repositories, either where the repository provides
         -- hashes as part of the repo metadata, or where we will have to
         -- download and hash the tarball.
-        repoTarballPkgsWithMetadata    :: [(PackageId, Repo)]
+        repoTarballPkgsWithMetadataUnvalidated    :: [(PackageId, Repo)]
         repoTarballPkgsWithoutMetadata :: [(PackageId, Repo)]
-        (repoTarballPkgsWithMetadata,
+        (repoTarballPkgsWithMetadataUnvalidated,
          repoTarballPkgsWithoutMetadata) =
           partitionEithers
           [ case repo of
@@ -926,10 +934,16 @@ getPackageSourceHashes verbosity withRepoCtx solverPlan = do
               _            -> Right (pkgid, repo)
           | (pkgid, RepoTarballPackage repo _ _) <- allPkgLocations ]
 
+    (repoTarballPkgsWithMetadata, repoTarballPkgsToRedownload) <- fmap partitionEithers $
+      liftIO $ withRepoCtx $ \repoctx -> forM repoTarballPkgsWithMetadataUnvalidated $
+        \x@(pkg, repo) -> verifyFetchedTarball verbosity repoctx repo pkg >>= \b -> case b of
+                          True -> return $ Left x
+                          False -> return $ Right x
+
     -- For tarballs from repos that do not have hashes available we now have
     -- to check if the packages were downloaded already.
     --
-    (repoTarballPkgsToDownload,
+    (repoTarballPkgsToDownload',
      repoTarballPkgsDownloaded)
       <- fmap partitionEithers $
          liftIO $ sequence
@@ -939,6 +953,7 @@ getPackageSourceHashes verbosity withRepoCtx solverPlan = do
                   Just tarball -> return (Right (pkgid, tarball))
            | (pkgid, repo) <- repoTarballPkgsWithoutMetadata ]
 
+    let repoTarballPkgsToDownload = repoTarballPkgsToRedownload ++ repoTarballPkgsToDownload'
     (hashesFromRepoMetadata,
      repoTarballPkgsNewlyDownloaded) <-
       -- Avoid having to initialise the repository (ie 'withRepoCtx') if we
@@ -1033,7 +1048,6 @@ planPackages :: Verbosity
 planPackages verbosity comp platform solver SolverSettings{..}
              installedPkgIndex sourcePkgDb pkgConfigDB
              localPackages pkgStanzasEnable =
-
     resolveDependencies
       platform (compilerInfo comp)
       pkgConfigDB solver
@@ -1348,6 +1362,7 @@ elaborateInstallPlan
   -> [PackageSpecifier (SourcePackage (PackageLocation loc))]
   -> Map PackageId PackageSourceHash
   -> InstallDirs.InstallDirTemplates
+  -> [PackageVersionConstraint]
   -> ProjectConfigShared
   -> PackageConfig
   -> PackageConfig
@@ -1359,6 +1374,7 @@ elaborateInstallPlan verbosity platform compiler compilerprogdb pkgConfigDB
                      solverPlan localPackages
                      sourcePackageHashes
                      defaultInstallDirs
+                     extraPackages
                      sharedPackageConfig
                      allPackagesConfig
                      localPackagesConfig
@@ -2029,15 +2045,21 @@ elaborateInstallPlan verbosity platform compiler compilerprogdb pkgConfigDB
       $ map packageId
       $ SolverInstallPlan.reverseDependencyClosure
           solverPlan
-          (map PlannedId (Set.toList pkgsLocalToProject))
+          (map PlannedId (Set.toList pkgsInplaceToProject))
 
     isLocalToProject :: Package pkg => pkg -> Bool
     isLocalToProject pkg = Set.member (packageId pkg)
                                       pkgsLocalToProject
 
+    pkgsInplaceToProject :: Set PackageId
+    pkgsInplaceToProject =
+        Set.fromList (catMaybes (map shouldBeLocal localPackages))
+        --TODO: localPackages is a misnomer, it's all project packages
+        -- here is where we decide which ones will be local!
+
     pkgsLocalToProject :: Set PackageId
     pkgsLocalToProject =
-        Set.fromList (catMaybes (map shouldBeLocal localPackages))
+        Set.fromList (catMaybes (map (isInLocal extraPackages) localPackages))
         --TODO: localPackages is a misnomer, it's all project packages
         -- here is where we decide which ones will be local!
 
@@ -2106,6 +2128,28 @@ shouldBeLocal (SpecificSourcePackage pkg) = case srcpkgSource pkg of
     LocalUnpackedPackage _ -> Just (packageId pkg)
     _                      -> Nothing
 
+-- Used to determine which packages are affected by local package configuration
+-- flags like ‘--enable-shared --enable-executable-dynamic --disable-library-vanilla’.
+isInLocal :: [PackageVersionConstraint] -> PackageSpecifier (SourcePackage (PackageLocation loc)) -> Maybe PackageId
+isInLocal _              NamedPackage{}              = Nothing
+isInLocal _extraPackages (SpecificSourcePackage pkg) = case srcpkgSource pkg of
+    LocalUnpackedPackage _ -> Just (packageId pkg)
+    -- LocalTarballPackage is matched here too, because otherwise ‘sdistize’
+    -- produces for ‘localPackages’ in the ‘ProjectBaseContext’ a
+    -- LocalTarballPackage, and ‘shouldBeLocal’ will make flags like
+    -- ‘--disable-library-vanilla’ have no effect for a typical
+    -- ‘cabal install --lib --enable-shared enable-executable-dynamic --disable-library-vanilla’,
+    -- as these flags would apply to local packages, but the sdist would
+    -- erroneously not get categorized as a local package, so the flags would be
+    -- ignored and produce a package with an unchanged hash.
+    LocalTarballPackage  _ -> Just (packageId pkg)
+    -- TODO: the docs say ‘extra-packages’ is implemented in cabal project
+    -- files.  We can fix that here by checking that the version range matches.
+    --RemoteTarballPackage    _ -> _
+    --RepoTarballPackage      _ -> _
+    --RemoteSourceRepoPackage _ -> _
+    _                      -> Nothing
+
 -- | Given a 'ElaboratedPlanPackage', report if it matches a 'ComponentName'.
 matchPlanPkg :: (ComponentName -> Bool) -> ElaboratedPlanPackage -> Bool
 matchPlanPkg p = InstallPlan.foldPlanPackage (p . ipiComponentName) (matchElabPkg p)
@@ -3385,7 +3429,8 @@ setupHsScriptOptions (ReadyPackage elab@ElaboratedConfiguredPackage{..})
       useWin32CleanHack        = False,   --TODO: [required eventually]
       forceExternalSetupMethod = isParallelBuild,
       setupCacheLock           = Just cacheLock,
-      isInteractive            = False
+      isInteractive            = False,
+      setupConfigDynamic       = elabDynExe
     }
 
 
@@ -3913,6 +3958,7 @@ packageHashConfigInputs shared@ElaboratedSharedConfig{..} pkg =
       pkgHashDebugInfo           = elabDebugInfo,
       pkgHashProgramArgs         = elabProgramArgs,
       pkgHashExtraLibDirs        = elabExtraLibDirs,
+      pkgHashExtraLibDirsStatic  = elabExtraLibDirsStatic,
       pkgHashExtraFrameworkDirs  = elabExtraFrameworkDirs,
       pkgHashExtraIncludeDirs    = elabExtraIncludeDirs,
       pkgHashProgPrefix          = elabProgPrefix,
diff --git a/cabal-install/src/Distribution/Client/Setup.hs b/cabal-install/src/Distribution/Client/Setup.hs
index b4653f977b6de0ea5f95f2ebcb79e8194a3778d2..8fd0788e1a3244b863befb9c95850dc1003e0d34 100644
--- a/cabal-install/src/Distribution/Client/Setup.hs
+++ b/cabal-install/src/Distribution/Client/Setup.hs
@@ -505,7 +505,7 @@ filterConfigureFlags flags cabalLibVersion
     flags_2_5_0 = flags_3_7_0 {
       -- Cabal < 2.5 does not understand --dependency=pkg:component=cid
       -- (public sublibraries), so we convert it to the legacy
-      -- --dependency=pkg_or_internal_compoent=cid
+      -- --dependency=pkg_or_internal_component=cid
         configDependencies =
           let convertToLegacyInternalDep (GivenComponent _ (LSubLibName cn) cid) =
                 Just $ GivenComponent
diff --git a/cabal-install/src/Distribution/Client/SetupWrapper.hs b/cabal-install/src/Distribution/Client/SetupWrapper.hs
index e4885ed07c639639200aeb2a805145725f7cbdf2..239e1a37908f9d3d36d635663f882fb432fb6497 100644
--- a/cabal-install/src/Distribution/Client/SetupWrapper.hs
+++ b/cabal-install/src/Distribution/Client/SetupWrapper.hs
@@ -71,7 +71,7 @@ import Distribution.Simple.BuildPaths
 import Distribution.Simple.Command
          ( CommandUI(..), commandShowOptions )
 import Distribution.Simple.Program.GHC
-         ( GhcMode(..), GhcOptions(..), renderGhcOptions )
+         ( GhcMode(..), GhcDynLinkMode(..), GhcOptions(..), renderGhcOptions )
 import qualified Distribution.Simple.PackageIndex as PackageIndex
 import Distribution.Simple.PackageIndex (InstalledPackageIndex)
 import qualified Distribution.InstalledPackageInfo as IPI
@@ -249,7 +249,12 @@ data SetupScriptOptions = SetupScriptOptions {
     -- | Is the task we are going to run an interactive foreground task,
     -- or an non-interactive background task? Based on this flag we
     -- decide whether or not to delegate ctrl+c to the spawned task
-    isInteractive            :: Bool
+    isInteractive            :: Bool,
+
+    -- Also track build output artifact configuration.
+
+    -- | Pass `-dynamic` to `ghc` for dynamic rather than static linking.
+    setupConfigDynamic       :: Bool
   }
 
 defaultSetupScriptOptions :: SetupScriptOptions
@@ -272,7 +277,8 @@ defaultSetupScriptOptions = SetupScriptOptions {
     useWin32CleanHack        = False,
     forceExternalSetupMethod = False,
     setupCacheLock           = Nothing,
-    isInteractive            = False
+    isInteractive            = False,
+    setupConfigDynamic       = False
   }
 
 workingDir :: SetupScriptOptions -> FilePath
@@ -840,6 +846,9 @@ getExternalSetupMethod verbosity options pkg bt = do
               -- --ghc-option=-v instead!
               ghcOptVerbosity       = Flag (min verbosity normal)
             , ghcOptMode            = Flag GhcModeMake
+            , ghcOptDynLinkMode     = case setupConfigDynamic options'' of
+                                      True  -> Flag GhcDynamicOnly
+                                      False -> Flag GhcStaticOnly
             , ghcOptInputFiles      = toNubListR [setupHs]
             , ghcOptOutputFile      = Flag setupProgFile
             , ghcOptObjDir          = Flag setupDir
diff --git a/cabal-install/src/Distribution/Client/SourceFiles.hs b/cabal-install/src/Distribution/Client/SourceFiles.hs
index dbfc8baaa82f1e6c7f79e6d9d843db1c2effb728..669f30a35b957f7faadaee0481aa382f85128a35 100644
--- a/cabal-install/src/Distribution/Client/SourceFiles.hs
+++ b/cabal-install/src/Distribution/Client/SourceFiles.hs
@@ -39,7 +39,7 @@ import Distribution.ModuleName
 
 import Prelude ()
 import Distribution.Client.Compat.Prelude
-import Distribution.Verbosity (silent)
+import Distribution.Verbosity (normal)
 
 import System.FilePath
 
@@ -150,7 +150,8 @@ needBuildInfo pkg_descr bi modules = do
     -- A.hs-boot; need to track both.
     findNeededModules ["hs", "lhs", "hsig", "lhsig"]
     findNeededModules ["hs-boot", "lhs-boot"]
-    expandedExtraSrcFiles <- liftIO $ fmap concat . for (extraSrcFiles pkg_descr) $ \fpath -> matchDirFileGlobWithDie silent (\ _ _ -> return []) (specVersion pkg_descr) "." fpath
+    root <- askRoot
+    expandedExtraSrcFiles <- liftIO $ fmap concat . for (extraSrcFiles pkg_descr) $ \fpath -> matchDirFileGlobWithDie normal (\ _ _ -> return []) (specVersion pkg_descr) root fpath
     traverse_ needIfExists $ concat
         [ cSources bi
         , cxxSources bi
diff --git a/cabal-install/src/Distribution/Client/Utils.hs b/cabal-install/src/Distribution/Client/Utils.hs
index c427c310370925875564b09b08468e498babd61a..4693ad022cd6b052d076116cf990139d6c243dfb 100644
--- a/cabal-install/src/Distribution/Client/Utils.hs
+++ b/cabal-install/src/Distribution/Client/Utils.hs
@@ -1,4 +1,4 @@
-{-# LANGUAGE ForeignFunctionInterface, ScopedTypeVariables, CPP #-}
+{-# LANGUAGE ScopedTypeVariables, CPP #-}
 
 module Distribution.Client.Utils
   ( MergeResult(..)
@@ -48,7 +48,6 @@ import Control.Monad
          ( zipWithM_ )
 import Data.List
          ( groupBy )
-import Foreign.C.Types ( CInt(..) )
 import qualified Control.Exception as Exception
          ( finally )
 import qualified Control.Exception.Safe as Safe
@@ -62,6 +61,7 @@ import System.IO
          )
 import System.IO.Unsafe ( unsafePerformIO )
 
+import GHC.Conc.Sync ( getNumProcessors )
 import GHC.IO.Encoding
          ( recover, TextEncoding(TextEncoding) )
 import GHC.IO.Encoding.Failure
@@ -196,12 +196,10 @@ logDirChange l (Just d) m = do
   m `Exception.finally`
     (l $ "cabal: Leaving directory '" ++ d ++ "'\n")
 
-foreign import ccall "getNumberOfProcessors" c_getNumberOfProcessors :: IO CInt
-
 -- The number of processors is not going to change during the duration of the
 -- program, so unsafePerformIO is safe here.
 numberOfProcessors :: Int
-numberOfProcessors = fromEnum $ unsafePerformIO c_getNumberOfProcessors
+numberOfProcessors = unsafePerformIO getNumProcessors
 
 -- | Determine the number of jobs to use given the value of the '-j' flag.
 determineNumJobs :: Flag (Maybe Int) -> Int
diff --git a/cabal-install/src/Distribution/Client/VCS.hs b/cabal-install/src/Distribution/Client/VCS.hs
index d6037f21b07c5568ff132b3be63214cfe8b46075..8b0a95462dada0c6be16de48879e0f9478935f95 100644
--- a/cabal-install/src/Distribution/Client/VCS.hs
+++ b/cabal-install/src/Distribution/Client/VCS.hs
@@ -205,7 +205,7 @@ cloneSourceRepo verbosity vcs
                                srcuri destdir
 
 
--- | Syncronise a set of 'SourceRepo's referring to the same repository with
+-- | Synchronise a set of 'SourceRepo's referring to the same repository with
 -- corresponding local directories. The local directories may or may not
 -- already exist.
 --
@@ -654,7 +654,7 @@ svnProgram = (simpleProgram "svn") {
 --
 --
 --                    ----->  foo on branch B ----->
---    resolve confict                                  Initial patch
+--    resolve conflict                                  Initial patch
 --                    ----->  foo on branch A ----->
 --
 --    Which is seems reasonable.
diff --git a/cabal-install/tests/IntegrationTests2.hs b/cabal-install/tests/IntegrationTests2.hs
index 0bdf1e964a69c380a235a0a7c54502b800896391..6b81643fe0b5a138a8336c9979d2b0913acfe51e 100644
--- a/cabal-install/tests/IntegrationTests2.hs
+++ b/cabal-install/tests/IntegrationTests2.hs
@@ -1591,7 +1591,7 @@ testProgramOptionsLocal config0 = do
                 (Just [ghcFlag])
                 (getProgArgs localPackages "q")
     assertEqual "p"
-                Nothing
+                (Just [ghcFlag])
                 (getProgArgs localPackages "p")
   where
     testdir = "regression/program-options"
@@ -1729,6 +1729,7 @@ planProject testdir cliConfig = do
                          distDirLayout cabalDirLayout
                          projectConfig
                          localPackages
+                         Nothing
 
     return (projDetails,
             elaboratedPlan,
diff --git a/cabal-install/tests/UnitTests/Distribution/Client/Init/Golden.hs b/cabal-install/tests/UnitTests/Distribution/Client/Init/Golden.hs
index de8e74e2b852d61f3b6e8e2870a53d724a84b854..45c585f55ccd8c96e2ba8ea40a1d7cc7b3bbfe53 100644
--- a/cabal-install/tests/UnitTests/Distribution/Client/Init/Golden.hs
+++ b/cabal-install/tests/UnitTests/Distribution/Client/Init/Golden.hs
@@ -68,7 +68,7 @@ tests v initFlags pkgIx srcDb = testGroup "golden"
     pkgDir = evalPrompt (getPackageDir initFlags)
       $ fromList ["."]
     pkgName = evalPrompt (packageNamePrompt srcDb initFlags)
-      $ fromList ["test-package", "y"]
+      $ fromList ["test-package", "test-package", "y"]
 
 goldenPkgDescTests
     :: Verbosity
@@ -337,6 +337,7 @@ pkgArgs :: NonEmpty String
 pkgArgs = fromList
     [ "5"
     , "foo-package"
+    , "foo-package"
     , "y"
     , "0.1.0.0"
     , "2"
diff --git a/cabal-install/tests/UnitTests/Distribution/Client/Init/Interactive.hs b/cabal-install/tests/UnitTests/Distribution/Client/Init/Interactive.hs
index 6e3b03c14907f86c42d6c442796ccb3b3ee48421..4a2d000cb4799c9482a8658e85650954630a46d4 100644
--- a/cabal-install/tests/UnitTests/Distribution/Client/Init/Interactive.hs
+++ b/cabal-install/tests/UnitTests/Distribution/Client/Init/Interactive.hs
@@ -140,6 +140,7 @@ createProjectTest pkgIx srcDb = testGroup "createProject tests"
               -- package name
               , "test-package"
               , "test-package"
+              , "test-package"
               -- version
               , "3.1.2.3"
               -- license
@@ -246,6 +247,7 @@ createProjectTest pkgIx srcDb = testGroup "createProject tests"
               -- package name
               , "test-package"
               , "test-package"
+              , "test-package"
               -- version
               , "3.1.2.3"
               -- license
@@ -337,6 +339,7 @@ createProjectTest pkgIx srcDb = testGroup "createProject tests"
               -- package name
               , "test-package"
               , "test-package"
+              , "test-package"
               -- version
               , "3.1.2.3"
               -- license
@@ -415,6 +418,7 @@ createProjectTest pkgIx srcDb = testGroup "createProject tests"
               -- package name
               , "test-package"
               , "test-package"
+              , "test-package"
               -- version
               , "3.1.2.3"
               -- license
@@ -507,6 +511,7 @@ createProjectTest pkgIx srcDb = testGroup "createProject tests"
               -- package name
               , "test-package"
               , "test-package"
+              , "test-package"
               -- version
               , "3.1.2.3"
               -- license
@@ -584,6 +589,7 @@ createProjectTest pkgIx srcDb = testGroup "createProject tests"
               -- package name
               , "test-package"
               , "test-package"
+              , "test-package"
               -- version
               , "3.1.2.3"
               -- license
@@ -667,6 +673,7 @@ createProjectTest pkgIx srcDb = testGroup "createProject tests"
               -- package name
               , "test-package"
               , "test-package"
+              , "test-package"
               -- version
               , "3.1.2.3"
               -- license
@@ -739,6 +746,7 @@ fileCreatorTests pkgIx srcDb _pkgName = testGroup "generators"
         let inputs = fromList
               [ "1"               -- pick the first cabal version in the list
               , "my-test-package" -- package name
+              , "my-test-package" -- current dir for the purpose of guessing the package name
               , "y"               -- "yes to prompt internal to package name"
               , "0.2.0.1"         -- package version
               , "2"               -- pick the second license in the list
@@ -796,15 +804,18 @@ interactiveTests srcDb = testGroup "Check top level getter functions"
           (packageNamePrompt srcDb) (mkPackageName "test-package")
           [ "test-package"
           , "test-package"
+          , "test-package"
           ]
       , testSimplePrompt "New package name 2"
           (packageNamePrompt srcDb) (mkPackageName "test-package")
           [ "test-package"
+          , "test-package"
           , ""
           ]
       , testSimplePrompt "Existing package name 1"
           (packageNamePrompt srcDb) (mkPackageName "test-package")
           [ "test-package"
+          , "test-package"
           , "cabal-install"
           , "y"
           , "test-package"
@@ -812,6 +823,7 @@ interactiveTests srcDb = testGroup "Check top level getter functions"
       , testSimplePrompt "Existing package name 2"
           (packageNamePrompt srcDb) (mkPackageName "cabal-install")
           [ "test-package"
+          , "test-package"
           , "cabal-install"
           , "n"
           ]
@@ -925,7 +937,7 @@ interactiveTests srcDb = testGroup "Check top level getter functions"
             ]
         ]
     , testGroup "Check srcDirsPrompt output"
-        [ testNumberedPrompt "Soruce dirs indices" srcDirsPrompt
+        [ testNumberedPrompt "Source dirs indices" srcDirsPrompt
             [[defaultSourceDir], ["lib"], ["src-lib"]]
         , testSimplePrompt "Other source dir"
             srcDirsPrompt ["src"]
diff --git a/cabal-install/tests/UnitTests/Distribution/Client/Init/Simple.hs b/cabal-install/tests/UnitTests/Distribution/Client/Init/Simple.hs
index c75792f3cbab32718503f4fde0b084a91b8a3de8..2100859e67860d17401d765481d016685bc7701e 100644
--- a/cabal-install/tests/UnitTests/Distribution/Client/Init/Simple.hs
+++ b/cabal-install/tests/UnitTests/Distribution/Client/Init/Simple.hs
@@ -50,7 +50,12 @@ simpleCreateProjectTests v pkgIx srcDb pkgName =
     [ testCase "Simple lib createProject - no tests" $ do
       let inputs = fromList
             [ "1"           -- package type: Library
-            , "simple-test" -- package dir (ignored, piped to current dir due to prompt monad)
+            , "simple.test" -- package dir: used for determining package name;
+                            -- note that . will be replaced with - in a sanitization step,
+                            -- and we get the expected "simple-test" -- regression test for #8404
+            , "simple.test" -- package dir again: the prompt monad needs extra parameter for every
+                            -- IO call, and this one will be used for canonicalizePath,
+                            -- which is called as a part of sanitization
             , "n"           -- no tests
             ]
 
@@ -65,7 +70,7 @@ simpleCreateProjectTests v pkgIx srcDb pkgName =
         Right (settings', _) -> settings @=? settings'
 
     , testCase "Simple lib createProject - with tests" $ do
-      let inputs = fromList ["1", "simple-test", "y", "1"]
+      let inputs = fromList ["1", "simple-test", "simple-test", "y", "1"]
           flags = emptyFlags { packageType = Flag Library }
           settings = ProjectSettings
             (WriteOpts False False False v "/home/test/1" Library pkgName defaultCabalVersion)
@@ -77,7 +82,7 @@ simpleCreateProjectTests v pkgIx srcDb pkgName =
         Right (settings', _) -> settings @=? settings'
 
     , testCase "Simple exe createProject" $ do
-      let inputs = fromList ["2", "simple-test"]
+      let inputs = fromList ["2", "simple-test", "simple-test"]
           flags = emptyFlags { packageType = Flag Executable }
           settings = ProjectSettings
             (WriteOpts False False False v "/home/test/2" Executable pkgName defaultCabalVersion)
@@ -89,7 +94,7 @@ simpleCreateProjectTests v pkgIx srcDb pkgName =
         Right (settings', _) -> settings @=? settings'
 
     , testCase "Simple lib+exe createProject - no tests" $ do
-      let inputs = fromList ["2", "simple-test", "n"]
+      let inputs = fromList ["2", "simple-test", "simple-test", "n"]
           flags = emptyFlags { packageType = Flag LibraryAndExecutable }
           settings = ProjectSettings
             (WriteOpts False False False v "/home/test/2" LibraryAndExecutable pkgName defaultCabalVersion)
@@ -100,7 +105,7 @@ simpleCreateProjectTests v pkgIx srcDb pkgName =
         Left e -> assertFailure $ "Failed to create simple lib+exe project: " ++ show e
         Right (settings', _) -> settings @=? settings'
     , testCase "Simple lib+exe createProject - with tests" $ do
-      let inputs = fromList ["2", "simple-test", "y", "1"]
+      let inputs = fromList ["2", "simple-test", "simple-test", "y", "1"]
           flags = emptyFlags { packageType = Flag LibraryAndExecutable }
           settings = ProjectSettings
             (WriteOpts False False False v "/home/test/2" LibraryAndExecutable pkgName defaultCabalVersion)
@@ -113,7 +118,7 @@ simpleCreateProjectTests v pkgIx srcDb pkgName =
         Right (settings', _) -> settings @=? settings'
 
     , testCase "Simple standalone tests" $ do
-      let inputs = fromList ["2", "simple-test", "y", "1"]
+      let inputs = fromList ["2", "simple-test", "simple-test", "y", "1"]
           flags = emptyFlags { packageType = Flag TestSuite }
           settings = ProjectSettings
             (WriteOpts False False False v "/home/test/2" TestSuite pkgName defaultCabalVersion)
diff --git a/cabal-install/tests/UnitTests/Distribution/Client/Init/Utils.hs b/cabal-install/tests/UnitTests/Distribution/Client/Init/Utils.hs
index e65bb15ab97a170578b16c4371d6fbf957444dc8..0729e507765914551f19bdf01d1ea46ac7fa2517 100644
--- a/cabal-install/tests/UnitTests/Distribution/Client/Init/Utils.hs
+++ b/cabal-install/tests/UnitTests/Distribution/Client/Init/Utils.hs
@@ -51,7 +51,7 @@ dummyFlags = emptyFlags
 emptyFlags :: InitFlags
 emptyFlags = mempty
 
--- | Retireves the proper base version based on the GHC version
+-- | Retrieves the proper base version based on the GHC version
 baseVersion :: Compiler -> VersionRange
 baseVersion Compiler {compilerId = CompilerId GHC ver} =
   let ghcToBase = baseVersion' . prettyShow $ ver in
diff --git a/cabal-install/tests/UnitTests/Distribution/Client/VCS.hs b/cabal-install/tests/UnitTests/Distribution/Client/VCS.hs
index 84bf78983d03dec7644090b41eabeaefb01bed95..b361bdd8ff381211f3e4f1fbab2bbaa7dc47cb73 100644
--- a/cabal-install/tests/UnitTests/Distribution/Client/VCS.hs
+++ b/cabal-install/tests/UnitTests/Distribution/Client/VCS.hs
@@ -301,7 +301,7 @@ prop_syncRepos vcs mkVCSTestDriver
 --
 -- So, given a source repo dir, the corresponding 'RepoState' and a number of
 -- target repo dirs, pick a sequence of (lists of) sync targets from the
--- 'RepoState' and syncronise the target dirs with those targets, checking for
+-- 'RepoState' and synchronise the target dirs with those targets, checking for
 -- each one that the actual working state matches the expected repo state.
 --
 checkSyncRepos
diff --git a/cabal-install/tests/UnitTests/Distribution/Solver/Modular/DSL.hs b/cabal-install/tests/UnitTests/Distribution/Solver/Modular/DSL.hs
index 157f5c3cc2f55edfa8291069088d45b8f0a3cb32..0d22d5fe7585cfb4a04957cff042bbb136d762c0 100644
--- a/cabal-install/tests/UnitTests/Distribution/Solver/Modular/DSL.hs
+++ b/cabal-install/tests/UnitTests/Distribution/Solver/Modular/DSL.hs
@@ -474,11 +474,14 @@ exAvSrcPkg ex =
               }
             }
         pkgCheckErrors =
-          -- We ignore these warnings because some unit tests test that the
-          -- solver allows unknown extensions/languages when the compiler
-          -- supports them.
+          -- We ignore unknown extensions/languages warnings because
+          -- some there are some unit tests test in which the solver allows
+          -- unknown extensions/languages when the compiler supports them.
+          -- Furthermore we ignore missing upper bound warnings because
+          -- they are not related to this test suite, and are tested
+          -- with golden tests.
           let checks = C.checkPackage (srcpkgDescription package) Nothing
-          in filter (not . isUnknownLangExt) checks
+          in filter (\x -> not (isMissingUpperBound x) && not (isUnknownLangExt x)) checks
     in if null pkgCheckErrors
        then package
        else error $ "invalid GenericPackageDescription for package "
@@ -671,6 +674,10 @@ exAvSrcPkg ex =
                             C.UnknownExtensions {} -> True
                             C.UnknownLanguages {} -> True
                             _ -> False
+    isMissingUpperBound :: C.PackageCheck -> Bool
+    isMissingUpperBound pc = case C.explanation pc of
+                            C.MissingUpperBounds {} -> True
+                            _ -> False
 
 
 mkSimpleVersion :: ExamplePkgVersion -> C.Version
diff --git a/cabal-install/tests/UnitTests/Distribution/Solver/Modular/Solver.hs b/cabal-install/tests/UnitTests/Distribution/Solver/Modular/Solver.hs
index 98d98ae4bbc3013c7a80bb493df77b4dd5a07d96..1101e05aff94d8f4ea8c6970738366c218c9a6c5 100644
--- a/cabal-install/tests/UnitTests/Distribution/Solver/Modular/Solver.hs
+++ b/cabal-install/tests/UnitTests/Distribution/Solver/Modular/Solver.hs
@@ -148,11 +148,17 @@ tests = [
         , runTest $ mkTest db12 "baseShim5" ["D"] anySolverFailure
         , runTest $ mkTest db12 "baseShim6" ["E"] (solverSuccess [("E", 1), ("syb", 2)])
         ]
-    , testGroup "Base" [
+    , testGroup "Base and Nonupgradable" [
           runTest $ mkTest dbBase "Refuse to install base without --allow-boot-library-installs" ["base"] $
                       solverFailure (isInfixOf "only already installed instances can be used")
         , runTest $ allowBootLibInstalls $ mkTest dbBase "Install base with --allow-boot-library-installs" ["base"] $
                       solverSuccess [("base", 1), ("ghc-prim", 1), ("integer-gmp", 1), ("integer-simple", 1)]
+        , runTest $ mkTest dbNonupgrade "Refuse to install newer ghc requested by another library" ["A"] $
+                      solverFailure (isInfixOf "rejecting: ghc-2.0.0 (constraint from non-upgradeable package requires installed instance)")
+        , runTest $ mkTest dbNonupgrade "Refuse to install newer ghci requested by another library" ["B"] $
+                      solverFailure (isInfixOf "rejecting: ghci-2.0.0 (constraint from non-upgradeable package requires installed instance)")
+        , runTest $ mkTest dbNonupgrade "Refuse to install newer ghc-boot requested by another library" ["C"] $
+                      solverFailure (isInfixOf "rejecting: ghc-boot-2.0.0 (constraint from non-upgradeable package requires installed instance)")
         ]
     , testGroup "reject-unconstrained" [
           runTest $ onlyConstrained $ mkTest db12 "missing syb" ["E"] $
@@ -1123,6 +1129,19 @@ dbBase = [
     , Right $ exAv "integer-gmp" 1 []
     ]
 
+dbNonupgrade :: ExampleDb
+dbNonupgrade = [
+    Left $ exInst "ghc" 1 "ghc-1" []
+  , Left $ exInst "ghci" 1 "ghci-1" []
+  , Left $ exInst "ghc-boot" 1 "ghc-boot-1" []
+  , Right $ exAv "ghc" 2 []
+  , Right $ exAv "ghci" 2 []
+  , Right $ exAv "ghc-boot" 2 []
+  , Right $ exAv "A" 1 [ExFix "ghc" 2]
+  , Right $ exAv "B" 1 [ExFix "ghci" 2]
+  , Right $ exAv "C" 1 [ExFix "ghc-boot" 2]
+  ]
+
 db13 :: ExampleDb
 db13 = [
     Right $ exAv "A" 1 []
diff --git a/cabal-testsuite/PackageTests/AutogenModules/Package/my.cabal b/cabal-testsuite/PackageTests/AutogenModules/Package/my.cabal
index 4119742ce247f2796c491248415b08446336fdea..37dfcbf7bce0b8ac998bb7fcffb8c773c44bc292 100644
--- a/cabal-testsuite/PackageTests/AutogenModules/Package/my.cabal
+++ b/cabal-testsuite/PackageTests/AutogenModules/Package/my.cabal
@@ -17,6 +17,7 @@ Library
     build-depends: base
     exposed-modules:
         MyLibrary
+        PackageInfo_AutogenModules
         Paths_AutogenModules
         MyLibHelperModule
     other-modules:
@@ -30,6 +31,7 @@ Executable Exe
     build-depends: base
     other-modules:
         MyExeModule
+        PackageInfo_AutogenModules
         Paths_AutogenModules
         MyExeHelperModule
     autogen-modules:
@@ -42,6 +44,7 @@ Test-Suite Test
     build-depends: base
     other-modules:
         MyTestModule
+        PackageInfo_AutogenModules
         Paths_AutogenModules
         MyTestHelperModule
     autogen-modules:
@@ -54,6 +57,7 @@ Benchmark Bench
     build-depends: base
     other-modules:
         MyBenchModule
+        PackageInfo_AutogenModules
         Paths_AutogenModules
         MyBenchHelperModule
     autogen-modules:
diff --git a/cabal-testsuite/PackageTests/AutogenModules/Package/setup.cabal.out b/cabal-testsuite/PackageTests/AutogenModules/Package/setup.cabal.out
index 77bb223e5428345c1eaf384ed07f26b839f51f77..a650205c593a3215277de9eddc0ba3008a9410fd 100644
--- a/cabal-testsuite/PackageTests/AutogenModules/Package/setup.cabal.out
+++ b/cabal-testsuite/PackageTests/AutogenModules/Package/setup.cabal.out
@@ -14,6 +14,7 @@ On executable 'Exe' an 'autogen-module' is not on 'other-modules'
 On test suite 'Test' an 'autogen-module' is not on 'other-modules'
 On benchmark 'Bench' an 'autogen-module' is not on 'other-modules'
 Packages using 'cabal-version: 2.0' and the autogenerated module Paths_* must include it also on the 'autogen-modules' field besides 'exposed-modules' and 'other-modules'. This specifies that the module does not come with the package and is generated on setup. Modules built with a custom Setup.hs script also go here to ensure that commands like sdist don't fail.
+Packages using 'cabal-version: 2.0' and the autogenerated module PackageInfo_* must include it in 'autogen-modules' as well as 'exposed-modules' and 'other-modules'. This specifies that the module does not come with the package and is generated on setup. Modules built with a custom Setup.hs script also go here to ensure that commands like sdist don't fail.
 The filename './my.cabal' does not match package name (expected: 'AutogenModules.cabal')
 Note: the public hackage server would reject this package.
 Building source dist for AutogenModules-0.1...
diff --git a/cabal-testsuite/PackageTests/AutogenModules/Package/setup.out b/cabal-testsuite/PackageTests/AutogenModules/Package/setup.out
index d6a70b803595b5fe5314d2a55dd1273534ec0ab7..c6203a641309ce2ce6bd730e5c0b3dc4d8b302e3 100644
--- a/cabal-testsuite/PackageTests/AutogenModules/Package/setup.out
+++ b/cabal-testsuite/PackageTests/AutogenModules/Package/setup.out
@@ -14,6 +14,7 @@ On executable 'Exe' an 'autogen-module' is not on 'other-modules'
 On test suite 'Test' an 'autogen-module' is not on 'other-modules'
 On benchmark 'Bench' an 'autogen-module' is not on 'other-modules'
 Packages using 'cabal-version: 2.0' and the autogenerated module Paths_* must include it also on the 'autogen-modules' field besides 'exposed-modules' and 'other-modules'. This specifies that the module does not come with the package and is generated on setup. Modules built with a custom Setup.hs script also go here to ensure that commands like sdist don't fail.
+Packages using 'cabal-version: 2.0' and the autogenerated module PackageInfo_* must include it in 'autogen-modules' as well as 'exposed-modules' and 'other-modules'. This specifies that the module does not come with the package and is generated on setup. Modules built with a custom Setup.hs script also go here to ensure that commands like sdist don't fail.
 The filename './my.cabal' does not match package name (expected: 'AutogenModules.cabal')
 Note: the public hackage server would reject this package.
 Building source dist for AutogenModules-0.1...
diff --git a/cabal-testsuite/PackageTests/AutogenModules/SrcDist/AutogenModules.cabal b/cabal-testsuite/PackageTests/AutogenModules/SrcDist/AutogenModules.cabal
index 92479b0c948e6cdb2714599c62101df232e977e3..8c8f1a98b897c3c51f138614baaa95768e2a5f3f 100644
--- a/cabal-testsuite/PackageTests/AutogenModules/SrcDist/AutogenModules.cabal
+++ b/cabal-testsuite/PackageTests/AutogenModules/SrcDist/AutogenModules.cabal
@@ -17,11 +17,13 @@ Library
     build-depends: base
     exposed-modules:
         MyLibrary
+        PackageInfo_AutogenModules
         Paths_AutogenModules
         MyLibHelperModule
     other-modules:
         MyLibModule
     autogen-modules:
+        PackageInfo_AutogenModules
         Paths_AutogenModules
         MyLibHelperModule
 
@@ -31,9 +33,11 @@ Executable Exe
     build-depends: base
     other-modules:
         MyExeModule
+        PackageInfo_AutogenModules
         Paths_AutogenModules
         MyExeHelperModule
     autogen-modules:
+        PackageInfo_AutogenModules
         Paths_AutogenModules
         MyExeHelperModule
 
@@ -44,9 +48,11 @@ Test-Suite Test
     build-depends: base
     other-modules:
         MyTestModule
+        PackageInfo_AutogenModules
         Paths_AutogenModules
         MyTestHelperModule
     autogen-modules:
+        PackageInfo_AutogenModules
         Paths_AutogenModules
         MyTestHelperModule
 
@@ -57,8 +63,10 @@ Benchmark Bench
     build-depends: base
     other-modules:
         MyBenchModule
+        PackageInfo_AutogenModules
         Paths_AutogenModules
         MyBenchHelperModule
     autogen-modules:
+        PackageInfo_AutogenModules
         Paths_AutogenModules
         MyBenchHelperModule
diff --git a/cabal-testsuite/PackageTests/AutogenModules/SrcDist/setup.test.hs b/cabal-testsuite/PackageTests/AutogenModules/SrcDist/setup.test.hs
index b6be6672ccbd38df37ba13529590fbc5735fbfe9..84d702c57d267554ab19d876f19b51e5026d225a 100644
--- a/cabal-testsuite/PackageTests/AutogenModules/SrcDist/setup.test.hs
+++ b/cabal-testsuite/PackageTests/AutogenModules/SrcDist/setup.test.hs
@@ -25,16 +25,16 @@ main = setupAndCabalTest $ do
         let gotTestSuite  = head $ testSuites  (localPkgDescr lbi)
         let gotBenchmark  = head $ benchmarks  (localPkgDescr lbi)
         assertEqual "library 'autogen-modules' field does not match expected"
-                [fromString "Paths_AutogenModules", fromString "MyLibHelperModule"]
+                [fromString "PackageInfo_AutogenModules", fromString "Paths_AutogenModules", fromString "MyLibHelperModule"]
                 (libModulesAutogen gotLibrary)
         assertEqual "executable 'autogen-modules' field does not match expected"
-                [fromString "Paths_AutogenModules", fromString "MyExeHelperModule"]
+                [fromString "PackageInfo_AutogenModules", fromString "Paths_AutogenModules", fromString "MyExeHelperModule"]
                 (exeModulesAutogen gotExecutable)
         assertEqual "test-suite 'autogen-modules' field does not match expected"
-                [fromString "Paths_AutogenModules", fromString "MyTestHelperModule"]
+                [fromString "PackageInfo_AutogenModules", fromString "Paths_AutogenModules", fromString "MyTestHelperModule"]
                 (testModulesAutogen gotTestSuite)
         assertEqual "benchmark 'autogen-modules' field does not match expected"
-                [fromString "Paths_AutogenModules", fromString "MyBenchHelperModule"]
+                [fromString "PackageInfo_AutogenModules", fromString "Paths_AutogenModules", fromString "MyBenchHelperModule"]
                 (benchmarkModulesAutogen gotBenchmark)
 
         -- Package check messages.
diff --git a/cabal-testsuite/PackageTests/Backpack/T8582/Main.hs b/cabal-testsuite/PackageTests/Backpack/T8582/Main.hs
new file mode 100644
index 0000000000000000000000000000000000000000..25f5c49d576fc6fa2cf04df1218d7a5f050a196a
--- /dev/null
+++ b/cabal-testsuite/PackageTests/Backpack/T8582/Main.hs
@@ -0,0 +1,2 @@
+module Main where
+main = return ()
diff --git a/cabal-testsuite/PackageTests/Backpack/T8582/T8582.cabal b/cabal-testsuite/PackageTests/Backpack/T8582/T8582.cabal
new file mode 100644
index 0000000000000000000000000000000000000000..e34ad386c7f7829edec5b2b9990bd56c999bd42b
--- /dev/null
+++ b/cabal-testsuite/PackageTests/Backpack/T8582/T8582.cabal
@@ -0,0 +1,22 @@
+name: T8582
+version: 1.0
+build-type: Simple
+cabal-version: 2.0
+
+library sig
+    default-language: Haskell2010
+    hs-source-dirs: sig
+    signatures: A
+    build-depends: base
+
+library impl
+    default-language: Haskell2010
+    hs-source-dirs: impl
+    exposed-modules: ImplA
+    reexported-modules: ImplA as A
+    build-depends: base, sig
+
+executable exe
+    default-language: Haskell2010
+    main-is: Main.hs
+    build-depends: base, impl, sig
diff --git a/cabal-testsuite/PackageTests/Backpack/T8582/cabal.project b/cabal-testsuite/PackageTests/Backpack/T8582/cabal.project
new file mode 100644
index 0000000000000000000000000000000000000000..e6fdbadb4398bc0e333947b5fb8021778310d943
--- /dev/null
+++ b/cabal-testsuite/PackageTests/Backpack/T8582/cabal.project
@@ -0,0 +1 @@
+packages: .
diff --git a/cabal-testsuite/PackageTests/Backpack/T8582/impl/ImplA.hs b/cabal-testsuite/PackageTests/Backpack/T8582/impl/ImplA.hs
new file mode 100644
index 0000000000000000000000000000000000000000..8c82be697db71678044bc5e5f48497f63d76e01e
--- /dev/null
+++ b/cabal-testsuite/PackageTests/Backpack/T8582/impl/ImplA.hs
@@ -0,0 +1 @@
+module ImplA where
diff --git a/cabal-testsuite/PackageTests/Backpack/T8582/setup.cabal.out b/cabal-testsuite/PackageTests/Backpack/T8582/setup.cabal.out
new file mode 100644
index 0000000000000000000000000000000000000000..577cf201e392d5293777dace89abc0344e77a5fa
--- /dev/null
+++ b/cabal-testsuite/PackageTests/Backpack/T8582/setup.cabal.out
@@ -0,0 +1,7 @@
+# Setup configure
+Configuring T8582-1.0...
+Error:
+    Cannot instantiate requirement 'ImplA'
+    Ensure "build-depends:" doesn't include any library with signatures: 'A'
+    as this creates a cyclic dependency, which GHC does not support.
+    In the stanza executable exe
\ No newline at end of file
diff --git a/cabal-testsuite/PackageTests/Backpack/T8582/setup.out b/cabal-testsuite/PackageTests/Backpack/T8582/setup.out
new file mode 100644
index 0000000000000000000000000000000000000000..577cf201e392d5293777dace89abc0344e77a5fa
--- /dev/null
+++ b/cabal-testsuite/PackageTests/Backpack/T8582/setup.out
@@ -0,0 +1,7 @@
+# Setup configure
+Configuring T8582-1.0...
+Error:
+    Cannot instantiate requirement 'ImplA'
+    Ensure "build-depends:" doesn't include any library with signatures: 'A'
+    as this creates a cyclic dependency, which GHC does not support.
+    In the stanza executable exe
\ No newline at end of file
diff --git a/cabal-testsuite/PackageTests/Backpack/T8582/setup.test.hs b/cabal-testsuite/PackageTests/Backpack/T8582/setup.test.hs
new file mode 100644
index 0000000000000000000000000000000000000000..e93fb1bb8e73f4d053d4a4a80a4ca927b392253f
--- /dev/null
+++ b/cabal-testsuite/PackageTests/Backpack/T8582/setup.test.hs
@@ -0,0 +1,4 @@
+import Test.Cabal.Prelude
+main = setupAndCabalTest $ do
+    skipUnlessGhcVersion ">= 8.1"
+    fails $ setup "configure" []
diff --git a/cabal-testsuite/PackageTests/Backpack/T8582/sig/A.sig b/cabal-testsuite/PackageTests/Backpack/T8582/sig/A.sig
new file mode 100644
index 0000000000000000000000000000000000000000..cd83bfff2a924e8f039ca03c85772fae702f143d
--- /dev/null
+++ b/cabal-testsuite/PackageTests/Backpack/T8582/sig/A.sig
@@ -0,0 +1 @@
+signature A where
diff --git a/cabal-testsuite/PackageTests/Check/ConfiguredPackage/CabalVersion/AutoGenMods/cabal.out b/cabal-testsuite/PackageTests/Check/ConfiguredPackage/CabalVersion/AutoGenMods/cabal.out
index 75379f0b1d22746c233cb3a9ca2153e7f55af101..6ed067c93ac62aa4f7f6b141b9b28336a62a6563 100644
--- a/cabal-testsuite/PackageTests/Check/ConfiguredPackage/CabalVersion/AutoGenMods/cabal.out
+++ b/cabal-testsuite/PackageTests/Check/ConfiguredPackage/CabalVersion/AutoGenMods/cabal.out
@@ -1,4 +1,5 @@
 # cabal check
 Warning: The following errors will cause portability problems on other environments:
 Warning: Packages using 'cabal-version: 2.0' and the autogenerated module Paths_* must include it also on the 'autogen-modules' field besides 'exposed-modules' and 'other-modules'. This specifies that the module does not come with the package and is generated on setup. Modules built with a custom Setup.hs script also go here to ensure that commands like sdist don't fail.
+Warning: Packages using 'cabal-version: 2.0' and the autogenerated module PackageInfo_* must include it in 'autogen-modules' as well as 'exposed-modules' and 'other-modules'. This specifies that the module does not come with the package and is generated on setup. Modules built with a custom Setup.hs script also go here to ensure that commands like sdist don't fail.
 Warning: Hackage would reject this package.
diff --git a/cabal-testsuite/PackageTests/Check/ConfiguredPackage/CabalVersion/AutoGenMods/pkg.cabal b/cabal-testsuite/PackageTests/Check/ConfiguredPackage/CabalVersion/AutoGenMods/pkg.cabal
index a00327cd1b5f65f59f32b4794c33e98e7feea0c4..8486891a3e32aca4fbf044e43d216a99e39a5d72 100644
--- a/cabal-testsuite/PackageTests/Check/ConfiguredPackage/CabalVersion/AutoGenMods/pkg.cabal
+++ b/cabal-testsuite/PackageTests/Check/ConfiguredPackage/CabalVersion/AutoGenMods/pkg.cabal
@@ -11,5 +11,7 @@ license-file: LICENSE
 
 library
   exposed-modules: Module
-  other-modules: Paths_pkg
+  other-modules:
+    PackageInfo_pkg
+    Paths_pkg
   default-language: Haskell2010
diff --git a/cabal-testsuite/PackageTests/Check/NonConfCheck/PathsExtensions/cabal.out b/cabal-testsuite/PackageTests/Check/NonConfCheck/PathsExtensions/cabal.out
index 2efd21d37f1e3f81d4df7c92d4efd09d9ac98647..d21149b6c45d9e2cd1ece81d8a4ecdd893c28e2d 100644
--- a/cabal-testsuite/PackageTests/Check/NonConfCheck/PathsExtensions/cabal.out
+++ b/cabal-testsuite/PackageTests/Check/NonConfCheck/PathsExtensions/cabal.out
@@ -1,4 +1,5 @@
 # cabal check
 Warning: The package will not build sanely due to these errors:
 Warning: Packages using RebindableSyntax with OverloadedStrings or OverloadedLists in default-extensions, in conjunction with the autogenerated module Paths_*, are known to cause compile failures with Cabal < 2.2. To use these default-extensions with a Paths_* autogen module, specify at least 'cabal-version: 2.2'.
+Warning: Packages using RebindableSyntax with OverloadedStrings or OverloadedLists in default-extensions, in conjunction with the autogenerated module PackageInfo_*, are known to cause compile failures with Cabal < 2.2. To use these default-extensions with a PackageInfo_* autogen module, specify at least 'cabal-version: 2.2'.
 Warning: Hackage would reject this package.
diff --git a/cabal-testsuite/PackageTests/Check/NonConfCheck/PathsExtensions/pkg.cabal b/cabal-testsuite/PackageTests/Check/NonConfCheck/PathsExtensions/pkg.cabal
index a3f160d87d9045b5e4a1e0293123108649130173..940f48a3cbbbceff8ea28ce93dbe9c7a33d28634 100644
--- a/cabal-testsuite/PackageTests/Check/NonConfCheck/PathsExtensions/pkg.cabal
+++ b/cabal-testsuite/PackageTests/Check/NonConfCheck/PathsExtensions/pkg.cabal
@@ -11,8 +11,12 @@ license-file: LICENSE
 
 library
   exposed-modules: Foo
-  autogen-modules: Paths_pkg
-  other-modules: Paths_pkg
+  autogen-modules:
+    PackageInfo_pkg
+    Paths_pkg
+  other-modules:
+    PackageInfo_pkg
+    Paths_pkg
   default-language: Haskell2010
   default-extensions: RebindableSyntax,
                       OverloadedLists
diff --git a/cabal-testsuite/PackageTests/Configure/cabal.out b/cabal-testsuite/PackageTests/Configure/cabal.out
index e4257e6b7c2c2ddffde0297b5bd3edb595154c7d..10989f43fd068da0b6d71a469d265070a75d5921 100644
--- a/cabal-testsuite/PackageTests/Configure/cabal.out
+++ b/cabal-testsuite/PackageTests/Configure/cabal.out
@@ -4,5 +4,6 @@ Build profile: -w ghc-<GHCVER> -O1
 In order, the following will be built:
  - zlib-1.1 (lib:zlib) (first run)
 Configuring zlib-1.1...
+Warning: Flags 'con_flict', 'con-flict' all map to the same environment variable 'CABAL_FLAG_con_flict' causing a collision. The value first flag 'con_flict' will be used.
 Preprocessing library for zlib-1.1..
 Building library for zlib-1.1..
diff --git a/cabal-testsuite/PackageTests/Configure/configure.ac b/cabal-testsuite/PackageTests/Configure/configure.ac
index 853d9d143904ee1c4c073213bf2f713d536b1b45..29529b1483acfa9087e4542a3c16fc5ae57e3023 100644
--- a/cabal-testsuite/PackageTests/Configure/configure.ac
+++ b/cabal-testsuite/PackageTests/Configure/configure.ac
@@ -9,6 +9,21 @@ AC_CONFIG_HEADERS([include/HsZlibConfig.h])
 # Check for zlib include
 AC_CHECK_HEADER(zlib.h, [ZLIB_HEADER=yes], [], [])
 
+# Check that flag assignment has been propagated correctly
+if test "$CABAL_FLAG_true_flag" != "1"; then
+    echo "true flag incorrectly set: got '$CABAL_FLAG_true_flag'"
+    exit 1
+fi
+if test "$CABAL_FLAG_false_flag" != "0"; then
+    echo "false flag incorrectly set: got '$CABAL_FLAG_false_flag'"
+    exit 1
+fi
+
+if test "$CABAL_FLAGS" != "+con-flict +con_flict -false-flag +true-flag"; then
+    echo "CABAL_FLAGS incorrectly set: got '$CABAL_FLAGS'"
+    exit 1
+fi
+
 # Build the package if we found X11 stuff
 if test "x$ZLIB_HEADER" = "x"
 then BUILD_PACKAGE_BOOL=False
diff --git a/cabal-testsuite/PackageTests/Configure/setup.cabal.out b/cabal-testsuite/PackageTests/Configure/setup.cabal.out
index 3aacce528b892a9aad4575c5b18ee39ba0f5401d..18061406c91f01106fadb81e9d9714fe197c3f39 100644
--- a/cabal-testsuite/PackageTests/Configure/setup.cabal.out
+++ b/cabal-testsuite/PackageTests/Configure/setup.cabal.out
@@ -1,6 +1,7 @@
 # Setup configure
 Resolving dependencies...
 Configuring zlib-1.1...
+Warning: Flags 'con_flict', 'con-flict' all map to the same environment variable 'CABAL_FLAG_con_flict' causing a collision. The value first flag 'con_flict' will be used.
 # Setup build
 Preprocessing library for zlib-1.1..
 Building library for zlib-1.1..
diff --git a/cabal-testsuite/PackageTests/Configure/setup.out b/cabal-testsuite/PackageTests/Configure/setup.out
index 2cc87467b4bc54fc29d68fd5577907aff3be6cef..39c7d85e5d178202e66b5d7b63e1d0614f7fb465 100644
--- a/cabal-testsuite/PackageTests/Configure/setup.out
+++ b/cabal-testsuite/PackageTests/Configure/setup.out
@@ -1,5 +1,6 @@
 # Setup configure
 Configuring zlib-1.1...
+Warning: Flags 'con_flict', 'con-flict' all map to the same environment variable 'CABAL_FLAG_con_flict' causing a collision. The value first flag 'con_flict' will be used.
 # Setup build
 Preprocessing library for zlib-1.1..
 Building library for zlib-1.1..
diff --git a/cabal-testsuite/PackageTests/Configure/zlib.cabal b/cabal-testsuite/PackageTests/Configure/zlib.cabal
index 2c78af8cf824793245aec6cc74985cd38ba0fdc8..7e5642929dad57846db4c0b4cf2b11e8b97a8d78 100644
--- a/cabal-testsuite/PackageTests/Configure/zlib.cabal
+++ b/cabal-testsuite/PackageTests/Configure/zlib.cabal
@@ -6,6 +6,22 @@ maintainer:          ezyang@cs.stanford.edu
 build-type:          Configure
 cabal-version:       >=1.10
 
+flag con-flict
+  description:       A flag that will share an env var
+  default:           True
+
+flag con_flict
+  description:       A flag that will share an env var
+  default:           True
+
+flag true-flag
+  description:       A flag to ensure that flags are correctly passed to @configure@
+  default:           True
+
+flag false-flag
+  description:       A flag to ensure that flags are correctly passed to @configure@
+  default:           False
+
 library
   exposed-modules:     A
   build-depends:       base
diff --git a/cabal-testsuite/PackageTests/LinkerOptions/NonignoredConfigs/basic/basic/Basic.hs b/cabal-testsuite/PackageTests/LinkerOptions/NonignoredConfigs/basic/basic/Basic.hs
new file mode 100644
index 0000000000000000000000000000000000000000..d8690293fffd7b0a686520f17e90f8cd44abe16b
--- /dev/null
+++ b/cabal-testsuite/PackageTests/LinkerOptions/NonignoredConfigs/basic/basic/Basic.hs
@@ -0,0 +1,10 @@
+module Basic where
+
+funcs :: (a -> b -> c) -> ((a -> b -> c) -> a -> b -> c) -> b -> a -> c
+funcs f g = \a b -> (g f) b a
+
+name :: String
+name = "Basic"
+
+number :: Integer
+number = 8
diff --git a/cabal-testsuite/PackageTests/LinkerOptions/NonignoredConfigs/basic/basic/basic.cabal b/cabal-testsuite/PackageTests/LinkerOptions/NonignoredConfigs/basic/basic/basic.cabal
new file mode 100644
index 0000000000000000000000000000000000000000..90f2414bc6a7cc8b3177d7c040acfeb5d45bb7b9
--- /dev/null
+++ b/cabal-testsuite/PackageTests/LinkerOptions/NonignoredConfigs/basic/basic/basic.cabal
@@ -0,0 +1,10 @@
+cabal-version: >= 1.10
+name: basic
+version: 0.1
+build-type: Simple
+
+library
+  default-language: Haskell2010
+  build-depends: base
+  exposed-modules:
+    Basic
diff --git a/cabal-testsuite/PackageTests/LinkerOptions/NonignoredConfigs/basic/cabal.project b/cabal-testsuite/PackageTests/LinkerOptions/NonignoredConfigs/basic/cabal.project
new file mode 100644
index 0000000000000000000000000000000000000000..6b9fac75bce689c68ada73cc1277f0641c3b41c5
--- /dev/null
+++ b/cabal-testsuite/PackageTests/LinkerOptions/NonignoredConfigs/basic/cabal.project
@@ -0,0 +1 @@
+packages: basic
diff --git a/cabal-testsuite/PackageTests/LinkerOptions/NonignoredConfigs/cabal.out b/cabal-testsuite/PackageTests/LinkerOptions/NonignoredConfigs/cabal.out
new file mode 100644
index 0000000000000000000000000000000000000000..fa5cb34ec0ed8f859c2213e77b56ef043214ca4e
--- /dev/null
+++ b/cabal-testsuite/PackageTests/LinkerOptions/NonignoredConfigs/cabal.out
@@ -0,0 +1,26 @@
+# cabal v2-install
+Wrote tarball sdist to <ROOT>/cabal.dist/work/./basic/../dist/sdist/basic-0.1.tar.gz
+Resolving dependencies...
+Build profile: -w ghc-<GHCVER> -O1
+In order, the following will be built:
+ - basic-0.1 (lib) (requires build)
+Configuring library for basic-0.1..
+Preprocessing library for basic-0.1..
+Building library for basic-0.1..
+Installing library in <PATH>
+# cabal v2-install
+Wrote tarball sdist to <ROOT>/cabal.dist/work/./basic/../dist/sdist/basic-0.1.tar.gz
+Resolving dependencies...
+Build profile: -w ghc-<GHCVER> -O1
+In order, the following will be built:
+ - basic-0.1 (lib) (requires build)
+Configuring library for basic-0.1..
+Preprocessing library for basic-0.1..
+Building library for basic-0.1..
+Installing library in <PATH>
+# cabal v2-install
+Wrote tarball sdist to <ROOT>/cabal.dist/work/./basic/../dist/sdist/basic-0.1.tar.gz
+Resolving dependencies...
+# cabal v2-install
+Wrote tarball sdist to <ROOT>/cabal.dist/work/./basic/../dist/sdist/basic-0.1.tar.gz
+Resolving dependencies...
diff --git a/cabal-testsuite/PackageTests/LinkerOptions/NonignoredConfigs/cabal.test.hs b/cabal-testsuite/PackageTests/LinkerOptions/NonignoredConfigs/cabal.test.hs
new file mode 100644
index 0000000000000000000000000000000000000000..098c49e62143b2f667c901730080cc3d1e6867aa
--- /dev/null
+++ b/cabal-testsuite/PackageTests/LinkerOptions/NonignoredConfigs/cabal.test.hs
@@ -0,0 +1,105 @@
+import Test.Cabal.Prelude
+
+-- This test ensures the following fix holds:
+-- > Fix project-local build flags being ignored.
+-- >
+-- > I noticed that running ‘cabal install’ with two separate sets of dynamic /
+-- > static build flags (e.g. one with none, and one with ‘--enable-shared
+-- > --enable-executable-dynamic --disable-library-vanilla’) produced packages with
+-- > the same hash, instead of different hashes.
+-- >
+-- > After debugging this issue I found that this command (with no explicit cabal
+-- > project file) was resulting in these build configuration flags being ignored,
+-- > because in ProjectPlanning.hs, the sdist was not considered a local package, so
+-- > the (non-shared) local-package-only configuration was being dropped.
+-- >
+-- > This fix ensures that these command-line arguments properly make it through to
+-- > where they belong in cases like this.
+--
+-- Basically, take a simple package, build it under two sets of build flags:
+-- > (nothing)
+-- > --enable-shared --enable-executable-dynamic --disable-library-vanilla
+--
+-- And ensure that whereas before they produced the same hash, now the package
+-- hashes produced are different.  (And also supplementarily ensure that
+-- re-running the same build with the same flags a second time produces a
+-- deterministic hash too; the hash should differ only when we change these
+-- flags.)
+--
+-- Based on the UniqueIPID test.
+
+import Control.Monad (forM, foldM_)
+import Data.List (isPrefixOf, tails)
+
+data Linking = Static | Dynamic deriving (Eq, Ord, Show)
+
+links :: [Linking]
+links = [Static, Dynamic]
+
+linkConfigFlags :: Linking -> [String]
+linkConfigFlags Static  =
+    [
+    ]
+linkConfigFlags Dynamic =
+    [
+        "--enable-shared",
+        "--enable-executable-dynamic",
+        "--disable-library-vanilla"
+    ]
+
+lrun :: [Linking]
+lrun = [Static, Dynamic, Static, Dynamic]
+
+main = cabalTest $ do
+    -- Skip if on Windows, since my default Chocolatey Windows setup (and the CI
+    -- server setup at the time, presumably) lacks support for dynamic builds
+    -- since the base package appears to be static only, lacking e.g. ‘.dyn_o’
+    -- files.  Normal Windows installations would need support for dynamic
+    -- builds, or else this test would fail when it tries to build with the
+    -- dynamic flags.
+    skipIfWindows
+
+    withPackageDb $ do
+        -- Phase 1: get 4 hashes according to config flags.
+        results <- forM (zip [0..] lrun) $ \(idx, linking) -> do
+            withDirectory "basic" $ do
+                withSourceCopyDir ("basic" ++ show idx) $ do
+                    cwd <- fmap testSourceCopyDir getTestEnv
+                    -- (Now do ‘cd ..’, since withSourceCopyDir made our previous
+                    -- previous such withDirectories now accumulate to be
+                    -- relative to setup.dist/basic0, not testSourceDir
+                    -- (see 'testCurrentDir').)
+                    withDirectory ".." $ do
+                        packageEnv <- (</> ("basic" ++ show idx ++ ".env")) . testWorkDir <$> getTestEnv
+                        cabal "v2-install" $ ["--disable-deterministic", "--lib", "--package-env=" ++ packageEnv] ++ linkConfigFlags linking ++ ["basic"]
+                        let exIPID s = takeWhile (/= '\n') . head . filter (\t -> any (`isPrefixOf` t) ["basic-0.1-", "bsc-0.1-"]) $ tails s
+                        hashedIpid <- exIPID <$> liftIO (readFile packageEnv)
+                        return $ ((idx, linking), hashedIpid)
+        -- Phase 2: make sure we have different hashes iff we have different config flags.
+        -- In particular make sure the dynamic config flags weren't silently
+        -- dropped and ignored, since this is the bug that prompted this test.
+        (\step -> foldM_ step (const $ return ()) results) $ \acc x -> do
+            acc x
+            return $ \future -> acc future >> do
+                let
+                    ((thisIdx,   thisLinking),   thisHashedIpid)   = x
+                    ((futureIdx, futureLinking), futureHashedIpid) = future
+                when ((thisHashedIpid == futureHashedIpid) /= (thisLinking == futureLinking)) $ do
+                    assertFailure . unlines $
+                        if thisLinking /= futureLinking
+                            then
+                                -- What we are primarily concerned with testing
+                                -- here.
+                                [
+                                    "Error: static and dynamic config flags produced an IPID with the same hash; were the dynamic flags silently dropped?",
+                                    "\thashed IPID: " ++ thisHashedIpid
+                                ]
+                            else
+                                -- Help test our test can also make equal
+                                -- hashes.
+                                [
+                                    "Error: config flags were equal, yet a different IPID hash was produced.",
+                                    "\thashed IPID 1 : " ++ thisHashedIpid,
+                                    "\thashed IPID 2 : " ++ futureHashedIpid,
+                                    "\tlinking flags : " ++ show thisLinking
+                                ]
diff --git a/cabal-testsuite/PackageTests/NewBuild/CmdBuild/ScriptBuildRun/cabal.out b/cabal-testsuite/PackageTests/NewBuild/CmdBuild/ScriptBuildRun/cabal.out
index 5641c7a2ed849150fcfbca38c6d517f551693ef8..208af7b3a0b3124d7e84b90454cb333b19770f1d 100644
--- a/cabal-testsuite/PackageTests/NewBuild/CmdBuild/ScriptBuildRun/cabal.out
+++ b/cabal-testsuite/PackageTests/NewBuild/CmdBuild/ScriptBuildRun/cabal.out
@@ -5,5 +5,4 @@ In order, the following will be built:
  - fake-package-0 (exe:cabal-script-script.hs) (first run)
 Configuring executable 'cabal-script-script.hs' for fake-package-0..
 Building executable 'cabal-script-script.hs' for fake-package-0..
-# cabal v2-run
-Up to date
+# cabal v2-run
\ No newline at end of file
diff --git a/cabal-testsuite/PackageTests/NewBuild/CmdRun/Datafiles/foo/foo.cabal b/cabal-testsuite/PackageTests/NewBuild/CmdRun/Datafiles/foo/foo.cabal
index ebd41dbf39b8d06c11aadf86974bb50c496b4e0a..b69379dd3834b4e550cd4f2f6aefe0ee0da72768 100644
--- a/cabal-testsuite/PackageTests/NewBuild/CmdRun/Datafiles/foo/foo.cabal
+++ b/cabal-testsuite/PackageTests/NewBuild/CmdRun/Datafiles/foo/foo.cabal
@@ -12,7 +12,9 @@ executable foo
 
 library
     exposed-modules: LibFoo
-    other-modules: Paths_foo
+    other-modules:
+        PackageInfo_foo
+        Paths_foo
     build-depends: base
     default-language: Haskell2010
 
diff --git a/cabal-testsuite/PackageTests/NewBuild/CmdRun/MultipleExes/cabal.out b/cabal-testsuite/PackageTests/NewBuild/CmdRun/MultipleExes/cabal.out
index 1c5a2e370523beb00f63277fda105a1b8b9b41d2..e03600972755f672ff53022ff22860bd1fed88f4 100644
--- a/cabal-testsuite/PackageTests/NewBuild/CmdRun/MultipleExes/cabal.out
+++ b/cabal-testsuite/PackageTests/NewBuild/CmdRun/MultipleExes/cabal.out
@@ -14,7 +14,7 @@ Configuring executable 'bar' for MultipleExes-1.0..
 Preprocessing executable 'bar' for MultipleExes-1.0..
 Building executable 'bar' for MultipleExes-1.0..
 # cabal v2-run
-Up to date
+
 # cabal v2-run
 Error: cabal: The run command is for running a single executable at once. The target '' refers to the package MultipleExes-1.0 which includes 
 - executables: bar and foo
diff --git a/cabal-testsuite/PackageTests/NewBuild/CmdRun/MultiplePackages/cabal.out b/cabal-testsuite/PackageTests/NewBuild/CmdRun/MultiplePackages/cabal.out
index 66606e2087084bfe62454638274699789904481c..d389571bb4f50b32559b64054b0d26913b545cfd 100644
--- a/cabal-testsuite/PackageTests/NewBuild/CmdRun/MultiplePackages/cabal.out
+++ b/cabal-testsuite/PackageTests/NewBuild/CmdRun/MultiplePackages/cabal.out
@@ -7,7 +7,6 @@ Configuring executable 'bar-exe' for bar-1.0..
 Preprocessing executable 'bar-exe' for bar-1.0..
 Building executable 'bar-exe' for bar-1.0..
 # cabal v2-run
-Up to date
 # cabal v2-run
 Build profile: -w ghc-<GHCVER> -O1
 In order, the following will be built:
diff --git a/cabal-testsuite/PackageTests/NewBuild/CmdRun/ScriptRerun/cabal.out b/cabal-testsuite/PackageTests/NewBuild/CmdRun/ScriptRerun/cabal.out
index f7a7ca06306c43926e9876c07d825c94d6425bf7..5384fa3bbe5d3529e4673eb7d9ed704cfb0d5fc7 100644
--- a/cabal-testsuite/PackageTests/NewBuild/CmdRun/ScriptRerun/cabal.out
+++ b/cabal-testsuite/PackageTests/NewBuild/CmdRun/ScriptRerun/cabal.out
@@ -6,4 +6,3 @@ In order, the following will be built:
 Configuring executable 'cabal-script-script.hs' for fake-package-0..
 Building executable 'cabal-script-script.hs' for fake-package-0..
 # cabal v2-run
-Up to date
diff --git a/cabal-testsuite/PackageTests/NewBuild/CmdRun/Single/cabal.out b/cabal-testsuite/PackageTests/NewBuild/CmdRun/Single/cabal.out
index 486372189517c65880a6b3b0fc0c5b37da09561d..78f3af0113245c2b04224054b439708d8123786b 100644
--- a/cabal-testsuite/PackageTests/NewBuild/CmdRun/Single/cabal.out
+++ b/cabal-testsuite/PackageTests/NewBuild/CmdRun/Single/cabal.out
@@ -7,12 +7,8 @@ Configuring executable 'foo' for Single-1.0..
 Preprocessing executable 'foo' for Single-1.0..
 Building executable 'foo' for Single-1.0..
 # cabal v2-run
-Up to date
 # cabal v2-run
-Up to date
 # cabal v2-run
-Up to date
 # cabal v2-run
-Up to date
 # cabal v2-run
 Error: cabal: Cannot run the package bar, it is not in this project (either directly or indirectly). If you want to add it to the project then edit the cabal.project file.
diff --git a/cabal-testsuite/PackageTests/NewBuild/T5164/setup-lib/setup-lib.cabal b/cabal-testsuite/PackageTests/NewBuild/T5164/setup-lib/setup-lib.cabal
index 7ec9ecb06b2f508c5b7a53d02a1ba83597af95f1..8f0faefa08c6a48e1387c105cfbbe035e2dbab6d 100644
--- a/cabal-testsuite/PackageTests/NewBuild/T5164/setup-lib/setup-lib.cabal
+++ b/cabal-testsuite/PackageTests/NewBuild/T5164/setup-lib/setup-lib.cabal
@@ -6,6 +6,8 @@ data-files: example.txt
 
 library
     exposed-modules: SetupLib
-    other-modules: Paths_setup_lib
+    other-modules:
+        PackageInfo_setup_lib
+        Paths_setup_lib
     build-depends: base
     default-language: Haskell2010
diff --git a/cabal-testsuite/PackageTests/PackageInfoModule/Executable/Main.hs b/cabal-testsuite/PackageTests/PackageInfoModule/Executable/Main.hs
new file mode 100644
index 0000000000000000000000000000000000000000..f39386735759538f424ae3df5d79c17a483072c2
--- /dev/null
+++ b/cabal-testsuite/PackageTests/PackageInfoModule/Executable/Main.hs
@@ -0,0 +1,7 @@
+module Main where
+
+import PackageInfo_PackageInfoModule (version)
+
+main :: IO ()
+main = do
+  print version
diff --git a/cabal-testsuite/PackageTests/PackageInfoModule/Executable/my.cabal b/cabal-testsuite/PackageTests/PackageInfoModule/Executable/my.cabal
new file mode 100644
index 0000000000000000000000000000000000000000..f04d2696c6cb04d29cc263ede81124c1a1af993f
--- /dev/null
+++ b/cabal-testsuite/PackageTests/PackageInfoModule/Executable/my.cabal
@@ -0,0 +1,18 @@
+name: PackageInfoModule
+version: 0.1
+license: BSD3
+author: Gautier DI FOLCO
+stability: stable
+category: PackageTests
+build-type: Simple
+Cabal-version: >= 1.2
+
+description:
+    Check that the generated package info module compiles.
+
+Executable TestPackageInfoModule
+    main-is: Main.hs
+    other-modules:
+        PackageInfo_PackageInfoModule
+        Paths_PackageInfoModule
+    build-depends: base
diff --git a/cabal-testsuite/PackageTests/PackageInfoModule/Executable/setup.cabal.out b/cabal-testsuite/PackageTests/PackageInfoModule/Executable/setup.cabal.out
new file mode 100644
index 0000000000000000000000000000000000000000..6a480f6f57630731526517158ea0114bcd5b9482
--- /dev/null
+++ b/cabal-testsuite/PackageTests/PackageInfoModule/Executable/setup.cabal.out
@@ -0,0 +1,5 @@
+# Setup configure
+Configuring PackageInfoModule-0.1...
+# Setup build
+Preprocessing executable 'TestPackageInfoModule' for PackageInfoModule-0.1..
+Building executable 'TestPackageInfoModule' for PackageInfoModule-0.1..
diff --git a/cabal-testsuite/PackageTests/PackageInfoModule/Executable/setup.out b/cabal-testsuite/PackageTests/PackageInfoModule/Executable/setup.out
new file mode 100644
index 0000000000000000000000000000000000000000..6a480f6f57630731526517158ea0114bcd5b9482
--- /dev/null
+++ b/cabal-testsuite/PackageTests/PackageInfoModule/Executable/setup.out
@@ -0,0 +1,5 @@
+# Setup configure
+Configuring PackageInfoModule-0.1...
+# Setup build
+Preprocessing executable 'TestPackageInfoModule' for PackageInfoModule-0.1..
+Building executable 'TestPackageInfoModule' for PackageInfoModule-0.1..
diff --git a/cabal-testsuite/PackageTests/PackageInfoModule/Executable/setup.test.hs b/cabal-testsuite/PackageTests/PackageInfoModule/Executable/setup.test.hs
new file mode 100644
index 0000000000000000000000000000000000000000..ac477fa75675666b1cfe51c46c4fde7659fc5bef
--- /dev/null
+++ b/cabal-testsuite/PackageTests/PackageInfoModule/Executable/setup.test.hs
@@ -0,0 +1,4 @@
+import Test.Cabal.Prelude
+-- Test that Paths module is generated and available for executables.
+main = setupAndCabalTest $ setup_build []
+
diff --git a/cabal-testsuite/PackageTests/PackageInfoModule/ImportQualifiedPost/Main.hs b/cabal-testsuite/PackageTests/PackageInfoModule/ImportQualifiedPost/Main.hs
new file mode 100644
index 0000000000000000000000000000000000000000..d82a4bd93b7e75a6ff9845150450ae0709b93086
--- /dev/null
+++ b/cabal-testsuite/PackageTests/PackageInfoModule/ImportQualifiedPost/Main.hs
@@ -0,0 +1,4 @@
+module Main where
+
+main :: IO ()
+main = return ()
diff --git a/cabal-testsuite/PackageTests/PackageInfoModule/ImportQualifiedPost/my.cabal b/cabal-testsuite/PackageTests/PackageInfoModule/ImportQualifiedPost/my.cabal
new file mode 100644
index 0000000000000000000000000000000000000000..7704aaa15b80d67ae497e50de2dec76b8b02d7bb
--- /dev/null
+++ b/cabal-testsuite/PackageTests/PackageInfoModule/ImportQualifiedPost/my.cabal
@@ -0,0 +1,19 @@
+name: PackageInfoModule
+version: 0.1
+license: BSD3
+author: Gautier DI FOLCO
+category: PackageTests
+build-type: Simple
+Cabal-version: >= 1.2
+
+description:
+    Check that the generated package info module compiles.
+
+Executable TestPackageInfoModule
+    main-is: Main.hs
+    if impl(ghc >= 8.10.0)
+        ghc-options: -Werror -fwarn-prepositive-qualified-module
+    other-modules:
+        PackageInfo_PackageInfoModule
+        Paths_PackageInfoModule
+    build-depends: base
diff --git a/cabal-testsuite/PackageTests/PackageInfoModule/ImportQualifiedPost/setup.cabal.out b/cabal-testsuite/PackageTests/PackageInfoModule/ImportQualifiedPost/setup.cabal.out
new file mode 100644
index 0000000000000000000000000000000000000000..6a480f6f57630731526517158ea0114bcd5b9482
--- /dev/null
+++ b/cabal-testsuite/PackageTests/PackageInfoModule/ImportQualifiedPost/setup.cabal.out
@@ -0,0 +1,5 @@
+# Setup configure
+Configuring PackageInfoModule-0.1...
+# Setup build
+Preprocessing executable 'TestPackageInfoModule' for PackageInfoModule-0.1..
+Building executable 'TestPackageInfoModule' for PackageInfoModule-0.1..
diff --git a/cabal-testsuite/PackageTests/PackageInfoModule/ImportQualifiedPost/setup.out b/cabal-testsuite/PackageTests/PackageInfoModule/ImportQualifiedPost/setup.out
new file mode 100644
index 0000000000000000000000000000000000000000..6a480f6f57630731526517158ea0114bcd5b9482
--- /dev/null
+++ b/cabal-testsuite/PackageTests/PackageInfoModule/ImportQualifiedPost/setup.out
@@ -0,0 +1,5 @@
+# Setup configure
+Configuring PackageInfoModule-0.1...
+# Setup build
+Preprocessing executable 'TestPackageInfoModule' for PackageInfoModule-0.1..
+Building executable 'TestPackageInfoModule' for PackageInfoModule-0.1..
diff --git a/cabal-testsuite/PackageTests/PackageInfoModule/ImportQualifiedPost/setup.test.hs b/cabal-testsuite/PackageTests/PackageInfoModule/ImportQualifiedPost/setup.test.hs
new file mode 100644
index 0000000000000000000000000000000000000000..ac477fa75675666b1cfe51c46c4fde7659fc5bef
--- /dev/null
+++ b/cabal-testsuite/PackageTests/PackageInfoModule/ImportQualifiedPost/setup.test.hs
@@ -0,0 +1,4 @@
+import Test.Cabal.Prelude
+-- Test that Paths module is generated and available for executables.
+main = setupAndCabalTest $ setup_build []
+
diff --git a/cabal-testsuite/PackageTests/PackageInfoModule/Library/my.cabal b/cabal-testsuite/PackageTests/PackageInfoModule/Library/my.cabal
new file mode 100644
index 0000000000000000000000000000000000000000..b356e8929ea9aa83c92cdc12c68d610706991d43
--- /dev/null
+++ b/cabal-testsuite/PackageTests/PackageInfoModule/Library/my.cabal
@@ -0,0 +1,36 @@
+Cabal-version: 2.2
+name: PackageInfoModule
+version: 0.1
+license: BSD-3-Clause
+author: Gautier DI FOLCO
+stability: stable
+category: PackageTests
+build-type: Simple
+
+description:
+    Check that the generated package info module compiles.
+
+Library
+    exposed-modules:
+        PackageInfo_PackageInfoModule
+        Paths_PackageInfoModule
+    build-depends: base
+    default-language: Haskell2010
+    default-extensions:
+        -- This is a non-exhaustive list of extensions that can cause code to
+        -- not compile when it would if the extension was disabled. This ensures
+        -- that autogen modules are compatible with default extensions.
+        NoImplicitPrelude
+        CPP
+        TemplateHaskell
+        QuasiQuotes
+        Arrows
+        OverloadedStrings
+    if impl(ghc >= 6.12)
+       default-extensions: MonoLocalBinds
+    if impl(ghc >= 7.0.1)
+       default-extensions: RebindableSyntax
+    if impl(ghc >= 7.4.1)
+       default-extensions: NoTraditionalRecordSyntax
+    if impl(ghc >= 7.8.1)
+       default-extensions: OverloadedLists
diff --git a/cabal-testsuite/PackageTests/PackageInfoModule/Library/setup.cabal.out b/cabal-testsuite/PackageTests/PackageInfoModule/Library/setup.cabal.out
new file mode 100644
index 0000000000000000000000000000000000000000..65d22a5fc4a523e04819507e11e8b4e7657b715d
--- /dev/null
+++ b/cabal-testsuite/PackageTests/PackageInfoModule/Library/setup.cabal.out
@@ -0,0 +1,5 @@
+# Setup configure
+Configuring PackageInfoModule-0.1...
+# Setup build
+Preprocessing library for PackageInfoModule-0.1..
+Building library for PackageInfoModule-0.1..
diff --git a/cabal-testsuite/PackageTests/PackageInfoModule/Library/setup.out b/cabal-testsuite/PackageTests/PackageInfoModule/Library/setup.out
new file mode 100644
index 0000000000000000000000000000000000000000..65d22a5fc4a523e04819507e11e8b4e7657b715d
--- /dev/null
+++ b/cabal-testsuite/PackageTests/PackageInfoModule/Library/setup.out
@@ -0,0 +1,5 @@
+# Setup configure
+Configuring PackageInfoModule-0.1...
+# Setup build
+Preprocessing library for PackageInfoModule-0.1..
+Building library for PackageInfoModule-0.1..
diff --git a/cabal-testsuite/PackageTests/PackageInfoModule/Library/setup.test.hs b/cabal-testsuite/PackageTests/PackageInfoModule/Library/setup.test.hs
new file mode 100644
index 0000000000000000000000000000000000000000..7c55afb42cadf2ed9b8c10c028f83a3b65d3abe4
--- /dev/null
+++ b/cabal-testsuite/PackageTests/PackageInfoModule/Library/setup.test.hs
@@ -0,0 +1,3 @@
+import Test.Cabal.Prelude
+-- Test that Paths module is generated and available for libraries.
+main = setupAndCabalTest $ setup_build []
diff --git a/cabal-testsuite/PackageTests/PathsModule/Executable-Relocatable/my.cabal b/cabal-testsuite/PackageTests/PathsModule/Executable-Relocatable/my.cabal
index 29a319ad43f1d1e459bf345b7cf46d9bdc449ed5..04337c3f3f79827ed1c97e492e519665e7c0411e 100644
--- a/cabal-testsuite/PackageTests/PathsModule/Executable-Relocatable/my.cabal
+++ b/cabal-testsuite/PackageTests/PathsModule/Executable-Relocatable/my.cabal
@@ -12,5 +12,7 @@ description:
 
 Executable TestPathsModule
     main-is: Main.hs
-    other-modules: Paths_PathsModule
+    other-modules:
+        PackageInfo_PathsModule
+        Paths_PathsModule
     build-depends: base
diff --git a/cabal-testsuite/PackageTests/PathsModule/Executable/my.cabal b/cabal-testsuite/PackageTests/PathsModule/Executable/my.cabal
index 29a319ad43f1d1e459bf345b7cf46d9bdc449ed5..04337c3f3f79827ed1c97e492e519665e7c0411e 100644
--- a/cabal-testsuite/PackageTests/PathsModule/Executable/my.cabal
+++ b/cabal-testsuite/PackageTests/PathsModule/Executable/my.cabal
@@ -12,5 +12,7 @@ description:
 
 Executable TestPathsModule
     main-is: Main.hs
-    other-modules: Paths_PathsModule
+    other-modules:
+        PackageInfo_PathsModule
+        Paths_PathsModule
     build-depends: base
diff --git a/cabal-testsuite/PackageTests/PathsModule/ImportQualifiedPost/my.cabal b/cabal-testsuite/PackageTests/PathsModule/ImportQualifiedPost/my.cabal
index 8ad771ececd78b10ff4819ac1b9f9772b18f4607..faacd4f1ff0715cd542087f903a95fe9820160b4 100644
--- a/cabal-testsuite/PackageTests/PathsModule/ImportQualifiedPost/my.cabal
+++ b/cabal-testsuite/PackageTests/PathsModule/ImportQualifiedPost/my.cabal
@@ -13,5 +13,7 @@ Executable TestPathsModule
     main-is: Main.hs
     if impl(ghc >= 8.10.0)
         ghc-options: -Werror -fwarn-prepositive-qualified-module
-    other-modules: Paths_PathsModule
+    other-modules:
+        PackageInfo_PathsModule
+        Paths_PathsModule
     build-depends: base
diff --git a/cabal-testsuite/PackageTests/PathsModule/Library/my.cabal b/cabal-testsuite/PackageTests/PathsModule/Library/my.cabal
index 5260d9cbd5c9989bf54201f9b9f3cfefdf9de5d0..47ee1f942d1c998441d8ec2928f94c1fe6886fb7 100644
--- a/cabal-testsuite/PackageTests/PathsModule/Library/my.cabal
+++ b/cabal-testsuite/PackageTests/PathsModule/Library/my.cabal
@@ -11,7 +11,9 @@ description:
     Check that the generated paths module compiles.
 
 Library
-    exposed-modules: Paths_PathsModule
+    exposed-modules:
+        PackageInfo_PathsModule
+        Paths_PathsModule
     build-depends: base
     default-language: Haskell2010
     default-extensions:
diff --git a/cabal-testsuite/PackageTests/PathsModule/MissingSafeHaskellMode/my.cabal b/cabal-testsuite/PackageTests/PathsModule/MissingSafeHaskellMode/my.cabal
index 355f5819120f275ed69521ce32c837e676760ee9..44140ee9019829ffac938d4508b00172b9639769 100644
--- a/cabal-testsuite/PackageTests/PathsModule/MissingSafeHaskellMode/my.cabal
+++ b/cabal-testsuite/PackageTests/PathsModule/MissingSafeHaskellMode/my.cabal
@@ -11,7 +11,9 @@ description:
     Check that the generated paths module compiles.
 
 Library
-    exposed-modules: Paths_PathsModule
+    exposed-modules:
+        PackageInfo_PathsModule
+        Paths_PathsModule
     build-depends: base
     default-language: Haskell2010
 
diff --git a/cabal-testsuite/README.md b/cabal-testsuite/README.md
index cc87122816d847b975ae67ae5d26a40e40454fa6..de9826ec439a4807a66920f49f279b40a78e9900 100644
--- a/cabal-testsuite/README.md
+++ b/cabal-testsuite/README.md
@@ -4,11 +4,12 @@ frameworks.
 How to run
 ----------
 
-1. Build `cabal-tests` (`cabal build cabal-tests`)
+1. Build `cabal-testsuite` (`cabal build cabal-testsuite:cabal-tests`)
 2. Run the `cabal-tests` executable. It will scan for all tests
    in your current directory and subdirectories and run them.
-   To run a specific set of tests, use `cabal-tests PATH ...`.  You can
-   control parallelism using the `-j` flag.
+   To run a specific set of tests, use `cabal-tests PATH ...`.
+   (e.g. `cabal run cabal-testsuite:cabal-tests -- cabal-testsuite/PackageTests/TestOptions/setup.test.hs`)
+   You can control parallelism using the `-j` flag.
 
 There are a few useful flags:
 
@@ -137,7 +138,7 @@ these with include `hasSharedLibraries`, `hasProfiledLibraries`,
 `hasCabalShared`, `isGhcVersion`, `isWindows`, `isLinux`, `isOSX`
 and `hasCabalForGhc`.
 
-**I programatically modified a file in my test suite, but Cabal/GHC
+**I programmatically modified a file in my test suite, but Cabal/GHC
 doesn't seem to be picking it up.**  You need to sleep sufficiently
 long before editing a file, in order for file system timestamp
 resolution to pick it up.  Use `withDelay` and `delay` prior to
@@ -152,7 +153,7 @@ Hermetic tests
 --------------
 
 By default, we run tests directly on the source code that is checked into the
-source code repository.  However, some tests require programatically
+source code repository.  However, some tests require programmatically
 modifying source files, or interact with Cabal commands which are
 not hermetic (e.g., `cabal freeze`).  In this case, cabal-testsuite
 supports opting into a hermetic test, where we first make copy of all
diff --git a/cabal-testsuite/cabal-testsuite.cabal b/cabal-testsuite/cabal-testsuite.cabal
index 35555d76b3c898689572b17b0a92a6e8b8a2e778..e78435b3ec9616801cb3ff7a85536951fe6b8dbd 100644
--- a/cabal-testsuite/cabal-testsuite.cabal
+++ b/cabal-testsuite/cabal-testsuite.cabal
@@ -76,7 +76,7 @@ library
     , array                 ^>= 0.4.0.1 || ^>= 0.5.0.0
     , temporary             ^>= 1.3
     , text                  ^>= 1.2.3.1 || ^>= 2.0.1
-    , transformers          ^>= 0.3.0.0 || ^>= 0.4.2.0 || ^>= 0.5.2.0
+    , transformers          ^>= 0.3.0.0 || ^>= 0.4.2.0 || ^>= 0.5.2.0 || ^>= 0.6.0.2
 
   if !os(windows)
     build-depends:
diff --git a/cabal-testsuite/src/Test/Cabal/Prelude.hs b/cabal-testsuite/src/Test/Cabal/Prelude.hs
index 6f8a0a7c51655b4a12f6c89e5a4c254e20d3935c..6918e2771f3c7e07081856c7b4cf91af1f9ee7fe 100644
--- a/cabal-testsuite/src/Test/Cabal/Prelude.hs
+++ b/cabal-testsuite/src/Test/Cabal/Prelude.hs
@@ -170,7 +170,7 @@ setup'' prefix cmd args = do
     defaultRecordMode RecordMarked $ do
     recordHeader ["Setup", cmd]
 
-    -- We test `cabal act-act-setup` when running cabal-tests.
+    -- We test `cabal act-as-setup` when running cabal-tests.
     --
     -- `cabal` and `Setup.hs` do have different interface.
     --
diff --git a/changelog.d/issue-4994 b/changelog.d/issue-4994
new file mode 100644
index 0000000000000000000000000000000000000000..e5b829599d3f8ff24b469c7501570e4321567093
--- /dev/null
+++ b/changelog.d/issue-4994
@@ -0,0 +1,4 @@
+synopsis: Do not print "up to date" for commands unless running "cabal build"
+packages: Cabal
+issues: #4994
+prs: #8569
diff --git a/changelog.d/issue-8489 b/changelog.d/issue-8489
new file mode 100644
index 0000000000000000000000000000000000000000..32f4c25ff8d435858375e21b538f604a763863e6
--- /dev/null
+++ b/changelog.d/issue-8489
@@ -0,0 +1,11 @@
+synopsis: `ghc`, `ghc-boot`, `ghci` packages should be non-upgradable
+packages: cabal-install
+prs: #8501
+issues: #8489
+
+description: {
+
+- Changed both `Distribution.Client.Dependency`'s `dontUpgradeNonUpgradeablePackages`
+  and `Distribution.Solver.Modular.Solver`'s `nonInstallable` to be in sync.
+
+}
\ No newline at end of file
diff --git a/changelog.d/issue-8564 b/changelog.d/issue-8564
new file mode 100644
index 0000000000000000000000000000000000000000..b6882027f06835f39deb5c9156ba9bcd3269877b
--- /dev/null
+++ b/changelog.d/issue-8564
@@ -0,0 +1,5 @@
+synopsis: The `configure` script of `build-type: configure` packages now has access to the flag assignment of the package being built via the `CABAL_FLAGS` and `CABAL_FLAG_<flag>` environment variables
+packages: Cabal
+prs: #8565
+issues: #8564
+
diff --git a/changelog.d/pr-7794 b/changelog.d/pr-7794
new file mode 100644
index 0000000000000000000000000000000000000000..744707b12556fc3f3398746d43bd49691c704057
--- /dev/null
+++ b/changelog.d/pr-7794
@@ -0,0 +1,4 @@
+synopsis: Include extra-lib-dirs-static into PackageHash
+packages: cabal-install
+prs: #7794
+issues: #6935
\ No newline at end of file
diff --git a/changelog.d/pr-8339 b/changelog.d/pr-8339
new file mode 100644
index 0000000000000000000000000000000000000000..1e602c1e9850286ef97c53df2d4c4613202bdef0
--- /dev/null
+++ b/changelog.d/pr-8339
@@ -0,0 +1,4 @@
+synopsis: Add check for upper bound on any dependency in cabal check
+report, list, init, fetch, info, upload, get.
+prs: #8339
+issues: #8291
diff --git a/changelog.d/pr-8496 b/changelog.d/pr-8496
new file mode 100644
index 0000000000000000000000000000000000000000..d35a68d867e977ebac054aec68eddc36616122c0
--- /dev/null
+++ b/changelog.d/pr-8496
@@ -0,0 +1,10 @@
+synopsis: build pkgconfig db individually when bulk fails
+packages: cabal-install cabal-install-solver
+prs: #8496
+issues: #8494
+
+description: {
+
+- When pkg-config fails to get versions for all packages in bulk, falls back to querying one-by-one.
+
+}
diff --git a/changelog.d/pr-8499 b/changelog.d/pr-8499
index f825339e31325f24a28258ca0cda6afed45a1fff..f909fbf18fd507e243110e0912c9f1396f9c1aa6 100644
--- a/changelog.d/pr-8499
+++ b/changelog.d/pr-8499
@@ -3,5 +3,5 @@ packages: Cabal
 prs: #8499
 issues: #8458
 description: {
-    Ensure thatt extra-src-dirs, extra sources, and extra other modules all are added using ordNub rather than incidentally alphabetized.
+    Ensure that extra-src-dirs, extra sources, and extra other modules all are added using ordNub rather than incidentally alphabetized.
 }
diff --git a/changelog.d/pr-8500 b/changelog.d/pr-8500
new file mode 100644
index 0000000000000000000000000000000000000000..a443764e90f943cf0a810eb8d786959dabe356aa
--- /dev/null
+++ b/changelog.d/pr-8500
@@ -0,0 +1,10 @@
+synopsis: Redownload pkgs when source hash verification fails
+packages: cabal-install
+prs: #8500
+issues: #7541
+
+description: {
+
+- Cabal-install will verify source hashes on cached downloads against the current index, and redownload on mismatch. (Which can occur with e.g. head.hackage)
+
+}
diff --git a/changelog.d/pr-8534 b/changelog.d/pr-8534
new file mode 100644
index 0000000000000000000000000000000000000000..2e654063ca616ab51f89a3a0acc1849d75e02968
--- /dev/null
+++ b/changelog.d/pr-8534
@@ -0,0 +1,10 @@
+synopsis: Add PackageInfo_ module
+packages: Cabal
+prs: #8534
+significance: significant
+
+description: {
+
+- Add PackageInfo_ module to embed portable package-related informations (issue #3909)
+
+}
diff --git a/changelog.d/pr-8561 b/changelog.d/pr-8561
new file mode 100644
index 0000000000000000000000000000000000000000..f860867228cd458bfef48cc5c85ebd99a6abc939
--- /dev/null
+++ b/changelog.d/pr-8561
@@ -0,0 +1,9 @@
+synopsis: cabal init -i should sanitize package name guessed from the directory name
+packages: cabal-install
+prs: #8561
+issues: #8404
+description: {
+    If the current directory name has any non-alphanumeric symbol in its name, the symbol will be replaced with a dash. Also, will make sure that the resulting package name starts with a letter.
+
+    This worked for cabal init -n already, and this PR only moves code around so that cabal init -i also benefits from this logic.
+}
diff --git a/changelog.d/pr-8582 b/changelog.d/pr-8582
new file mode 100644
index 0000000000000000000000000000000000000000..01889700ea9884c71ea628f0b493c1831959dbe1
--- /dev/null
+++ b/changelog.d/pr-8582
@@ -0,0 +1,8 @@
+synopsis: Improve mutually recursive unit identifier error message
+packages: Cabal
+prs: #8582
+description: {
+Improves the error message in case of mutually recursive unit identifiers
+by specifying the name of the identifier, the name of the signature, and a suggestion
+to check the 'build-depends:' section.
+}
diff --git a/changelog.d/pr-8607 b/changelog.d/pr-8607
new file mode 100644
index 0000000000000000000000000000000000000000..8490646121f618c639c507906e7dc8fede442852
--- /dev/null
+++ b/changelog.d/pr-8607
@@ -0,0 +1,13 @@
+synopsis: No global packages auto written to env files, allow --force-reinstalls
+packages: cabal-install
+issues: #6165 #5559
+prs: #8607
+significance: significant
+
+description: {
+
+- When v2-install runs on a library, it does not pin global packages in the env file, only those directly necessary for the library.
+
+-- Further, it now fails if there is a reinstall in the plan, and suggests the --force-reinstalls flag, which also now works, cleaning out previous entries from the env file for any target which is reinstalled.
+
+}
diff --git a/changelog.d/pr-8623 b/changelog.d/pr-8623
new file mode 100644
index 0000000000000000000000000000000000000000..29c9c3bb2c5a85b65c61413b982db933be62c7b6
--- /dev/null
+++ b/changelog.d/pr-8623
@@ -0,0 +1,7 @@
+synopsis: Fix project-local flags being ignored
+packages: cabal-install
+prs: #8623
+description: {
+    Fix some cases of configuration flags being dropped, e.g. with `v2-install`
+    and `--enable-shared --enable-executable-dynamic --disable-library-vanilla`.
+}
diff --git a/changelog.d/pr-8633 b/changelog.d/pr-8633
new file mode 100644
index 0000000000000000000000000000000000000000..2aafda9a83702ab965c513ae4d2ec5261f7ce95b
--- /dev/null
+++ b/changelog.d/pr-8633
@@ -0,0 +1,7 @@
+synopsis: Specify default exe extension on wasm32 to be .wasm
+packages: Cabal
+prs: #8633
+issues:
+description: {
+  Specify default exe extension on wasm32 to be .wasm, following the convention in other WebAssembly toolchains.
+}
diff --git a/changelog.d/pr-8640 b/changelog.d/pr-8640
new file mode 100644
index 0000000000000000000000000000000000000000..2ea80c8dc323ef5d2fd2b0d0d6f40255cf981123
--- /dev/null
+++ b/changelog.d/pr-8640
@@ -0,0 +1,10 @@
+synopsis: Fix extra-source-file rebuild tracking when run in a multi-package project
+packages: cabal-install
+issues: #8632 #8634
+prs: #8640
+
+description: {
+
+- Fixes an issue where glob expansion of extra-source-files for rebuild tracking purposes was not occuring correctly when run in a multi-package setting (i.e. when the globs needed to be expanded relative to something other than ".").
+
+}
diff --git a/changelog.d/pr-8648 b/changelog.d/pr-8648
new file mode 100644
index 0000000000000000000000000000000000000000..7a4e47931e8f7d92a91eb2850318b13286d5d8a5
--- /dev/null
+++ b/changelog.d/pr-8648
@@ -0,0 +1,12 @@
+synopsis: Tiny refactor of how Cabal handles configure scripts
+packages: Cabal
+prs: #8648
+
+description: {
+None of this is visible downstream
+
+- Remove needless parameter on one private function.
+
+- Move another internal function (and ones that only it uses from the same module) to new private module.
+
+}
diff --git a/doc/cabal-commands.rst b/doc/cabal-commands.rst
index 7671e41cdf96e3e017ba88017d7ddd116878298c..0ea968b0f5de24cf6697e992ef9ee8baef35c2f1 100644
--- a/doc/cabal-commands.rst
+++ b/doc/cabal-commands.rst
@@ -511,9 +511,9 @@ description file or freeze file.
 
     :since: 2.4
 
-    Read dependendency version bounds from the v2-style freeze file
+    Read dependency version bounds from the v2-style freeze file
     related to the named project file (i.e., ``$PROJECTFILE.freeze``)
-    instead of the package desctription file. If multiple ``--project-file``
+    instead of the package description file. If multiple ``--project-file``
     flags are provided, only the final one is considered. This flag
     must only be passed in when ``--new-freeze-file`` is present.
 
@@ -845,6 +845,8 @@ The configuration information for the script is cached under the cabal directory
 and can be pre-built with ``cabal build path/to/script``.
 See ``cabal run`` for more information on scripts.
 
+.. _cabal run:
+
 cabal run
 ^^^^^^^^^
 
diff --git a/doc/cabal-package.rst b/doc/cabal-package.rst
index ef236aeb58651bdd57357ba1fe3c4b0110a0b42d..a5af5ad34166d8b4fce85d0e881153e9eaee44d1 100644
--- a/doc/cabal-package.rst
+++ b/doc/cabal-package.rst
@@ -999,6 +999,11 @@ a real-world use case:
 
       default-language: Haskell2010
 
+.. note::
+    For packages using ``cabal-version: 3.4`` or higher, the syntax to
+    specify an internal library in a ``build-depends:`` section is
+    ``package-name:internal-library-name``.
+
 **Multiple public libraries**
 
 Cabal 3.0 and later support exposing multiple libraries from a single package
@@ -3152,12 +3157,29 @@ the configured data directory for ``pretty-show`` is controlled with the
 Accessing the package version
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
-The aforementioned auto generated :file:`Paths_{pkgname}` module also
-exports the constant ``version ::``
-`Version <http://hackage.haskell.org/package/base/docs/Data-Version.html>`__
+The auto generated :file:`PackageInfo_{pkgname}` module exports the constant
+``version ::`` `Version <http://hackage.haskell.org/package/base/docs/Data-Version.html>`__
 which is defined as the version of your package as specified in the
 ``version`` field.
 
+Accessing package-related informations
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+The auto generated :file:`PackageInfo_{pkgname}` module exports the following
+package-related constants:
+
+.. code-block:: haskell
+
+    name :: String
+    version :: Version
+    synopsis :: String
+    copyright :: String
+    homepage :: String
+
+Unlike :file:`Paths_{pkgname}` (see <#accessing-data-files-from-package-code>),
+:file:`PackageInfo_{pkgname}` is system- and path-independent. It aims to be
+easier to work with for hash-based tools such as Nix.
+
 .. _system-dependent parameters:
 
 System-dependent parameters
@@ -3196,6 +3218,20 @@ The :pkg-field:`build-type` ``Configure`` differs from ``Simple`` in two ways:
    generated by the ``configure`` script mentioned above, allowing these
    settings to vary depending on the build environment.
 
+Note that the package's ``extra-source-files`` are available to the
+``configure`` script when it is executed. In typical ``autoconf`` fashion,
+``--host`` flag will be passed to the ``configure`` script to indicate the host
+platform when cross-compiling. Moreover, various bits of build configuration
+will be passed via environment variables:
+
+ - ``CC`` will reflect the path to the C compiler
+ - ``CFLAGS`` will reflect the path to the C compiler
+ - ``CABAL_FLAGS`` will contain the Cabal flag assignment of the current
+   package using traditional Cabal flag syntax (e.g. ``+flagA -flagB``)
+ - ``CABAL_FLAG_<flag>`` will be set to either ``0`` or ``1`` depending upon
+   whether flag ``<flag>`` is enabled. Note that any any non-alpha-numeric
+   characters in the flag name are replaced with ``_``.
+
 The build information file should have the following structure:
 
     *buildinfo*
diff --git a/doc/cabal-project.rst b/doc/cabal-project.rst
index 863ad1bf3cb926fdbd14b5cda53237d3e4b7202f..d12c08475cdea29d1ee3da1cd8865ab919468fee 100644
--- a/doc/cabal-project.rst
+++ b/doc/cabal-project.rst
@@ -913,7 +913,7 @@ Object code options
 
     :default: False
 
-    If the compiler (e.g., GHC 7.10 and later) supports outputing OS
+    If the compiler (e.g., GHC 7.10 and later) supports outputting OS
     native debug info (e.g., DWARF), setting ``debug-info: True`` will
     instruct it to do so. See the GHC wiki page on :ghc-wiki:`DWARF`
     for more information about this feature.
diff --git a/doc/file-format-changelog.rst b/doc/file-format-changelog.rst
index d2faf6d4a3767581272b1ce3cd0f5320ce8bdd66..300bdb21d3c91363b2556a5d87e651b603e7f04e 100644
--- a/doc/file-format-changelog.rst
+++ b/doc/file-format-changelog.rst
@@ -70,8 +70,9 @@ relative to the respective preceding *published* version.
 * License fields use identifiers from SPDX License List version
   ``3.9 2020-05-15``
 
-* Dependencies to sublibraries have to be specified explicitly,
+* Dependencies to sublibraries must be specified explicitly,
   even for current package.
+  For example: ``build-depends: mypackage:internal-lib``
   This way you can have an internal library with the same
   name as some external dependency.
 
diff --git a/doc/getting-started.rst b/doc/getting-started.rst
index f1a64d6b0c02f8e6959cd6d3022822df0ca88eee..416a5dd77ae1cb6552d441172e07fb9edb72065d 100644
--- a/doc/getting-started.rst
+++ b/doc/getting-started.rst
@@ -166,6 +166,44 @@ Now you can build and re-run your code to see the new output:
         /    /  /    /   \    \
        /____/  /____/     \____\
 
+Run a single-file Haskell script
+--------------------------------
+
+Cabal also enables us to run single-file Haskell scripts
+without creating a project directory or ``.cabal`` file.
+The cabal directives are placed in the file within a comment.
+
+.. code-block:: haskell
+
+    #!/usr/bin/env cabal
+    {- cabal:
+    build-depends: base, split
+    -}
+
+    import Data.List.Split (chunksOf)
+
+    main :: IO ()
+    main = getLine >>= print . chunksOf 3
+
+This can be run using ``cabal run myscript``.
+On Unix-like systems this can be run directly with execute permission.
+
+.. code-block:: console
+
+    $ cabal run myscript
+
+    $ chmod +x myscript
+    $ ./myscript
+
+Project metadata can also be included:
+
+.. code-block:: haskell
+
+    {- project:
+    with-compiler: ghc-8.10.7
+    -}
+
+See more in the documentation for :ref:`cabal run`.
 
 What Next?
 ----------
diff --git a/doc/nix-local-build.rst b/doc/nix-local-build.rst
index 3186be8bbf2165b8fa406022ebb9b911c28d6a19..70ebd28359dd834823c11d94585f8af6def0df15 100644
--- a/doc/nix-local-build.rst
+++ b/doc/nix-local-build.rst
@@ -125,7 +125,7 @@ versions of packages that the this snapshot specifies:
 ::
 
     packages: .
-    import https://www.stackage.org/lts-19.2/cabal.config
+    import: https://www.stackage.org/lts-19.2/cabal.config
 
 Please note that project files do not get bundled in Cabal package tarballs,
 made using e.g. ``cabal sdist``. Project files are intended for use in local
diff --git a/doc/setup-commands.rst b/doc/setup-commands.rst
index fd1c08e2a2e2e1a6c19985848901a6ed89d9260c..12af7db7fd6d87abeb81a5a8854ddd45cec26dca 100644
--- a/doc/setup-commands.rst
+++ b/doc/setup-commands.rst
@@ -790,7 +790,7 @@ Miscellaneous options
 
    Build a static library. This passes ``-staticlib`` to GHC (available
    for iOS, and with 8.4 more platforms).  The result is an archive ``.a``
-   containing all dependent haskell libararies combined.
+   containing all dependent haskell libraries combined.
 
 .. option:: --disable-static
 
diff --git a/release-notes/Cabal-3.4.0.0.md b/release-notes/Cabal-3.4.0.0.md
index d17a56d815957e52b5d19d9a40167fea0c86c1fb..bc337de34091cbf5227cc15fcc0d605854ad8714 100644
--- a/release-notes/Cabal-3.4.0.0.md
+++ b/release-notes/Cabal-3.4.0.0.md
@@ -9,7 +9,7 @@
   - Support for `-this-package-key` deprecation
   - Use process `createPipe`
   - Add support for WINIO to Cabal
-  - Adopt to simplfied subsumption changes
+  - Adopt to simplified subsumption changes
 
   There are no magical `IO = WithCallStack Prelude.IO` alias in Cabal,
   as it is hard to get working with GHC-9.0's simplified subsumption.
@@ -131,7 +131,7 @@
 - default-language field is optional in cabal-version: 3.4 [#6288](https://github.com/haskell/cabal/issues/6288) [!6924](https://github.com/haskell/cabal/pull/6924) [!6926](https://github.com/haskell/cabal/pull/6926)
 - Split `KnownRepoType` out of `RepoType` [#6432](https://github.com/haskell/cabal/issues/6432) [!6612](https://github.com/haskell/cabal/pull/6612)
 - Include component name in unit-id [#6485](https://github.com/haskell/cabal/issues/6485) [!6547](https://github.com/haskell/cabal/pull/6547)
-- Change 'optional-packages' default to empty, when cabal.project is mising. [#4797](https://github.com/haskell/cabal/issues/4797) [#6739](https://github.com/haskell/cabal/issues/6739) [!6740](https://github.com/haskell/cabal/pull/6740)
+- Change 'optional-packages' default to empty, when cabal.project is missing. [#4797](https://github.com/haskell/cabal/issues/4797) [#6739](https://github.com/haskell/cabal/issues/6739) [!6740](https://github.com/haskell/cabal/pull/6740)
 - Fix rpmvercmp (trailing non-digit characters) [#6805](https://github.com/haskell/cabal/issues/6805) [!6808](https://github.com/haskell/cabal/pull/6808)
 - other changes [!6556](https://github.com/haskell/cabal/pull/6556) [!6598](https://github.com/haskell/cabal/pull/6598) [!6910](https://github.com/haskell/cabal/pull/6910)
 - Package description parser benchmark [!6594](https://github.com/haskell/cabal/pull/6594)
diff --git a/release-notes/Cabal-3.6.1.0.md b/release-notes/Cabal-3.6.1.0.md
index cf207ae902aff200c9d7efbab80e1b187aaf6be7..4336060a76d689a2f77714936a19a6b02c5922f3 100644
--- a/release-notes/Cabal-3.6.1.0.md
+++ b/release-notes/Cabal-3.6.1.0.md
@@ -33,15 +33,15 @@ Cabal 3.6.1.0 Changelog
   As such, this patch provides a workaround for
   older, already existing GHC versions by first always
   following the symbolic link of the ghc binary (if it is one)
-  and prefering its target directory as the guess lookup
+  and preferring its target directory as the guess lookup
   location.
 
   Rationale
 
   The canonicalized path of the ghc binary usually points to the
   bin/ directory unpacked from a bindist, which is less likely to be
-  tampered with by distributions and tools. As such, prefering the
-  canoncialized path should get us more robust results.
+  tampered with by distributions and tools. As such, preferring the
+  canonicalized path should get us more robust results.
 
 - Fix `cabal test --enable-library-coverage` for other-modules [#5213](https://github.com/haskell/cabal/issues/5213) [#7493](https://github.com/haskell/cabal/pull/7493)
 
diff --git a/release-notes/Cabal-3.8.0.20220526.md b/release-notes/Cabal-3.8.0.20220526.md
index 40fddd2e0b927989a7f49f4f3b074138b88faeb1..42e58aec85fcaf8c2341220900d82197a9843f8d 100644
--- a/release-notes/Cabal-3.8.0.20220526.md
+++ b/release-notes/Cabal-3.8.0.20220526.md
@@ -105,7 +105,7 @@ Cabal 3.8.0.20220526 Changelog
 
   - Make builds that use experimental Cabal language features less noisy. At -v1
     (normal) we show just first instance of use of experimental cabal language
-  features, along with count of further occurences in the same file.
+  features, along with count of further occurrences in the same file.
 
 - Fix Cabal not finding public sublibraries of installed packages [#7270](https://github.com/haskell/cabal/issues/7270) [#8089](https://github.com/haskell/cabal/pull/8089)
 
@@ -135,7 +135,7 @@ Cabal 3.8.0.20220526 Changelog
 - Add "prompt" strategy when symlinking binaries. [#5672](https://github.com/haskell/cabal/pull/5672)
 - Add fields extra-libraries-static and extra-lib-dirs-static [#6688](https://github.com/haskell/cabal/issues/6688) [#7399](https://github.com/haskell/cabal/issues/7399) [#7536](https://github.com/haskell/cabal/pull/7536)
 - Paths passed to GHC are now relative to the current working directory
-- Autoatically pipe auth from repo uris into curl transport. [#4743](https://github.com/haskell/cabal/issues/4743) [#7630](https://github.com/haskell/cabal/pull/7630)
+- Automatically pipe auth from repo uris into curl transport. [#4743](https://github.com/haskell/cabal/issues/4743) [#7630](https://github.com/haskell/cabal/pull/7630)
 - raise lower bound of process and remove compatibility shims [#7922](https://github.com/haskell/cabal/pull/7922)
 - changes the cabal check warning about long synopsis, so it warns only synopsis bigger than the set size [#7932](https://github.com/haskell/cabal/issues/7932) [#7933](https://github.com/haskell/cabal/pull/7933)
 - Remove bootstrapping plan files from version control, and simplify bootstrap update Makefile targets. [#7949](https://github.com/haskell/cabal/pull/7949)
diff --git a/release-notes/Cabal-3.8.1.0.md b/release-notes/Cabal-3.8.1.0.md
index 63ed935af3fbb19d9d991d36f6c69e0bb4505b94..44e0f2aac66621cd74246822f9d61663c5af673b 100644
--- a/release-notes/Cabal-3.8.1.0.md
+++ b/release-notes/Cabal-3.8.1.0.md
@@ -78,7 +78,7 @@ Cabal 3.8.1.0 Changelog
 
   - Make builds that use experimental Cabal language features less noisy. At -v1
     (normal) we show just first instance of use of experimental cabal language
-  features, along with count of further occurences in the same file.
+  features, along with count of further occurrences in the same file.
 
 - Fix Cabal not finding public sublibraries of installed packages [#7270](https://github.com/haskell/cabal/issues/7270) [#8089](https://github.com/haskell/cabal/pull/8089)
 
diff --git a/release-notes/cabal-install-3.4.0.0.md b/release-notes/cabal-install-3.4.0.0.md
index 88d0080a716ee2d38dd397519817e68576e63da7..d91143a4413c330ffd687bd6f3f8845cd68b922c 100644
--- a/release-notes/cabal-install-3.4.0.0.md
+++ b/release-notes/cabal-install-3.4.0.0.md
@@ -9,7 +9,7 @@
   - Support for `-this-package-key` deprecation
   - Use process `createPipe`
   - Add support for WINIO to Cabal
-  - Adopt to simplfied subsumption changes
+  - Adopt to simplified subsumption changes
 
   There are no magical `IO = WithCallStack Prelude.IO` alias in Cabal,
   as it is hard to get working with GHC-8.12's simplified subsumption.
@@ -28,7 +28,7 @@
   build-depends: thispkg:somesublib
   ```
 
-  This fixes an issue, where it was impossible to refer to extenral
+  This fixes an issue, where it was impossible to refer to external
   library, if you had sublibrary of the same name.
 
 - Add active-repositories configuration [#6819](https://github.com/haskell/cabal/issues/6819) [!6724](https://github.com/haskell/cabal/pull/6724) [!6868](https://github.com/haskell/cabal/pull/6868)
@@ -218,7 +218,7 @@
 - Include component name in unit-id [#6485](https://github.com/haskell/cabal/issues/6485) [!6547](https://github.com/haskell/cabal/pull/6547)
 - cabal v2-install prints copy/symlink destination [#6575](https://github.com/haskell/cabal/issues/6575) [!6582](https://github.com/haskell/cabal/pull/6582) [!6890](https://github.com/haskell/cabal/pull/6890)
 - Prepend hs-source-dir to match-component, fixes `cabal repl file` [#6622](https://github.com/haskell/cabal/issues/6622) [!6623](https://github.com/haskell/cabal/pull/6623) [!6826](https://github.com/haskell/cabal/pull/6826) [!6875](https://github.com/haskell/cabal/pull/6875)
-- Change 'optional-packages' default to empty, when cabal.project is mising. [#4797](https://github.com/haskell/cabal/issues/4797) [#6739](https://github.com/haskell/cabal/issues/6739) [!6740](https://github.com/haskell/cabal/pull/6740)
+- Change 'optional-packages' default to empty, when cabal.project is missing. [#4797](https://github.com/haskell/cabal/issues/4797) [#6739](https://github.com/haskell/cabal/issues/6739) [!6740](https://github.com/haskell/cabal/pull/6740)
 - v2-update reports new index-state [#6804](https://github.com/haskell/cabal/issues/6804) [!6810](https://github.com/haskell/cabal/pull/6810)
 - Fix rpmvercmp (trailing non-digit characters) [#6805](https://github.com/haskell/cabal/issues/6805) [!6808](https://github.com/haskell/cabal/pull/6808)
 - Add `-z` / `--ignore-project` flag to `cabal v2-update` [#6809](https://github.com/haskell/cabal/issues/6809) [!6814](https://github.com/haskell/cabal/pull/6814)
diff --git a/release-notes/cabal-install-3.8.0.20220526.md b/release-notes/cabal-install-3.8.0.20220526.md
index 674847423ed111ad2e8c3172c0fb3c3e776bd443..aae97c185719f268dd2212ce66147120f07f1ae0 100644
--- a/release-notes/cabal-install-3.8.0.20220526.md
+++ b/release-notes/cabal-install-3.8.0.20220526.md
@@ -201,7 +201,7 @@ cabal-install 3.8.0.20220526 Changelog
 
 - Fix running GHCJS executables [#6175](https://github.com/haskell/cabal/issues/6175) [#6361](https://github.com/haskell/cabal/issues/6361) [#7575](https://github.com/haskell/cabal/pull/7575)
 
-- Support Git submodules in `source-package-respository` [#5536](https://github.com/haskell/cabal/issues/5536) [#7625](https://github.com/haskell/cabal/pull/7625)
+- Support Git submodules in `source-package-repository` [#5536](https://github.com/haskell/cabal/issues/5536) [#7625](https://github.com/haskell/cabal/pull/7625)
 
 - Add support for `--package-db` flags to v2 commands [#5773](https://github.com/haskell/cabal/issues/5773) [#7676](https://github.com/haskell/cabal/pull/7676)
 
diff --git a/release-notes/cabal-install-3.8.1.0.md b/release-notes/cabal-install-3.8.1.0.md
index ebddac2d64b2e3f29ed940daf06aba8087d2f848..95565d936c73469861b18951a82b39e346f26283 100644
--- a/release-notes/cabal-install-3.8.1.0.md
+++ b/release-notes/cabal-install-3.8.1.0.md
@@ -195,7 +195,7 @@ cabal-install 3.8.1.0 Changelog
 
 - Fix running GHCJS executables [#6175](https://github.com/haskell/cabal/issues/6175) [#6361](https://github.com/haskell/cabal/issues/6361) [#7575](https://github.com/haskell/cabal/pull/7575)
 
-- Support Git submodules in `source-package-respository` [#5536](https://github.com/haskell/cabal/issues/5536) [#7625](https://github.com/haskell/cabal/pull/7625)
+- Support Git submodules in `source-package-repository` [#5536](https://github.com/haskell/cabal/issues/5536) [#7625](https://github.com/haskell/cabal/pull/7625)
 
 - Add support for `--package-db` flags to v2 commands [#5773](https://github.com/haskell/cabal/issues/5773) [#7676](https://github.com/haskell/cabal/pull/7676)
 
diff --git a/solver-benchmarks/HackageBenchmark.hs b/solver-benchmarks/HackageBenchmark.hs
index 75f471f42fb8b99eed483be43cdace9135970e21..d650f38e56a18ffeb3d43cd9b5db13665eb1b312 100644
--- a/solver-benchmarks/HackageBenchmark.hs
+++ b/solver-benchmarks/HackageBenchmark.hs
@@ -213,7 +213,7 @@ runCabal timeoutSeconds cabalUnderTest cabal flags = do
   putStrLn $ "Cabal directory (for " ++ cabal ++ ") " ++ cabalDir
   createDirectoryIfMissing True cabalDir
 
-  -- shell enviroment
+  -- shell environment
   currEnv <- Map.fromList <$>  getEnvironment
   let thisEnv :: [(String, String)]
       thisEnv = Map.toList $ currEnv
diff --git a/solver-benchmarks/solver-benchmarks.cabal b/solver-benchmarks/solver-benchmarks.cabal
index c1a3d6b224b855b39521d04c6554f98222920859..a1c974a6cb832bddcad04bfbff5c983fef14a808 100644
--- a/solver-benchmarks/solver-benchmarks.cabal
+++ b/solver-benchmarks/solver-benchmarks.cabal
@@ -37,7 +37,7 @@ library
     optparse-applicative,
     process,
     time,
-    statistics >= 0.14 && < 0.16,
+    statistics >= 0.14 && < 0.17,
     vector
   default-language: Haskell2010
 
@@ -58,7 +58,7 @@ test-suite unit-tests
   build-depends:
     base,
     solver-benchmarks,
-    statistics >= 0.14 && < 0.16,
+    statistics >= 0.14 && < 0.17,
     tasty,
     tasty-hunit
   default-language: Haskell2010