Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More cleanup #11

Draft
wants to merge 28 commits into
base: pglite/REL_16_STABLE
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion configure
Original file line number Diff line number Diff line change
Expand Up @@ -19446,7 +19446,7 @@ ac_config_files="$ac_config_files GNUmakefile src/Makefile.global"


ac_config_links="$ac_config_links src/backend/port/pg_sema.c:${SEMA_IMPLEMENTATION} src/backend/port/pg_shmem.c:${SHMEM_IMPLEMENTATION} src/include/pg_config_os.h:src/include/port/${template}.h src/Makefile.port:src/makefiles/Makefile.${template}"

ac_config_links="$ac_config_links src/include/port/wasm_common.h:src/include/port/wasm_common.h"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

try to avoid patching configure file, this file is auto generated whenever upstream update it with autotools and makes it hard for diff to apply. prefer add changes to CONFIG_SITE when it is possible


if test "$PORTNAME" = "win32"; then
ac_config_commands="$ac_config_commands check_win32_symlinks"
Expand Down
9 changes: 0 additions & 9 deletions pglite/cibuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -240,15 +240,6 @@ END

. ${PGROOT}/pgopts.sh

# make sure no non-mvp feature gets in.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some compilers will try to use cpu intrinsics by default and some of them are allowed or emulated but outside MVP which may breaks compat on mobile browsers. Better force off to keep close to wasm MVP

cat > ${PGROOT}/config.site <<END
pgac_cv_sse42_crc32_intrinsics_=no
pgac_cv_sse42_crc32_intrinsics__msse4_2=no
pgac_sse42_crc32_intrinsics=no
pgac_armv8_crc32c_intrinsics=no
ac_cv_search_sem_open=no
END


# workaround no "locale -a" for Node.
# this is simply the minimal result a popen call would give.
Expand Down
5 changes: 0 additions & 5 deletions pglite/cibuild/build-with-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,9 @@ fi
IMG_NAME="electricsql/pglite-builder"
IMG_TAG="${PG_VERSION}_${SDK_VERSION}"

SDK_ARCHIVE="${SDK_ARCHIVE:-python3.13-wasm-sdk-Ubuntu-22.04.tar.lz4}"
WASI_SDK_ARCHIVE="${WASI_SDK_ARCHIVE:-python3.13-wasi-sdk-Ubuntu-22.04.tar.lz4}"

docker run \
--rm \
-e OBJDUMP=${OBJDUMP:-true} \
-e SDK_ARCHIVE \
-e WASI_SDK_ARCHIVE \
-e PGSRC=/workspace/postgres-src \
-e POSTGRES_PGLITE_OUT=/workspace/dist \
-v ./pglite/cibuild.sh:/workspace/cibuild.sh:rw \
Expand Down
7 changes: 6 additions & 1 deletion pglite/cibuild/pg-16.x.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ then
"
else
echo "Building $ARCHIVE (patched) from $PGSRC"
. cibuild/pgbuild.sh
if ${WASI}
then
. cibuild/pgbuild.sh
else
. cibuild/pgbuild.emscripten.sh
fi
fi

7 changes: 6 additions & 1 deletion pglite/cibuild/pg-git.sh
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,12 @@ else

else
echo "Building $ARCHIVE (patched) from $PGSRC"
. cibuild/pgbuild.sh
if ${WASI}
then
. cibuild/pgbuild.sh
else
. cibuild/pgbuild.emscripten.sh
fi
fi
fi

111 changes: 111 additions & 0 deletions pglite/cibuild/pgbuild.emscripten.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
echo "



pgbuild.wasm:begin

CC_PGLITE=$CC_PGLITE

"
mkdir -p build/postgres
pushd build/postgres

# create empty package.json to avoid emsdk node conflicts
# with root package.json of project
echo "{}" > package.json

export MAIN_MODULE="-sMAIN_MODULE=1"
export XML2_CONFIG=$PREFIX/bin/xml2-config
export ZIC=$(pwd)/bin/zic
export EXT=wasm

