summaryrefslogtreecommitdiff
path: root/hadrian
diff options
context:
space:
mode:
authorBrian Jaress <bjaress@gmail.com>2020-06-07 13:11:44 -0700
committerBen Gamari <ben@smart-cactus.org>2020-09-30 23:37:15 -0400
commitc3e3650ba498088598ed2f53362346d6d55816ef (patch)
tree04c76dd52cca3655fd0bb4ccf47e527895e544b9 /hadrian
parent235e410f63a4725bbc4466dbdef7d5f661793e84 (diff)
downloadhaskell-c3e3650ba498088598ed2f53362346d6d55816ef.tar.gz
alpine-static-flavour -- created static flavour
Diffstat (limited to 'hadrian')
-rw-r--r--hadrian/doc/flavours.md34
-rw-r--r--hadrian/hadrian.cabal1
-rwxr-xr-xhadrian/src/Settings.hs3
-rw-r--r--hadrian/src/Settings/Flavours/Performance.hs2
-rw-r--r--hadrian/src/Settings/Flavours/Static.hs55
5 files changed, 93 insertions, 2 deletions
diff --git a/hadrian/doc/flavours.md b/hadrian/doc/flavours.md
index 61af4f4075..dd0bbe2d86 100644
--- a/hadrian/doc/flavours.md
+++ b/hadrian/doc/flavours.md
@@ -142,6 +142,17 @@ when compiling the `compiler` library, and `hsGhc` when compiling/linking the GH
<td>-O</td>
<td>-O</td>
</tr>
+ <tr>
+ <th>static</td>
+ <td>-O<br>-H64m<br>-fPIC -static</td>
+ <td>-O<br>-H64m<br>-fPIC -static</td>
+ <td></td>
+ <td>-O2</td>
+ <td>-O2</td>
+ <td>-O2</td>
+ <td>-O<br>-optl -static</td>
+ <td>-O2<br>-optl -static</td>
+ </tr>
</table>
### LLVM variants
@@ -152,6 +163,16 @@ In addition to the above, there are LLVM variants for the flavours `quick`,
is an additional `-fllvm` flag in `hsDefault` when the stage0 compiler is GHC.
See `src/Settings/Flavours/Llvm.hs` for details.
+### Static
+
+The `static` flavour does not strictly follow the groupings in the table
+above because it links all the executables statically, not just GHC
+itself, and because it passes `-optc -static` when delegating to a C
+compiler. It also adds the `-dynamic-system-linker` cabal flag to the
+`ghc` package build and only adds static flags when building in a
+non-dynamic _way_. Some of the considerations for a static build aren't
+a great fit for the flavour system, so it's a little bit hacky.
+
## Ways
Libraries and GHC can be built in different _ways_, e.g. with or without profiling
@@ -190,6 +211,19 @@ information. The following table lists ways that are built in different flavours
<td>Only in<br>prof<br>flavour</td>
</tr>
<tr>
+ <th>static</td>
+ <td>vanilla</td>
+ <td>vanilla<br>profiling</td>
+ <td>logging<br>debug<br>threaded<br>threadedDebug<br>threadedLogging
+ </td>
+ <td>
+ logging<br>debug<br>threaded<br>threadedDebug<br>
+ threadedLogging<br>threadedProfiling
+ </td>
+ <td>Only in<br>prof<br>flavour</td>
+ <td>Only in<br>prof<br>flavour</td>
+</tr>
+<tr>
<th>quick<br>quick-llvm</th>
<td>vanilla</td>
<td>vanilla<br>dynamic</td>
diff --git a/hadrian/hadrian.cabal b/hadrian/hadrian.cabal
index 611cd20796..a4b7e0172b 100644
--- a/hadrian/hadrian.cabal
+++ b/hadrian/hadrian.cabal
@@ -111,6 +111,7 @@ executable hadrian
, Settings.Flavours.Quick
, Settings.Flavours.QuickCross
, Settings.Flavours.Quickest
+ , Settings.Flavours.Static
, Settings.Flavours.GhcInGhci
, Settings.Flavours.Validate
, Settings.Packages
diff --git a/hadrian/src/Settings.hs b/hadrian/src/Settings.hs
index 30f65bb4f1..1f2dd20eb7 100755
--- a/hadrian/src/Settings.hs
+++ b/hadrian/src/Settings.hs
@@ -20,6 +20,7 @@ import Settings.Flavours.Profiled
import Settings.Flavours.Quick
import Settings.Flavours.Quickest
import Settings.Flavours.QuickCross
+import Settings.Flavours.Static
import Settings.Flavours.GhcInGhci
import Settings.Flavours.Validate
@@ -57,7 +58,7 @@ hadrianFlavours =
, quickFlavour, quickValidateFlavour, quickestFlavour
, quickCrossFlavour, benchmarkLlvmFlavour
, performanceLlvmFlavour, profiledLlvmFlavour, quickLlvmFlavour
- , ghcInGhciFlavour, validateFlavour, slowValidateFlavour ]
+ , ghcInGhciFlavour, validateFlavour, slowValidateFlavour, staticFlavour ]
-- | This action looks up a flavour with the name given on the
-- command line with @--flavour@, defaulting to 'userDefaultFlavour'
diff --git a/hadrian/src/Settings/Flavours/Performance.hs b/hadrian/src/Settings/Flavours/Performance.hs
index aee5ddf6ca..fc46920703 100644
--- a/hadrian/src/Settings/Flavours/Performance.hs
+++ b/hadrian/src/Settings/Flavours/Performance.hs
@@ -1,4 +1,4 @@
-module Settings.Flavours.Performance (performanceFlavour) where
+module Settings.Flavours.Performance (performanceFlavour, performanceArgs) where
import Expression
import Flavour
diff --git a/hadrian/src/Settings/Flavours/Static.hs b/hadrian/src/Settings/Flavours/Static.hs
new file mode 100644
index 0000000000..fc4ba05f92
--- /dev/null
+++ b/hadrian/src/Settings/Flavours/Static.hs
@@ -0,0 +1,55 @@
+module Settings.Flavours.Static (staticFlavour) where
+
+import Expression
+import Flavour
+import Packages
+import {-# SOURCE #-} Settings.Default
+
+import Settings.Flavours.Performance (performanceArgs)
+
+-- Please update doc/flavours.md when changing this file.
+
+-- |Produce statically-linked executables. Also compiles libraries
+-- suitable for static linking.
+staticFlavour :: Flavour
+staticFlavour = defaultFlavour
+ { name = "static"
+ , args = defaultBuilderArgs <> performanceArgs <> defaultPackageArgs <> staticExec
+ , dynamicGhcPrograms = return False
+ , libraryWays = prune $ libraryWays defaultFlavour
+ , rtsWays = prune $ rtsWays defaultFlavour
+ }
+
+-- Remove any Way that contains a WayUnit of Dynamic
+prune :: Ways -> Ways
+prune = fmap $ filter staticCompatible
+
+staticCompatible :: Way -> Bool
+staticCompatible = not . wayUnit Dynamic
+
+staticExec :: Args
+{- Some packages, especially iserv, seem to force a set of build ways,
+ - including some that are dynamic (in Rules.BinaryDist). Trying to
+ - build statically and dynamically at the same time breaks the build,
+ - so we respect that overriding of the Ways. Any code that overrides
+ - the Ways will need to include a Way that's not explicitly dynamic
+ - (like "vanilla").
+ -}
+staticExec = staticCompatible <$> getWay ? mconcat
+ {-
+ - Disable dynamic linking by the built ghc executable because the
+ - statically-linked musl doesn't support dynamic linking, but will
+ - try and fail.
+ -}
+ [ package compiler ? builder (Cabal Flags) ? arg "-dynamic-system-linker"
+ {-
+ - The final executables don't work unless the libraries linked into
+ - it are compiled with "-fPIC." The PI stands for "position
+ - independent" and generates libraries that work when inlined into
+ - an executable (where their position is not at the beginning of
+ - the file).
+ -}
+ , builder (Ghc CompileHs) ? pure [ "-fPIC", "-static" ]
+ , builder (Ghc CompileCWithGhc) ? pure [ "-fPIC", "-optc", "-static"]
+ , builder (Ghc LinkHs) ? pure [ "-optl", "-static" ]
+ ]