Skip to content

Commit 2db55f9

Browse files
committed
test ci+wasi sdk
1 parent 8c35aeb commit 2db55f9

File tree

12 files changed

+147
-191
lines changed

12 files changed

+147
-191
lines changed

ci-alpine-proot.sh

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ then
106106
if $LOCAL
107107
then
108108
echo "TODO: start a test server for $PG_DIST_WEB"
109+
cp -vf ${CONTAINER_PATH}/tmp/pglite/bin/pg_dump.wasi ${PG_DIST_WEB}/bin/pg_dump.wasm
109110
else
110111
# gh pages publish
111112
PG_DIST_WEB=/tmp/web
@@ -126,8 +127,7 @@ then
126127
then
127128
echo "found postgres core static libraries in ${BUILD_PATH}"
128129
else
129-
echo "failed to build libpgcore static at ${BUILD_PATH}/libpgcore.a"
130-
exit 85
130+
echo "failed to build libpgcore static at ${BUILD_PATH}/libpgcore.a"; exit $LINENO
131131
fi
132132

133133
if [ -f pglite/packages/pglite/dist/pglite.wasm ]
@@ -144,6 +144,5 @@ then
144144
fi
145145
fi
146146
else
147-
echo "build failed"
148-
exit 148
147+
echo "build failed"; exit $LINENO
149148
fi

extra/pg_uuidv7.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,3 @@ pushd $PG_EXTRA/pg_uuidv7
2323
PG_CONFIG=${PGROOT}/bin/pg_config emmake make OPTFLAGS="" install || exit 25
2424
popd
2525

26-
read

