From a5a7b332f155adcc967a6db848a9fd5e1270bf32 Mon Sep 17 00:00:00 2001 From: Oleg Grenrus Date: Mon, 10 Sep 2018 17:19:31 +0300 Subject: [PATCH] Use LLVM + split-sections --- Dockerfile | 48 +++++++++++++++++++++++++++++++++++++++++------- ShellCheck.cabal | 12 ++++++------ 2 files changed, 47 insertions(+), 13 deletions(-) diff --git a/Dockerfile b/Dockerfile index ce50460..7dd43be 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,22 +1,56 @@ # Build-only image -FROM ubuntu:17.10 AS build +FROM ubuntu:18.04 AS build USER root WORKDIR /opt/shellCheck -# Install OS deps -RUN apt-get update && apt-get install -y ghc cabal-install +# Install OS deps, including GHC from HVR-PPA +# https://launchpad.net/~hvr/+archive/ubuntu/ghc +RUN apt-get -yq update \ + && apt-get -yq install software-properties-common \ + && apt-add-repository -y "ppa:hvr/ghc" \ + && apt-get -yq update \ + && apt-get -yq install cabal-install-2.4 ghc-8.4.3 llvm-5.0 pandoc \ + && rm -rf /var/lib/apt/lists/* + +ENV PATH="/opt/ghc/bin:/usr/lib/llvm-5.0/bin:${PATH}" + +# Use gold linker and check tools versions +RUN ln -s $(which ld.gold) /usr/local/bin/ld && \ + cabal --version \ + && ghc --version \ + && ld --version # Install Haskell deps # (This is a separate copy/run so that source changes don't require rebuilding) +# +# We also patch regex-tdfa and aeson removing hard-coded -O2 flag. +# This makes compilation faster and binary smaller. +# Performance loss is unnoticeable for ShellCheck +# +# Remember to update versions, once in a while. COPY ShellCheck.cabal ./ -RUN cabal update && cabal install --dependencies-only --ghc-options="-optlo-Os -split-sections" +RUN cabal update && \ + cabal get regex-tdfa-1.2.3.1 && sed -i 's/-O2//' regex-tdfa-1.2.3.1/regex-tdfa.cabal && \ + cabal get aeson-1.4.0.0 && sed -i 's/-O2//' aeson-1.4.0.0/aeson.cabal && \ + echo 'packages: . regex-tdfa-1.2.3.1 aeson-1.4.0.0 > cabal.project' && \ + cabal new-build --dependencies-only \ + --ghc-options='-fllvm -optlo-Os' \ + --disable-executable-dynamic --enable-split-sections --disable-tests # Copy source and build it -COPY LICENSE Setup.hs shellcheck.hs ./ +COPY LICENSE Setup.hs shellcheck.hs shellcheck.1.md ./ COPY src src -RUN cabal build Paths_ShellCheck && \ - ghc -optl-static -optl-pthread -isrc -idist/build/autogen --make shellcheck -split-sections -optc-Wl,--gc-sections -optlo-Os && \ +COPY test test +# This SED is the only "nastyness" we have to do +# Hopefully soon we could add per-component ld-options to cabal.project +RUN sed -i 's/-- STATIC/ld-options: -static -pthread -Wl,--gc-sections/' ShellCheck.cabal && \ + cat ShellCheck.cabal && \ + cabal new-build \ + --ghc-options='-fllvm -optlo-Os' \ + --disable-executable-dynamic --enable-split-sections --disable-tests && \ + cp $(find dist-newstyle -type f -name shellcheck) . && \ strip --strip-all shellcheck && \ + file shellcheck && \ ls -l shellcheck RUN mkdir -p /out/bin && \ diff --git a/ShellCheck.cabal b/ShellCheck.cabal index 14410b2..c409704 100644 --- a/ShellCheck.cabal +++ b/ShellCheck.cabal @@ -28,15 +28,13 @@ Extra-Source-Files: shellcheck.1.md -- built with a cabal sdist hook shellcheck.1 - -- tests - test/shellcheck.hs custom-setup setup-depends: - base >= 4 && <5, - process >= 1.0 && <1.7, + base >= 4 && <5, + process >= 1.0 && <1.7, cabal-doctest >= 1.0.6 && <1.1, - Cabal >= 1.10 && <2.5 + Cabal >= 1.10 && <2.5 source-repository head type: git @@ -94,10 +92,12 @@ executable shellcheck directory, mtl >= 2.2.1, parsec >= 3.0, - QuickCheck >= 2.7.4, regex-tdfa main-is: shellcheck.hs + -- Marker to add flags for static linking + -- STATIC + test-suite doctests type: exitcode-stdio-1.0 main-is: doctests.hs