Cabal: tell configure scripts which compiler is in use - #12340
andreabedini wants to merge 1 commit into
Conversation
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.
| hcEnv = | ||
| [ (var, Just path) | ||
| | Just GHC <- [flagToMaybe (configHcFlavor cfg)] | ||
| , (var, Just path) <- [("GHC", mHcPath), ("GHC_PKG", mHcPkgPath)] | ||
| ] |
There was a problem hiding this comment.
Fair point. HC= and the GHC/GHC_PKG variables now come from cfg', the same values configureArgs turns into --with-compiler/--with-hc-pkg, so an explicit flag shows up in all of them.
|
Could you include such a configure script that you QA note requires, e.g., in a comment in this issue? People may be depending on this bug, so please write in your changelog snippet that this requires a Release Notes point with maybe a hint of how to get back the old behaviour. |
| ++ hcEnv | ||
| ++ cabalFlagEnv | ||
| maybeHostFlag = ["--host=" ++ show (pretty hp) | hp /= buildPlatform] | ||
| backwardsCompatHack = False |
There was a problem hiding this comment.
Maybe it's time to retire that?
There was a problem hiding this comment.
Pre-existing: it picks --with-hc= over --with-compiler= in configureArgs, and it has been hard-wired to False since 3d9a490 (the TODO next to it mentions defaultUserHooks, which is long gone). Happy to drop the Bool, but configureArgs is exported from Distribution.Simple.Setup, so I'd do it in a separate PR.
'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.
e90a74a to
d3c12d6
Compare
|
The changelog now says this needs a release notes entry and how to get the old value back: A #!/bin/sh
echo "configure args: $*"
echo "GHC=${GHC:-<unset>}"With after: |
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.