1111-- directly. As GHC 9.6.4 boot packages Cabal and Cabal-syntax expose modules
1212-- with the same names, the language extension PackageImports is required.
1313
14+ -- EXPERIMENTAL
15+
16+ -- release.hs can be run on macOS/AArch64, using a Docker image for
17+ -- Alpine Linux/AArch64, in order to create a statically-linked Linux/AArch64
18+ -- version of Stack:
19+ --
20+ -- Install pre-requisites:
21+ --
22+ -- > brew install docker
23+ -- > brew install colima
24+ --
25+ -- Start colima (with sufficient memory for Stack's integration tests) and run
26+ -- script:
27+ --
28+ -- > colima start --memory 4 # The default 2 GB is likely insufficient
29+ -- > stack etc/scripts/release.hs check --alpine --stack-args=--docker-stack-exe=image
30+ -- > stack etc/scripts/release.hs build --alpine --stack-args=--docker-stack-exe=image
31+ -- > colima stop
32+
1433{-# LANGUAGE OverloadedRecordDot #-}
1534{-# LANGUAGE PackageImports #-}
1635{-# LANGUAGE PatternSynonyms #-}
@@ -28,7 +47,7 @@ import Development.Shake
2847 ( Action , Change (.. ), pattern Chatty , CmdOption (.. ), Rules
2948 , ShakeOptions (.. ), Stdout (.. ), (%>) , actionOnException
3049 , alwaysRerun , cmd , command_ , copyFileChanged
31- , getDirectoryFiles , liftIO , need , phony , putNormal
50+ , getDirectoryFiles , liftIO , need , phony , putInfo
3251 , removeFilesAfter , shakeArgsWith , shakeOptions , want
3352 )
3453import Development.Shake.FilePath
@@ -72,10 +91,13 @@ main = shakeArgsWith
7291 let gAllowDirty = False
7392 Platform arch _ = buildPlatform
7493 gArch = arch
94+ gTargetOS = platformOS
7595 gBinarySuffix = " "
7696 gTestHaddocks = True
7797 gProjectRoot = " " -- Set to real value below.
7898 gBuildArgs = [" --flag" , " stack:-developer-mode" ]
99+ gStackArgs = []
100+ gCheckStackArgs = []
79101 gCertificateName = Nothing
80102 global0 = foldl
81103 (flip id )
@@ -87,9 +109,12 @@ main = shakeArgsWith
87109 , gProjectRoot
88110 , gHomeDir
89111 , gArch
112+ , gTargetOS
90113 , gBinarySuffix
91114 , gTestHaddocks
92115 , gBuildArgs
116+ , gStackArgs
117+ , gCheckStackArgs
93118 , gCertificateName
94119 }
95120 flags
@@ -131,13 +156,28 @@ options =
131156 g { gBuildArgs =
132157 gBuildArgs g
133158 ++ [ " --flag=stack:static"
134- , " --docker"
159+ ]
160+ , gStackArgs =
161+ gStackArgs g
162+ ++ [ " --docker"
135163 , " --system-ghc"
136164 , " --no-install-ghc"
137165 ]
166+ , gCheckStackArgs =
167+ gCheckStackArgs g
168+ ++ [ " --system-ghc"
169+ , " --no-install-ghc"
170+ ]
171+ , gTargetOS = Linux
138172 }
139173 )
140- " Build a statically linked binary using an Alpine Docker image."
174+ " Build a statically-linked binary using an Alpine Linux Docker image."
175+ , Option " " [stackArgsOptName]
176+ ( ReqArg
177+ (\ v -> Right $ \ g -> g{gStackArgs = gStackArgs g ++ words v})
178+ " \" ARG1 ARG2 ...\" "
179+ )
180+ " Additional arguments to pass to 'stack'."
141181 , Option " " [buildArgsOptName]
142182 ( ReqArg
143183 (\ v -> Right $ \ g -> g{gBuildArgs = gBuildArgs g ++ words v})
@@ -180,29 +220,33 @@ rules global args = do
180220 , show dirty
181221 ]
182222 () <- cmd
223+ stackProgName -- Use the platform's Stack
224+ global. gStackArgs -- Possibly to set up a Docker container
225+ [" exec" ] -- To execute the target Stack
183226 [ global. gProjectRoot </> releaseBinDir </> binaryName </>
184227 stackExeFileName
185228 ]
229+ [" --" ]
186230 (stackArgs global)
187- [" build" ]
231+ global. gCheckStackArgs -- Possible use the Docker image's GHC
232+ [" build" ] -- To build the target Stack (Stack builds Stack)
188233 global. gBuildArgs
189234 integrationTestFlagArgs
190235 [" --pedantic" , " --no-haddock-deps" , " --test" ]
191236 [" --haddock" | global. gTestHaddocks]
192237 [" stack" ]
193238 () <- cmd
194- [ global. gProjectRoot </> releaseBinDir </> binaryName </>
195- stackExeFileName
196- ]
197- [" exec" ]
239+ stackProgName -- Use the platform's Stack
240+ global. gStackArgs -- Possibiy to set up a Docker container
241+ [" exec" ] -- To execute the target stack-integration-test
198242 [ global. gProjectRoot </> releaseBinDir </> binaryName </>
199243 " stack-integration-test"
200244 ]
201245 copyFileChanged (releaseBinDir </> binaryName </> stackExeFileName) out
202246
203247 releaseDir </> binaryPkgZipFileName %> \ out -> do
204248 stageFiles <- getBinaryPkgStageFiles
205- putNormal $ " zip " ++ out
249+ putInfo $ " zip " ++ out
206250 liftIO $ do
207251 entries <- forM stageFiles $ \ stageFile -> do
208252 Zip. readEntry
@@ -234,7 +278,13 @@ rules global args = do
234278 releaseDir </> binaryExeFileName %> \ out -> do
235279 need [releaseBinDir </> binaryName </> stackExeFileName]
236280 (Stdout versionOut) <-
237- cmd (releaseBinDir </> binaryName </> stackExeFileName) " --version"
281+ cmd
282+ stackProgName -- Use the platform's Stack
283+ global. gStackArgs -- Possibly to set up a Docker container
284+ [" exec" ] -- To execute the target Stack and get its version info
285+ (releaseBinDir </> binaryName </> stackExeFileName)
286+ [" --" ]
287+ [" --version" ]
238288 when (not global. gAllowDirty && " dirty" `isInfixOf` lower versionOut) $
239289 error
240290 ( " Refusing continue because 'stack --version' reports dirty. Use --"
@@ -295,10 +345,12 @@ rules global args = do
295345 releaseBinDir </> binaryName </> stackExeFileName %> \ out -> do
296346 alwaysRerun
297347 actionOnException
298- ( cmd stackProgName
348+ ( cmd
349+ stackProgName -- Use the platform's Stack
299350 (stackArgs global)
300351 [" --local-bin-path=" ++ takeDirectory out]
301- " install"
352+ global. gStackArgs -- Possibly to set up a Docker container
353+ " install" -- To build and install Stack to that local bin path
302354 global. gBuildArgs
303355 integrationTestFlagArgs
304356 " --pedantic"
@@ -336,7 +388,7 @@ rules global args = do
336388 releaseBinDir = releaseDir </> " bin"
337389
338390 binaryPkgFileNames =
339- case platformOS of
391+ case global . gTargetOS of
340392 Windows ->
341393 [ binaryExeFileName
342394 , binaryPkgZipFileName
@@ -357,7 +409,7 @@ rules global args = do
357409 , " -"
358410 , stackVersionStr global
359411 , " -"
360- , display platformOS
412+ , display global . gTargetOS
361413 , " -"
362414 , display global. gArch
363415 , if null global. gBinarySuffix then " " else " -" ++ global. gBinarySuffix
@@ -438,6 +490,10 @@ binaryVariantOptName = "binary-variant"
438490noTestHaddocksOptName :: String
439491noTestHaddocksOptName = " no-test-haddocks"
440492
493+ -- | @--stack-args@ command-line option name.
494+ stackArgsOptName :: String
495+ stackArgsOptName = " stack-args"
496+
441497-- | @--build-args@ command-line option name.
442498buildArgsOptName :: String
443499buildArgsOptName = " build-args"
@@ -469,9 +525,12 @@ data Global = Global
469525 , gProjectRoot :: ! FilePath
470526 , gHomeDir :: ! FilePath
471527 , gArch :: ! Arch
528+ , gTargetOS :: ! OS
472529 , gBinarySuffix :: ! String
473530 , gTestHaddocks :: ! Bool
474531 , gBuildArgs :: [String ]
532+ , gStackArgs :: [String ]
533+ , gCheckStackArgs :: [String ]
475534 , gCertificateName :: ! (Maybe String )
476535 }
477536 deriving Show
0 commit comments