pglite-REL_17_4_WASM/interactive_one.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ interactive_one() {
459459
peek = IO[0];
460460
packetlen = cma_rsize;
461461

462-
if (cma_rsize) {
462+
if (packetlen) {
463463
sockfiles = false;
464464
if (!is_repl) {
465465
whereToSendOutput = DestRemote;
@@ -472,7 +472,7 @@ interactive_one() {
472472
}
473473
} else {
474474
fp = fopen(PGS_IN, "r");
475-
PDEBUG("# 452:" PGS_IN "\n");
475+
puts("# 475:" PGS_IN "\r\n");
476476
// read file in socket buffer for SocketBackend to consumme.
477477
if (fp) {
478478
fseek(fp, 0L, SEEK_END);

pglite-REL_17_4_WASM/pg_proto.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -270,10 +270,11 @@ PDEBUG("# 259: EndImplicitTransactionBlock: pending");
270270
send_ready_for_query = true;
271271
}
272272
#if defined(PGL_LOOP)
273-
if (notifyInterruptPending)
273+
if (notifyInterruptPending) {
274274
PDEBUG("# 267: EndImplicitTransactionBlock: NOTIFICATION");
275-
else
275+
} else {
276276
PDEBUG("# 269: EndImplicitTransactionBlock: ok");
277+
}
277278
#endif
278279
break;
279280

@@ -306,10 +307,11 @@ else
306307
* it will fail to be called during other backend-shutdown
307308
* scenarios.
308309
*/
309-
if (sf_connected)
310+
if (sf_connected) {
310311
sf_connected--;
311-
else
312+
} else {
312313
PDEBUG("ERROR: more exits than connections");
314+
}
313315
PDEBUG("# 251:proc_exit/skip and repl stop"); //proc_exit(0);
314316
is_repl = false;
315317
ignore_till_sync = false;

pglite-REL_17_4_WASM/pgl_os.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
#pragma once
22

3-
// to override chmod()
4-
#include <sys/stat.h>
53

6-
extern int pg_chmod(const char * path, int mode_t);
7-
// initdb chmod is not supported by wasi, so just don't use it anywhere
8-
// #if defined(__wasi__)
9-
#define chmod(path, mode) pg_chmod(path, mode)
10-
//#endif
4+
#include <sys/stat.h>
115

126

137
#include <stdio.h> // FILE

pglite-REL_17_4_WASM/repl.html

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,7 @@
748748
}
749749
if (line.startsWith('!')){
750750
setTimeout(async()=> { await os.exec("pg_dump", "-U", "postgres", "--inserts", "-j", "1", "-v", "-c", "-C", "-f", "/tmp/out.sql", "--disable-dollar-quoting", "postgres") } , 0 )
751+
//setTimeout(async()=> { await os.exec("pg_dump", "host=/tmp/pglite/base sslmode=disable user=postgres dbname=template1") } , 0 )
751752
return
752753
}
753754

@@ -817,12 +818,12 @@
817818

818819
const { WasmTerminal } = await /**/ import("https://pmp-p.ddns.net/pglite-web/vtx.js")
819820

820-
Module.vt = new WasmTerminal("repl", 200, 60, 10)
821+
Module.vt = new WasmTerminal("repl", 200, 55, 16)
821822

822823
Module.bc = new BroadcastChannel("pglite")
823824

824825

825-
const pg_lck = "/tmp/pglite/base/.s.PGSQL.5432.lck.in"
826+
const pg_lck = "/tmp/pglite/base/.s.PGSQL.5432.lock.in"
826827
const pg_in = "/tmp/pglite/base/.s.PGSQL.5432.in"
827828
const pg_out = "/tmp/pglite/base/.s.PGSQL.5432.out"
828829

@@ -836,7 +837,7 @@
836837
FS.rename(pg_lck, pg_in)
837838
console.log("send_to_pglite(sf):", count)
838839
Module._interactive_one()
839-
if (os.FS.analyzePath(pg_in).exists) {
840+
if (os.FS.analyzePath(pg_out).exists) {
840841
const fstat = FS.stat(pg_out)
841842
console.log("pgreply", fstat.size)
842843
var stream = FS.open(pg_out, 'r');
@@ -953,14 +954,30 @@
953954
}
954955

955956
function os_sched_yield() {
957+
console.warn("--os_sched_yield--")
958+
const pg_lck = "/tmp/pglite/base/.s.PGSQL.5432.lock.in"
956959
const pg_in = "/tmp/pglite/base/.s.PGSQL.5432.in"
957960
const pg_out = "/tmp/pglite/base/.s.PGSQL.5432.out"
961+
962+
if (os.FS.analyzePath(pg_lck).exists) {
963+
os.FS.rename(pg_lck, pg_in)
964+
console.log("rename lock for send:", pg_lck,'->', pg_in)
965+
}
966+
958967
if (os.FS.analyzePath(pg_in).exists){
959968
// call interactive one
960-
const sf_data = os.FS.readFileSync(pg_in)
969+
vm._use_wire(1)
970+
vm._interactive_write(0)
971+
var sf_data = os.FS.readFileSync(pg_in)
972+
console.log("os_sched_yield/send_to_pglite(sf):", pg_in, sf_data.byteLength)
961973
vm._interactive_one()
962-
const fstat = vm.FS.stat(pg_out)
963-
console.log("socket file",sf_data.length, "pgreply", fstat.size)
974+
if (os.FS.analyzePath(pg_out).exists) {
975+
//sf_data = os.FS.readFileSync(pg_out)
976+
const fstat = os.FS.stat(pg_out)
977+
console.log("socket file", sf_data.length, "pgreply", fstat.size)
978+
} else {
979+
console.warn('no reply from server')
980+
}
964981
} else {
965982
console.log('sched_yield - no aio')
966983
}
@@ -1050,10 +1067,10 @@
10501067
globalThis.async_wasi_init = async_wasi_init
10511068

10521069

1053-
console.log("Using wasi : easywasi")
1070+
console.log("Using wasi : dinovm-wasm32_wasip1 (easywasi)")
10541071
console.log("---------------------")
10551072

1056-
import { WasiPreview1 } from 'easywasi'
1073+
import { wasm32_wasip1 } from 'easywasi'
10571074

10581075
async function os_exec(bin, ...stack) {
10591076
var kw = {PWD: '/'}
@@ -1066,7 +1083,7 @@
10661083
var argv= [bin]
10671084
argv.push(...stack)
10681085

1069-
var wasi = new WasiPreview1({
1086+
var wasi = new wasm32_wasip1({
10701087
fs: os.FS,
10711088
args: argv,
10721089
env: kw,
@@ -1093,6 +1110,8 @@
10931110
} catch (x) {
10941111
console.trace()
10951112
console.warn("abnormal program termination", x)
1113+
const dv = new DataView(app.instance.exports.memory.buffer)
1114+
ec = dv.getUint8(0);
10961115
}
10971116
console.log(`${bin} ${wasi.args} exit code = ${ec}`)
10981117
return ec

portable/wasi-sdk-25.tar.xz

4.04 MB
Binary file not shown.

wasm-build.sh

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,15 @@ else
7878
export LOPTS=${LOPTS:-"-O2 -g3 --no-wasm-opt -sASSERTIONS=1"}
7979

8080
else
81-
# docker debug ( exepected to be ide friendly )
81+
# docker debug ( expected to be ide friendly )
8282
export COPTS="-g3 --no-wasm-opt"
8383
export LOPTS=${LOPTS:-"-g3 --no-wasm-opt -sASSERTIONS=1"}
84+
# TODO: test those
85+
export COPTS="-O0 -sDEMANGLE_SUPPORT=1 -frtti -gsource-map --no-wasm-opt"
86+
export LOPTS=${LOPTS:-"-O0 -sDEMANGLE_SUPPORT=1 -frtti -gsource-map --no-wasm-opt -sASSERTIONS=1"}
87+
8488
fi
8589

86-
export COPTS="-O2 -sDEMANGLE_SUPPORT=1 -frtti -g4 --no-wasm-opt"
87-
export LOPTS=${LOPTS:-"-O1 -sDEMANGLE_SUPPORT=1 -frtti -g4 --no-wasm-opt -sASSERTIONS=1"}
8890

8991
else
9092
# DO NOT CHANGE COPTS - optimized wasm corruption fix
@@ -182,8 +184,7 @@ pushd ${SDKROOT}
182184
then
183185
echo "$PORTABLE : sdk check passed (emscripten)"
184186
else
185-
echo emsdk failed
186-
exit 181
187+
echo "emsdk failed"; exit $LINENO
187188
fi
188189

189190

@@ -208,6 +209,13 @@ popd
208209
# nb: wasi does not use -sGLOBAL_BASE
209210
export CC_PGLITE="-DPYDK=1 -DPG_PREFIX=${PGROOT} -I${PGROOT}/include -DCMA_MB=${CMA_MB}"
210211

212+
if $WASI
213+
then
214+
export WASI_CFLAGS="-D_WASI_EMULATED_PROCESS_CLOCKS -D_WASI_EMULATED_SIGNAL --target=wasm32-wasip1 -D__wasilibc_use_wasip1" # -mllvm -wasm-enable-sjlj"
215+
export CC_PGLITE="$WASI_CFLAGS $CC_PGLITE"
216+
fi
217+
218+
211219

212220

213221
echo "
@@ -282,8 +290,7 @@ END
282290
echo "
283291
ERROR: $(which wasm-objdump) not working properly ( is wasmtime ok ? )
284292
285-
"
286-
exit 281
293+
"; exit $LINENO
287294
fi
288295
fi
289296
fi
@@ -311,7 +318,7 @@ else
311318
#define I_PGDEBUG
312319
#define WASM_USERNAME "$PGUSER"
313320
#define PGDEBUG 1
314-
#define PDEBUG(string) fputs(string, stderr)
321+
#define PDEBUG(string) { fputs(string, stderr); fputs("\r\n", stderr); }
315322
#define JSDEBUG(string) {EM_ASM({ console.log(string); });}
316323
#define ADEBUG(string) { PDEBUG(string); JSDEBUG(string) }
317324
#endif
@@ -440,7 +447,14 @@ export PATH=${WORKSPACE}/${BUILD_PATH}/bin:${PGROOT}/bin:${HOST_PREFIX}/bin:$PAT
440447
# EXTENSIONS
441448

442449
cd ${WORKSPACE}
443-
. ./wasm-build/build-ext.sh
450+
if ./wasm-build/build-ext.sh
451+
then
452+
echo "
453+
contrib extensions built
454+
"
455+
else
456+
echo "some contrib extensions failed to build"; exit $LINENO
457+
fi
444458

445459
# ===========================================================================
446460
# ===========================================================================
@@ -529,13 +543,12 @@ then
529543
else
530544
if $CI
531545
then
532-
./runtests.sh || exit 515
546+
./runtests.sh || exit 539
533547
fi
534548
fi
535549
fi
536550
else
537-
echo "pglite linking failed"
538-
exit 657
551+
echo "pglite linking failed"; exit 544
539552
fi
540553
END
541554
chmod +x pglite-link.sh
@@ -553,7 +566,7 @@ END
553566
done
554567
fi
555568
else
556-
exit 539
569+
exit $LINENO
557570
fi
558571
fi
559572
else

wasm-build/build-ext.sh

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#!/bin/bash
2+
3+
SKIP_CONTRIB=${SKIP_CONTRIB:-false}
14

25
mkdir -p ${PGL_DIST_LINK}/exports ${PGL_DIST_LINK}/imports
36
cd ${WORKSPACE}
@@ -17,7 +20,7 @@ then
1720
ltree_plpython sepgsql bool_plperl start-scripts\
1821
pgcrypto uuid-ossp xml2\
1922
]"
20-
23+
SKIP_CONTRIB=true
2124
else
2225

2326
# TEMP FIX for SDK
@@ -32,6 +35,13 @@ else
3235
fi
3336

3437
# common wasi/emsdk contrib build
38+
if $SKIP_CONTRIB
39+
then
40+
echo "
41+
* skipping contrib build
42+
"
43+
exit 0
44+
fi
3545

3646
for extdir in postgresql-${PG_BRANCH}/contrib/*
3747
do

wasm-build/sdk.sh

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,32 @@ then
4848
wget -q "${VMLABS}/libs%2Flibxml2%2F2.11.4%2B20230623-2993864/libxml2-2.11.4-wasi-sdk-20.0.tar.gz" -O-| tar xfz -
4949
wget -q "${VMLABS}/libs%2Fbzip2%2F1.0.8%2B20230623-2993864/libbzip2-1.0.8-wasi-sdk-20.0.tar.gz" -O-| tar xfz -
5050
wget -q "${VMLABS}/libs%2Flibuuid%2F1.0.3%2B20230623-2993864/libuuid-1.0.3-wasi-sdk-20.0.tar.gz" -O-| tar xfz -
51+
cat > ./include/wasm32-wasi/__struct_sockaddr_un.h <<END
52+
#ifndef __wasilibc___struct_sockaddr_un_h
53+
#define __wasilibc___struct_sockaddr_un_h
54+
55+
#include <__typedef_sa_family_t.h>
56+
57+
struct sockaddr_un {
58+
__attribute__((aligned(__BIGGEST_ALIGNMENT__))) sa_family_t sun_family;
59+
char sun_path[108];
60+
};
61+
62+
#endif
63+
END
64+
65+
for level in p1 p2
66+
do
67+
cp -Rn lib/wasm32-wasi/* lib/wasm32-wasi${level}/
68+
cp include/wasm32-wasi/__struct_sockaddr_un.h include/wasm32-wasi${level}/__struct_sockaddr_un.h
69+
cp include/wasm32-wasi/sys/shm.h include/wasm32-wasi${level}/sys/shm.h
70+
cp include/wasm32-wasi/bits/shm.h include/wasm32-wasi${level}/bits/shm.h
71+
sed -i 's|extern FILE \*const stdin;|extern FILE \* stdin;|g' include/wasm32-wasi${level}/stdio.h
72+
sed -i 's|extern FILE \*const stdout;|extern FILE \* stdout;|g' include/wasm32-wasi${level}/stdio.h
73+
sed -i 's|extern FILE \*const stderr;|extern FILE \* stderr;|g' include/wasm32-wasi${level}/stdio.h
74+
75+
sed -i 's|int getrusage|//int getrusage|g' include/wasm32-wasi${level}/__header_sys_resource.h
76+
done
5177
popd
5278
touch ${WASI_SYSROOT}/extra
5379
fi
@@ -73,7 +99,23 @@ else
7399
}
74100
return resolved(...args);
75101
END
102+
# this one for debug mode and changing -Wl,--global-base= with -sGLOBAL_BASE
103+
patch -p1 <<END
104+
--- emsdk/upstream/emscripten/tools/link.py 2025-06-23 08:45:26.554013381 +0200
105+
+++ emsdk.fix/upstream/emscripten/tools/link.py 2025-06-23 08:45:31.445921560 +0200
106+
@@ -1662,7 +1662,7 @@
107+
# use a smaller LEB encoding).
108+
# However, for debugability is better to have the stack come first
109+
# (because stack overflows will trap rather than corrupting data).
110+
- settings.STACK_FIRST = True
111+
+ settings.STACK_FIRST = False
112+
113+
if state.has_link_flag('--stack-first'):
114+
settings.STACK_FIRST = True
115+
END
116+
76117
popd
118+
77119
fi
78120

79121

0 commit comments

Comments
 (0)