Skip to content

Commit 1a0bdab

Browse files
tdrztudor
andauthored
Tdrz/ccoderefactoring (#50)
* some cleanup * do not run ./configure if not needed; specify portname in clean script * cleanup * remove startup_hacks * readd initdb requirements * add linker search path for backend * remove get_buffer_size and get_buffer_addr" * remove recv_password_packet in interactive_one * removed pglite-modpython.c; removed __PYDK__ * remove specifing MIN_SAFARI_VERSION since that is the default value anyway * moved some of the emscripten flags to bash script to allow a native build * docker run under current user * improved cleanup * readd recv_password_packet to interactive_one.c * remove -it when running docker * script fix * fix build-with-docker.sh script for GH actions; cleanup target for extensions * fix * cb data transport * cleanup * nothing * more cleanup * cleanup is_repl and others * sort included imports * add a pq_flush() at the end of interactive_one(). this is needed because of the new frontend <-> backend data transfer mechanism because before the write was not buffered. * more cleanup * remove repl.html * more cleanup * :) * remove things not working --------- Co-authored-by: tudor <tudor@swisstch.com>
1 parent 6c55ae1 commit 1a0bdab

File tree

20 files changed

+182
-2193
lines changed

20 files changed

+182
-2193
lines changed

build-pglite.sh

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,28 @@ fi
2121

2222
echo "pglite: PGLITE_CFLAGS=$PGLITE_CFLAGS"
2323

24+
# run ./configure only if config.status is older than this file
25+
# TODO: we should ALSO check if any of the PGLITE_CFLAGS have changed and trigger a ./configure if they did!!!
26+
REF_FILE="build-pglite.sh"
27+
CONFIG_STATUS="config.status"
28+
RUN_CONFIGURE=false
29+
30+
if [ ! -f "$CONFIG_STATUS" ]; then
31+
echo "$CONFIG_STATUS does not exist, need to run ./configure"
32+
RUN_CONFIGURE=true
33+
elif [ "$REF_FILE" -nt "$CONFIG_STATUS" ]; then
34+
echo "$CONFIG_STATUS is older than $REF_FILE. Need to run ./configure."
35+
RUN_CONFIGURE=true
36+
else
37+
echo "$CONFIG_STATUS exists and is newer than $REF_FILE. ./configure will NOT be run."
38+
fi
39+
2440
# Step 1: configure the project
25-
LDFLAGS="-sWASM_BIGINT -sUSE_PTHREADS=0" CFLAGS="${PGLITE_CFLAGS} -sWASM_BIGINT -fpic -sENVIRONMENT=node,web,worker -sSUPPORT_LONGJMP=emscripten -DPYDK=1 -DCMA_MB=12 -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; }
41+
if [ "$RUN_CONFIGURE" = true ]; then
42+
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; }
43+
else
44+
echo "Warning: configure has not been run because RUN_CONFIGURE=${RUN_CONFIGURE}"
45+
fi
2646

2747
# Step 2: make and install all except pglite
2848
emmake make PORTNAME=emscripten -j || { echo 'error: emmake make PORTNAME=emscripten -j' ; exit 21; }
@@ -42,5 +62,16 @@ emmake make OPTFLAGS="" PORTNAME=emscripten LDFLAGS_SL="-sSIDE_MODULE=1" -C pgli
4262
PATH=$SAVE_PATH
4363

4464
# Step 5: make and install pglite
65+
# we define here "all" emscripten flags in order to allow native builds (like libpglite)
66+
EXPORTED_RUNTIME_METHODS="MEMFS,IDBFS,FS,setValue,getValue,UTF8ToString,stringToNewUTF8,stringToUTF8OnStack,addFunction,removeFunction"
67+
PGLITE_EMSCRIPTEN_FLAGS="-sWASM_BIGINT \
68+
-sSUPPORT_LONGJMP=emscripten \
69+
-sFORCE_FILESYSTEM=1 \
70+
-sNO_EXIT_RUNTIME=1 -sENVIRONMENT=node,web,worker \
71+
-sMAIN_MODULE=2 -sMODULARIZE=1 -sEXPORT_ES6=1 \
72+
-sEXPORT_NAME=Module -sALLOW_TABLE_GROWTH -sALLOW_MEMORY_GROWTH \
73+
-sERROR_ON_UNDEFINED_SYMBOLS=1 \
74+
-sEXPORTED_RUNTIME_METHODS=$EXPORTED_RUNTIME_METHODS"
75+
4576
# 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.
46-
PGLITE_CFLAGS=$PGLITE_CFLAGS emmake make PORTNAME=emscripten -j -C src/backend/ install-pglite || { echo 'emmake make OPTFLAGS="" PORTNAME=emscripten -j -C pglite' ; exit 51; }
77+
PGLITE_CFLAGS="$PGLITE_CFLAGS $PGLITE_EMSCRIPTEN_FLAGS" emmake make PORTNAME=emscripten -j -C src/backend/ install-pglite || { echo 'emmake make OPTFLAGS="" PORTNAME=emscripten -j -C pglite' ; exit 51; }

