From 0eca2954b33f47a9fc6dc082a9bc59461fec2309 Mon Sep 17 00:00:00 2001 From: Wolfgang Walther Date: Thu, 1 Feb 2024 18:30:09 +0100 Subject: [PATCH] ci: Reduce file size of cabal and stack based builds By passing -split-sections to all dependencies, GHC will link only the modules we actually use and not the full package for each dependency. This does neither work on MacOS nor Windows, thus we don't do it for stack right now. Stripping unused symbols in CI will further decrease the size of those files. --- .cirrus.yml | 5 ++++- .github/scripts/arm/build.sh | 6 +++++- .github/workflows/ci.yaml | 2 ++ cabal.project.non-nix | 3 +++ 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/.cirrus.yml b/.cirrus.yml index 6f01cf669..02fce0ff2 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -10,6 +10,9 @@ build_task: fingerprint_script: cat postgrest.cabal stack.yaml.lock reupload_on_changes: false - build_script: stack build -j 1 --local-bin-path . --copy-bins + build_script: | + stack build -j 1 --local-bin-path . --copy-bins + strip postgrest + bin_artifacts: path: postgrest diff --git a/.github/scripts/arm/build.sh b/.github/scripts/arm/build.sh index 989a3cdaf..ea9e349b7 100644 --- a/.github/scripts/arm/build.sh +++ b/.github/scripts/arm/build.sh @@ -55,10 +55,14 @@ cd ~/$SCRIPT_DIR git clone https://github.com/PostgREST/postgrest.git cd postgrest git checkout $PGRST_GITHUB_COMMIT +cp cabal.project.non-nix cabal.project cabal v2-update && cabal v2-build -# Copy the built binary to the Dockerfile directory +# Strip unused symbols from executable PGRST_BIN=$(cabal exec which postgrest | tail -1) +strip $PGRST_BIN + +# Copy the built binary to the Dockerfile directory cp $PGRST_BIN ~/$DOCKER_BUILD_DIR # Move and compress the built binary diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index a8b8ab357..11a239b5d 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -207,6 +207,8 @@ jobs: run: ${{ matrix.deps }} - name: Build with Stack run: stack build --local-bin-path result --copy-bins + - name: Strip Executable + run: strip result/postgrest* - name: Save built executable as artifact uses: actions/upload-artifact@v4 with: diff --git a/cabal.project.non-nix b/cabal.project.non-nix index f37e81ef1..a18204e74 100644 --- a/cabal.project.non-nix +++ b/cabal.project.non-nix @@ -4,6 +4,9 @@ packages: . +package * + ghc-options: -split-sections + -- Example of depending on a forked repository (the same dependency -- would be mentioned in nix/overlays/haskell-packages.nix and -- stack.yaml, and should refer to a main branch commit of the