Cabal: tell configure scripts which compiler is in use - #12340
Open
andreabedini wants to merge 1 commit into
Open
Cabal: tell configure scripts which compiler is in use#12340andreabedini wants to merge 1 commit into
andreabedini wants to merge 1 commit into
Conversation
'runConfigureScript' passes '--with-compiler=' to a package's configure
script, but takes the value from 'configHcPath', which cabal-install never
sets: it hands the compiler over as a program path override instead. The
script therefore got the bare flavour name ("--with-compiler=ghc") and,
following autoconf convention, looked up "ghc" on PATH. A script that
needs the actual compiler then ran the wrong one. GHC's own ghc-internal
does exactly that ('ghc --print-prim-module' to generate GHC/Internal/Prim.hs)
and fails under any other ghc, which broke building GHC's stage2 libraries
with the stage1 compiler.
Take the compiler and its package tool from the configured ProgramDb when
the flags do not name them, and pass them as '--with-compiler=' and
'--with-hc-pkg=', as the standard autoconf 'HC=/path' argument next to the
existing 'CC='/'CXX=' (the form haskell#2947 asks for; '--with-compiler' stays for
the scripts that use it), and for GHC as GHC and GHC_PKG in the environment,
for scripts that use AC_ARG_VAR([GHC]) rather than an option. Explicit
'--with-compiler'/'--with-hc-pkg' flags are left as given.
The new ConfigureCompiler test has a configure script that checks the
arguments are executable paths, that HC= agrees with --with-compiler, and
that the variables are set.
Fixes haskell#7452.
andreabedini
force-pushed
the
andrea/wip/prep/configure-script-compiler
branch
from
September 9, 2026 03:35
559d3a0 to
e90a74a
Compare
There was a problem hiding this comment.
🟡 Changes recommended
The new HC= and GHC/GHC_PKG exports can disagree with an explicitly provided --with-compiler/--with-hc-pkg, causing inconsistent inputs to configure scripts.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR fixes how build-type: Configure packages learn which Haskell compiler Cabal is using, ensuring configure scripts receive the actual configured compiler path (not just the flavor name like ghc) and adding a regression test to prevent future breakage.
Changes:
- Recover compiler and package-tool paths from the configured
ProgramDband pass them toconfigurevia--with-compiler,--with-hc-pkg,HC=..., and (for GHC)GHC/GHC_PKGenv vars. - Add a new testsuite package (
PackageTests/ConfigureCompiler) whoseconfigurescript asserts the above are executable paths and that the compiler runs. - Document the behavior change in the changelog.
File summaries
| File | Description |
|---|---|
| changelog.d/configure-script-compiler.md | Changelog entry describing the new configure script compiler-path propagation. |
| Cabal/src/Distribution/Simple/ConfigureScript.hs | Implements compiler/path recovery from ProgramDb and exports it to configure via args and env. |
| cabal-testsuite/PackageTests/ConfigureCompiler/configure-compiler.cabal | New minimal build-type: Configure test package. |
| cabal-testsuite/PackageTests/ConfigureCompiler/configure | New configure script asserting correct --with-compiler/HC=/env behavior. |
| cabal-testsuite/PackageTests/ConfigureCompiler/cabal.test.hs | New testsuite driver (skips on Windows, runs v2-build). |
| cabal-testsuite/PackageTests/ConfigureCompiler/cabal.project | New test project file for the testsuite package. |
| cabal-testsuite/PackageTests/ConfigureCompiler/cabal.out | Golden output for the new test. |
| cabal-testsuite/PackageTests/ConfigureCompiler/A.hs | Minimal library module for the test package. |
Review details
Suppressed comments (1)
Cabal/src/Distribution/Simple/ConfigureScript.hs:222
HC=is currently derived frommHcPath(theProgramDbvalue) rather than the effective--with-compilervalue passed viaconfigureArgs cfg'. This can makeHC=disagree with--with-compilerwhenconfigHcPathis explicitly set. Prefer usingconfigHcPath cfg'so all configure-script spellings stay in sync.
-- The standard autoconf spelling for the Haskell compiler (#2947);
-- '--with-compiler' above is kept for the scripts that use it.
++ ["HC=" ++ hcPath | Just hcPath <- [mHcPath]]
- Files reviewed: 8/8 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+112
to
+116
| hcEnv = | ||
| [ (var, Just path) | ||
| | Just GHC <- [flagToMaybe (configHcFlavor cfg)] | ||
| , (var, Just path) <- [("GHC", mHcPath), ("GHC_PKG", mHcPkgPath)] | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #7452. First step of #2947.
runConfigureScriptpasses--with-compiler=to a package'sconfigurescript, but takes thevalue from
configHcPath, and cabal-install never sets that: it hands the compiler over as aprogram path override (
--ghc=/path) and leavesconfigHcPathempty on purpose. So the scriptgets the flavour name and, following autoconf convention, goes looking for
ghconPATH.With cabal-install 3.16.1.0 and a configure script that just echoes its arguments:
A script that needs the actual compiler runs the wrong one. GHC's own
ghc-internaldoesexactly that (
$GHC --print-prim-moduleto generateGHC/Internal/Prim.hs) and fails under anyother ghc, which is how I ran into it: building GHC's stage2 libraries with the stage1 compiler
via cabal picked up the
ghconPATH.The fix takes the compiler and its package tool from the configured
ProgramDbwhen the flagsdo not name them, and passes them as:
--with-compiler=/pathand--with-hc-pkg=/path(what existing scripts look at);HC=/pathas a configure argument, the standard autoconf form suggested in Replace the--with-compilerconfigure script argument with HC=/path/to/hc #2947, alongsidethe existing
CC=/CXX=;GHCandGHC_PKGin the environment, for GHC, for scripts that useAC_ARG_VAR([GHC])rather than an option.
Explicit
--with-compiler/--with-hc-pkgflags are left as given. With the fix:I have not removed
--with-compiler(the second half of #2947); the six or so packages onHackage that implement it still work, and dropping it is a separate compatibility decision.
Testing
New
cabal-testsuite/PackageTests/ConfigureCompiler: abuild-type: Configurepackage whosehand-written
configurechecks that--with-compiler/--with-hc-pkgare executable paths,that
HC=matches--with-compiler, thatGHC/GHC_PKGare set, and that the compiler runs.It fails on master (
[ -x ghc ]is false) and passes with the change. The existing Configuretests (
Configure,BuildTypeConfigure,ConfigureCXX,ConfigureComponent) still pass.Skipped on Windows (POSIX shell script).
QA notes
Create a package with
build-type: Configurewhoseconfigurescript prints its arguments and$GHC, thencabal build -w /full/path/to/ghc. Before:--with-compiler=ghc,GHCunset.After: the full path in
--with-compiler,--with-hc-pkg,HC=andGHC.