Skip to content

Instantly share code, notes, and snippets.

@dkubb
Last active August 29, 2015 14:25
Show Gist options
  • Select an option

  • Save dkubb/842da22c212c944673b1 to your computer and use it in GitHub Desktop.

Select an option

Save dkubb/842da22c212c944673b1 to your computer and use it in GitHub Desktop.

Revisions

  1. dkubb revised this gist Jul 14, 2015. 1 changed file with 41 additions and 0 deletions.
    41 changes: 41 additions & 0 deletions Build.hs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,41 @@
    {-# LANGUAGE OverloadedStrings #-}
    {-# LANGUAGE RecordWildCards #-}

    import Turtle
    import Prelude hiding (FilePath)

    data Options = Options
    { repo :: Text
    , file :: FilePath
    }

    parser :: Parser Options
    parser = Options
    <$> (optText "repo" 'r' "The docker repo name" <|> pure "nilcons/ghc-musl")
    <*> argPath "file" "The source file path"

    compile :: FilePath -> Text -> IO ExitCode
    compile inFile repo = do
    let inDir = directory inFile
    shell (cmd inDir inDir repo inFile) empty
    where
    cmd = format ("docker run --volume "%fp%":"%fp%" --rm "%s%" ghc -O2 -threaded -optl-static -optl-s "%fp)

    compress :: FilePath -> IO ExitCode
    compress outFile = shell (cmd outFile) empty
    where
    cmd = format ("upx --best --ultra-brute --lzma -- "%fp)

    main :: IO ()
    main = do
    -- Parse command-line options
    Options{..} <- options "Static Haskell Binary Creation" parser

    -- Get the full input directory
    inFile <- realpath file

    -- Compile and compress the static binaries
    status <- compile inFile repo .&&. compress (dropExtension inFile)
    case status of
    ExitSuccess -> return ()
    ExitFailure msg -> die ("compilation failure" <> repr msg)
  2. dkubb revised this gist Jul 14, 2015. 2 changed files with 17 additions and 0 deletions.
    16 changes: 16 additions & 0 deletions minimal-docker-image.cabal
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    name: minimal-docker-image
    version: 0.0.0
    cabal-version: >= 1.2

    executable Build
    ghc-options: -Wall
    -Werror
    -fwarn-incomplete-record-updates
    -fwarn-tabs
    -fwarn-monomorphism-restriction
    -fwarn-unused-do-bind
    -fwarn-implicit-prelude
    default-language: Haskell2010
    main-is: Build.hs
    build-depends: base >= 4 && < 5,
    turtle >= 1.2.0 && < 2
    1 change: 1 addition & 0 deletions stack.yaml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    resolver: nightly-2015-07-12
  3. dkubb revised this gist Jul 13, 2015. 1 changed file with 7 additions and 0 deletions.
    7 changes: 7 additions & 0 deletions .gitignore
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    *.hi
    *.o
    *.sw[op]
    /.shake
    /.stack-work
    /dist
    /output
  4. dkubb created this gist Jul 13, 2015.