Skip to content

Commit

Permalink
ci: Reduce file size of cabal and stack based builds
Browse files Browse the repository at this point in the history
By passing -split-sections to all dependencies, GHC will link only the
modules we actually use and not the full package for each dependency.

Stripping unused symbols in CI will further decrease the size of those files.
  • Loading branch information
wolfgangwalther committed Feb 1, 2024
1 parent 48c47b4 commit 3a1d5af
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 16 deletions.
5 changes: 4 additions & 1 deletion .github/scripts/arm/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,11 @@ cd postgrest
git checkout $PGRST_GITHUB_COMMIT
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
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions cabal.project.non-nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions stack.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
resolver: lts-21.7 # 2023-08-14, GHC 9.4.5

ghc-options:
$everything: -split-sections

nix:
packages:
- pcre
Expand Down
26 changes: 11 additions & 15 deletions stack.yaml.lock
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,12 @@ packages:
original:
hackage: configurator-pg-0.2.7
- completed:
commit: 890a0a16cf57dd401420fdc6c7d576fb696003bc
git: https://github.com/PostgREST/postgresql-libpq.git
name: postgresql-libpq
hackage: fuzzyset-0.3.1@sha256:344e16deedb43da5cabae558450e5710843cff7ac2f3073be9db453c6f3a3fb7,2373
pantry-tree:
sha256: 074668b9669b9c49f3c522c8af5c608799a1965e203c463b188b2632995beac2
size: 1414
version: 0.9.4.3
sha256: 89e22c2ce70a7c7c4b599ffe2546cda5699e4f8f15410eac49f39af8c4c381c8
size: 643
original:
commit: 890a0a16cf57dd401420fdc6c7d576fb696003bc
git: https://github.com/PostgREST/postgresql-libpq.git
hackage: fuzzyset-0.3.1
- completed:
hackage: hasql-notifications-0.2.0.6@sha256:16d783f5cd1660fad924fd3769380889de5804e057f09b304dcdc3a3ff11eb3c,2028
pantry-tree:
Expand All @@ -36,20 +32,20 @@ packages:
size: 346
original:
hackage: hasql-pool-0.10
- completed:
hackage: fuzzyset-0.3.1@sha256:344e16deedb43da5cabae558450e5710843cff7ac2f3073be9db453c6f3a3fb7,2373
pantry-tree:
sha256: 89e22c2ce70a7c7c4b599ffe2546cda5699e4f8f15410eac49f39af8c4c381c8
size: 643
original:
hackage: fuzzyset-0.3.1
- completed:
hackage: megaparsec-9.2.2@sha256:c306a135ec25d91d252032c6128f03598a00e87ea12fcf5fc4878fdffc75c768,3219
pantry-tree:
sha256: db9715d6910e64d3bbfce69895042a66fcdcd64a54805563834bf0821562b74f
size: 1518
original:
hackage: megaparsec-9.2.2
- completed:
hackage: postgresql-libpq-0.10.0.0@sha256:5c1cafdc2e3e5c0036b6801b10b6f14ae95b98428d6c88bc8ae560bd700d0ef7,3089
pantry-tree:
sha256: a7790b5283fc1510bde9e7c70772cdbf1ad6a3bad32ea966c6fc95e1b3c524c7
size: 1019
original:
hackage: postgresql-libpq-0.10.0.0
snapshots:
- completed:
sha256: 23bb9bb355bfdb1635252e120a29b712f0d5e8a6c6a65c5ab5bd6692f46c438e
Expand Down

0 comments on commit 3a1d5af

Please sign in to comment.