diff options
author | Ben Gamari <ben@smart-cactus.org> | 2021-10-27 00:04:28 -0400 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2021-10-27 13:30:55 -0400 |
commit | 638f65482ca5265c268aa97abfcc14cdc27e46ba (patch) | |
tree | f062eb6945fb6791b75eb415b4acff59bd783e0c | |
parent | ed9ec655dcbd538383d5f1191440f152113adad2 (diff) | |
download | haskell-638f65482ca5265c268aa97abfcc14cdc27e46ba.tar.gz |
hadrian: Turn the `static` flavour into a transformer
This turns the `static` flavour into the `+fully_static` flavour
transformer.
-rw-r--r-- | .gitlab-ci.yml | 6 | ||||
-rw-r--r-- | hadrian/hadrian.cabal | 1 | ||||
-rw-r--r-- | hadrian/src/Flavour.hs | 52 | ||||
-rwxr-xr-x | hadrian/src/Settings.hs | 3 | ||||
-rw-r--r-- | hadrian/src/Settings/Flavours/Static.hs | 55 |
5 files changed, 54 insertions, 63 deletions
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 16653c13b0..114792831c 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -989,7 +989,7 @@ release-x86_64-linux-ubuntu2004: allow_failure: true variables: TEST_ENV: "x86_64-linux-alpine" - BUILD_FLAVOUR: "static" + BUILD_FLAVOUR: "validate+fully_static" BIN_DIST_NAME: "ghc-x86_64-alpine-linux" # Can't use ld.gold due to #13958. CONFIGURE_ARGS: "--disable-ld-override" @@ -1015,7 +1015,7 @@ release-x86_64-linux-alpine-integer-simple: - .release variables: BIGNUM_BACKEND: native - BUILD_FLAVOUR: "static" + BUILD_FLAVOUR: "validate+fully_static" release-x86_64-linux-alpine-integer-gmp: extends: @@ -1023,7 +1023,7 @@ release-x86_64-linux-alpine-integer-gmp: - .release variables: BIGNUM_BACKEND: gmp - BUILD_FLAVOUR: "static" + BUILD_FLAVOUR: "validate+fully_static" nightly-x86_64-linux-alpine: <<: *nightly diff --git a/hadrian/hadrian.cabal b/hadrian/hadrian.cabal index 2df0ef9c30..aaedeca80c 100644 --- a/hadrian/hadrian.cabal +++ b/hadrian/hadrian.cabal @@ -112,7 +112,6 @@ executable hadrian , Settings.Flavours.Quick , Settings.Flavours.QuickCross , Settings.Flavours.Quickest - , Settings.Flavours.Static , Settings.Flavours.Validate , Settings.Packages , Settings.Parser diff --git a/hadrian/src/Flavour.hs b/hadrian/src/Flavour.hs index d555246c4b..40cce02e51 100644 --- a/hadrian/src/Flavour.hs +++ b/hadrian/src/Flavour.hs @@ -45,6 +45,7 @@ flavourTransformers = M.fromList , "no_profiled_libs" =: disableProfiledLibs , "omit_pragmas" =: omitPragmas , "ipe" =: enableIPE + , "fully_static" =: fullyStatic ] where (=:) = (,) @@ -179,9 +180,12 @@ disableDynamicGhcPrograms flavour = flavour { dynamicGhcPrograms = pure False } -- | Don't build libraries in profiled 'Way's. disableProfiledLibs :: Flavour -> Flavour disableProfiledLibs flavour = - flavour { libraryWays = filter (not . wayUnit Profiling) <$> libraryWays flavour - , rtsWays = filter (not . wayUnit Profiling) <$> rtsWays flavour + flavour { libraryWays = prune $ libraryWays flavour + , rtsWays = prune $ rtsWays flavour } + where + prune :: Ways -> Ways + prune = fmap $ filter (not . wayUnit Profiling) -- | Build stage2 compiler with -fomit-interface-pragmas to reduce -- recompilation. @@ -199,6 +203,50 @@ enableIPE = Right transformer = applySetting kv in transformer +-- | Produce fully statically-linked executables and build libraries suitable +-- for static linking. +fullyStatic :: Flavour -> Flavour +fullyStatic flavour = + addArgs staticExec + $ flavour { dynamicGhcPrograms = return False + , libraryWays = prune $ libraryWays flavour + , rtsWays = prune $ rtsWays flavour } + where + -- 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" ] + ] + + -- * CLI and <root>/hadrian.settings options {- diff --git a/hadrian/src/Settings.hs b/hadrian/src/Settings.hs index 9a6cf16140..50ef988036 100755 --- a/hadrian/src/Settings.hs +++ b/hadrian/src/Settings.hs @@ -21,7 +21,6 @@ import Settings.Flavours.Performance import Settings.Flavours.Quick import Settings.Flavours.Quickest import Settings.Flavours.QuickCross -import Settings.Flavours.Static import Settings.Flavours.Validate @@ -57,7 +56,7 @@ hadrianFlavours = , quickestFlavour , quickCrossFlavour , 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/Static.hs b/hadrian/src/Settings/Flavours/Static.hs deleted file mode 100644 index fc4ba05f92..0000000000 --- a/hadrian/src/Settings/Flavours/Static.hs +++ /dev/null @@ -1,55 +0,0 @@ -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" ] - ] |