Unverified Commit c9f02b27 authored by Niklas Hambüchen's avatar Niklas Hambüchen Committed by Mikhail Glushenkov

Add `--enable-executable-static` flag. Fixes #391.

Also update the docs for `--enable-executable-dynamic`
as they were slightly misleading.
parent 14ebc936
......@@ -426,6 +426,11 @@ configure (pkg_descr0, pbi) cfg = do
die' verbosity $ "--enable-tests/--enable-benchmarks are incompatible with" ++
" explicitly specifying a component to configure."
-- Some sanity checks related to dynamic/static linking.
when (fromFlag (configDynExe cfg) && fromFlag (configFullyStaticExe cfg)) $
die' verbosity $ "--enable-executable-dynamic and --enable-executable-static" ++
" are incompatible with each other."
-- allConstraints: The set of all 'Dependency's we have. Used ONLY
-- to 'configureFinalizedPackage'.
-- requiredDepsMap: A map from 'PackageName' to the specifically
......@@ -684,6 +689,8 @@ configure (pkg_descr0, pbi) cfg = do
fromFlagOrDefault False $ configStaticLib cfg
withDynExe_ = fromFlag $ configDynExe cfg
withFullyStaticExe_ = fromFlag $ configFullyStaticExe cfg
when (withDynExe_ && not withSharedLib_) $ warn verbosity $
"Executables will use dynamic linking, but a shared library "
++ "is not being built. Linking will fail if any executables "
......@@ -723,6 +730,7 @@ configure (pkg_descr0, pbi) cfg = do
withSharedLib = withSharedLib_,
withStaticLib = withStaticLib_,
withDynExe = withDynExe_,
withFullyStaticExe = withFullyStaticExe_,
withProfLib = False,
withProfLibDetail = ProfDetailNone,
withProfExe = False,
......
......@@ -572,7 +572,8 @@ buildOrReplLib mReplFlags verbosity numJobs pkg_descr lbi lib clbi = do
ghcOptHPCDir = hpcdir Hpc.Dyn
}
linkerOpts = mempty {
ghcOptLinkOptions = PD.ldOptions libBi,
ghcOptLinkOptions = PD.ldOptions libBi
++ [ "-static" | withFullyStaticExe lbi ],
ghcOptLinkLibs = extraLibs libBi,
ghcOptLinkLibPath = toNubListR $ extraLibDirs libBi,
ghcOptLinkFrameworks = toNubListR $ PD.frameworks libBi,
......@@ -1254,7 +1255,8 @@ gbuild verbosity numJobs pkg_descr lbi bm clbi = do
ghcOptHPCDir = hpcdir Hpc.Dyn
}
linkerOpts = mempty {
ghcOptLinkOptions = PD.ldOptions bnfo,
ghcOptLinkOptions = PD.ldOptions bnfo
++ [ "-static" | withFullyStaticExe lbi ],
ghcOptLinkLibs = extraLibs bnfo,
ghcOptLinkLibPath = toNubListR $ extraLibDirs bnfo,
ghcOptLinkFrameworks = toNubListR $
......
......@@ -218,6 +218,8 @@ data ConfigFlags = ConfigFlags {
configStaticLib :: Flag Bool, -- ^Build static library
configDynExe :: Flag Bool, -- ^Enable dynamic linking of the
-- executables.
configFullyStaticExe :: Flag Bool, -- ^Enable fully static linking of the
-- executables.
configProfExe :: Flag Bool, -- ^Enable profiling in the
-- executables.
configProf :: Flag Bool, -- ^Enable profiling in the library
......@@ -300,6 +302,7 @@ instance Eq ConfigFlags where
&& equal configSharedLib
&& equal configStaticLib
&& equal configDynExe
&& equal configFullyStaticExe
&& equal configProfExe
&& equal configProf
&& equal configProfDetail
......@@ -354,6 +357,7 @@ defaultConfigFlags progDb = emptyConfigFlags {
configSharedLib = NoFlag,
configStaticLib = NoFlag,
configDynExe = Flag False,
configFullyStaticExe = Flag False,
configProfExe = NoFlag,
configProf = NoFlag,
configProfDetail = NoFlag,
......@@ -492,6 +496,11 @@ configureOptions showOrParseArgs =
configDynExe (\v flags -> flags { configDynExe = v })
(boolOpt [] [])
,option "" ["executable-static"]
"Executable fully static linking"
configFullyStaticExe (\v flags -> flags { configFullyStaticExe = v })
(boolOpt [] [])
,option "" ["profiling"]
"Executable and library profiling"
configProf (\v flags -> flags { configProf = v })
......
......@@ -146,6 +146,7 @@ data LocalBuildInfo = LocalBuildInfo {
withSharedLib :: Bool, -- ^Whether to build shared versions of libs.
withStaticLib :: Bool, -- ^Whether to build static versions of libs (with all other libs rolled in)
withDynExe :: Bool, -- ^Whether to link executables dynamically
withFullyStaticExe :: Bool, -- ^Whether to link executables fully statically
withProfExe :: Bool, -- ^Whether to build executables for profiling.
withProfLibDetail :: ProfDetailLevel, -- ^Level of automatic profile detail.
withProfExeDetail :: ProfDetailLevel, -- ^Level of automatic profile detail.
......
......@@ -1160,13 +1160,27 @@ Miscellaneous options
.. option:: --enable-executable-dynamic
Link executables dynamically. The executable's library dependencies
should be built as shared objects. This implies :option:`--enable-shared`
Link dependent Haskell libraries into executables dynamically.
The executable's library dependencies must have been
built as shared objects. This implies :option:`--enable-shared`
unless :option:`--disable-shared` is explicitly specified.
.. option:: --disable-executable-dynamic
(default) Link executables statically.
(default) Link dependent Haskell libraries into executables statically.
Non-Haskell (C) libraries are still linked dynamically, including libc,
so the result is still not a fully static executable
unless :option:`--enable-executable-dynamic` is given.
.. option:: --enable-executable-static
Build fully static executables.
This link all dependent libraries into executables statically,
including libc.
.. option:: --disable-executable-static
(default) Do not build fully static executables.
.. option:: --configure-option=str
......
......@@ -1544,6 +1544,19 @@ Static linking options
This uses GHCs ``-staticlib`` flag, which is available for iOS and with
GHC 8.4 and later for other platforms as well.
.. cfg-field:: executable-static: boolean
--enable-executable-static
--disable-executable-static
:synopsis: Build fully static executables.
:default: False
Build fully static executables.
This link all dependent libraries into executables statically,
including libc.
This passes ``-static`` and ``-optl=-static`` to GHC.
Foreign function interface options
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
......
......@@ -349,6 +349,7 @@ instance Semigroup SavedConfig where
configSharedLib = combine configSharedLib,
configStaticLib = combine configStaticLib,
configDynExe = combine configDynExe,
configFullyStaticExe = combine configFullyStaticExe,
configProfExe = combine configProfExe,
configProfDetail = combine configProfDetail,
configProfLibDetail = combine configProfLibDetail,
......
......@@ -194,6 +194,7 @@ data PackageHashConfigInputs = PackageHashConfigInputs {
pkgHashVanillaLib :: Bool,
pkgHashSharedLib :: Bool,
pkgHashDynExe :: Bool,
pkgHashFullyStaticExe :: Bool,
pkgHashGHCiLib :: Bool,
pkgHashProfLib :: Bool,
pkgHashProfExe :: Bool,
......@@ -287,6 +288,7 @@ renderPackageHashInputs PackageHashInputs{
, opt "vanilla-lib" True display pkgHashVanillaLib
, opt "shared-lib" False display pkgHashSharedLib
, opt "dynamic-exe" False display pkgHashDynExe
, opt "fully-static-exe" False display pkgHashFullyStaticExe
, opt "ghci-lib" False display pkgHashGHCiLib
, opt "prof-lib" False display pkgHashProfLib
, opt "prof-exe" False display pkgHashProfExe
......
......@@ -380,6 +380,7 @@ convertLegacyPerPackageFlags configFlags installFlags haddockFlags testFlags =
configSharedLib = packageConfigSharedLib,
configStaticLib = packageConfigStaticLib,
configDynExe = packageConfigDynExe,
configFullyStaticExe = packageConfigFullyStaticExe,
configProfExe = packageConfigProfExe,
configProf = packageConfigProf,
configProfDetail = packageConfigProfDetail,
......@@ -632,6 +633,7 @@ convertToLegacyAllPackageConfig
configSharedLib = mempty,
configStaticLib = mempty,
configDynExe = mempty,
configFullyStaticExe = mempty,
configProfExe = mempty,
configProf = mempty,
configProfDetail = mempty,
......@@ -701,6 +703,7 @@ convertToLegacyPerPackageConfig PackageConfig {..} =
configSharedLib = packageConfigSharedLib,
configStaticLib = packageConfigStaticLib,
configDynExe = packageConfigDynExe,
configFullyStaticExe = packageConfigFullyStaticExe,
configProfExe = packageConfigProfExe,
configProf = packageConfigProf,
configProfDetail = packageConfigProfDetail,
......
......@@ -242,6 +242,7 @@ data PackageConfig
packageConfigSharedLib :: Flag Bool,
packageConfigStaticLib :: Flag Bool,
packageConfigDynExe :: Flag Bool,
packageConfigFullyStaticExe :: Flag Bool,
packageConfigProf :: Flag Bool, --TODO: [code cleanup] sort out
packageConfigProfLib :: Flag Bool, -- this duplication
packageConfigProfExe :: Flag Bool, -- and consistency
......
......@@ -1819,6 +1819,7 @@ elaborateInstallPlan verbosity platform compiler compilerprogdb pkgConfigDB
elabSharedLib = pkgid `Set.member` pkgsUseSharedLibrary
elabStaticLib = perPkgOptionFlag pkgid False packageConfigStaticLib
elabDynExe = perPkgOptionFlag pkgid False packageConfigDynExe
elabFullyStaticExe = perPkgOptionFlag pkgid False packageConfigFullyStaticExe
elabGHCiLib = perPkgOptionFlag pkgid False packageConfigGHCiLib --TODO: [required feature] needs to default to enabled on windows still
elabProfExe = perPkgOptionFlag pkgid False packageConfigProf
......@@ -3272,6 +3273,7 @@ setupHsConfigureFlags (ReadyPackage elab@ElaboratedConfiguredPackage{..})
configStaticLib = toFlag elabStaticLib
configDynExe = toFlag elabDynExe
configFullyStaticExe = toFlag elabFullyStaticExe
configGHCiLib = toFlag elabGHCiLib
configProfExe = mempty
configProfLib = toFlag elabProfLib
......@@ -3625,6 +3627,7 @@ packageHashConfigInputs shared@ElaboratedSharedConfig{..} pkg =
pkgHashVanillaLib = elabVanillaLib,
pkgHashSharedLib = elabSharedLib,
pkgHashDynExe = elabDynExe,
pkgHashFullyStaticExe = elabFullyStaticExe,
pkgHashGHCiLib = elabGHCiLib,
pkgHashProfLib = elabProfLib,
pkgHashProfExe = elabProfExe,
......
......@@ -248,6 +248,7 @@ data ElaboratedConfiguredPackage
elabSharedLib :: Bool,
elabStaticLib :: Bool,
elabDynExe :: Bool,
elabFullyStaticExe :: Bool,
elabGHCiLib :: Bool,
elabProfLib :: Bool,
elabProfExe :: Bool,
......
......@@ -560,6 +560,7 @@ filterConfigureFlags flags cabalLibVersion
-- Cabal < 1.23 doesn't know about '--profiling-detail'.
-- Cabal < 1.23 has a hacked up version of 'enable-profiling'
-- which we shouldn't use.
-- Cabal < 1.23 doesn't know about '--enable/disable-executable-static'.
(tryLibProfiling, tryExeProfiling) = computeEffectiveProfiling flags
flags_1_23_0 = flags_1_25_0 { configProfDetail = NoFlag
, configProfLibDetail = NoFlag
......@@ -567,6 +568,7 @@ filterConfigureFlags flags cabalLibVersion
, configProf = NoFlag
, configProfExe = Flag tryExeProfiling
, configProfLib = Flag tryLibProfiling
, configFullyStaticExe = NoFlag
}
-- Cabal < 1.22 doesn't know about '--disable-debug-info'.
......
......@@ -544,6 +544,7 @@ instance Arbitrary PackageConfig where
<*> arbitrary
<*> arbitrary <*> arbitrary <*> arbitrary
<*> arbitrary <*> arbitrary
<*> arbitrary
<*> arbitrary <*> arbitrary
<*> arbitrary <*> arbitrary
<*> shortListOf 5 arbitraryShortToken
......@@ -590,6 +591,7 @@ instance Arbitrary PackageConfig where
, packageConfigSharedLib = x05
, packageConfigStaticLib = x42
, packageConfigDynExe = x06
, packageConfigFullyStaticExe = x44
, packageConfigProf = x07
, packageConfigProfLib = x08
, packageConfigProfExe = x09
......@@ -642,6 +644,7 @@ instance Arbitrary PackageConfig where
, packageConfigSharedLib = x05'
, packageConfigStaticLib = x42'
, packageConfigDynExe = x06'
, packageConfigFullyStaticExe = x44'
, packageConfigProf = x07'
, packageConfigProfLib = x08'
, packageConfigProfExe = x09'
......@@ -687,7 +690,7 @@ instance Arbitrary PackageConfig where
, packageConfigTestFailWhenNoTestSuites = x48'
, packageConfigTestTestOptions = x49' }
| (((x00', x01', x02', x03', x04'),
(x05', x42', x06', x07', x08', x09'),
(x05', x42', x06', x44', x07', x08', x09'),
(x10', x11', x12', x13', x14'),
(x15', x16', x17', x18', x19')),
((x20', x20_1', x21', x22', x23', x24'),
......@@ -698,7 +701,7 @@ instance Arbitrary PackageConfig where
(x44', x45', x46', x47', x48', x49')))
<- shrink
(((preShrink_Paths x00, preShrink_Args x01, x02, x03, x04),
(x05, x42, x06, x07, x08, x09),
(x05, x42, x06, x44, x07, x08, x09),
(x10, x11, map NonEmpty x12, x13, x14),
(x15, map NonEmpty x16,
map NonEmpty x17,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment