From 9ca9f78814d8072b701ffaf5052d5239ef4a2045 Mon Sep 17 00:00:00 2001 From: tudor Date: Thu, 30 Oct 2025 22:17:55 +0100 Subject: [PATCH 01/15] needs more exported symbols --- build-pglite.sh | 2 +- contrib/pgcrypto/Makefile | 6 +++--- src/backend/Makefile | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/build-pglite.sh b/build-pglite.sh index 8fd4b25572087..a90136c6311f7 100755 --- a/build-pglite.sh +++ b/build-pglite.sh @@ -39,7 +39,7 @@ fi # Step 1: configure the project if [ "$RUN_CONFIGURE" = true ]; then - LDFLAGS="-sWASM_BIGINT -sUSE_PTHREADS=0" CFLAGS="${PGLITE_CFLAGS} -sWASM_BIGINT -fpic -sENVIRONMENT=node,web,worker -sSUPPORT_LONGJMP=emscripten -Wno-declaration-after-statement -Wno-macro-redefined -Wno-unused-function -Wno-missing-prototypes -Wno-incompatible-pointer-types" emconfigure ./configure ac_cv_exeext=.cjs --disable-spinlocks --disable-largefile --without-llvm --without-pam --disable-largefile --with-openssl=no --without-readline --without-icu --with-includes=$INSTALL_PREFIX/include:$INSTALL_PREFIX/include/libxml2 --with-libraries=$INSTALL_PREFIX/lib --with-uuid=ossp --with-zlib --with-libxml --with-libxslt --with-template=emscripten --prefix=$INSTALL_FOLDER || { echo 'error: emconfigure failed' ; exit 11; } + LDFLAGS="-sWASM_BIGINT -sUSE_PTHREADS=0" CFLAGS="${PGLITE_CFLAGS} -sWASM_BIGINT -fpic -sENVIRONMENT=node,web,worker -sSUPPORT_LONGJMP=emscripten -Wno-declaration-after-statement -Wno-macro-redefined -Wno-unused-function -Wno-missing-prototypes -Wno-incompatible-pointer-types" emconfigure ./configure ac_cv_exeext=.cjs --disable-spinlocks --disable-largefile --without-llvm --without-pam --disable-largefile --with-openssl=yes --without-readline --without-icu --with-includes=$INSTALL_PREFIX/include:$INSTALL_PREFIX/include/libxml2 --with-libraries=$INSTALL_PREFIX/lib --with-uuid=ossp --with-zlib --with-libxml --with-libxslt --with-template=emscripten --prefix=$INSTALL_FOLDER || { echo 'error: emconfigure failed' ; exit 11; } else echo "Warning: configure has not been run because RUN_CONFIGURE=${RUN_CONFIGURE}" fi diff --git a/contrib/pgcrypto/Makefile b/contrib/pgcrypto/Makefile index 8085114dca6c2..7fc5918984695 100644 --- a/contrib/pgcrypto/Makefile +++ b/contrib/pgcrypto/Makefile @@ -62,9 +62,9 @@ endif # shared library link. (The order in which you list them here doesn't # matter.) SHLIB_LINK += $(filter -lcrypto -lz, $(LIBS)) -ifeq ($(PORTNAME), emscripten) -SHLIB_LINK += -lcrypto -endif +# ifeq ($(PORTNAME), emscripten) +# SHLIB_LINK += -lcrypto +# endif ifeq ($(PORTNAME), win32) SHLIB_LINK += $(filter -leay32, $(LIBS)) # those must be at the end diff --git a/src/backend/Makefile b/src/backend/Makefile index 0bc6a84c3b10a..841649b20e7ff 100644 --- a/src/backend/Makefile +++ b/src/backend/Makefile @@ -107,7 +107,7 @@ pglite-exported-functions: # PGLITE_EMSCRIPTEN_FLAGS are the emscripten flags to be passed to the build. Ideally they would be completely transparent, such that we # could build a libpglite with or without those flags (to switch between native and wasm builds) pglite: pglite-exported-functions - $(CC) $(CFLAGS) $(LDFLAGS) -DPG_PREFIX=/tmp/pglite -I$(top_builddir)/src/include -I$(top_builddir)/src/ -I$(top_builddir)/src/interfaces/libpq -o pglite.o -c $(top_builddir)/$(PGLITE_MAIN) -Wno-incompatible-pointer-types-discards-qualifiers + $(CC) $(CFLAGS) $(LDFLAGS) -DPG_PREFIX=/tmp/pglite -I$(top_builddir)/src/include -I$(top_builddir)/src/ -I$(top_builddir)/src/interfaces/libpq -I/install/libs/include -o pglite.o -c $(top_builddir)/$(PGLITE_MAIN) -Wno-incompatible-pointer-types-discards-qualifiers $(CC) \ $(PGLITE_CFLAGS) \ -fPIC -m32 -D_FILE_OFFSET_BITS=64 -mno-bulk-memory -mnontrapping-fptoint -mno-reference-types -mno-sign-ext -mno-extended-const -mno-atomics -mno-tail-call -mno-multivalue -mno-relaxed-simd -mno-simd128 -mno-multimemory -mno-exception-handling -Wno-unused-command-line-argument -Wno-unreachable-code-fallthrough -Wno-unused-function -Wno-invalid-noreturn -Wno-declaration-after-statement -Wno-invalid-noreturn \ @@ -115,7 +115,7 @@ pglite: pglite-exported-functions $(PGPRELOAD) \ -ferror-limit=1 \ -sEXPORTED_FUNCTIONS=@$(emscripten_imports_dir)/exported_functions.txt \ - -I./src/include -I./src/ -I./src/interfaces/libpq \ + -I./src/include -I./src/ -I./src/interfaces/libpq -I/install/libs/include \ -L/install/libs/lib -L$(top_builddir) -L$(top_builddir)/src/interfaces/libpq/ -L. \ pglite.o \ -Ldict_snowball \ From a77f7ab9336676a78496d23b8d58031f638e78d2 Mon Sep 17 00:00:00 2001 From: tudor Date: Sat, 1 Nov 2025 18:55:47 +0100 Subject: [PATCH 02/15] building and simple test --- build-pglite.sh | 2 +- build-with-docker.sh | 2 +- pglite-wasm/builder/Dockerfile | 5 +++-- pglite-wasm/included.pglite.imports | 1 + src/backend/Makefile | 1 + 5 files changed, 7 insertions(+), 4 deletions(-) diff --git a/build-pglite.sh b/build-pglite.sh index a90136c6311f7..67dd79818cc08 100755 --- a/build-pglite.sh +++ b/build-pglite.sh @@ -70,7 +70,7 @@ PGLITE_EMSCRIPTEN_FLAGS="-sWASM_BIGINT \ -sNO_EXIT_RUNTIME=1 -sENVIRONMENT=node,web,worker \ -sMAIN_MODULE=2 -sMODULARIZE=1 -sEXPORT_ES6=1 \ -sEXPORT_NAME=Module -sALLOW_TABLE_GROWTH -sALLOW_MEMORY_GROWTH \ --sERROR_ON_UNDEFINED_SYMBOLS=1 \ +-sERROR_ON_UNDEFINED_SYMBOLS=0 \ -sEXPORTED_RUNTIME_METHODS=$EXPORTED_RUNTIME_METHODS" # Building pglite itself needs to be the last step because of the PRELOAD_FILES parameter (a list of files and folders) need to be available. diff --git a/build-with-docker.sh b/build-with-docker.sh index 6a849b52ab863..e4addc67fc9f6 100755 --- a/build-with-docker.sh +++ b/build-with-docker.sh @@ -8,6 +8,6 @@ docker run $@ \ --workdir=${DOCKER_WORKSPACE} \ -v .:${DOCKER_WORKSPACE}:rw \ -v ./dist:/install/pglite:rw \ - electricsql/pglite-builder:3.1.74_2 \ + electricsql/pglite-builder:3.1.74_2-pgcrypto \ ./build-pglite.sh diff --git a/pglite-wasm/builder/Dockerfile b/pglite-wasm/builder/Dockerfile index cf613dd2ddc85..4629d4881b377 100644 --- a/pglite-wasm/builder/Dockerfile +++ b/pglite-wasm/builder/Dockerfile @@ -3,7 +3,7 @@ ARG BUILDPLATFORM # we only need to build on one platform, since we're interested in the WASM output # building on the native (BUILDPLATFORM) is much faster, so use that # remove "-arm64" suffix if building on x86_64 -FROM --platform=$BUILDPLATFORM emscripten/emsdk:${EMSDK_VER} AS builder +FROM --platform=$BUILDPLATFORM emscripten/emsdk:${EMSDK_VER}-arm64 AS builder ENV LLVM_NM=/emsdk/upstream/bin/llvm-nm @@ -52,11 +52,12 @@ RUN ${LLVM_NM} /install/libs/lib/libxslt.a | awk '$2 ~ /^[TDB]$/ {print $3}' | s WORKDIR /src RUN curl -L https://github.com/openssl/openssl/releases/download/openssl-3.0.17/openssl-3.0.17.tar.gz | tar xz WORKDIR /src/openssl-3.0.17 -RUN emconfigure ./Configure no-tests linux-generic64 --prefix=/install/libs +RUN emconfigure ./Configure no-tests linux-generic64 --prefix=/install/libs no-shared RUN sed -i 's|^CROSS_COMPILE.*$|CROSS_COMPILE=|g' Makefile # see https://github.com/emscripten-core/emscripten/issues/19597#issue-1754476454 RUN emmake make -j && emmake make install # extract exported symbols - useful for passing them to emscripten as EXPORTED_FUNCTIONS RUN ${LLVM_NM} /install/libs/lib/libssl.a | awk '$2 ~ /^[TDB]$/ {print $3}' | sed '/^$/d' | sort -u > /install/exports/libssl.exports +RUN ${LLVM_NM} /install/libs/lib/libcrypto.a | awk '$2 ~ /^[TDB]$/ {print $3}' | sed '/^$/d' | sort -u > /install/exports/libcrypto.exports WORKDIR /src RUN curl -L ftp://ftp.ossp.org/pkg/lib/uuid/uuid-1.6.2.tar.gz | tar xz diff --git a/pglite-wasm/included.pglite.imports b/pglite-wasm/included.pglite.imports index 7a5d30d895111..dd51b87f21f68 100644 --- a/pglite-wasm/included.pglite.imports +++ b/pglite-wasm/included.pglite.imports @@ -27,6 +27,7 @@ searchstoplist set_read_write_cbs socket srand +stderr strcmp strftime strlen diff --git a/src/backend/Makefile b/src/backend/Makefile index 841649b20e7ff..bec9e6567cd6c 100644 --- a/src/backend/Makefile +++ b/src/backend/Makefile @@ -121,6 +121,7 @@ pglite: pglite-exported-functions -Ldict_snowball \ -lxslt \ -lpgcore \ + -lcrypto \ -lnodefs.js -lidbfs.js -lxml2 -lz endif From 225fb92df605f7711d49e34486fae4918c64816d Mon Sep 17 00:00:00 2001 From: tudor Date: Sun, 2 Nov 2025 17:26:32 +0100 Subject: [PATCH 03/15] changes for more tests --- build-pglite.sh | 2 +- pglite-wasm/included.pglite.imports | 2 ++ src/backend/Makefile | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/build-pglite.sh b/build-pglite.sh index 67dd79818cc08..a8e6097cfddde 100755 --- a/build-pglite.sh +++ b/build-pglite.sh @@ -12,7 +12,7 @@ PGLITE_CFLAGS="-O2" if [ "$DEBUG" = true ] then echo "pglite: building debug version." - PGLITE_CFLAGS="-g -gsource-map --no-wasm-opt" + PGLITE_CFLAGS="-sDYLINK_DEBUG=2 -g -gsource-map --no-wasm-opt" else echo "pglite: building release version." # we shouldn't need to do this, but there's a bug somewhere that prevents a successful build if this is set diff --git a/pglite-wasm/included.pglite.imports b/pglite-wasm/included.pglite.imports index dd51b87f21f68..964ed2d234e4d 100644 --- a/pglite-wasm/included.pglite.imports +++ b/pglite-wasm/included.pglite.imports @@ -1,4 +1,5 @@ close +errfinish fcntl free getpid @@ -16,6 +17,7 @@ memcpy memset nanosleep open +pg_free pgl_backend pgl_initdb pgl_shutdown diff --git a/src/backend/Makefile b/src/backend/Makefile index bec9e6567cd6c..fb284247bbb19 100644 --- a/src/backend/Makefile +++ b/src/backend/Makefile @@ -121,6 +121,7 @@ pglite: pglite-exported-functions -Ldict_snowball \ -lxslt \ -lpgcore \ + -lssl \ -lcrypto \ -lnodefs.js -lidbfs.js -lxml2 -lz endif From b9825796ebf1efdd1eddd2c19f98eac4dad97965 Mon Sep 17 00:00:00 2001 From: tudor Date: Sun, 2 Nov 2025 18:25:22 +0100 Subject: [PATCH 04/15] remove pg_free from included exported functions --- pglite-wasm/included.pglite.imports | 1 - 1 file changed, 1 deletion(-) diff --git a/pglite-wasm/included.pglite.imports b/pglite-wasm/included.pglite.imports index 964ed2d234e4d..87cebfac82892 100644 --- a/pglite-wasm/included.pglite.imports +++ b/pglite-wasm/included.pglite.imports @@ -17,7 +17,6 @@ memcpy memset nanosleep open -pg_free pgl_backend pgl_initdb pgl_shutdown From f66f9eee51ca121baec7ebf33f6adec255b2b4ce Mon Sep 17 00:00:00 2001 From: tudor Date: Thu, 6 Nov 2025 16:06:25 +0100 Subject: [PATCH 05/15] build libssl and libxml2 WITHOUT threads support --- pglite-wasm/builder/Dockerfile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pglite-wasm/builder/Dockerfile b/pglite-wasm/builder/Dockerfile index 4629d4881b377..1debb55926f4c 100644 --- a/pglite-wasm/builder/Dockerfile +++ b/pglite-wasm/builder/Dockerfile @@ -3,7 +3,7 @@ ARG BUILDPLATFORM # we only need to build on one platform, since we're interested in the WASM output # building on the native (BUILDPLATFORM) is much faster, so use that # remove "-arm64" suffix if building on x86_64 -FROM --platform=$BUILDPLATFORM emscripten/emsdk:${EMSDK_VER}-arm64 AS builder +FROM --platform=$BUILDPLATFORM emscripten/emsdk:${EMSDK_VER} AS builder ENV LLVM_NM=/emsdk/upstream/bin/llvm-nm @@ -34,7 +34,7 @@ RUN ${LLVM_NM} /install/libs/lib/libz.a | awk '$2 ~ /^[TDB]$/ {print $3}' | sed WORKDIR /src RUN curl -L https://gitlab.gnome.org/GNOME/libxml2/-/archive/v2.14.5/libxml2-v2.14.5.tar.gz | tar -xz WORKDIR /src/libxml2-v2.14.5 -RUN ./autogen.sh --with-python=no +RUN ./autogen.sh --with-python=no --with-threads=no RUN CFLAGS="${EMCC_COMMON_FLAGS}" CXXFLAGS="${EMCC_COMMON_FLAGS}" emconfigure ./configure --enable-shared=no --enable-static=yes --with-python=no --prefix=/install/libs RUN emmake make -j && emmake make install # extract exported symbols - useful for passing them to emscripten as EXPORTED_FUNCTIONS @@ -52,9 +52,9 @@ RUN ${LLVM_NM} /install/libs/lib/libxslt.a | awk '$2 ~ /^[TDB]$/ {print $3}' | s WORKDIR /src RUN curl -L https://github.com/openssl/openssl/releases/download/openssl-3.0.17/openssl-3.0.17.tar.gz | tar xz WORKDIR /src/openssl-3.0.17 -RUN emconfigure ./Configure no-tests linux-generic64 --prefix=/install/libs no-shared +RUN emconfigure ./Configure no-tests no-threads no-shared linux-generic64 --prefix=/install/libs RUN sed -i 's|^CROSS_COMPILE.*$|CROSS_COMPILE=|g' Makefile # see https://github.com/emscripten-core/emscripten/issues/19597#issue-1754476454 -RUN emmake make -j && emmake make install +RUN emmake make -j && emmake make install_sw install_ssldirs # extract exported symbols - useful for passing them to emscripten as EXPORTED_FUNCTIONS RUN ${LLVM_NM} /install/libs/lib/libssl.a | awk '$2 ~ /^[TDB]$/ {print $3}' | sed '/^$/d' | sort -u > /install/exports/libssl.exports RUN ${LLVM_NM} /install/libs/lib/libcrypto.a | awk '$2 ~ /^[TDB]$/ {print $3}' | sed '/^$/d' | sort -u > /install/exports/libcrypto.exports From b5cecf06773fee9f32d50e6bba936d64fb65a9aa Mon Sep 17 00:00:00 2001 From: tudor Date: Thu, 6 Nov 2025 16:06:35 +0100 Subject: [PATCH 06/15] use new docker builder --- build-with-docker.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/build-with-docker.sh b/build-with-docker.sh index e4addc67fc9f6..bd75477a916da 100755 --- a/build-with-docker.sh +++ b/build-with-docker.sh @@ -3,11 +3,12 @@ DOCKER_WORKSPACE=$(pwd) docker run $@ \ + --name pglite-builder \ --rm \ -e DEBUG=${DEBUG:-false} \ --workdir=${DOCKER_WORKSPACE} \ -v .:${DOCKER_WORKSPACE}:rw \ -v ./dist:/install/pglite:rw \ - electricsql/pglite-builder:3.1.74_2-pgcrypto \ + electricsql/pglite-builder:3.1.74_2-pgcrypto_2 \ ./build-pglite.sh From 67dc30465279a558fcb3c84b24421347dc785ecb Mon Sep 17 00:00:00 2001 From: tudor Date: Thu, 6 Nov 2025 16:07:14 +0100 Subject: [PATCH 07/15] add functions used by pgcrypto see comments in https://github.com/electric-sql/pglite/pull/834 --- pglite-wasm/included.pglite.imports | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pglite-wasm/included.pglite.imports b/pglite-wasm/included.pglite.imports index 87cebfac82892..462b94f7f8e1e 100644 --- a/pglite-wasm/included.pglite.imports +++ b/pglite-wasm/included.pglite.imports @@ -1,9 +1,18 @@ +atexit close errfinish +fclose fcntl +fopen +fread free +getegid +getenv +geteuid +getgid getpid gettimeofday +getuid gmtime interactive_one ioctl From b6bdf27d22a2c9186e4b5f3df9991b1c219749b4 Mon Sep 17 00:00:00 2001 From: tudor Date: Sun, 9 Nov 2025 19:09:17 +0100 Subject: [PATCH 08/15] whole archive link of libssl and libcrypto to pgcrypto.so --- build-pglite.sh | 8 +++++++- pglite/build-pgcrypto.sh | 9 +++++++++ src/backend/Makefile | 2 -- 3 files changed, 16 insertions(+), 3 deletions(-) create mode 100755 pglite/build-pgcrypto.sh diff --git a/build-pglite.sh b/build-pglite.sh index 1abd4a5231613..0694474ad5165 100755 --- a/build-pglite.sh +++ b/build-pglite.sh @@ -55,7 +55,7 @@ if [ "$RUN_CONFIGURE" = true ]; then LDFLAGS="-sWASM_BIGINT -sUSE_PTHREADS=0" \ LDFLAGS_SL="-sSIDE_MODULE=1" \ LDFLAGS_EX=$PGLITE_EMSCRIPTEN_FLAGS \ - CFLAGS="${PGLITE_CFLAGS} -sWASM_BIGINT -fpic -sENVIRONMENT=node,web,worker -sSUPPORT_LONGJMP=emscripten -Wno-declaration-after-statement -Wno-macro-redefined -Wno-unused-function -Wno-missing-prototypes -Wno-incompatible-pointer-types" emconfigure ./configure ac_cv_exeext=.js --host aarch64-unknown-linux-gnu --disable-spinlocks --disable-largefile --without-llvm --without-pam --disable-largefile --with-openssl=yes --without-readline --without-icu --with-includes=$INSTALL_PREFIX/include:$INSTALL_PREFIX/include/libxml2:$(pwd)/pglite/includes --with-libraries=$INSTALL_PREFIX/lib --with-uuid=ossp --with-zlib --with-libxml --with-libxslt --with-template=emscripten --prefix=$INSTALL_FOLDER || { echo 'error: emconfigure failed' ; exit 11; } + CFLAGS="${PGLITE_CFLAGS} -sWASM_BIGINT -fpic -sENVIRONMENT=node,web,worker -sSUPPORT_LONGJMP=emscripten -Wno-declaration-after-statement -Wno-macro-redefined -Wno-unused-function -Wno-missing-prototypes -Wno-incompatible-pointer-types" emconfigure ./configure ac_cv_exeext=.js --host aarch64-unknown-linux-gnu --disable-spinlocks --disable-largefile --without-llvm --without-pam --disable-largefile --with-openssl=no --without-readline --without-icu --with-includes=$INSTALL_PREFIX/include:$INSTALL_PREFIX/include/libxml2:$(pwd)/pglite/includes --with-libraries=$INSTALL_PREFIX/lib --with-uuid=ossp --with-zlib --with-libxml --with-libxslt --with-template=emscripten --prefix=$INSTALL_FOLDER || { echo 'error: emconfigure failed' ; exit 11; } else echo "Warning: configure has not been run because RUN_CONFIGURE=${RUN_CONFIGURE}" fi @@ -65,11 +65,17 @@ emmake make PORTNAME=emscripten -j || { echo 'error: emmake make PORTNAME=emscri emmake make PORTNAME=emscripten install || { echo 'error: emmake make PORTNAME=emscripten install' ; exit 22; } # Step 3.1: make all contrib extensions - do not install +# Step 3.1.1 pgcrypto - special case +cd ./pglite/ && ./build-pgcrypto.sh && cd ../ +# Step 3.1.2 all the rest of contrib emmake make PORTNAME=emscripten -C contrib/ -j || { echo 'error: emmake make PORTNAME=emscripten -C contrib/ -j' ; exit 31; } # Step 3.2: make dist contrib extensions - this will create an archive for each extension emmake make PORTNAME=emscripten -C contrib/ dist || { echo 'error: emmake make PORTNAME=emscripten -C contrib/ dist' ; exit 32; } # the above will also create a file with the imports that each extension needs - we pass these as input in the next step for emscripten to keep alive +# hack for pgcrypto: +find / -name pgcrypto.imports -exec rm -f {} \; + # Step 4: make and dist other extensions SAVE_PATH=$PATH PATH=$PATH:$INSTALL_FOLDER/bin diff --git a/pglite/build-pgcrypto.sh b/pglite/build-pgcrypto.sh new file mode 100755 index 0000000000000..253c6ca1082e0 --- /dev/null +++ b/pglite/build-pgcrypto.sh @@ -0,0 +1,9 @@ +#!/bin/bash +# current_dir=$(pwd) +pushd ../contrib/pgcrypto +# 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 -lssl -lcrypto" CFLAGS_SL="$PGLITE_CFLAGS -fexceptions -sWASM_BIGINT" -j +emmake make PORTNAME=emscripten install +# emmake make PG_LDFLAGS="-L/install/libs/lib -lpgport -lpgcommon -sSIDE_MODULE=1" -j +popd +# cd current_dir diff --git a/src/backend/Makefile b/src/backend/Makefile index 8770c2c7a40aa..76e66203895d9 100644 --- a/src/backend/Makefile +++ b/src/backend/Makefile @@ -121,8 +121,6 @@ pglite: pglite-exported-functions -Ldict_snowball \ -lxslt \ -lpgcore \ - -lssl \ - -lcrypto \ -lnodefs.js -lidbfs.js -lxml2 -lz endif From 99569d259d4d9c699349090bba29709435624249 Mon Sep 17 00:00:00 2001 From: tudor Date: Sun, 9 Nov 2025 19:24:33 +0100 Subject: [PATCH 09/15] more included imports needed by pgcrypto --- pglite-wasm/included.pglite.imports | 137 +++++++++++++++++++++++++++- 1 file changed, 136 insertions(+), 1 deletion(-) diff --git a/pglite-wasm/included.pglite.imports b/pglite-wasm/included.pglite.imports index 462b94f7f8e1e..179eedc72ac62 100644 --- a/pglite-wasm/included.pglite.imports +++ b/pglite-wasm/included.pglite.imports @@ -1,44 +1,179 @@ +__errno_location +abort +accept +appendStringInfo +appendStringInfoChar +appendStringInfoString atexit +atoi +bind +BuildTupleFromCStrings +calloc +chmod +clearerr +clock_gettime close +closedir +closelog +connect +cstring_to_text +cstring_to_text_with_len +deconstruct_array_builtin +dladdr +dlclose +dlerror +dlopen +dlsym +downcase_truncate_identifier +end_MultiFuncCall +enlargeStringInfo +errcode errfinish +errmsg +errmsg_internal +errstart +errstart_cold fclose fcntl +fdopen +feof +ferror +fflush +fgets +fileno +fiprintf fopen +fputc +fputs fread free +freeaddrinfo +fseek +fstat +ftell +fwrite +gai_strerror +gen_random_uuid +get_call_result_type +getaddrinfo +GetDatabaseEncoding getegid getenv geteuid getgid +gethostbyname +getnameinfo getpid +getsockname +getsockopt gettimeofday getuid gmtime +HeapTupleHeaderGetDatum +init_MultiFuncCall +initStringInfo interactive_one ioctl isalnum isxdigit +listen lowerstr +lseek +madvise main malloc +memchr memcmp memcpy +memmove +MemoryContextAlloc +MemoryContextAllocZero memset +mlock +mmap +mprotect +munmap nanosleep +ntohs open +opendir +openlog +palloc +palloc0 +per_MultiFuncCall +perror +pfree +pg_any_to_server +pg_detoast_datum +pg_detoast_datum_packed +pg_do_encoding_conversion +pg_is_ascii +pg_strcasecmp +pg_strong_random +pg_vsnprintf pgl_backend pgl_initdb pgl_shutdown +ProcessInterrupts +pstrdup +puts +qsort rand read +readdir readstoplist realloc +recvfrom +repalloc +ResourceOwnerEnlarge +ResourceOwnerForget +ResourceOwnerRemember searchstoplist +select +sendto set_read_write_cbs +setbuf +setsockopt +shutdown +sigaction +signal +siprintf +sleep +snprintf socket srand +sscanf +stat stderr +strcat +strchr strcmp +strcpy +strcspn +strdup +strerror +strerror_r strftime +strlcpy strlen -strtoul \ No newline at end of file +strncat +strncmp +strncpy +strrchr +strspn +strstr +strtol +strtoul +sysconf +syslog +tcgetattr +tcsetattr +text_to_cstring +text_to_cstring_buffer +time +tolower +TupleDescGetAttInMetadata +usleep +vfprintf +vsnprintf +write \ No newline at end of file From 2210ec74db3219ab7ae4fdce09ccc4d18b87e726 Mon Sep 17 00:00:00 2001 From: tudor Date: Sun, 9 Nov 2025 19:47:07 +0100 Subject: [PATCH 10/15] cleanup --- src/backend/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/backend/Makefile b/src/backend/Makefile index 76e66203895d9..1c04efeab0099 100644 --- a/src/backend/Makefile +++ b/src/backend/Makefile @@ -107,7 +107,7 @@ pglite-exported-functions: # PGLITE_EMSCRIPTEN_FLAGS are the emscripten flags to be passed to the build. Ideally they would be completely transparent, such that we # could build a libpglite with or without those flags (to switch between native and wasm builds) pglite: pglite-exported-functions - $(CC) $(CFLAGS) $(LDFLAGS) -DPG_PREFIX=/tmp/pglite -I$(top_builddir)/src/include -I$(top_builddir)/src/ -I$(top_builddir)/src/interfaces/libpq -I/install/libs/include -o pglite.o -c $(top_builddir)/$(PGLITE_MAIN) -Wno-incompatible-pointer-types-discards-qualifiers + $(CC) $(CFLAGS) $(LDFLAGS) -DPG_PREFIX=/tmp/pglite -I$(top_builddir)/src/include -I$(top_builddir)/src/ -I$(top_builddir)/src/interfaces/libpq -o pglite.o -c $(top_builddir)/$(PGLITE_MAIN) -Wno-incompatible-pointer-types-discards-qualifiers $(CC) \ $(PGLITE_CFLAGS) \ -fPIC -m32 -mno-bulk-memory -mnontrapping-fptoint -mno-reference-types -mno-sign-ext -mno-extended-const -mno-atomics -mno-tail-call -mno-multivalue -mno-relaxed-simd -mno-simd128 -mno-multimemory -mno-exception-handling -Wno-unused-command-line-argument -Wno-unreachable-code-fallthrough -Wno-unused-function -Wno-invalid-noreturn -Wno-declaration-after-statement -Wno-invalid-noreturn \ @@ -115,7 +115,7 @@ pglite: pglite-exported-functions $(PGPRELOAD) \ -ferror-limit=1 \ -sEXPORTED_FUNCTIONS=@$(emscripten_imports_dir)/exported_functions.txt \ - -I./src/include -I./src/ -I./src/interfaces/libpq -I/install/libs/include \ + -I./src/include -I./src/ -I./src/interfaces/libpq \ -L/install/libs/lib -L$(top_builddir) -L$(top_builddir)/src/interfaces/libpq/ -L. \ pglite.o \ -Ldict_snowball \ From 31db23e12f4aaa3699c08e9bb0add678db62cdd3 Mon Sep 17 00:00:00 2001 From: tudor Date: Sun, 9 Nov 2025 19:49:56 +0100 Subject: [PATCH 11/15] new builder --- build-with-docker.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build-with-docker.sh b/build-with-docker.sh index bd75477a916da..e9930ac75465d 100755 --- a/build-with-docker.sh +++ b/build-with-docker.sh @@ -9,6 +9,6 @@ docker run $@ \ --workdir=${DOCKER_WORKSPACE} \ -v .:${DOCKER_WORKSPACE}:rw \ -v ./dist:/install/pglite:rw \ - electricsql/pglite-builder:3.1.74_2-pgcrypto_2 \ + electricsql/pglite-builder:3.1.74_3 \ ./build-pglite.sh From f38af53ef1211410b57ca31ec2b5ef69259b4c5c Mon Sep 17 00:00:00 2001 From: tudor Date: Sun, 9 Nov 2025 19:52:36 +0100 Subject: [PATCH 12/15] cleanup --- pglite/build-pgcrypto.sh | 3 --- 1 file changed, 3 deletions(-) diff --git a/pglite/build-pgcrypto.sh b/pglite/build-pgcrypto.sh index 253c6ca1082e0..396fc0d803f7c 100755 --- a/pglite/build-pgcrypto.sh +++ b/pglite/build-pgcrypto.sh @@ -1,9 +1,6 @@ #!/bin/bash -# current_dir=$(pwd) pushd ../contrib/pgcrypto # 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 -lssl -lcrypto" CFLAGS_SL="$PGLITE_CFLAGS -fexceptions -sWASM_BIGINT" -j emmake make PORTNAME=emscripten install -# emmake make PG_LDFLAGS="-L/install/libs/lib -lpgport -lpgcommon -sSIDE_MODULE=1" -j popd -# cd current_dir From 9a4255caa69f1e43be717edfe4fbd0f7717ee5f8 Mon Sep 17 00:00:00 2001 From: tudor Date: Sun, 9 Nov 2025 19:54:52 +0100 Subject: [PATCH 13/15] simplifications --- build-pglite.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build-pglite.sh b/build-pglite.sh index 0694474ad5165..211d586f02b9a 100755 --- a/build-pglite.sh +++ b/build-pglite.sh @@ -66,14 +66,14 @@ emmake make PORTNAME=emscripten install || { echo 'error: emmake make PORTNAME=e # Step 3.1: make all contrib extensions - do not install # Step 3.1.1 pgcrypto - special case -cd ./pglite/ && ./build-pgcrypto.sh && cd ../ +cd ./pglite/ && PGLITE_CFLAGS=$PGLITE_CFLAGS ./build-pgcrypto.sh && cd ../ # Step 3.1.2 all the rest of contrib emmake make PORTNAME=emscripten -C contrib/ -j || { echo 'error: emmake make PORTNAME=emscripten -C contrib/ -j' ; exit 31; } # Step 3.2: make dist contrib extensions - this will create an archive for each extension emmake make PORTNAME=emscripten -C contrib/ dist || { echo 'error: emmake make PORTNAME=emscripten -C contrib/ dist' ; exit 32; } # the above will also create a file with the imports that each extension needs - we pass these as input in the next step for emscripten to keep alive -# hack for pgcrypto: +# hack for pgcrypto. since we're linking lssl and lcrypto directly to the extension, their respective symbols should not be exported find / -name pgcrypto.imports -exec rm -f {} \; # Step 4: make and dist other extensions From 094d1a9082a9e6af5189ed70301461e1bc05393e Mon Sep 17 00:00:00 2001 From: tudor Date: Sun, 9 Nov 2025 20:45:14 +0100 Subject: [PATCH 14/15] cleanup --- contrib/pgcrypto/Makefile | 3 --- 1 file changed, 3 deletions(-) diff --git a/contrib/pgcrypto/Makefile b/contrib/pgcrypto/Makefile index 7fc5918984695..5efa10c334c80 100644 --- a/contrib/pgcrypto/Makefile +++ b/contrib/pgcrypto/Makefile @@ -62,9 +62,6 @@ endif # shared library link. (The order in which you list them here doesn't # matter.) SHLIB_LINK += $(filter -lcrypto -lz, $(LIBS)) -# ifeq ($(PORTNAME), emscripten) -# SHLIB_LINK += -lcrypto -# endif ifeq ($(PORTNAME), win32) SHLIB_LINK += $(filter -leay32, $(LIBS)) # those must be at the end From 0f25bfabdcdb637682fdba378ab6ec7b49990d7f Mon Sep 17 00:00:00 2001 From: tudor Date: Sun, 9 Nov 2025 20:48:52 +0100 Subject: [PATCH 15/15] fix build --- build-pglite.sh | 2 +- contrib/Makefile | 4 ++++ pglite/build-pgcrypto.sh | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/build-pglite.sh b/build-pglite.sh index 211d586f02b9a..0760c256ecc22 100755 --- a/build-pglite.sh +++ b/build-pglite.sh @@ -66,7 +66,7 @@ emmake make PORTNAME=emscripten install || { echo 'error: emmake make PORTNAME=e # Step 3.1: make all contrib extensions - do not install # Step 3.1.1 pgcrypto - special case -cd ./pglite/ && PGLITE_CFLAGS=$PGLITE_CFLAGS ./build-pgcrypto.sh && cd ../ +cd ./pglite/ && ./build-pgcrypto.sh && cd ../ # Step 3.1.2 all the rest of contrib emmake make PORTNAME=emscripten -C contrib/ -j || { echo 'error: emmake make PORTNAME=emscripten -C contrib/ -j' ; exit 31; } # Step 3.2: make dist contrib extensions - this will create an archive for each extension diff --git a/contrib/Makefile b/contrib/Makefile index 603636cd4d248..ec0e4c7fa84ea 100644 --- a/contrib/Makefile +++ b/contrib/Makefile @@ -57,6 +57,10 @@ else ALWAYS_SUBDIRS += pgcrypto sslinfo endif +ifeq ($(PORTNAME), emscripten) +SUBDIRS += pgcrypto +endif + ifneq ($(with_uuid),no) SUBDIRS += uuid-ossp else diff --git a/pglite/build-pgcrypto.sh b/pglite/build-pgcrypto.sh index 396fc0d803f7c..2084ad14e2f6a 100755 --- a/pglite/build-pgcrypto.sh +++ b/pglite/build-pgcrypto.sh @@ -2,5 +2,5 @@ pushd ../contrib/pgcrypto # 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 -lssl -lcrypto" CFLAGS_SL="$PGLITE_CFLAGS -fexceptions -sWASM_BIGINT" -j -emmake make PORTNAME=emscripten install +# emmake make PORTNAME=emscripten dist popd