Skip to content

Commit 81017f4

Browse files
thomieenolan
authored andcommitted
Strip libraries at install/copy time. Never strip libraries in build directory.
Two changes: * strip static libraries (.a files) at install/copy time, instead of at build time. Note that Cabal strips shared libraries (.so files) and executables at install/copy time also. This is needed for GHC, because it uses Cabal (via ghc-cabal copy) to install the boot libraries, and relies on Cabal to take of library stripping. Currently .so files indeed get properly stripped, but .a files do not. (Stripping static libraries at build time was introduced in 60409cb, with the explanation: "Call 'stripLib' from createLibArchive so that it's done only once.") This bug (if you want to call it that) partially explains the difference in size of a GHC installation before and after manual stripping, reported in #1622 (comment) (The other parts are that the GHC build system currently doesn't strip executables on installation: https://ghc.haskell.org/trac/ghc/ticket/9087, and neither are the RTS library stripped, since they don't go through Cabal). * never strip the copy of a library in the build directory. Only strip the copy that is installed. Note that Cabal never strips executables in the build directory either. This might speed up compilation of a package under development, since stripping won't be performed for every 'cabal build'. It is also consistent with the GNU coding standards for 'install-strip': "install-strip should not strip the executables in the build directory which are being copied for installation. It should only strip the copies that are installed." Source: http://www.gnu.org/prep/standards/html_node/Standard-Targets.html
1 parent 1a1cc2a commit 81017f4

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

Cabal/Distribution/Simple/GHC.hs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,12 +1074,14 @@ installLib verbosity lbi targetDir dynlibTargetDir builtDir _pkg lib clbi = do
10741074
let src = srcDir </> name
10751075
dst = dstDir </> name
10761076
createDirectoryIfMissingVerbose verbosity True dstDir
1077+
10771078
if isShared
1078-
then do when (stripLibs lbi) $ Strip.stripLib verbosity
1079-
(hostPlatform lbi) (withPrograms lbi) src
1080-
installExecutableFile verbosity src dst
1079+
then installExecutableFile verbosity src dst
10811080
else installOrdinaryFile verbosity src dst
10821081

1082+
when (stripLibs lbi) $ Strip.stripLib verbosity
1083+
(hostPlatform lbi) (withPrograms lbi) dst
1084+
10831085
installOrdinary = install False
10841086
installShared = install True
10851087

Cabal/Distribution/Simple/GHCJS.hs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -740,12 +740,14 @@ installLib verbosity lbi targetDir dynlibTargetDir builtDir _pkg lib clbi = do
740740
let src = srcDir </> name
741741
dst = dstDir </> name
742742
createDirectoryIfMissingVerbose verbosity True dstDir
743+
743744
if isShared
744-
then do when (stripLibs lbi) $ Strip.stripLib verbosity
745-
(hostPlatform lbi) (withPrograms lbi) src
746-
installExecutableFile verbosity src dst
745+
then installExecutableFile verbosity src dst
747746
else installOrdinaryFile verbosity src dst
748747

748+
when (stripLibs lbi) $ Strip.stripLib verbosity
749+
(hostPlatform lbi) (withPrograms lbi) dst
750+
749751
installOrdinary = install False
750752
installShared = install True
751753

Cabal/Distribution/Simple/Program/Ar.hs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ module Distribution.Simple.Program.Ar (
1515
multiStageProgramInvocation
1616
) where
1717

18-
import Control.Monad (when, unless)
18+
import Control.Monad (unless)
1919
import qualified Data.ByteString as BS
2020
import qualified Data.ByteString.Char8 as BS8
2121
import Data.Char (isSpace)
@@ -26,8 +26,6 @@ import Distribution.Simple.Program
2626
import Distribution.Simple.Program.Run
2727
( programInvocation, multiStageProgramInvocation
2828
, runProgramInvocation )
29-
import qualified Distribution.Simple.Program.Strip as Strip
30-
( stripLib )
3129
import Distribution.Simple.Utils
3230
( dieWithLocation, withTempDirectory )
3331
import Distribution.System
@@ -86,16 +84,14 @@ createArLibArchive verbosity lbi targetPath files = do
8684
| inv <- multiStageProgramInvocation
8785
simple (initial, middle, final) files ]
8886

89-
when stripLib $ Strip.stripLib verbosity platform progConf tmpPath
9087
unless (hostArch == Arm) $ -- See #1537
9188
wipeMetadata tmpPath
9289
equal <- filesEqual tmpPath targetPath
9390
unless equal $ renameFile tmpPath targetPath
9491

9592
where
9693
progConf = withPrograms lbi
97-
stripLib = stripLibs lbi
98-
platform@(Platform hostArch hostOS) = hostPlatform lbi
94+
Platform hostArch hostOS = hostPlatform lbi
9995
verbosityOpts v | v >= deafening = ["-v"]
10096
| v >= verbose = []
10197
| otherwise = ["-c"]

0 commit comments

Comments
 (0)