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

WIP: wasi-native #433

Open
wants to merge 72 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
72 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
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
9 changes: 6 additions & 3 deletions .buildconfig
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
PG_VERSION=16.4
SDK_VERSION=3.1.72.3bi
WASI_SDK_VERSION=24.0.4
PG_VERSION=git
SDK_VERSION=3.1.74.2bi
WASI_SDK_VERSION=24.0.5
SDKROOT=/opt/python-wasm-sdk
PG_GIT_COMMIT=8e6af359aabdf0b687dfdb8e42b489fb7d27ce0a
COPTS="-Os -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 postgis
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
71 changes: 34 additions & 37 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,7 +13,7 @@ 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)}
Expand All @@ -30,10 +33,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 @@ -231,9 +234,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 @@ -288,7 +292,12 @@ END

# install emsdk-shared along with pg config tool
# for building user ext.
cp build/postgres/bin/emsdk-shared $PGROOT/bin/
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 +327,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 +500,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 +526,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 +568,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
31 changes: 20 additions & 11 deletions cibuild/linkweb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ emcc $CDEBUG -shared -o ${WEBROOT}/libpgc.so \

# this override completely pg server main loop for web use purpose
pushd src
rm pg_initdb.o backend/main/main.o ./backend/tcop/postgres.o ./backend/utils/init/postinit.o
for obj in pg_initdb.o backend/main/main.o ./backend/tcop/postgres.o ./backend/utils/init/postinit.o
do
[ -f $obj ] && rm $obj
done

emcc -DPG_INITDB_MAIN=1 -sFORCE_FILESYSTEM -DPREFIX=${PGROOT} ${CC_PGLITE} \
-I${PGROOT}/include -I${PGROOT}/include/postgresql/server -I${PGROOT}/include/postgresql/internal \
Expand Down Expand Up @@ -94,17 +97,22 @@ pushd src/backend
# -sSINGLE_FILE => Uncaught SyntaxError: Cannot use 'import.meta' outside a module (at postgres.html:1:6033)
# -sENVIRONMENT=web => XHR

export EMCC_WEB="-sNO_EXIT_RUNTIME=1 -sFORCE_FILESYSTEM=1"
export EMCC_WEB="-sENVIRONMENT=node,web" -sNO_EXIT_RUNTIME=1 -sFORCE_FILESYSTEM=1"

if ${PGES6:-true}
then
# es6
MODULE="$LDEBUG --closure 0 -sMODULARIZE=1 -sEXPORT_ES6=1 -sEXPORT_NAME=Module"
export COPTS="-O2 -g0"
MODULE="$LDEBUG --closure 1 -sMODULARIZE=1 -sEXPORT_ES6=1 -sEXPORT_NAME=Module"
if $DEBUG
then
export COPTS=${COPTS:-"-O2 -g3"}
else
export COPTS=${COPTS:-"-Os -g0"}
fi
else
export COPTS="-O0 -g3"
export COPTS="-O2 -g3"
# local debug always fast build
MODULE="-sMODULARIZE=0 -sEXPORT_ES6=0"
MODULE="--closure 0 -sMODULARIZE=0 -sEXPORT_ES6=0"
fi

MODULE="$MODULE --shell-file ${WORKSPACE}/tests/repl.html"
Expand All @@ -113,8 +121,8 @@ pushd src/backend
# =======================================================
# size optimisations
# =======================================================

rm ${PGROOT}/lib/lib*.so.? 2>/dev/null
touch ${PGROOT}/lib/libany.so.x
rm ${PGROOT}/lib/lib*.so.?

echo "#!/bin/true" > placeholder
chmod +x placeholder
Expand All @@ -132,7 +140,8 @@ pushd src/backend

# encodings ?
# ./lib/postgresql/utf8_and*.so
rm ${PGROOT}/lib/postgresql/utf8_and*.so
touch ${PGROOT}/lib/postgresql/utf8_andany.so
rm -f ${PGROOT}/lib/postgresql/utf8_and*.so


# =========================================================
Expand Down Expand Up @@ -193,7 +202,7 @@ _________________________________________________________
# LINKER="-sMAIN_MODULE=1 -sEXPORTED_FUNCTIONS=@exports"


emcc $EMCC_WEB $LINKER $MODULE \
emcc $EMCC_WEB $LINKER $MODULE \
-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 Expand Up @@ -227,7 +236,7 @@ popd


echo "
============= link web : end ===============
============= link web : end COPTS=$COPTS ===============



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
2 changes: 1 addition & 1 deletion cibuild/pg-16.x.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ else
# either a submodule dir or a symlink.
# release only use symlink

rm postgresql 2>/dev/null
[ -f postgresql/configure ] && rm postgresql 2>/dev/null
ln -s postgresql-${PG_VERSION} postgresql

fi
Expand Down
Loading
Loading