Skip to content

Commit 2fc2e79

Browse files
committed
Use nix to build linux binaries
1 parent 8cf9503 commit 2fc2e79

File tree

5 files changed

+49
-0
lines changed

5 files changed

+49
-0
lines changed

Shakefile/build-elm-format.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ executable build-elm-format
1212
Shakefiles.ElmFormat.IntegrationTests
1313
Shakefiles.Extra
1414
Shakefiles.Haskell
15+
Shakefiles.NestedCheckout
1516
Shakefiles.NixBuild
1617
Shakefiles.Platform
1718
Shakefiles.Shellcheck

Shakefile/src/Main.hs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import qualified Shakefiles.Dependencies
1313
import qualified Shakefiles.Signature
1414
import Shakefiles.Extra
1515
import qualified Shakefiles.NixBuild
16+
import qualified Shakefiles.NestedCheckout
1617

1718

1819
main :: IO ()
@@ -46,6 +47,9 @@ rules = do
4647

4748
phony "build" $ need [ "elm-format" ]
4849
phony "elm-format" $ need [ elmFormat ]
50+
phony "generated" $ need
51+
[ "generated/Build_elm_format.hs"
52+
]
4953
phony "unit-tests" $ need
5054
[ "_build/cabal/elm-format-lib/test.ok"
5155
, "_build/cabal/elm-format-test-lib/test.ok"
@@ -135,4 +139,6 @@ rules = do
135139

136140
Shakefiles.ElmFormat.IntegrationTests.rules gitSha elmFormat
137141

142+
Shakefiles.NestedCheckout.rules
143+
138144
Shakefiles.Shellcheck.rules shellcheck

Shakefile/src/Shakefiles/Haskell.hs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,10 @@ executable target projectName gitDescribe =
108108
Shakefiles.Platform.all
109109

110110
let buildInDocker =
111+
[]
112+
let buildViaNix =
111113
[ Shakefiles.Platform.LinuxX86
114+
, Shakefiles.Platform.LinuxAarch64
112115
]
113116
let buildOnCi =
114117
[ Shakefiles.Platform.Windows
@@ -134,6 +137,17 @@ executable target projectName gitDescribe =
134137
need [ binDir </> binFile ]
135138
cmd_ "tar" "zcvf" out "-C" binDir binFile
136139

140+
forEach buildViaNix $ \target -> do
141+
let zipExt = Shakefiles.Platform.zipFormatFor target
142+
143+
("publish" </> "*" </> projectName ++ "-*-" ++ show target <.> zipExt) %> \out -> do
144+
let tag = takeDirectory1 $ dropDirectory1 out
145+
StdoutTrim sha <- cmd "git" "rev-list" "-n1" ("tags/" ++ tag)
146+
let binDir = "_build" </> "nix-build" </> "from-git" </> sha </> "out" </> "default" </> "dist." <> show target </> "bin"
147+
let binFile = projectName ++ Shakefiles.Platform.binExt target
148+
need [ binDir </> binFile ]
149+
cmd_ "tar" "zcvf" out "-C" binDir binFile
150+
137151
forEach buildOnCi $ \target -> do
138152
let ciArchiveLabel = Shakefiles.Platform.ciArchiveLabel target
139153
let zipExt = Shakefiles.Platform.zipFormatFor target
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
module Shakefiles.NestedCheckout where
2+
3+
import Development.Shake
4+
import Development.Shake.FilePath
5+
import qualified System.Directory
6+
7+
rules :: Rules ()
8+
rules = do
9+
"_build/git/checkout/*.ok" %> \out -> do
10+
let cloneDir = dropExtension out
11+
let sha = dropDirectory1 $ dropDirectory1 $ dropDirectory1 cloneDir
12+
exists <- liftIO $ System.Directory.doesDirectoryExist cloneDir
13+
if exists
14+
then return ()
15+
else cmd_ "git" "clone" "--local" "." cloneDir
16+
cmd_ (Cwd cloneDir) "git" "reset" "--hard" sha
17+
cmd_ (Cwd cloneDir) "./dev/build.sh" "generated"
18+
writeFileChanged out sha

Shakefile/src/Shakefiles/NixBuild.hs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ module Shakefiles.NixBuild where
22

33
import Development.Shake
44
import Development.Shake.FilePath
5+
import qualified System.Directory
56

67
rules :: Rules ()
78
rules = do
@@ -26,3 +27,12 @@ rules = do
2627

2728
cmd_ "nix-build" "-A" attr "-o" gcroot
2829
copyFileChanged (gcroot </> foldl (</>) "" rest) out
30+
31+
"_build/nix-build/from-git/*/out/default/*/bin/elm-format" %> \out -> do
32+
let (b1:b2:b3:sha:_:_:attr:rest) = splitDirectories out
33+
gcroot <- liftIO $ System.Directory.makeAbsolute (b1 </> b2 </> b3 </> sha </> "gcroots/default" </> attr)
34+
35+
let checkoutDir = "_build/git/checkout" </> sha
36+
need [ checkoutDir <.> "ok" ]
37+
cmd_ (Cwd checkoutDir) "nix-build" "-A" attr "-o" gcroot
38+
copyFileChanged (gcroot </> foldl (</>) "" rest) out

0 commit comments

Comments
 (0)