Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
105 commits
Select commit Hold shift + click to select a range
95ac97e
sdk self check, disable wasm-opt temporarily
pmp-p Nov 25, 2024
410094d
check env control
pmp-p Nov 25, 2024
b2400eb
upg patches and linker
pmp-p Nov 25, 2024
0a9eb99
missing file
pmp-p Nov 25, 2024
97d1cf2
loop change
pmp-p Nov 25, 2024
ab83a1f
test
pmp-p Nov 25, 2024
c3fe53e
Merge branch 'main' into wasi-merge
pmp-p Nov 25, 2024
88880b7
test
pmp-p Nov 25, 2024
d6fa341
wasi argv startup
pmp-p Nov 25, 2024
0d7a900
port address !!
pmp-p Nov 25, 2024
5ffce80
fix cma port replygit push
pmp-p Nov 25, 2024
af43290
fix cma base
pmp-p Nov 25, 2024
fe99ee9
wrong version
pmp-p Nov 25, 2024
e6d09e3
ts decl
pmp-p Nov 25, 2024
9721472
test
pmp-p Nov 25, 2024
c5cc5cd
test
pmp-p Nov 25, 2024
68e39a8
debug
pmp-p Nov 25, 2024
c9c5b37
get back real cma
pmp-p Nov 26, 2024
8393960
remove faulty patch
pmp-p Nov 26, 2024
23c9380
sync
pmp-p Nov 26, 2024
cc52f3c
sync
pmp-p Nov 26, 2024
3ac214a
Update sdk.sh
pmp-p Nov 26, 2024
84312f5
sync
pmp-p Nov 26, 2024
0495f2b
split
pmp-p Nov 26, 2024
1cff24a
Merge branch 'main' into wasi-merge
pmp-p Nov 26, 2024
ace67a0
fix sym
pmp-p Nov 26, 2024
53d407f
split the loops
pmp-p Nov 26, 2024
83b8e25
split
pmp-p Nov 26, 2024
76a7599
remove sym
pmp-p Nov 26, 2024
a0ed889
wasi split
pmp-p Nov 26, 2024
fad7d23
test split emsdk part
pmp-p Nov 26, 2024
0ed256d
sync + opt level
pmp-p Nov 26, 2024
11fa619
Merge remote-tracking branch 'origin/main' into wasi-merge
pmp-p Nov 28, 2024
53b97a6
dual build
pmp-p Nov 28, 2024
0c7f28e
wrong path
pmp-p Dec 4, 2024
1ada6a6
more checks, some dce
pmp-p Dec 6, 2024
4bb898d
more checks
pmp-p Dec 6, 2024
ee3df2f
move demo-site stage to own script
pmp-p Dec 6, 2024
e9ac698
test
pmp-p Dec 6, 2024
1d418e7
sync
pmp-p Dec 6, 2024
6e732f4
fence emsdk bin/* wrappers
pmp-p Dec 9, 2024
27e6050
lgtm
pmp-p Dec 9, 2024
d214b3f
move com and build patches to pglite layer
pmp-p Dec 9, 2024
562e6fd
test build against upstreaming 16x repo
pmp-p Dec 9, 2024
a24bec9
typo
pmp-p Dec 9, 2024
8f98d70
move conflicting patches away
pmp-p Dec 9, 2024
a5a1eb7
8e6af359aabdf0b687dfdb8e42b489fb7d27ce0a
pmp-p Dec 9, 2024
51b8d08
Osg3
pmp-p Dec 10, 2024
e8267c4
O3g0
pmp-p Dec 10, 2024
c1c762a
use sdk opt level
pmp-p Dec 10, 2024
1abfadf
use ubuntu docker image to run most build steps
Dec 16, 2024
6a11606
remove sudo
Dec 16, 2024
af8e16e
update before install
Dec 16, 2024
7e4e896
Revert "use ubuntu docker image to run most build steps"
Dec 16, 2024
d721d13
move wasi hotfix to correct place
pmp-p Dec 19, 2024
9b2870e
opt sdk -Os -g0
pmp-p Dec 20, 2024
072de11
turn off cma self test
pmp-p Dec 20, 2024
b3908b3
oops
pmp-p Dec 20, 2024
4edce29
O3g3
pmp-p Dec 20, 2024
a3e211e
sdk opt
pmp-p Dec 20, 2024
4fb8c75
missing export
pmp-p Dec 21, 2024
22bda7e
O2g3
pmp-p Dec 21, 2024
90789a4
only opt link pass
pmp-p Dec 21, 2024
c4efc80
remove clo
pmp-p Dec 21, 2024
6ee85a1
Os g3 -clo
pmp-p Dec 21, 2024
68834ad
O3 g0 -clo
pmp-p Dec 21, 2024
4365096
O2 g0 -clo
pmp-p Dec 21, 2024
6b0a8ea
Oz g0 -clo
pmp-p Dec 22, 2024
4be2cb8
flags
pmp-p Dec 22, 2024
38a4071
hybrid opt test
pmp-p Dec 22, 2024
6ff019e
hybrid opt test
pmp-p Dec 23, 2024
94117bb
osg0
pmp-p Dec 23, 2024
db4a14a
ci test
pmp-p Jan 2, 2025
03eecde
sdk check fix
pmp-p Jan 6, 2025
e8c5d16
sync
pmp-p Jan 6, 2025
22e4d57
Merge branch 'main' into wasi-merge
pmp-p Jan 6, 2025
bcceef7
Os g0 +clo
pmp-p Jan 6, 2025
c36a53a
O3 g0 -clo
pmp-p Jan 6, 2025
bb0db58
O3g0+c
pmp-p Jan 6, 2025
ab3531e
O2g0+c
pmp-p Jan 7, 2025
09784de
O3g0+c
pmp-p Jan 7, 2025
3ffb98d
O3g0-c
pmp-p Jan 7, 2025
c1c6069
O2g0+c
pmp-p Jan 7, 2025
df1aeac
workaround for closure
pmp-p Jan 8, 2025
3f34353
fixes for closure
pmp-p Jan 9, 2025
cf30d33
closure fixes
pmp-p Jan 9, 2025
18e95e3
end clo test
pmp-p Jan 9, 2025
b1ce14c
-c
pmp-p Jan 9, 2025
90e4480
force -c
pmp-p Jan 9, 2025
4a14476
O2g3-c
pmp-p Jan 9, 2025
db666de
O2g2-c
pmp-p Jan 9, 2025
9276a81
emsdk ci test
pmp-p Jan 12, 2025
a0967b9
Osg0+c
pmp-p Jan 13, 2025
da7d7d7
default to cma reply in wasi embed mode
pmp-p Jan 13, 2025
3ce0174
Merge branch 'main' into wasi-merge
pmp-p Jan 13, 2025
e13e734
resolve source dir either from checkout or submodule
pmp-p Jan 13, 2025
20f29d6
remove "upstreamed" ( postgres-pglite ) patches
pmp-p Jan 13, 2025
758f454
wasi loop control
pmp-p Jan 14, 2025
0385f04
opt test
pmp-p Jan 14, 2025
036ce01
remove opt
pmp-p Jan 14, 2025
c456252
wasi p1 cma loop (full wire)
pmp-p Jan 16, 2025
2c68d70
cma fullwire loop
pmp-p Jan 16, 2025
5b80f3a
Merge branch 'main' into wasi-merge
pmp-p Jan 16, 2025
25532b3
wire/socketfiles/repl wasi loop
pmp-p Jan 16, 2025
8a1d2b4
wasi loop optimal
pmp-p Jan 16, 2025
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
4 changes: 3 additions & 1 deletion .buildconfig
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
PG_VERSION=16.4
PG_VERSION=REL_16_STABLE
SDK_VERSION=3.1.74.2bi
WASI_SDK_VERSION=24.0.5
SDKROOT=/opt/python-wasm-sdk
PG_GIT_COMMIT=8e6af359aabdf0b687dfdb8e42b489fb7d27ce0a
COPTS="-O2 -g0"
2 changes: 1 addition & 1 deletion .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ jobs:

- name: Build demo site
run: |
NO_SDK_CHECK=true SDKROOT=/opt/python-wasm-sdk bash ./cibuild.sh demo-site
bash ./cibuild/demo-site.sh

- name: Build docs
working-directory: ./docs
Expand Down
9 changes: 7 additions & 2 deletions .github/workflows/build_wasm_postgres.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ jobs:
SDKROOT: /opt/python-wasm-sdk
SYS_PYTHON: /usr/bin/python3
PGROOT: /tmp/pglite
TOTAL_MEMORY: 128MB
TOTAL_MEMORY: 192MB
CMA_MB: 16
DEBUG: false
OBJDUMP: true
contrib: contrib
extra: extra
EXTRA_EXT: vector
DEBUG: false

steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -84,6 +84,11 @@ jobs:
run: |
bash ./cibuild.sh linkweb

- name: Build and Link postgres WASI for wasi/native
if: steps.cache-restore.outputs.cache-hit != 'true'
run: |
bash ./extra/native/wip.sh

- name: Copy release for PGlite build
run: |
bash ./cibuild.sh pglite-prep
Expand Down
119 changes: 75 additions & 44 deletions cibuild.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/bin/bash

#set -x;
#set -e;

# data transfer zone this is == (wire query size + result size ) + 2
# expressed in EMSDK MB
export CMA_MB=${CMA_MB:-64}
Expand All @@ -10,9 +13,8 @@ chmod +x ./extra/*.sh cibuild/*.sh

. .buildconfig

export PG_VERSION SDK_VERSION WASI_SDK_VERSION SDKROOT
export PG_VERSION SDK_VERSION WASI_SDK_VERSION SDKROOT COPTS

export PG_VERSION=${PG_VERSION:-16.4}
export WORKSPACE=${GITHUB_WORKSPACE:-$(pwd)}
export PGROOT=${PGROOT:-/tmp/pglite}
export WEBROOT=${WEBROOT:-/tmp/web}
Expand All @@ -30,10 +32,10 @@ EOE=false

if ./cibuild/sdk.sh
then
echo "sdk check passed (emscripten)"
echo "sdk check passed (emscripten+wasi)"
else
echo sdk failed
exit 44
exit 39
fi


Expand Down Expand Up @@ -82,8 +84,39 @@ System node/pnpm ( may interfer) :
if ${WASI:-false}
then
echo "Wasi build (experimental)"
. /opt/python-wasm-sdk/wasm32-wasi-shell.sh
export WASI_SDK=24.0
export WASI_SDK_PREFIX=/opt/python-wasm-sdk/wasisdk/wasi-sdk-${WASI_SDK}-x86_64-linux
export WASI_SYSROOT=${WASI_SDK_PREFIX}/share/wasi-sysroot

if [ -f ${WASI_SYSROOT}/extra ]
then
echo -n
else
pushd ${WASI_SYSROOT}
VMLABS="https://github.com/vmware-labs/webassembly-language-runtimes/releases/download"
wget -q "${VMLABS}/libs%2Flibpng%2F1.6.39%2B20230629-ccb4cb0/libpng-1.6.39-wasi-sdk-20.0.tar.gz" -O-| tar xfz -
wget -q "${VMLABS}/libs%2Fzlib%2F1.2.13%2B20230623-2993864/libz-1.2.13-wasi-sdk-20.0.tar.gz" -O-| tar xfz -
wget -q "${VMLABS}/libs%2Fsqlite%2F3.42.0%2B20230623-2993864/libsqlite-3.42.0-wasi-sdk-20.0.tar.gz" -O-| tar xfz -
wget -q "${VMLABS}/libs%2Flibxml2%2F2.11.4%2B20230623-2993864/libxml2-2.11.4-wasi-sdk-20.0.tar.gz" -O-| tar xfz -
wget -q "${VMLABS}/libs%2Fbzip2%2F1.0.8%2B20230623-2993864/libbzip2-1.0.8-wasi-sdk-20.0.tar.gz" -O-| tar xfz -
wget -q "${VMLABS}/libs%2Flibuuid%2F1.0.3%2B20230623-2993864/libuuid-1.0.3-wasi-sdk-20.0.tar.gz" -O-| tar xfz -
popd
touch ${WASI_SYSROOT}/extra
fi


if false
then
. /opt/python-wasm-sdk/wasisdk/wasisdk_env.sh
env|grep WASI
export CC=${WASI_SDK_DIR}/bin/clang
export CPP=${WASI_SDK_DIR}/bin/clang-cpp
export CXX=${WASI_SDK_DIR}/bin/clang++
export CFLAGS="-D_WASI_EMULATED_SIGNAL"
export LDFLAGS="-lwasi-emulated-signal"
else
. ${SDKROOT}/wasm32-wasi-shell.sh
fi
else
if which emcc
then
Expand Down Expand Up @@ -173,6 +206,8 @@ if $OBJDUMP
then
mkdir -p patches/imports patches/imports.pgcore
else
mkdir -p patches/imports
touch patches/imports/plpgsql
echo "

WARNING: wasm-objdump not found or OBJDUMP disabled, some extensions may not load properly
Expand Down Expand Up @@ -231,9 +266,10 @@ END
fi

mkdir -p ${PGROOT}/include/postgresql/server
cp ${PG_DEBUG_HEADER} ${PGROOT}/include/
cp ${PG_DEBUG_HEADER} ${PGROOT}/include/postgresql
cp ${PG_DEBUG_HEADER} ${PGROOT}/include/postgresql/server
for dest in ${PGROOT}/include ${PGROOT}/include/postgresql ${PGROOT}/include/postgresql/server
do
[ -f $dest/pg_debug.h ] || cp ${PG_DEBUG_HEADER} $dest/
done

# store all pg options that have impact on cmd line initdb/boot
cat > ${PGROOT}/pgopts.sh <<END
Expand Down Expand Up @@ -279,16 +315,23 @@ END
# to get same path for wasm shared link tools in the path
# for extensions building.
# we always symlink in-tree build to "postgresql" folder
if echo $PG_VERSION|grep -q ^16
if echo $PG_VERSION|grep -q git
then
. cibuild/pg-16.x.sh
else
echo "building from git"
. cibuild/pg-git.sh
else
echo " * building from stable repo"
. cibuild/pg-16.x.sh
fi

# install emsdk-shared along with pg config tool
# for building user ext.
cp build/postgres/bin/emsdk-shared $PGROOT/bin/
# # install emsdk-shared along with pg config tool
# # for building user ext.
# if [ -f $PGROOT/bin/emsdk-shared ]
# then
# echo emsdk-shared already installed
# else
# cp -vf build/postgres/bin/emsdk-shared $PGROOT/bin/
# fi

export PGLITE=$(pwd)/packages/pglite

Expand Down Expand Up @@ -318,14 +361,26 @@ export PATH=${WORKSPACE}/build/postgres/bin:${PGROOT}/bin:$PATH

if echo " $*"|grep -q " contrib"
then
# TEMP FIX for SDK
SSL_INCDIR=$EMSDK/upstream/emscripten/cache/sysroot/include/openssl
[ -f $SSL_INCDIR/evp.h ] || ln -s $PREFIX/include/openssl $SSL_INCDIR
SKIP="\

if $WASI
then
echo " ========= TODO WASI openssl ============== "
SKIP="\
[\
sslinfo bool_plperl hstore_plperl hstore_plpython jsonb_plperl jsonb_plpython\
ltree_plpython sepgsql bool_plperl start-scripts\
pgcrypto uuid-ossp xml2\
]"
else
# TEMP FIX for SDK
SSL_INCDIR=$EMSDK/upstream/emscripten/cache/sysroot/include/openssl
[ -f $SSL_INCDIR/evp.h ] || ln -s $PREFIX/include/openssl $SSL_INCDIR
SKIP="\
[\
sslinfo bool_plperl hstore_plperl hstore_plpython jsonb_plperl jsonb_plpython\
ltree_plpython sepgsql bool_plperl start-scripts\
]"
fi

for extdir in postgresql/contrib/*
do
Expand Down Expand Up @@ -479,19 +534,6 @@ ________________________________________________________________________________

mv $packed /tmp/sdk/pg${PG_VERSION}-${packed}

# for repl demo
# mkdir -p /tmp/web/pglite

#cp -r ${PGLITE}/dist ${WEBROOT}/pglite/
#cp -r ${PGLITE}/examples ${WEBROOT}/pglite/

# for dir in /tmp/web ${WEBROOT}/pglite/examples
# do
# pushd "$dir"
# cp ${PGLITE}/dist/postgres.data ./
# popd
# done

echo "<html>
<body>
<ul>
Expand All @@ -518,7 +560,7 @@ ________________________________________________________________________________
tar -cpRz ${PGROOT} > /tmp/sdk/pglite-pg${PG_VERSION}.tar.gz

# build sdk (node)
cp /tmp/sdk/postgres-${PG_VERSION}.tar.gz ${WEBROOT}/
cp /tmp/sdk/postgres-${PG_VERSION}-*.tar.gz ${WEBROOT}/

# pglite (web)
cp /tmp/sdk/pglite-pg${PG_VERSION}.tar.gz ${WEBROOT}/
Expand Down Expand Up @@ -560,18 +602,7 @@ ________________________________________________________________________________
;;

demo-site) echo "==================== demo-site =========================="
# Move all existing files to a subfolder
mkdir -p /tmp/web/x-term-repl
mv /tmp/web/* /tmp/web/x-term-repl/

mkdir -p /tmp/web/dist
mkdir -p /tmp/web/examples
mkdir -p /tmp/web/benchmark

PGLITE=$(pwd)/packages/pglite
cp -r ${PGLITE}/dist/* /tmp/web/dist/
cp -r ${PGLITE}/examples/* /tmp/web/examples/
cp -r ${WORKSPACE}/packages/benchmark/dist/* /tmp/web/benchmark/
./cibuild/demo-site.sh
;;
esac
shift
Expand Down
15 changes: 15 additions & 0 deletions cibuild/demo-site.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

# Move all existing files to a subfolder
mkdir -p /tmp/web/x-term-repl
mv /tmp/web/* /tmp/web/x-term-repl/

mkdir -p /tmp/web/dist
mkdir -p /tmp/web/examples
mkdir -p /tmp/web/benchmark

PGLITE=$(pwd)/packages/pglite
cp -r ${PGLITE}/dist/* /tmp/web/dist/
cp -r ${PGLITE}/examples/* /tmp/web/examples/
cp -r ${WORKSPACE:-$GITHUB_WORKSPACE}/packages/benchmark/dist/* /tmp/web/benchmark/

6 changes: 2 additions & 4 deletions cibuild/linkimports.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ echo "============= link imports : begin ==============="

pushd ${WORKSPACE}
> patches/imports/pgcore

for extra_pg_so in $(find $PGROOT/lib/postgresql/|grep \.so$)
do
SOBASE=patches/imports.pgcore/$(basename $extra_pg_so .so)
Expand Down Expand Up @@ -50,6 +51,7 @@ matches = list( imports.intersection(exports) )

# ?
for sym in """
_ErrorContext
_check_function_bodies
_clock_gettime
_CurrentMemoryContext
Expand All @@ -61,9 +63,7 @@ _interactive_read
_interactive_write
_lowerstr
_main
_main_repl
_pg_initdb
_pg_repl_raf
_pg_shutdown
_readstoplist
_searchstoplist
Expand All @@ -76,8 +76,6 @@ _TopMemoryContext
if sym and not sym in matches:
matches.append(sym)

#__ZNSt13runtime_errorD1Ev

matches.sort()

for sym in matches:
Expand Down
7 changes: 4 additions & 3 deletions cibuild/linkwasi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
. /opt/python-wasm-sdk/wasisdk/wasisdk_env.sh
# dlfcn emulation

WASI_CFLAGS="-DPATCH_PG_DEBUG=/tmp/pglite/include/pg_debug.h -DPREFIX=/tmp/pglite -DPYDK=1" wasi-c -fPIC \
WASI_CFLAGS="-DPATCH_PG_DEBUG=/tmp/pglite/include/pg_debug.h -DPREFIX=${PGROOT} -DPYDK=1" wasi-c -fPIC \
-Ipostgresql/src/include \
-Ipostgresql/src/backend \
-c -o build/postgres/wasi_dlfcn.o \
-Ibuild/postgres/src/include patches/wasi_dlfcn.c || exit 8
-Ibuild/postgres/src/include patches/wasi_dlfcn.c || exit 9

# -L./build/postgres/src/backend/snowball -ldict_snowball
# ./build/postgres/src/backend/snowball/dict_snowball.o
Expand Down Expand Up @@ -789,11 +789,12 @@ $CC -o postgres \
-Wl,--export=loop \
-Wl,--export=interactive_one \
-Wl,--export=use_socketfile \
-Wl,--export=use_wire \
-Wl,--export=interactive_write \
-Wl,--export=interactive_read \
-Wl,--global-base=33333333

cp -vf postgres postgres.wasi || exit 192
cp -vf postgres postgres.wasi || exit 796
#cp -vf postgres.wasi /tmp/pglite/bin/postgres.wasi

popd
8 changes: 4 additions & 4 deletions cibuild/linkweb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ pushd src/backend
if ${PGES6:-true}
then
# es6
MODULE="$LDEBUG --closure 0 -sMODULARIZE=1 -sEXPORT_ES6=1 -sEXPORT_NAME=Module"
export COPTS="-O2 -g0"
MODULE="$LDEBUG -sMODULARIZE=1 -sEXPORT_ES6=1 -sEXPORT_NAME=Module"
export COPTS=${COPTS:-"-O2 -g0"}
else
export COPTS="-O0 -g3"
export COPTS="-O2 -g3"
# local debug always fast build
MODULE="-sMODULARIZE=0 -sEXPORT_ES6=0"
fi
Expand Down Expand Up @@ -193,7 +193,7 @@ _________________________________________________________
# LINKER="-sMAIN_MODULE=1 -sEXPORTED_FUNCTIONS=@exports"


emcc $EMCC_WEB $LINKER $MODULE \
emcc $EMCC_WEB $LINKER $MODULE --closure 0 \
-sTOTAL_MEMORY=${TOTAL_MEMORY} -sSTACK_SIZE=4MB -sGLOBAL_BASE=${CMA_MB}MB \
-fPIC -D__PYDK__=1 -DPREFIX=${PGROOT} \
-sALLOW_TABLE_GROWTH -sALLOW_MEMORY_GROWTH -sERROR_ON_UNDEFINED_SYMBOLS -sASSERTIONS=0 \
Expand Down
7 changes: 5 additions & 2 deletions cibuild/pack_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ async def archive(target_folder):
if asp.startswith('/base/'):
continue

if asp.startswith('/dump.'):
continue

fp = PGROOT / asp[1:]
if fp.is_symlink():
continue
Expand Down Expand Up @@ -107,8 +110,8 @@ async def archive(target_folder):
print("="*80)

if not EXTNAME:
print("ERROR: no new installed extension found, is it builtin ?")
sys.exit(105)
print("MAYBE ERROR: no new installed extension found, is it builtin ?")
sys.exit(0)

print(f"""
PG installed in : {PGROOT=}
Expand Down
Loading