Skip to content

Rework precedence of configuration - #12556

Open
sheaf wants to merge 6 commits into
haskell:masterfrom
sheaf:b-e-p
Open

sheaf wants to merge 6 commits into
haskell:masterfrom
sheaf:b-e-p

Conversation

@sheaf

@sheaf sheaf commented Nov 9, 2026 •

Copy link
Copy Markdown
Collaborator

This PR reworks the precedence of all configuration options. The global Cabal user configuration is overridden by cabal.project, which in turn is overridden by the freeze file, then cabal.project.local, then the command-line arguments.

Within a single project file, package * is overridden by top-level options which is then overriden by package pkg.

For program search paths, I reworked it completely as explained in Note [Program search paths]:

  • O: overrides --with-PROG=<...>
  • B: build-tools, as they were solved for so should be picked up in priority
  • C: programs bundled with the compiler, e.g. look up ghc-pkg next to where we found ghc
  • E: --extra-prog-path
  • P: fallback to PATH

Tickets fixed: #12535, #12694. Progress towards #12544.


Template Α: This PR modifies behaviour or interface

Include the following checklist in your PR:

@mergify mergify Bot added the 1️⃣ more approval needed Set by Mergify: has one of the two required approvals label Nov 14, 2026
@sheaf sheaf changed the title OC BEP: consistent ordering for program search paths OB CEP: consistent ordering for program search paths Dec 3, 2026
@sheaf sheaf changed the title OB CEP: consistent ordering for program search paths OBCEP: consistent ordering for program search paths Dec 3, 2026
@sheaf sheaf changed the title OBCEP: consistent ordering for program search paths Rework precedence of configuration Dec 3, 2026
@sheaf
sheaf force-pushed the b-e-p branch 2 times, most recently from 8df355d to 6499b1d Compare December 3, 2026 20:12
sheaf added 6 commits December 4, 2026 10:05
Options given in more specific stanzas within a project file now
consistently override more general options, and command line options
have the last say in the matter.

The configuration as a whole now follows the order:

  - cabal/config
  - cabal.project
  - cabal.project.freeze
  - cabal.project.local
  - command line arguments

with later options overriding earlier ones. Then, within a single
project file:

  - settings in a "package *" stanza
  - top-level settings
  - settings in a "package <pkg-name>" stanza
The program search path of each package started from the search path of
the compiler's ProgramDb, which leaked the extra-prog-path of the local
packages.
The program search path used to find programs is now consistently structured
to avoid duplicates and enforce the following ordering:

  (B) Programs specified in `build-tool-depends`
  (E) Programs found from `--extra-prog-path`
  (P) Fallback search on `PATH`.

See Note [Program search paths] in Distribution.Simple.Configure.

Removes the duplicate search path entries reported in haskell#12544.
The check in Distribution.Client.ProjectConfig.checkBadPerPackageCompilerPaths
made sure that one didn't try to change the compiler (or hc-pkg) on a
per-package basis, as that isn't valid. This patch extends that treatment
to other compiler toolchain programs (such as the C compiler). Other
programs that come with GHC, such as hsc2hs or haddock, are merely found
next to the GHC executable but are not part of the toolchain proper.

Other (related) changes:

  - The locations given by the user are now taken into account when
    configuring the toolchain programs at the project level: Cabal's
    'configCompilerProgDb' is split into 'addCompilerPrograms' and
    'configCompilerPrograms', so that user locations can be recorded in
    between.

  - The compiler ProgramDb shared by all packages now only retains
    configured programs, so that the first run behaves the same as when
    the plan is read back from the cache.

  - 'cabal install --with-gcc=<..> foo' now works as expected, with the
    GCC setting taken to be a global setting and not a per-package
    override (which would be invalid).

  - The locations of the other programs given at the top level of the
    project only apply to local packages: they no longer reach the
    dependencies through the compiler ProgramDb.

Fixes haskell#12694.
The programs that come with the compiler but are not part of its toolchain
(e.g. hsc2hs, haddock) are configured once for the whole project, but
can now be overridden on a per-package basis (instead of silently
ignoring e.g. hsc2hs-location).

If the program specified on a per-package basis matches the project level
one, we re-use it (to avoid pointlessly reconfiguring); otherwise
we reconfigure.

Fixes haskell#12535.
When running the solver, we now make sure that configuration intended
for local packages does not apply to other packages in the project.
This makes the solver consistent with plan elaboration.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

attention: needs-review 1️⃣ more approval needed Set by Mergify: has one of the two required approvals

Projects

None yet

3 participants