From cb1c817bf5f52787f517c91a06ccfdee3bf8c55f Mon Sep 17 00:00:00 2001 From: Cheng Shao <terrorjack@type.dance> Date: Thu, 2 May 2024 13:07:17 +0000 Subject: [PATCH] hadrian: add the host_fully_static flavour transformer This commit adds the host_fully_static flavour transformer to hadrian, which ensures stage0 is fully statically linked while still permitting stage1 libdir to contain shared libraries. This is intended to be used by the wasm backend to build portable linux bindists that contain wasm shared libraries. (cherry picked from commit b45080a3e34200767b76faca495f5aea95bb94f5) (cherry picked from commit 91c0dbd4deba147981e7cc1c0cb65d9887e8ac12) --- hadrian/doc/flavours.md | 4 ++++ hadrian/src/Flavour.hs | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/hadrian/doc/flavours.md b/hadrian/doc/flavours.md index 24c2945995d..7a3e75cf304 100644 --- a/hadrian/doc/flavours.md +++ b/hadrian/doc/flavours.md @@ -294,6 +294,10 @@ The supported transformers are listed below: <td><code>fully_static</code></td> <td>Produce fully statically-linked executables and build libraries suitable for static linking.</td> </tr> + <tr> + <td><code>host_fully_static</code></td> + <td>Ensure host executables are fully static, while still permitting shared target libraries.</td> + </tr> <tr> <td><code>collect_timings</code></td> <td>Collects timings while building the stage2+ compiler by adding the diff --git a/hadrian/src/Flavour.hs b/hadrian/src/Flavour.hs index b4f92fbd62b..d4877227642 100644 --- a/hadrian/src/Flavour.hs +++ b/hadrian/src/Flavour.hs @@ -57,6 +57,7 @@ flavourTransformers = M.fromList , "omit_pragmas" =: omitPragmas , "ipe" =: enableIPE , "fully_static" =: fullyStatic + , "host_fully_static" =: hostFullyStatic , "collect_timings" =: collectTimings , "assertions" =: enableAssertions , "debug_ghc" =: debugGhc Stage2 @@ -354,6 +355,23 @@ fullyStatic flavour = , builder (Ghc LinkHs) ? pure [ "-optl", "-static" ] ] +-- | Ensure stage0 executables and libraries are fully static. Useful +-- for building cross GHC bindists that still contain shared target +-- libraries. +hostFullyStatic :: Flavour -> Flavour +hostFullyStatic flavour = + addArgs staticExec $ disableDynamicGhcPrograms flavour + where + -- Unlike 'fullyStatic', we need to ensure these flags are only + -- applied to host code. + staticExec :: Args + staticExec = stage0 ? mconcat + [ + builder (Ghc CompileHs) ? pure [ "-fPIC", "-static" ] + , builder (Ghc CompileCWithGhc) ? pure [ "-fPIC", "-optc", "-static"] + , builder (Ghc LinkHs) ? pure [ "-optl", "-static" ] + ] + -- | Build stage2 dependencies with options to enable collection of compiler -- stats. collectTimings :: Flavour -> Flavour -- GitLab