@@ -46,6 +46,7 @@ import System.IO.Error
46
46
import System.Process
47
47
48
48
import qualified Codec.Archive.Tar as Tar
49
+ import qualified Codec.Archive.Tar.Entry as TarEntry
49
50
import qualified Codec.Archive.Zip as Zip
50
51
import qualified Codec.Compression.GZip as GZip
51
52
import Data.List.Extra
84
85
gTestHaddocks = True
85
86
gProjectRoot = " " -- Set to real value velow.
86
87
gBuildArgs = [" --flag" , " stack:-developer-mode" ]
88
+ gStaticLinux = False
87
89
gCertificateName = Nothing
88
90
global0 = foldl (flip id ) Global {.. } flags
89
91
@@ -118,7 +120,8 @@ options =
118
120
(NoArg $ Right $ \ g ->
119
121
g{gBuildArgs =
120
122
gBuildArgs g ++
121
- [" --flag=stack:static" , " --docker" , " --system-ghc" , " --no-install-ghc" ]})
123
+ [" --flag=stack:static" , " --docker" , " --system-ghc" , " --no-install-ghc" ],
124
+ gStaticLinux = True })
122
125
" Build a static binary using Alpine Docker image."
123
126
, Option " " [buildArgsOptName]
124
127
(ReqArg
@@ -194,7 +197,14 @@ rules global@Global{..} args = do
194
197
195
198
releaseDir </> binaryPkgTarGzFileName %> \ out -> do
196
199
stageFiles <- getBinaryPkgStageFiles
197
- writeTarGz out releaseStageDir stageFiles
200
+ writeTarGz id out releaseStageDir stageFiles
201
+
202
+ releaseDir </> binaryPkgStaticTarGzFileName %> \ out -> do
203
+ stageFiles <- getBinaryPkgStageFiles
204
+ let fixPath path =
205
+ let (x, y) = break (== ' /' ) path
206
+ in concat [x, " -static" , y]
207
+ writeTarGz fixPath out releaseStageDir stageFiles
198
208
199
209
releaseStageDir </> binaryName </> stackExeFileName %> \ out -> do
200
210
copyFileChanged (releaseDir </> binaryExeFileName) out
@@ -296,16 +306,21 @@ rules global@Global{..} args = do
296
306
binaryPkgFileNames =
297
307
case platformOS of
298
308
Windows -> [binaryExeFileName, binaryPkgZipFileName, binaryPkgTarGzFileName, binaryInstallerFileName]
309
+ Linux -> concat
310
+ [ [binaryExeFileName, binaryPkgTarGzFileName]
311
+ , [binaryPkgStaticTarGzFileName | gStaticLinux]
312
+ ]
299
313
_ -> [binaryExeFileName, binaryPkgTarGzFileName]
300
314
binaryPkgZipFileName = binaryName <.> zipExt
301
315
binaryPkgTarGzFileName = binaryName <.> tarGzExt
316
+ binaryPkgStaticTarGzFileName = binaryStaticName <.> tarGzExt
302
317
-- Adding '-bin' to name to work around https://github.com/commercialhaskell/stack/issues/4961
303
318
binaryExeFileName = binaryName ++ " -bin" <.> exe
304
319
-- Prefix with 'installer-' so it doesn't get included in release artifacts
305
320
-- (due to NSIS limitation, needs to be in same directory as executable)
306
321
binaryInstallerNSIFileName = " installer-" ++ binaryName <.> nsiExt
307
322
binaryInstallerFileName = binaryName ++ " -installer" <.> exe
308
- binaryName =
323
+ mkBinaryName isStatic =
309
324
concat
310
325
[ stackProgName
311
326
, " -"
@@ -314,7 +329,10 @@ rules global@Global{..} args = do
314
329
, display platformOS
315
330
, " -"
316
331
, display gArch
332
+ , if isStatic then " -static" else " "
317
333
, if null gBinarySuffix then " " else " -" ++ gBinarySuffix ]
334
+ binaryName = mkBinaryName False
335
+ binaryStaticName = mkBinaryName True
318
336
stackExeFileName = stackProgName <.> exe
319
337
320
338
zipExt = " .zip"
@@ -325,10 +343,21 @@ rules global@Global{..} args = do
325
343
326
344
-- | Create a .tar.gz files from files. The paths should be absolute, and will
327
345
-- be made relative to the base directory in the tarball.
328
- writeTarGz :: FilePath -> FilePath -> [FilePath ] -> Action ()
329
- writeTarGz out baseDir inputFiles = liftIO $ do
346
+ writeTarGz :: ( FilePath -> FilePath ) -> FilePath -> FilePath -> [FilePath ] -> Action ()
347
+ writeTarGz fixPath out baseDir inputFiles = liftIO $ do
330
348
content <- Tar. pack baseDir $ map (dropDirectoryPrefix baseDir) inputFiles
331
- L8. writeFile out $ GZip. compress $ Tar. write content
349
+ L8. writeFile out $ GZip. compress $ Tar. write $ map fixPath' content
350
+ where
351
+ fixPath' :: Tar. Entry -> Tar. Entry
352
+ fixPath' entry =
353
+ case TarEntry. toTarPath isDir $ fixPath $ TarEntry. entryPath entry of
354
+ Left e -> error $ show (Tar. entryPath entry, e)
355
+ Right tarPath -> entry { TarEntry. entryTarPath = tarPath }
356
+ where
357
+ isDir =
358
+ case TarEntry. entryContent entry of
359
+ TarEntry. Directory -> True
360
+ _ -> False
332
361
333
362
-- | Drops a directory prefix from a path. The prefix automatically has a path
334
363
-- separator character appended. Fails if the path does not begin with the prefix.
@@ -407,6 +436,7 @@ data Global = Global
407
436
, gBinarySuffix :: ! String
408
437
, gTestHaddocks :: ! Bool
409
438
, gBuildArgs :: [String ]
439
+ , gStaticLinux :: ! Bool
410
440
, gCertificateName :: ! (Maybe String )
411
441
}
412
442
deriving (Show )
0 commit comments