cp -r ${PGSRC}/pglite/other/* /tmp/pglite/

echo " ==== building wasm MVP:$MVP Debug=${PGDEBUG} with opts : $@ == "

mkdir -p bin

cat > bin/zic <<END
#!/bin/bash
TZ=UTC PGTZ=UTC node $(pwd)/src/timezone/zic.cjs \$@
END
export CONFIG_SITE=${PGSRC}/pglite/config.site

if emconfigure ${PGSRC}/configure
then
echo configure ok
else
echo configure failed
exit 76
fi

mkdir -p /tmp/pglite/bin

ln -sf /tmp/pglite/bin/emsdk-shared bin/emsdk-shared

chmod +x bin/zic /tmp/pglite/bin/emsdk-shared

# for zic and emsdk-shared/wasi-shared called from makefile
export PATH=$(pwd)/bin:$PATH

EMCC_NODE="-sEXIT_RUNTIME=1 -DEXIT_RUNTIME -sNODERAWFS -sENVIRONMENT=node"

# EMCC_ENV="${EMCC_NODE} -sFORCE_FILESYSTEM=0"
EMCC_ENV="${EMCC_NODE} -sERROR_ON_UNDEFINED_SYMBOLS"

# PREFIX only required for static initdb
EMCC_CFLAGS="-sERROR_ON_UNDEFINED_SYMBOLS=1 ${CC_PGLITE} -DPREFIX=/tmp/pglite -Wno-macro-redefined -Wno-unused-function"

# ZIC=${ZIC:-$(realpath bin/zic)}

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

# if running a 32bits zic from current build
unset LD_PRELOAD

if EMCC_CFLAGS="${EMCC_ENV} ${EMCC_CFLAGS}" emmake make emscripten=1 install 2>&1 > /tmp/install.log
then
echo install ok
pushd /tmp/pglite

find . -type f | grep -v plpgsql > /tmp/pglite/pg.installed
popd

goback=$(pwd)
popd
python3 cibuild/pack_extension.py builtin
pushd $goback

pushd /tmp/pglite
find . -type f > /tmp/pglite/pg.installed
popd

else
cat /tmp/install.log
echo "install failed"
exit 225
fi
else
cat /tmp/build.log
echo "build failed"
exit 230
fi

# wip
mv -vf ./src/bin/psql/psql.$EXT ./src/bin/pg_config/pg_config.$EXT /tmp/pglite/bin/
mv -vf ./src/bin/pg_dump/pg_restore.$EXT ./src/bin/pg_dump/pg_dump.$EXT ./src/bin/pg_dump/pg_dumpall.$EXT /tmp/pglite/bin/
mv -vf ./src/bin/pg_resetwal/pg_resetwal.$EXT ./src/bin/initdb/initdb.$EXT ./src/backend/postgres.$EXT /tmp/pglite/bin/

# force node wasm version
cp -vf /tmp/pglite/postgres /tmp/pglite/bin/postgres && chmod +x /tmp/pglite/postgres /tmp/pglite/bin/postgres

popd
echo "pgbuild:end




"
7 changes: 6 additions & 1 deletion pglite/cibuild/repo-pg-16.x.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,9 @@ rm postgresql 2>/dev/null
ln -s $PGSRC postgresql

echo "Building postgresql-${PG_VERSION} in folder $PGSRC"
. cibuild/pgbuild.sh
if ${WASI}
then
. cibuild/pgbuild.sh
else
. cibuild/pgbuild.emscripten.sh
fi
46 changes: 46 additions & 0 deletions pglite/config.site
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# config.site for PostgreSQL custom build

# Installation prefix
prefix=/tmp/pglite

# Cache file location
cache_file=/tmp/pglite/config.cache.emscripten

# Disable spinlocks
ac_cv_spinlock=no

# Disable large file support
ac_cv_sys_large_files=no

# Disable LLVM support
with_llvm=no

# Disable PAM
with_pam=no

# Explicitly disable OpenSSL
with_openssl=no

# Disable readline support
with_readline=no

# Disable ICU support
with_icu=no

# Enable OSSP UUID
with_uuid=ossp

# Enable zlib
with_zlib=yes

# Enable libxml
with_libxml=yes

# Enable libxslt
with_libxslt=yes

# Set extension
ac_cv_exeext=.cjs

# Set template
with_template=emscripten
9 changes: 9 additions & 0 deletions pglite/other/PGPASSFILE
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
USER="postgres"
PASS="postgres"
md5pass = "md5" + __import__('hashlib').md5(USER.encode() + PASS.encode()).hexdigest()
print(f"localhost:5432:postgres:{USER}:{md5pass}")

USER="login"
PASS="password"
md5pass = "md5" + __import__('hashlib').md5(USER.encode() + PASS.encode()).hexdigest()
print(f"localhost:5432:postgres:{USER}:{md5pass}")
4 changes: 4 additions & 0 deletions pglite/other/bin/emsdk-shared
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
echo "[$(pwd)] $0 $@" >> /tmp/disable-shared.log
# shared build
${PG_LINK:-emcc} -L${PREFIX}/lib -DPREFIX=/tmp/pglite -shared -sSIDE_MODULE=1 $@ -Wno-unused-function
2 changes: 2 additions & 0 deletions pglite/other/bin/pg_config
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
node /tmp/pglite/bin/pg_config.cjs $@
3 changes: 3 additions & 0 deletions pglite/other/initdb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
. /opt/python-wasm-sdk/wasm32-bi-emscripten-shell.sh
TZ=UTC PGTZ=UTC node /tmp/pglite/bin/initdb.cjs $@
3 changes: 3 additions & 0 deletions pglite/other/postgres
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
. /opt/python-wasm-sdk/wasm32-bi-emscripten-shell.sh
TZ=UTC PGTZ=UTC PGDATA=${PGDATA} node /tmp/pglite/bin/postgres.cjs $@
Loading