Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Implement '--enable-library-stripping'. #1623

Merged
merged 1 commit into from

2 participants

Mikhail Glushenkov Johan Tibell
Mikhail Glushenkov
Collaborator

Fixes #1622.

Johan Tibell
Owner

:+1:

Mikhail Glushenkov 23Skidoo merged commit faa7c9f into from
Mikhail Glushenkov 23Skidoo deleted the branch
Mikhail Glushenkov
Collaborator

Looks like this broke the DeterministicAr test. Investigating.

Mikhail Glushenkov
Collaborator

Looks like this broke the DeterministicAr test. Investigating.

Fixed in 681e9af.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 19, 2013
  1. Mikhail Glushenkov
This page is out of date. Refresh to see the latest.
1  Cabal/Distribution/Simple/Configure.hs
View
@@ -574,6 +574,7 @@ configure (pkg_descr0, pbi) cfg
withGHCiLib = fromFlag $ configGHCiLib cfg,
splitObjs = split_objs,
stripExes = fromFlag $ configStripExes cfg,
+ stripLibs = fromFlag $ configStripLibs cfg,
withPackageDB = packageDbs,
progPrefix = fromFlag $ configProgPrefix cfg,
progSuffix = fromFlag $ configProgSuffix cfg
58 Cabal/Distribution/Simple/GHC.hs
View
@@ -1258,14 +1258,8 @@ installExe verbosity lbi installDirs buildPref
installBinary (binDir </> fixedExeBaseName)
stripExe :: Verbosity -> LocalBuildInfo -> FilePath -> FilePath -> IO ()
-stripExe verbosity lbi name path = when (stripExes lbi) $
- case lookupProgram stripProgram (withPrograms lbi) of
- Just strip -> rawSystemProgram verbosity strip args
- Nothing -> unless (buildOS == Windows) $
- -- Don't bother warning on windows, we don't expect them to
- -- have the strip program anyway.
- warn verbosity $ "Unable to strip executable '" ++ name
- ++ "' (missing the 'strip' program)"
+stripExe verbosity lbi name path =
+ when (stripExes lbi) $ runStrip verbosity (withPrograms lbi) name args
where
args = path : case buildOS of
OSX -> ["-x"] -- By default, stripping the ghc binary on at least
@@ -1274,6 +1268,22 @@ stripExe verbosity lbi name path = when (stripExes lbi) $
-- The -x flag fixes that.
_ -> []
+runStrip :: Verbosity -> ProgramConfiguration -> FilePath -> [String] -> IO ()
+runStrip verbosity progConf name args =
+ case lookupProgram stripProgram progConf of
+ Just strip -> rawSystemProgram verbosity strip args
+ Nothing -> unless (buildOS == Windows) $
+ -- Don't bother warning on windows, we don't expect them to
+ -- have the strip program anyway.
+ warn verbosity $ "Unable to strip executable or library '"
+ ++ name ++ "' (missing the 'strip' program)"
+
+stripLib :: Verbosity -> LocalBuildInfo -> FilePath -> FilePath -> IO ()
+stripLib verbosity lbi name path =
+ when (stripLibs lbi) $ runStrip verbosity (withPrograms lbi) name args
+ where
+ args = [path, "--strip-unneeded"]
+
-- |Install for ghc, .hi, .a and, if --with-ghci given, .o
installLib :: Verbosity
-> LocalBuildInfo
@@ -1286,25 +1296,33 @@ installLib :: Verbosity
-> IO ()
installLib verbosity lbi targetDir dynlibTargetDir builtDir _pkg lib clbi = do
-- copy .hi files over:
- let copyHelper installFun src dst n = do
- createDirectoryIfMissingVerbose verbosity True dst
- installFun verbosity (src </> n) (dst </> n)
- copy = copyHelper installOrdinaryFile
- copyShared = copyHelper installExecutableFile
- copyModuleFiles ext =
- findModuleFiles [builtDir] [ext] (libModules lib)
- >>= installOrdinaryFiles verbosity targetDir
whenVanilla $ copyModuleFiles "hi"
whenProf $ copyModuleFiles "p_hi"
whenShared $ copyModuleFiles "dyn_hi"
-- copy the built library files over:
- whenVanilla $ mapM_ (copy builtDir targetDir) vanillaLibNames
- whenProf $ mapM_ (copy builtDir targetDir) profileLibNames
- whenGHCi $ mapM_ (copy builtDir targetDir) ghciLibNames
- whenShared $ mapM_ (copyShared builtDir dynlibTargetDir) sharedLibNames
+ whenVanilla $ mapM_ (installOrdinary builtDir targetDir) vanillaLibNames
+ whenProf $ mapM_ (installOrdinary builtDir targetDir) profileLibNames
+ whenGHCi $ mapM_ (installOrdinary builtDir targetDir) ghciLibNames
+ whenShared $ mapM_ (installShared builtDir dynlibTargetDir) sharedLibNames
where
+ install isShared srcDir dstDir name = do
+ let src = srcDir </> name
+ dst = dstDir </> name
+ createDirectoryIfMissingVerbose verbosity True dstDir
+ stripLib verbosity lbi name src
+ if isShared
+ then installExecutableFile verbosity src dst
+ else installOrdinaryFile verbosity src dst
+
+ installOrdinary = install False
+ installShared = install True
+
+ copyModuleFiles ext =
+ findModuleFiles [builtDir] [ext] (libModules lib)
+ >>= installOrdinaryFiles verbosity targetDir
+
cid = compilerId (compiler lbi)
libNames = componentLibraries clbi
vanillaLibNames = map mkLibName libNames
1  Cabal/Distribution/Simple/LocalBuildInfo.hs
View
@@ -155,6 +155,7 @@ data LocalBuildInfo = LocalBuildInfo {
withGHCiLib :: Bool, -- ^Whether to build libs suitable for use with GHCi.
splitObjs :: Bool, -- ^Use -split-objs with GHC, if available
stripExes :: Bool, -- ^Whether to strip executables during install
+ stripLibs :: Bool, -- ^Whether to strip libraries during install
progPrefix :: PathTemplate, -- ^Prefix to be prepended to installed executables
progSuffix :: PathTemplate -- ^Suffix to be appended to installed executables
} deriving (Read, Show)
9 Cabal/Distribution/Simple/Setup.hs
View
@@ -309,6 +309,7 @@ data ConfigFlags = ConfigFlags {
configGHCiLib :: Flag Bool, -- ^Enable compiling library for GHCi
configSplitObjs :: Flag Bool, -- ^Enable -split-objs with GHC
configStripExes :: Flag Bool, -- ^Enable executable stripping
+ configStripLibs :: Flag Bool, -- ^Enable library stripping
configConstraints :: [Dependency], -- ^Additional constraints for
-- dependencies.
configDependencies :: [(PackageName, InstalledPackageId)],
@@ -353,6 +354,7 @@ defaultConfigFlags progConf = emptyConfigFlags {
#endif
configSplitObjs = Flag False, -- takes longer, so turn off by default
configStripExes = Flag True,
+ configStripLibs = Flag True,
configTests = Flag False,
configBenchmarks = Flag False,
configLibCoverage = Flag False,
@@ -481,6 +483,11 @@ configureOptions showOrParseArgs =
configStripExes (\v flags -> flags { configStripExes = v })
(boolOpt [] [])
+ ,option "" ["library-stripping"]
+ "strip libraries upon installation to reduce binary sizes"
+ configStripLibs (\v flags -> flags { configStripLibs = v })
+ (boolOpt [] [])
+
,option "" ["configure-option"]
"Extra option for configure"
configConfigureArgs (\v flags -> flags { configConfigureArgs = v })
@@ -682,6 +689,7 @@ instance Monoid ConfigFlags where
configGHCiLib = mempty,
configSplitObjs = mempty,
configStripExes = mempty,
+ configStripLibs = mempty,
configExtraLibDirs = mempty,
configConstraints = mempty,
configDependencies = mempty,
@@ -718,6 +726,7 @@ instance Monoid ConfigFlags where
configGHCiLib = combine configGHCiLib,
configSplitObjs = combine configSplitObjs,
configStripExes = combine configStripExes,
+ configStripLibs = combine configStripExes,
configExtraLibDirs = combine configExtraLibDirs,
configConstraints = combine configConstraints,
configDependencies = combine configDependencies,
Something went wrong with that request. Please try again.