Skip to content

Commit

Permalink
use .cjs for binaries
Browse files Browse the repository at this point in the history
  • Loading branch information
pmp-p committed Sep 3, 2024
1 parent 278d2cd commit 93127f2
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 21 deletions.
4 changes: 2 additions & 2 deletions cibuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -437,8 +437,8 @@ do
mkdir -p $PGLITE/release
rm $PGLITE/release/* 2>/dev/null

# move packed extensions
mv ${WEBROOT}/*.tar.gz ${PGLITE}/release/
# copy packed extensions for dist
cp ${WEBROOT}/*.tar.gz ${PGLITE}/release/

# copy wasm web prebuilt artifacts to release folder
# TODO: get them from web for nosdk systems.
Expand Down
47 changes: 31 additions & 16 deletions cibuild/pgbuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ fi
# --with-libxml does not fit with --without-zlib

export XML2_CONFIG=$PREFIX/bin/xml2-config
export ZIC=$(pwd)/bin/zic

CNF="${PGSRC}/configure --prefix=${PGROOT} \
--cache-file=${PGROOT}/config.cache.${BUILD} \
Expand All @@ -67,12 +68,16 @@ fi

# crash clang CFLAGS=-Wno-error=implicit-function-declaration

if EM_PKG_CONFIG_PATH=$PREFIX/lib/pkgconfig CONFIG_SITE==${PGDATA}/config.site emconfigure $CNF --with-template=emscripten
cat > ${PGROOT}/config.site <<END
ac_cv_exeext=.cjs
END

if EM_PKG_CONFIG_PATH=$PREFIX/lib/pkgconfig CONFIG_SITE=${PGROOT}/config.site emconfigure $CNF --with-template=emscripten
then
echo configure ok
else
echo configure failed
exit 262
exit 76
fi

if grep -q MAIN_MODULE ${PGSRC}/src/backend/Makefile
Expand All @@ -87,7 +92,7 @@ fi
cat > bin/zic <<END
#!/bin/bash
#. /opt/python-wasm-sdk/wasm32-bi-emscripten-shell.sh
TZ=UTC PGTZ=UTC node $(pwd)/src/timezone/zic \$@
TZ=UTC PGTZ=UTC node $(pwd)/src/timezone/zic.cjs \$@
END

# --disable-shared not supported so be able to use a fake linker
Expand Down Expand Up @@ -123,19 +128,22 @@ END
EMCC_ENV="${EMCC_NODE} -sERROR_ON_UNDEFINED_SYMBOLS"

# only required for static initdb
EMCC_CFLAGS="-sERROR_ON_UNDEFINED_SYMBOLS=0 ${CC_PGLITE}"
EMCC_CFLAGS="-sERROR_ON_UNDEFINED_SYMBOLS=1 ${CC_PGLITE}"
EMCC_CFLAGS="${EMCC_CFLAGS} -sTOTAL_MEMORY=${TOTAL_MEMORY} -sSTACK_SIZE=5MB -sALLOW_TABLE_GROWTH -sALLOW_MEMORY_GROWTH -sGLOBAL_BASE=${CMA_MB}MB"
EMCC_CFLAGS="${EMCC_CFLAGS} -DPREFIX=${PGROOT}"

export EMCC_CFLAGS="${EMCC_CFLAGS} -Wno-macro-redefined -Wno-unused-function"


if EMCC_CFLAGS="${EMCC_ENV} ${EMCC_CFLAGS}" emmake make ZIC=$ZIC -j $(nproc) 2>&1 > /tmp/build.log
#ZIC=$ZIC
if EMCC_CFLAGS="${EMCC_ENV} ${EMCC_CFLAGS}" emmake make -j $(nproc) 2>&1 > /tmp/build.log
then
echo build ok
cp -vf src/backend/postgres src/backend/postgres.cjs

# for 32bits zic
unset LD_PRELOAD
if EMCC_CFLAGS="${EMCC_ENV} ${EMCC_CFLAGS}" emmake make ZIC=$ZIC install 2>&1 > /tmp/install.log

if EMCC_CFLAGS="${EMCC_ENV} ${EMCC_CFLAGS}" emmake make install 2>&1 > /tmp/install.log
then
echo install ok
pushd ${PGROOT}
Expand All @@ -155,33 +163,40 @@ END
else
cat /tmp/install.log
echo "install failed"
exit 143
exit 164
fi
else
cat /tmp/build.log
echo "build failed"
exit 148
exit 169
fi

# wip
mv -vf ./src/bin/psql/psql.wasm ./src/bin/pg_config/pg_config.wasm ${PGROOT}/bin/
mv -vf ./src/bin/pg_dump/pg_restore.wasm ./src/bin/pg_dump/pg_dump.wasm ./src/bin/pg_dump/pg_dumpall.wasm ${PGROOT}/bin/
mv -vf ./src/bin/pg_resetwal/pg_resetwal.wasm ./src/bin/initdb/initdb.wasm ./src/backend/postgres.wasm ${PGROOT}/bin/

mv -vf ${PGROOT}/bin/pg_config ${PGROOT}/bin/pg_config.js
mv -vf ./src/bin/initdb/initdb ${PGROOT}/bin/initdb.js
mv -vf ./src/bin/pg_resetwal/pg_resetwal ${PGROOT}/bin/pg_resetwal.js
mv -vf ./src/backend/postgres ${PGROOT}/bin/postgres.js
# mv -vf ${PGROOT}/bin/pg_config ${PGROOT}/bin/pg_config.js
# mv -vf ./src/bin/initdb/initdb ${PGROOT}/bin/initdb.js
# mv -vf ./src/bin/pg_resetwal/pg_resetwal ${PGROOT}/bin/pg_resetwal.js
# mv -vf ./src/backend/postgres ${PGROOT}/bin/postgres.js

if [ -f $PGROOT/bin/pg_config.wasm ]
then
echo pg_config installed
else
echo "pg_config build failed"; exit 186
fi

cat > ${PGROOT}/bin/pg_config <<END
#!/bin/bash
node ${PGROOT}/bin/pg_config.js \$@
$(which node) ${PGROOT}/bin/pg_config.cjs \$@
END

cat > ${PGROOT}/postgres <<END
#!/bin/bash
. /opt/python-wasm-sdk/wasm32-bi-emscripten-shell.sh
TZ=UTC PGTZ=UTC PGDATA=${PGDATA} node ${PGROOT}/bin/postgres.js \$@
TZ=UTC PGTZ=UTC PGDATA=${PGDATA} $(which node) ${PGROOT}/bin/postgres.cjs \$@
END

# remove the abort but stall prompt
Expand All @@ -193,7 +208,7 @@ END
cat > ${PGROOT}/initdb <<END
#!/bin/bash
. /opt/python-wasm-sdk/wasm32-bi-emscripten-shell.sh
TZ=UTC PGTZ=UTC node ${PGROOT}/bin/initdb.js \$@
TZ=UTC PGTZ=UTC $(which node) ${PGROOT}/bin/initdb.cjs \$@
END

chmod +x ${PGROOT}/postgres ${PGROOT}/bin/postgres
Expand Down
8 changes: 5 additions & 3 deletions extra/postgis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ END

# --without-raster --without-topology --without-address-standardizer
# --without-raster => --with-gdalconfig=
CONFIG_SITE=config.site emconfigure ./configure --with-gdalconfig=$PREFIX/bin/gdal-config\
# --with-gdalconfig=$PREFIX/bin/gdal-config
CONFIG_SITE=config.site emconfigure ./configure \
--without-raster --without-topology --without-address-standardizer \
--without-gui --without-phony-revision --without-protobuf \
--without-interrupt-tests --without-json \
--without-libiconv --without-libiconv-prefix \
Expand All @@ -52,9 +54,9 @@ END

# or would fail on some frontend functions linking.
sed -i 's/PGSQL_FE_LDFLAGS=-L/PGSQL_FE_LDFLAGS=-sERROR_ON_UNDEFINED_SYMBOLS=0 -L/g' loader/Makefile
EMCC_CFLAGS="-sERROR_ON_UNDEFINED_SYMBOLS=0 -Wno-unused-function -lpng -ljpeg -lsqlite3" emmake make install
EMCC_CFLAGS="-sERROR_ON_UNDEFINED_SYMBOLS=0 -Wno-unused-function -lc++-noexcept -lpng -ljpeg -lsqlite3" emmake make install
rm $PGROOT/share/postgresql/extension/postgis*.sql
cp extensions/postgis_tiger_geocoder/sql/postgis_tiger_geocoder--TEMPLATED--TO--ANY.sql $PGROOT/share/postgresql/extension/postgis--3.4.2.sql
cp extensions/postgis/sql/postgis--TEMPLATED--TO--ANY.sql $PGROOT/share/postgresql/extension/postgis--3.4.2.sql

popd

0 comments on commit 93127f2

Please sign in to comment.