David Eichmann pushed to branch wip/27162/hadrian-linkhs-response-file at Glasgow Haskell Compiler / GHC
Commits:
e51ca131 by Duncan Coutts at 2026-04-13T10:40:35+01:00
Use response files for hadrian linking with ghc.
In future supoort for windows dynamic linking, we expect long command
lines for linking dll files (which use ghc calling (l)ld) rather than
ar as is done for static linking). Experiments yielded a link command
line for ghc-internal well over 32kb. We did not encounter this before
for static libs, since we already use ar's @file feature (if available,
which it is for the llvm toolchain).
Co-authored-by: David Eichmann
- - - - -
1 changed file:
- hadrian/src/Builder.hs
Changes:
=====================================
hadrian/src/Builder.hs
=====================================
@@ -345,12 +345,16 @@ instance H.Builder Builder where
Haddock BuildPackage -> runHaddock path buildArgs buildInputs
- Ghc FindHsDependencies _ -> do
- -- Use a response file for ghc -M invocations, to
- -- avoid issues with command line size limit on
- -- Windows (#26637)
+ Ghc FindHsDependencies _ ->
+ -- We can't put the flags in a response file, because some flags
+ -- require empty arguments (such as the -dep-suffix flag), but
+ -- that isn't supported yet due to #26560.
runGhcWithResponse path buildArgs buildInputs
+ Ghc LinkHs _ ->
+ -- We do not pass `buildInputs` as they are duplicated in `buildArgs`
+ runGhcWithResponse path [] buildArgs
+
HsCpp -> captureStdout
Make dir -> cmd' buildOptions path ["-C", dir] buildArgs
@@ -393,15 +397,31 @@ runHaddock haddockPath flagArgs fileInputs = withTempFile $ \tmp -> do
writeFile' tmp $ escapeArgs fileInputs
cmd [haddockPath] flagArgs ('@' : tmp)
-runGhcWithResponse :: FilePath -> [String] -> [FilePath] -> Action ()
-runGhcWithResponse ghcPath flagArgs fileInputs = withTempFile $ \tmp -> do
-
- writeFile' tmp $ escapeArgs fileInputs
-
- -- We can't put the flags in a response file, because some flags
- -- require empty arguments (such as the -dep-suffix flag), but
- -- that isn't supported yet due to #26560.
- cmd [ghcPath] flagArgs ('@' : tmp)
+-- | Use a response file for ghc invocations to avoid issues with command line
+-- size limit on Windows (#26637).
+runGhcWithResponse :: FilePath -- ^ Path to ghc
+ -> [String] -- ^ Arguments passed on the command line
+ -> [String] -- ^ Arguments passed via the response file (cannot contain empty arguemnts)
+ -> Action ()
+runGhcWithResponse ghcPath args responseFileArgs = withTempFile $ \tmp -> do
+ -- Extract RTS options from reponseFileArgs. Returns (ghc args, rts args)
+ let splitRtsArgs inRtsSection argsRest = case argsRest of
+ [] -> ([], [])
+ "--RTS":rest -> (rest, [])
+ "-RTS":rest -> splitRtsArgs False rest
+ "+RTS":rest -> splitRtsArgs True rest
+ arg:rest -> let (restGhc, restRts) = splitRtsArgs inRtsSection rest
+ in if inRtsSection
+ then (restGhc, arg:restRts)
+ else (arg:restGhc, restRts)
+ (responseFileArgsGhc, argsRts) = splitRtsArgs False responseFileArgs
+ tmpContents = escapeArgs responseFileArgsGhc
+ when
+ (any null responseFileArgsGhc)
+ (putWarn $ "Response file arguments (" <> tmp <> ") contains empty arguments")
+ putVerbose $ tmp <> ": " <> tmpContents
+ writeFile' tmp tmpContents
+ cmd [ghcPath] ("+RTS" : argsRts ++ ["-RTS"] ++ args) ('@' : tmp)
-- TODO: Some builders are required only on certain platforms. For example,
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/e51ca131520d0bb0d7efed266d82ea7a...
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/e51ca131520d0bb0d7efed266d82ea7a...
You're receiving this email because of your account on gitlab.haskell.org.