David Eichmann pushed to branch wip/27162/hadrian-linkhs-response-file at Glasgow Haskell Compiler / GHC
Commits:
38b5866d by Duncan Coutts at 2026-04-13T14:22:35+01:00
Use response files for hadrian linking with ghc (support long command lines)
In future supoort for windows dynamic linking, we expect long command
lines for linking dll files with ghc. Experiments with dynamic linking the
ghc-internal library yielded a link command 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,34 @@ 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
+ -- RTS options are not supported in response files, so the are extracted here.
+ -- Returns (ghc args, rts args)
+ let (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)
+ where
+ 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)
-- TODO: Some builders are required only on certain platforms. For example,
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/38b5866d8ddbc00c8879587f1b380766...
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/38b5866d8ddbc00c8879587f1b380766...
You're receiving this email because of your account on gitlab.haskell.org.