Simon Hengel pushed to branch wip/sol/pp-set-ghc-version at Glasgow Haskell Compiler / GHC Commits: 38f26df9 by Simon Hengel at 2026-06-20T21:34:06+07:00 Set GHC_VERSION when calling custom pre-processors (see #25952) (so that pre-processors can emit backwards compatible code) - - - - - 3 changed files: - + changelog.d/pp-set-ghc-version - compiler/GHC/SysTools/Tasks.hs - docs/users_guide/phases.rst Changes: ===================================== changelog.d/pp-set-ghc-version ===================================== @@ -0,0 +1,7 @@ +section: compiler +synopsis: + Set the environment variable `GHC_VERSION` to the current GHC version when + invoking custom pre-processors, so that pre-processors can emit + backward-compatible code. +issues: #25952 +mrs: !16224 ===================================== compiler/GHC/SysTools/Tasks.hs ===================================== @@ -45,6 +45,7 @@ import GHC.ForeignSrcLang import GHC.CmmToLlvm.Version (LlvmVersion, llvmVersionStr, supportedLlvmVersionUpperBound, parseLlvmVersion, supportedLlvmVersionLowerBound) +import GHC.Version import GHC.Settings import GHC.SysTools.Process @@ -63,6 +64,7 @@ import Data.List (tails, isPrefixOf) import Data.Maybe (fromMaybe) import System.IO import System.Process +import System.Environment import GHC.Driver.Config.Diagnostic import GHC.Driver.Errors import GHC.Driver.Errors.Types (GhcMessage(..), DriverMessage (DriverNoConfiguredLLVMToolchain)) @@ -217,7 +219,8 @@ runPp :: Logger -> DynFlags -> [Option] -> IO () runPp logger dflags args = traceSystoolCommand logger "pp" $ do let prog = pgm_F dflags opts = map Option (getOpts dflags opt_F) - runSomething logger "Haskell pre-processor" prog (args ++ opts) + env <- (("GHC_VERSION", cProjectVersion) :) <$> getEnvironment + runSomethingFiltered logger id "Haskell pre-processor" prog (args ++ opts) Nothing (Just env) data CcConfig = CcConfig { ccProg :: String ===================================== docs/users_guide/phases.rst ===================================== @@ -603,7 +603,7 @@ Options affecting a Haskell pre-processor appropriate and useful. The ``-F`` option lets you run a pre-processor as part of the overall GHC compilation pipeline, which has the advantage over running a Haskell pre-processor separately in - that it works in interpreted mode and you can continue to take reap + that it works in interpreted mode and you can continue to reap the benefits of GHC's recompilation checker. The pre-processor is run just before the Haskell compiler proper @@ -622,6 +622,10 @@ Options affecting a Haskell pre-processor :ghc-flag:`-optF ⟨option⟩` option. These are fed to ⟨cmd⟩ on the command line after the three standard input and output arguments. + GHC sets the environment variable `GHC_VERSION` to the current GHC version + when invoking a pre-processor. The pre-processor can use this to emit + backward-compatible code. + An example of a pre-processor is to convert your source files to the input encoding that GHC expects, i.e. create a script ``convert.sh`` containing the lines: View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/38f26df972e535fca196ba78421ada7f... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/38f26df972e535fca196ba78421ada7f... You're receiving this email because of your account on gitlab.haskell.org.
participants (1)
-
Simon Hengel (@sol)