build-with-docker.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ docker run $@ \
88
--workdir=${DOCKER_WORKSPACE} \
99
-v .:${DOCKER_WORKSPACE}:rw \
1010
-v ./dist:/install/pglite:rw \
11-
electricsql/pglite-builder:3.1.74_1 \
11+
electricsql/pglite-builder:3.1.74_2 \
1212
./build-pglite.sh
1313

clean-pglite.sh

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
#!/bin/bash
22

3-
emmake make -C src/backend uninstall; emmake make -C src/backend clean;
4-
emmake make -C pglite/ clean; emmake make -C pglite/ uninstall;
5-
emmake make -C contrib/ clean; emmake make -C contrib/ uninstall; emmake make -C pglite clean; emmake make -C pglite uninstall;
6-
emmake make clean; emmake make uninstal
3+
emmake make PORTNAME=emscripten -C src/backend uninstall; emmake make PORTNAME=emscripten -C src/backend clean;
4+
emmake make PORTNAME=emscripten -C pglite/ clean; emmake make PORTNAME=emscripten -C pglite/ uninstall;
5+
emmake make PORTNAME=emscripten -C contrib/ clean; emmake make PORTNAME=emscripten -C contrib/ uninstall;
6+
emmake make PORTNAME=emscripten -C pglite clean; emmake make PORTNAME=emscripten -C pglite uninstall;
7+
emmake make PORTNAME=emscripten clean; emmake make PORTNAME=emscripten uninstall;
8+
9+
echo "removing config.status"
10+
rm config.status

other/empty

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
PGlite is the best!

pglite-wasm/builder/Dockerfile

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ ARG BUILDPLATFORM
33
# we only need to build on one platform, since we're interested in the WASM output
44
# building on the native (BUILDPLATFORM) is much faster, so use that
55
# remove "-arm64" suffix if building on x86_64
6-
FROM --platform=$BUILDPLATFORM emscripten/emsdk:${EMSDK_VER}-arm64 AS builder
6+
FROM --platform=$BUILDPLATFORM emscripten/emsdk:${EMSDK_VER} AS builder
77

88
ENV LLVM_NM=/emsdk/upstream/bin/llvm-nm
99

@@ -21,7 +21,7 @@ WORKDIR /install/libs
2121

2222
WORKDIR /src
2323

24-
# ENV EMCC_COMMON_FLAGS="-fPIC -sWASM_BIGINT -sMIN_SAFARI_VERSION=150000 -D__PYDK__=1 -O2 -m32 -D_FILE_OFFSET_BITS=64 -sSUPPORT_LONGJMP=emscripten -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"
24+
# ENV EMCC_COMMON_FLAGS="-fPIC -sWASM_BIGINT -sMIN_SAFARI_VERSION=150000 -O2 -m32 -D_FILE_OFFSET_BITS=64 -sSUPPORT_LONGJMP=emscripten -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"
2525
ENV EMCC_COMMON_FLAGS="-O2 -fPIC"
2626

2727
WORKDIR /src
@@ -60,6 +60,8 @@ RUN ${LLVM_NM} /install/libs/lib/libssl.a | awk '$2 ~ /^[TDB]$/ {print $3}' | se
6060

6161
WORKDIR /src
6262
RUN curl -L ftp://ftp.ossp.org/pkg/lib/uuid/uuid-1.6.2.tar.gz | tar xz
63+
# COPY . .
64+
# RUN tar xvf uuid-1.6.2.tar.gz
6365
WORKDIR /src/uuid-1.6.2
6466
RUN CFLAGS="${EMCC_COMMON_FLAGS}" CXXFLAGS="${EMCC_COMMON_FLAGS}" emconfigure ./configure --build=aarch64-unknown-linux-gnu --enable-shared=no --enable-static=yes --with-perl=no --with-perl-compat=no --prefix=/install/libs --with-php=no --with-pic=yes
6567
RUN emmake make -j && emmake make install || true # install tries to strip the wasm, but it doesnt recognize the format, so ignore atm
@@ -85,5 +87,8 @@ ENV LIB_EXPORTS_DIR=${LIB_EXPORTS_DIR}
8587
COPY --from=builder /install/libs ${INSTALL_PREFIX}
8688
COPY --from=builder /install/exports ${LIB_EXPORTS_DIR}
8789

90+
# allow access to anyone
91+
RUN chmod -R 777 /install
92+
8893
# needed in building pglite.wasm
8994
ENV LLVM_NM=/emsdk/upstream/bin/llvm-nm

pglite-wasm/included.pglite.imports

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
11
close
22
fcntl
33
free
4-
get_buffer_addr
5-
get_buffer_size
6-
get_channel
74
getpid
85
gettimeofday
96
gmtime
107
interactive_one
11-
interactive_read
12-
interactive_write
138
ioctl
149
isalnum
1510
isxdigit
@@ -29,10 +24,10 @@ read
2924
readstoplist
3025
realloc
3126
searchstoplist
27+
set_read_write_cbs
3228
socket
3329
srand
3430
strcmp
3531
strftime
3632
strlen
37-
strtoul
38-
use_wire
33+
strtoul

0 commit comments

Comments
 (0)