From c2c6d42f59cae551b702abf74bf90580e2331fcc Mon Sep 17 00:00:00 2001 From: Lars Mennen <1162951+larsmennen@users.noreply.github.com> Date: Sun, 22 Feb 2026 15:55:15 +0000 Subject: [PATCH] Reduce Postgis shared library size to <8mb --- pglite/build-postgis.sh | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pglite/build-postgis.sh b/pglite/build-postgis.sh index 5ff083c17d50d..5e5c092175901 100755 --- a/pglite/build-postgis.sh +++ b/pglite/build-postgis.sh @@ -12,9 +12,11 @@ PROJ_VERSION=9.7.0 LDFLAGS="-L/install/libs/lib" CFLAGS="${PGLITE_CFLAGS}" CXXFL # touch ./loader/pgsql2shp.wasm emmake make raster-sql || true # these flags are used in pgxs.mk (postgresql extension makefile) and passed to the build process of that extension -emmake make LDFLAGS_SL="-sWASM_BIGINT -sSIDE_MODULE=1 -fexceptions -Wl,--whole-archive -lstdc++ -lsqlite3 -lgeos -Wl,--no-whole-archive" \ -CFLAGS_SL="-fexceptions -sWASM_BIGINT" \ -CXXFLAGS_SL="-fexceptions -sWASM_BIGINT" -j || { echo 'emmake make postgis failed' ; exit 442; } +emmake make LDFLAGS_SL="-sWASM_BIGINT -sSIDE_MODULE=1 -fexceptions -Wl,--whole-archive -lgeos_c -Wl,--no-whole-archive -lstdc++ -lsqlite3 -lgeos -flto" \ +CFLAGS_SL="-fexceptions -sWASM_BIGINT -Oz -flto -ffunction-sections -fdata-sections" \ +CXXFLAGS_SL="-fexceptions -sWASM_BIGINT -Oz -flto -ffunction-sections -fdata-sections" -j || { echo 'emmake make postgis failed' ; exit 442; } +/emsdk/upstream/bin/wasm-opt -Oz postgis/postgis-3.so -o postgis/postgis-3.opt.so || { echo 'wasm-opt postgis failed' ; exit 443; } +mv postgis/postgis-3.opt.so postgis/postgis-3.so # emmake make PG_LDFLAGS="-L/install/libs/lib -lpgport -lpgcommon -sSIDE_MODULE=1" -j cd ..