From 51a5e0e354dcd98b24636be43065e6b0105996a4 Mon Sep 17 00:00:00 2001 From: pmp-p Date: Mon, 15 Jul 2024 08:51:50 +0200 Subject: [PATCH] move ecpg bits to static core --- cibuild/linkweb.sh | 20 +++++++++++++--- patches/pg_main.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+), 3 deletions(-) diff --git a/cibuild/linkweb.sh b/cibuild/linkweb.sh index 39c62f88..a2d33d8e 100755 --- a/cibuild/linkweb.sh +++ b/cibuild/linkweb.sh @@ -34,11 +34,12 @@ pushd src -c -o ../pg_initdb.o ${PGSRC}/src/bin/initdb/initdb.c $NOWARN || exit 34 # - emcc -DPG_LINK_MAIN=1 -DPREFIX=${PGROOT} ${CC_PGLITE} \ + emcc -DPG_LINK_MAIN=1 -DPREFIX=${PGROOT} ${CC_PGLITE} -DPG_EC_STATIC \ -I${PGROOT}/include -I${PGROOT}/include/postgresql/server -I${PGROOT}/include/postgresql/internal \ -c -o ./backend/tcop/postgres.o ${PGSRC}/src/backend/tcop/postgres.c $NOWARN|| exit 39 - EMCC_CFLAGS="${CC_PGLITE} -DPREFIX=${PGROOT} -DPG_INITDB_MAIN=1 $NOWARN" emmake make backend/main/main.o backend/utils/init/postinit.o || exit 41 + EMCC_CFLAGS="${CC_PGLITE} -DPREFIX=${PGROOT} -DPG_INITDB_MAIN=1 $NOWARN" \ + emmake make backend/main/main.o backend/utils/init/postinit.o || exit 41 popd @@ -80,8 +81,21 @@ then PG_L="$PG_L -L../../src/interfaces/ecpg/ecpglib ../../src/interfaces/ecpg/ecpglib/libecpg.so /tmp/libduckdb.so -lstdc++" else PG_L="$PG_L -L../../src/interfaces/ecpg/ecpglib ../../src/interfaces/ecpg/ecpglib/libecpg.so" + PG_L="../../src/common/libpgcommon_srv.a ../../src/port/libpgport_srv.a ../.././src/interfaces/libpq/libpq.a" + fi +# ../../src/common/libpgcommon_shlib.a" +# ./src/common/libpgcommon.a: binary file matches +# ./src/common/libpgcommon_shlib.a: binary file matches +# error: undefined symbol: fsync_pgdata (referenced by root reference (e.g. compiled C/C++ code)) +# error: undefined symbol: get_restricted_token (referenced by root reference (e.g. compiled C/C++ code)) +# error: undefined symbol: pg_malloc_extended (referenced by root reference (e.g. compiled C/C++ code)) +# error: undefined symbol: pg_realloc (referenced by root reference (e.g. compiled C/C++ code)) +# error: undefined symbol: pg_strdup (referenced by root reference (e.g. compiled C/C++ code)) +# error: undefined symbol: simple_prompt (referenced by root reference (e.g. compiled C/C++ code)) + + ## \ # /opt/python-wasm-sdk/devices/emsdk/usr/lib/libxml2.a \ @@ -206,7 +220,7 @@ emcc $EMCC_WEB -fPIC -sMAIN_MODULE=2 \ mkdir -p ${WEBROOT} cp -v postgres.* ${WEBROOT}/ -cp ${PGROOT}/lib/libecpg.so ${WEBROOT}/ +#cp ${PGROOT}/lib/libecpg.so ${WEBROOT}/ cp ${PGROOT}/sdk/*.tar ${WEBROOT}/ for tarf in ${WEBROOT}/*.tar do diff --git a/patches/pg_main.c b/patches/pg_main.c index bfb403b5..d16c91fc 100644 --- a/patches/pg_main.c +++ b/patches/pg_main.c @@ -1,6 +1,63 @@ #if defined(PG_MAIN) +#if defined(PG_EC_STATIC) +#warning "PG_EC_STATIC" + +EMSCRIPTEN_KEEPALIVE void +fsync_pgdata(const char *pg_data, int serverVersion) { + // stub +} + +EMSCRIPTEN_KEEPALIVE void +get_restricted_token(void) { + // stub +} + +EMSCRIPTEN_KEEPALIVE void * +pg_malloc(size_t size) +{ + return malloc(size); +} +EMSCRIPTEN_KEEPALIVE void * +pg_malloc_extended(size_t size, int flags) { + return malloc(size); +} + +EMSCRIPTEN_KEEPALIVE void * +pg_realloc(void *ptr, size_t size) { + return realloc(ptr, size); +} + +EMSCRIPTEN_KEEPALIVE char * +pg_strdup(const char *in) { + char *tmp; + + if (!in) + { + fprintf(stderr, + _("cannot duplicate null pointer (internal error)\n")); + exit(EXIT_FAILURE); + } + tmp = strdup(in); + if (!tmp) + { + fprintf(stderr, _("out of memory\n")); + exit(EXIT_FAILURE); + } + return tmp; +} + +EMSCRIPTEN_KEEPALIVE char * +simple_prompt(const char *prompt, bool echo) { + return pg_strdup(""); +} + + + +#endif + + bool is_node = false; bool is_repl = true;