diff --git a/build-pglite.sh b/build-pglite.sh index 3500a9dc1ebee..8c12c1c78676e 100755 --- a/build-pglite.sh +++ b/build-pglite.sh @@ -7,13 +7,15 @@ # final output folder INSTALL_FOLDER=${INSTALL_FOLDER:-"/install/pglite"} +PGLITE_CFLAGS="-D__PGLITE__" # build with optimizations by default aka release -PGLITE_CFLAGS="-O2" if [ "$DEBUG" = true ] then echo "pglite: building debug version." - PGLITE_CFLAGS="-g -gsource-map --no-wasm-opt" + # -sDYLINK_DEBUG=2 + PGLITE_CFLAGS="$PGLITE_CFLAGS -g -gsource-map --no-wasm-opt" else + PGLITE_CFLAGS="$PGLITE_CFLAGS -O2" echo "pglite: building release version." # we shouldn't need to do this, but there's a bug somewhere that prevents a successful build if this is set unset DEBUG @@ -50,12 +52,31 @@ PGLITE_EMSCRIPTEN_FLAGS="-sWASM_BIGINT \ -sTOTAL_MEMORY=32MB \ --embed-file $(pwd)/other/PGPASSFILE@/home/web_user/.pgpass" +CONFIGURE_PARAMS="\ +ac_cv_exeext=.js \ +--host aarch64-unknown-linux-gnu \ +--disable-spinlocks \ +--disable-largefile \ +--without-llvm \ +--without-pam \ +--with-openssl=no \ +--without-readline \ +--without-icu \ +--with-uuid=ossp \ +--with-zlib \ +--with-libxml \ +--with-libxslt \ +--with-template=emscripten \ +--with-includes=$INSTALL_PREFIX/include:$INSTALL_PREFIX/include/libxml2:$(pwd)/pglite/includes \ +--with-libraries=$INSTALL_PREFIX/lib \ +--prefix=$INSTALL_FOLDER" + # Step 1: configure the project if [ "$RUN_CONFIGURE" = true ]; then LDFLAGS="-sWASM_BIGINT -sUSE_PTHREADS=0" \ LDFLAGS_SL="-sSIDE_MODULE=1" \ LDFLAGS_EX=$PGLITE_EMSCRIPTEN_FLAGS \ - 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=.js --host aarch64-unknown-linux-gnu --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:$(pwd)/pglite/includes --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; } + 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 $CONFIGURE_PARAMS || { echo 'error: emconfigure failed' ; exit 11; } else echo "Warning: configure has not been run because RUN_CONFIGURE=${RUN_CONFIGURE}" fi @@ -65,11 +86,17 @@ emmake make PORTNAME=emscripten -j || { echo 'error: emmake make PORTNAME=emscri emmake make PORTNAME=emscripten install || { echo 'error: emmake make PORTNAME=emscripten install' ; exit 22; } # Step 3.1: make all contrib extensions - do not install +# Step 3.1.1 pgcrypto - special case +cd ./pglite/ && ./build-pgcrypto.sh && cd ../ +# Step 3.1.2 all the rest of contrib emmake make PORTNAME=emscripten -C contrib/ -j || { echo 'error: emmake make PORTNAME=emscripten -C contrib/ -j' ; exit 31; } # Step 3.2: make dist contrib extensions - this will create an archive for each extension emmake make PORTNAME=emscripten -C contrib/ dist || { echo 'error: emmake make PORTNAME=emscripten -C contrib/ dist' ; exit 32; } # the above will also create a file with the imports that each extension needs - we pass these as input in the next step for emscripten to keep alive +# hack for pgcrypto. since we're linking lssl and lcrypto directly to the extension, their respective symbols should not be exported +find / -name pgcrypto.imports -exec rm -f {} \; + # Step 4: make and dist other extensions SAVE_PATH=$PATH PATH=$PATH:$INSTALL_FOLDER/bin @@ -87,5 +114,20 @@ PGLITE_EMSCRIPTEN_FLAGS="-sWASM_BIGINT \ -sEXPORT_NAME=Module -sALLOW_TABLE_GROWTH -sALLOW_MEMORY_GROWTH \ -sERROR_ON_UNDEFINED_SYMBOLS=0 \ -sEXPORTED_RUNTIME_METHODS=$EXPORTED_RUNTIME_METHODS" + +PGROOT=/install/pglite +PGLITE_PRELOAD="\ +--preload-file ${PGROOT}/share/postgresql@/tmp/pglite/share/postgresql \ +--preload-file ${PGROOT}/lib/postgresql@/tmp/pglite/lib/postgresql \ +--preload-file $(pwd)/other/password@/tmp/pglite/password \ +--preload-file $(pwd)/other/PGPASSFILE@/home/web_user/.pgpass \ +--preload-file $(pwd)/other/empty@/tmp/pglite/bin/postgres \ +--preload-file $(pwd)/other/empty@/tmp/pglite/bin/initdb" + +PGLITE_EMSCRIPTEN_LIBS="-lnodefs.js -lidbfs.js" +EXPORTED_FUNCTIONS="-sEXPORTED_FUNCTIONS=@/tmp/exported_functions.txt" + +# -sDYLINK_DEBUG=2 use this for debugging missing exported symbols (ex when an extension calls a pgcore function that hasn't been exported) + # 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. -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; } +PGLITE_FLAGS="$PGLITE_CFLAGS $PGLITE_EMSCRIPTEN_FLAGS $PGLITE_PRELOAD $PGLITE_EMSCRIPTEN_LIBS $EXPORTED_FUNCTIONS" emmake make PORTNAME=emscripten -j -C src/backend/ install-pglite || { echo 'emmake make OPTFLAGS="" PORTNAME=emscripten -j -C pglite' ; exit 51; } diff --git a/build-with-docker.sh b/build-with-docker.sh index 6a849b52ab863..1f92c727a4dcb 100755 --- a/build-with-docker.sh +++ b/build-with-docker.sh @@ -3,11 +3,12 @@ DOCKER_WORKSPACE=$(pwd) docker run $@ \ + --name pglite-builder \ --rm \ -e DEBUG=${DEBUG:-false} \ --workdir=${DOCKER_WORKSPACE} \ -v .:${DOCKER_WORKSPACE}:rw \ -v ./dist:/install/pglite:rw \ - electricsql/pglite-builder:3.1.74_2 \ + electricsql/pglite-builder:3.1.74_4 \ ./build-pglite.sh diff --git a/contrib/Makefile b/contrib/Makefile index 603636cd4d248..ec0e4c7fa84ea 100644 --- a/contrib/Makefile +++ b/contrib/Makefile @@ -57,6 +57,10 @@ else ALWAYS_SUBDIRS += pgcrypto sslinfo endif +ifeq ($(PORTNAME), emscripten) +SUBDIRS += pgcrypto +endif + ifneq ($(with_uuid),no) SUBDIRS += uuid-ossp else diff --git a/contrib/pgcrypto/Makefile b/contrib/pgcrypto/Makefile index 8085114dca6c2..5efa10c334c80 100644 --- a/contrib/pgcrypto/Makefile +++ b/contrib/pgcrypto/Makefile @@ -62,9 +62,6 @@ endif # shared library link. (The order in which you list them here doesn't # matter.) SHLIB_LINK += $(filter -lcrypto -lz, $(LIBS)) -ifeq ($(PORTNAME), emscripten) -SHLIB_LINK += -lcrypto -endif ifeq ($(PORTNAME), win32) SHLIB_LINK += $(filter -leay32, $(LIBS)) # those must be at the end diff --git a/pglite-wasm/builder/Dockerfile b/pglite-wasm/builder/Dockerfile index cf613dd2ddc85..8bcf3c6bb6aa3 100644 --- a/pglite-wasm/builder/Dockerfile +++ b/pglite-wasm/builder/Dockerfile @@ -22,7 +22,7 @@ WORKDIR /install/libs WORKDIR /src # 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" -ENV EMCC_COMMON_FLAGS="-O2 -fPIC" +ENV EMCC_COMMON_FLAGS="-O2 -fPIC -sWASM_BIGINT" WORKDIR /src RUN curl -L https://www.zlib.net/zlib-1.3.1.tar.gz | tar -xz @@ -34,7 +34,7 @@ RUN ${LLVM_NM} /install/libs/lib/libz.a | awk '$2 ~ /^[TDB]$/ {print $3}' | sed WORKDIR /src RUN curl -L https://gitlab.gnome.org/GNOME/libxml2/-/archive/v2.14.5/libxml2-v2.14.5.tar.gz | tar -xz WORKDIR /src/libxml2-v2.14.5 -RUN ./autogen.sh --with-python=no +RUN ./autogen.sh --with-python=no --with-threads=no RUN CFLAGS="${EMCC_COMMON_FLAGS}" CXXFLAGS="${EMCC_COMMON_FLAGS}" emconfigure ./configure --enable-shared=no --enable-static=yes --with-python=no --prefix=/install/libs RUN emmake make -j && emmake make install # extract exported symbols - useful for passing them to emscripten as EXPORTED_FUNCTIONS @@ -52,11 +52,12 @@ RUN ${LLVM_NM} /install/libs/lib/libxslt.a | awk '$2 ~ /^[TDB]$/ {print $3}' | s WORKDIR /src RUN curl -L https://github.com/openssl/openssl/releases/download/openssl-3.0.17/openssl-3.0.17.tar.gz | tar xz WORKDIR /src/openssl-3.0.17 -RUN emconfigure ./Configure no-tests linux-generic64 --prefix=/install/libs +RUN CFLAGS="${EMCC_COMMON_FLAGS}" CXXFLAGS="${EMCC_COMMON_FLAGS}" emconfigure ./config no-sse2 no-hw no-asm no-tests no-threads no-shared linux-generic32 --prefix=/install/libs RUN sed -i 's|^CROSS_COMPILE.*$|CROSS_COMPILE=|g' Makefile # see https://github.com/emscripten-core/emscripten/issues/19597#issue-1754476454 -RUN emmake make -j && emmake make install +RUN emmake make -j && emmake make install_sw install_ssldirs # extract exported symbols - useful for passing them to emscripten as EXPORTED_FUNCTIONS RUN ${LLVM_NM} /install/libs/lib/libssl.a | awk '$2 ~ /^[TDB]$/ {print $3}' | sed '/^$/d' | sort -u > /install/exports/libssl.exports +RUN ${LLVM_NM} /install/libs/lib/libcrypto.a | awk '$2 ~ /^[TDB]$/ {print $3}' | sed '/^$/d' | sort -u > /install/exports/libcrypto.exports WORKDIR /src RUN curl -L ftp://ftp.ossp.org/pkg/lib/uuid/uuid-1.6.2.tar.gz | tar xz diff --git a/pglite-wasm/included.pglite.imports b/pglite-wasm/included.pglite.imports index 7a5d30d895111..179eedc72ac62 100644 --- a/pglite-wasm/included.pglite.imports +++ b/pglite-wasm/included.pglite.imports @@ -1,33 +1,179 @@ +__errno_location +abort +accept +appendStringInfo +appendStringInfoChar +appendStringInfoString +atexit +atoi +bind +BuildTupleFromCStrings +calloc +chmod +clearerr +clock_gettime close +closedir +closelog +connect +cstring_to_text +cstring_to_text_with_len +deconstruct_array_builtin +dladdr +dlclose +dlerror +dlopen +dlsym +downcase_truncate_identifier +end_MultiFuncCall +enlargeStringInfo +errcode +errfinish +errmsg +errmsg_internal +errstart +errstart_cold +fclose fcntl +fdopen +feof +ferror +fflush +fgets +fileno +fiprintf +fopen +fputc +fputs +fread free +freeaddrinfo +fseek +fstat +ftell +fwrite +gai_strerror +gen_random_uuid +get_call_result_type +getaddrinfo +GetDatabaseEncoding +getegid +getenv +geteuid +getgid +gethostbyname +getnameinfo getpid +getsockname +getsockopt gettimeofday +getuid gmtime +HeapTupleHeaderGetDatum +init_MultiFuncCall +initStringInfo interactive_one ioctl isalnum isxdigit +listen lowerstr +lseek +madvise main malloc +memchr memcmp memcpy +memmove +MemoryContextAlloc +MemoryContextAllocZero memset +mlock +mmap +mprotect +munmap nanosleep +ntohs open +opendir +openlog +palloc +palloc0 +per_MultiFuncCall +perror +pfree +pg_any_to_server +pg_detoast_datum +pg_detoast_datum_packed +pg_do_encoding_conversion +pg_is_ascii +pg_strcasecmp +pg_strong_random +pg_vsnprintf pgl_backend pgl_initdb pgl_shutdown +ProcessInterrupts +pstrdup +puts +qsort rand read +readdir readstoplist realloc +recvfrom +repalloc +ResourceOwnerEnlarge +ResourceOwnerForget +ResourceOwnerRemember searchstoplist +select +sendto set_read_write_cbs +setbuf +setsockopt +shutdown +sigaction +signal +siprintf +sleep +snprintf socket srand +sscanf +stat +stderr +strcat +strchr strcmp +strcpy +strcspn +strdup +strerror +strerror_r strftime +strlcpy strlen -strtoul \ No newline at end of file +strncat +strncmp +strncpy +strrchr +strspn +strstr +strtol +strtoul +sysconf +syslog +tcgetattr +tcsetattr +text_to_cstring +text_to_cstring_buffer +time +tolower +TupleDescGetAttInMetadata +usleep +vfprintf +vsnprintf +write \ No newline at end of file diff --git a/pglite-wasm/interactive_one.c b/pglite-wasm/interactive_one.c index c520e2d149c74..acf6a6114f3fb 100644 --- a/pglite-wasm/interactive_one.c +++ b/pglite-wasm/interactive_one.c @@ -304,7 +304,7 @@ interactive_one(int packetlen, int peek) { } incoming: -#if defined(__EMSCRIPTEN__) || defined(__wasi__) //PGDEBUG +#if defined(__PGLITE__) //PGDEBUG # include "pgl_sjlj.c" #else #error "sigsetjmp unsupported" diff --git a/pglite-wasm/pg_main.c b/pglite-wasm/pg_main.c index bbfa698606dcb..553061fc97ed9 100644 --- a/pglite-wasm/pg_main.c +++ b/pglite-wasm/pg_main.c @@ -1,6 +1,6 @@ // for handling REVOKE exception in initdb -#if defined(__wasi__) || defined(__EMSCRIPTEN__) +#if defined(__PGLITE__) # define FIXME 1 #else # define FIXME 0 @@ -26,7 +26,7 @@ #include /* chdir */ #include /* mkdir */ -#if defined(__EMSCRIPTEN__) +#if defined(__PGLITE__) #include #endif @@ -151,7 +151,7 @@ main_pre(int argc, char *argv[]) { -#if defined(__EMSCRIPTEN__) +#if defined(__PGLITE__) EM_ASM( { Module.is_worker = (typeof WorkerGlobalScope !== 'undefined') && self instanceof WorkerGlobalScope; Module.FD_BUFFER_MAX = $0; Module.emscripten_copy_to = console.warn;} // tdrz: what is FD_BUFFER_MAX? @@ -212,7 +212,7 @@ main_pre(int argc, char *argv[]) { }; }); // *INDENT-ON* -#endif // __EMSCRIPTEN__ +#endif // __PGLITE__ chdir("/"); mkdirp("/tmp"); mkdirp(PREFIX); @@ -313,17 +313,12 @@ main_post() { * variables installed by pg_perm_setlocale have force. */ unsetenv("LC_ALL"); -} // main_post +}// main_post +void pgl_backend() { -__attribute__ ((export_name("pgl_backend"))) - void pgl_backend() { -#if PGDEBUG - print_bits(sizeof(pgl_idb_status), &pgl_idb_status); -#endif if (!(pgl_idb_status & IDB_CALLED)) { puts("# 336: initdb must be called before starting/resuming backend"); - //abort(); } if (async_restart) { @@ -377,8 +372,6 @@ __attribute__ ((export_name("pgl_backend"))) #endif setenv("PGUSER", PGUSER, 1); - - AsyncPostgresSingleUserMain(single_argc, single_argv, PGUSER, async_restart); @@ -394,15 +387,9 @@ __attribute__ ((export_name("pgl_backend"))) puts("# 403: initdb done, oid base too low but OID range will be set because IsPostmasterEnvironment"); #endif } - } +} -#if defined(__EMSCRIPTEN__) - EMSCRIPTEN_KEEPALIVE -#else - __attribute__ ((export_name("pgl_initdb"))) -#endif - int pgl_initdb() { - PDEBUG("# 412: pg_initdb()"); +int pgl_initdb() { optind = 1; pgl_idb_status |= IDB_FAILED; @@ -414,29 +401,15 @@ __attribute__ ((export_name("pgl_backend"))) /* assume auth success for now */ pgl_idb_status |= IDB_HASUSER; -#if PGDEBUG - fprintf(stdout, "# 427: pg_initdb: db exists at : %s TODO: test for db name : %s \n", PGDATA, getenv("PGDATABASE")); -#endif // PGDEBUG async_restart = 0; goto initdb_done; } chdir("/"); -#if PGDEBUG - fprintf(stderr, "# 435: pg_initdb no db found at : %s\n", PGDATA); -#endif // PGDEBUG - } else { -#if PGDEBUG - fprintf(stderr, "# 439: pg_initdb db folder not found at : %s\n", PGDATA); -#endif // PGDEBUG } int initdb_rc = pgl_initdb_main(); -#if PGDEBUG - fprintf(stderr, "\n\n# 444: " __FILE__ "pgl_initdb_main = %d\n", initdb_rc); -#endif // PGDEBUG - PDEBUG("# 448:" __FILE__); /* save stdin and use previous initdb output to feed boot mode */ int saved_stdin = dup(STDIN_FILENO); { @@ -459,52 +432,19 @@ __attribute__ ((export_name("pgl_backend"))) optind = 1; BootstrapModeMain(boot_argc, boot_argv, false); fclose(stdin); -#if PGDEBUG - puts("BOOT FILE:"); - puts(IDB_PIPE_BOOT); -#else + remove(IDB_PIPE_BOOT); -#endif + // tdrz: I've commented this out!!! // stdin = fdopen(saved_stdin, "r"); PDEBUG("# 479: initdb faking shutdown to complete WAL/OID states"); pg_proc_exit(66); } - - /* use previous initdb output to feed single mode */ - - /* or resume a previous db */ - //IsPostmasterEnvironment = true; - if (TransamVariables->nextOid < ((Oid) FirstNormalObjectId)) { -#if PGDEBUG - puts("# 482: warning oid base too low, will need to set OID range after initdb(bootstrap/single)"); -#endif - } -/* - { -#if PGDEBUG - fprintf(stdout, "\n\n\n# 483: restarting in single mode for initdb with user '%s' instead of %s\n", getenv("PGUSER"), PGUSER); -#endif - char *single_argv[] = { - WASM_PREFIX "/bin/postgres", - "--single", - "-d", "1", "-B", "16", "-S", "512", "-f", "siobtnmh", - "-D", PGDATA, - "-F", "-O", "-j", - WASM_PGOPTS, - "template1", - NULL - }; - int single_argc = sizeof(single_argv) / sizeof(char*) - 1; - optind = 1; - RePostgresSingleUserMain(single_argc, single_argv, WASM_USERNAME); -PDEBUG("# 498: initdb faking shutdown to complete WAL/OID states in single mode"); - async_restart = 1; - } -*/ + async_restart = 1; - initdb_done:; + +initdb_done:; pgl_idb_status |= IDB_CALLED; if (optind > 0) { @@ -517,7 +457,7 @@ PDEBUG("# 498: initdb faking shutdown to complete WAL/OID states in single mode" // TODO raise js exception } return pgl_idb_status; -} // pgl_initdb +} diff --git a/pglite/build-pgcrypto.sh b/pglite/build-pgcrypto.sh new file mode 100755 index 0000000000000..58c1bc56a60d6 --- /dev/null +++ b/pglite/build-pgcrypto.sh @@ -0,0 +1,6 @@ +#!/bin/bash +pushd ../contrib/pgcrypto +# these flags are used in pgxs.mk (postgresql extension makefile) and passed to the build process of that extension +emmake make LDFLAGS_SL="-sWASM_BIGINT -sSIDE_MODULE=1 -fexceptions -Wl,--whole-archive -lssl -lcrypto -Wl,--no-whole-archive" CFLAGS_SL="$PGLITE_CFLAGS -fexceptions -sWASM_BIGINT" -j +# emmake make PORTNAME=emscripten dist +popd diff --git a/pglite/includes/pglite-comm.h b/pglite/includes/pglite-comm.h index 2a84cbf406d2e..27c1860ee8563 100644 --- a/pglite/includes/pglite-comm.h +++ b/pglite/includes/pglite-comm.h @@ -1,4 +1,4 @@ -#if defined(__EMSCRIPTEN__) +#if defined(__PGLITE__) #ifndef PGLITE_COMM_H #define PGLITE_COMM_H diff --git a/src/backend/Makefile b/src/backend/Makefile index 1c04efeab0099..357d785a288ac 100644 --- a/src/backend/Makefile +++ b/src/backend/Makefile @@ -81,8 +81,6 @@ LIBPGMAIN = libpgmain.a PGCORE = $(top_builddir)/src/common/libpgcommon_srv.a $(top_builddir)/src/port/libpgport_srv.a $(LIBPG) PGMAIN = main/main.o tcop/postgres.o PGLITE_MAIN = pglite-wasm/pg_main.c -PGROOT=/install/pglite -PGPRELOAD=--preload-file ${PGROOT}/share/postgresql@/tmp/pglite/share/postgresql --preload-file ${PGROOT}/lib/postgresql@/tmp/pglite/lib/postgresql --preload-file $(top_builddir)/other/password@/tmp/pglite/password --preload-file $(top_builddir)/other/PGPASSFILE@/home/web_user/.pgpass --preload-file $(top_builddir)/other/empty@/tmp/pglite/bin/postgres --preload-file $(top_builddir)/other/empty@/tmp/pglite/bin/initdb postgres: $(OBJS) $(AR) rcs $(LIBPGMAIN) $(PGMAIN) $(AR) rcs $(LIBPG) $(filter-out $(PGMAIN),$(call expand_subsys,$(ONLYOBJS))) @@ -94,50 +92,27 @@ postgres: $(OBJS) # The following target gathers all extension imports + the default ones (included.pglite.imports), # excludes the one in excluded.pglite.imports and adds a leading _ to each. pglite-exported-functions: - $(MKDIR_P) '$(emscripten_imports_dir)' cat $(top_builddir)/pglite-wasm/excluded.*.imports $(top_builddir)/src/interfaces/libpq/exports.list $(LIB_EXPORTS_DIR)/libossp-uuid.exports | sort -u > '$(top_builddir)/pglite-wasm/excluded.imports' cat $(DESTDIR)$(emscripten_extension_imports_dir)/*.imports '$(top_builddir)/pglite-wasm/included.pglite.imports' | \ sort -u | \ grep -Fvx -f '$(top_builddir)/pglite-wasm/excluded.imports' | \ sed 's/^/_/' \ - > '$(emscripten_imports_dir)/exported_functions.txt' + > '/tmp/exported_functions.txt' -# -sDYLINK_DEBUG=2 use this for debugging missing exported symbols (ex when an extension calls a pgcore function that hasn't been exported) -# PGLITE_CFLAGS is something like "-O2" (aka release version) or "-g -gsource-map --no-wasm-opt" (aka debug version) -# PGLITE_EMSCRIPTEN_FLAGS are the emscripten flags to be passed to the build. Ideally they would be completely transparent, such that we -# could build a libpglite with or without those flags (to switch between native and wasm builds) pglite: pglite-exported-functions $(CC) $(CFLAGS) $(LDFLAGS) -DPG_PREFIX=/tmp/pglite -I$(top_builddir)/src/include -I$(top_builddir)/src/ -I$(top_builddir)/src/interfaces/libpq -o pglite.o -c $(top_builddir)/$(PGLITE_MAIN) -Wno-incompatible-pointer-types-discards-qualifiers $(CC) \ - $(PGLITE_CFLAGS) \ - -fPIC -m32 -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 \ - -DPG_PREFIX=/tmp/pglite -o pglite.html \ - $(PGPRELOAD) \ - -ferror-limit=1 \ - -sEXPORTED_FUNCTIONS=@$(emscripten_imports_dir)/exported_functions.txt \ - -I./src/include -I./src/ -I./src/interfaces/libpq \ - -L/install/libs/lib -L$(top_builddir) -L$(top_builddir)/src/interfaces/libpq/ -L. \ - pglite.o \ - -Ldict_snowball \ - -lxslt \ - -lpgcore \ - -lnodefs.js -lidbfs.js -lxml2 -lz -endif - -ifeq ($(PORTNAME), wasi) -AR ?= llvm-ar -LIBPGCORE ?= $(top_builddir)/libpgcore.a -LIBPG = $(top_builddir)/libpostgres.a -PGCORE = $(top_builddir)/src/common/libpgcommon_srv.a $(top_builddir)/src/port/libpgport_srv.a $(LIBPG) -PGMAIN = main/main.o tcop/postgres.o -postgres: $(OBJS) - $(AR) rcs $(top_builddir)/libpgmain.a $(PGMAIN) - $(AR) rcs $(LIBPG) $(filter-out $(PGMAIN),$(call expand_subsys,$(ONLYOBJS))) - $(CC) -r -o $(top_builddir)/libpgcore.o -Wl,--whole-archive $(PGCORE) - $(AR) rcs $(LIBPGCORE) $(top_builddir)/libpgcore.o - COPTS="$(LOPTS)" $(CC) $(MAIN_MODULE) $(CFLAGS) $(LDFLAGS) -nostartfiles -o $@ $(LIBPGCORE) $(top_builddir)/libpgmain.a $(LIBS) - mv $@ $@.wasi - touch $@ + $(PGLITE_FLAGS) \ + -DPG_PREFIX=/tmp/pglite \ + -o pglite.html \ + -ferror-limit=1 \ + -I./src/include -I./src/ -I./src/interfaces/libpq \ + -L/install/libs/lib -L$(top_builddir) -L$(top_builddir)/src/interfaces/libpq/ -L. \ + pglite.o \ + -Ldict_snowball \ + -lxslt \ + -lpgcore \ + -lxml2 -lz endif ifeq ($(PORTNAME), cygwin) diff --git a/src/backend/access/nbtree/nbtutils.c b/src/backend/access/nbtree/nbtutils.c index 5c5061fbc709a..aaaded57ceca4 100644 --- a/src/backend/access/nbtree/nbtutils.c +++ b/src/backend/access/nbtree/nbtutils.c @@ -5163,7 +5163,7 @@ _bt_allequalimage(Relation rel, bool debugmessage) break; } } -#if !defined(__EMSCRIPTEN__) +#if !defined(__PGLITE__) if (debugmessage) { if (allequalimage) diff --git a/src/backend/access/transam/xact.c b/src/backend/access/transam/xact.c index 1c9dfc10184d0..c72596ad2001f 100644 --- a/src/backend/access/transam/xact.c +++ b/src/backend/access/transam/xact.c @@ -2805,7 +2805,7 @@ AbortTransaction(void) * handler. We do this fairly early in the sequence so that the timeout * infrastructure will be functional if needed while aborting. */ -#if !defined(__EMSCRIPTEN__) && !defined(__wasi__) +#if !defined(__PGLITE__) sigprocmask(SIG_SETMASK, &UnBlockSig, NULL); #endif @@ -5214,7 +5214,7 @@ AbortSubTransaction(void) * handler. We do this fairly early in the sequence so that the timeout * infrastructure will be functional if needed while aborting. */ -#if !defined(__EMSCRIPTEN__) && !defined(__wasi__) +#if !defined(__PGLITE__) sigprocmask(SIG_SETMASK, &UnBlockSig, NULL); #endif diff --git a/src/backend/bootstrap/bootstrap.c b/src/backend/bootstrap/bootstrap.c index 8b226b212f5b3..1ec43afff6375 100644 --- a/src/backend/bootstrap/bootstrap.c +++ b/src/backend/bootstrap/bootstrap.c @@ -195,7 +195,7 @@ CheckerModeMain(void) * to shared memory sizing, options work (or at least do not cause an error * up to shared memory creation). */ -#if !defined(__EMSCRIPTEN__) && !defined(__wasi__) +#if !defined(__PGLITE__) void #else int @@ -369,7 +369,7 @@ BootstrapModeMain(int argc, char *argv[], bool check_only) /* Clean up and exit */ cleanup(); -#if !defined(__EMSCRIPTEN__) && !defined(__wasi__) +#if !defined(__PGLITE__) proc_exit(0); #else puts("# 338 cleanup(boot): " __FILE__); diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index 225be70358437..7b26ffc060b0c 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -2967,7 +2967,7 @@ index_build(Relation heapRelation, indexInfo->ii_ParallelWorkers = plan_create_index_workers(RelationGetRelid(heapRelation), RelationGetRelid(indexRelation)); -#if !defined(__EMSCRIPTEN__) +#if !defined(__PGLITE__) if (indexInfo->ii_ParallelWorkers == 0) ereport(DEBUG1, (errmsg_internal("building index \"%s\" on table \"%s\" serially", diff --git a/src/backend/commands/async.c b/src/backend/commands/async.c index 172692281bc29..6879f5ff95149 100644 --- a/src/backend/commands/async.c +++ b/src/backend/commands/async.c @@ -1651,7 +1651,7 @@ SignalBackends(void) * NotifyQueueLock; which is unlikely but certainly possible. So we * just log a low-level debug message if it happens. */ -#if defined(__EMSCRIPTEN__) || defined(__wasi__) +#if defined(__PGLITE__) HandleNotifyInterrupt(); #else if (SendProcSignal(pid, PROCSIG_NOTIFY_INTERRUPT, procnos[i]) < 0) diff --git a/src/backend/commands/dbcommands.c b/src/backend/commands/dbcommands.c index 9db4495facea3..a098f26d997af 100644 --- a/src/backend/commands/dbcommands.c +++ b/src/backend/commands/dbcommands.c @@ -1834,7 +1834,7 @@ dropdb(const char *dbname, bool missing_ok, bool force) RequestCheckpoint(CHECKPOINT_IMMEDIATE | CHECKPOINT_FORCE | CHECKPOINT_WAIT); /* Close all smgr fds in all backends. */ -#if !defined(__wasi__) && !defined(__EMSCRIPTEN__) +#if !defined(__PGLITE__) WaitForProcSignalBarrier(EmitProcSignalBarrier(PROCSIGNAL_BARRIER_SMGRRELEASE)); #endif /* diff --git a/src/backend/commands/event_trigger.c b/src/backend/commands/event_trigger.c index a84cf281c5906..fab948b7ff65e 100644 --- a/src/backend/commands/event_trigger.c +++ b/src/backend/commands/event_trigger.c @@ -723,7 +723,7 @@ EventTriggerDDLCommandStart(Node *parsetree) List *runlist; EventTriggerData trigdata; -#if !defined(__EMSCRIPTEN__) && !defined(__wasi__) +#if !defined(__PGLITE__) /* * Event Triggers are completely disabled in standalone mode. There are * (at least) two reasons for this: @@ -778,7 +778,7 @@ EventTriggerDDLCommandEnd(Node *parsetree) { List *runlist; EventTriggerData trigdata; -#if !defined(__EMSCRIPTEN__) && !defined(__wasi__) +#if !defined(__PGLITE__) /* * See EventTriggerDDLCommandStart for a discussion about why event * triggers are disabled in single user mode or via GUC. @@ -829,7 +829,7 @@ EventTriggerSQLDrop(Node *parsetree) { List *runlist; EventTriggerData trigdata; -#if !defined(__EMSCRIPTEN__) && !defined(__wasi__) +#if !defined(__PGLITE__) /* * See EventTriggerDDLCommandStart for a discussion about why event * triggers are disabled in single user mode or via a GUC. @@ -905,7 +905,7 @@ EventTriggerOnLogin(void) { List *runlist; EventTriggerData trigdata; -#if !defined(__EMSCRIPTEN__) && !defined(__wasi__) +#if !defined(__PGLITE__) /* * See EventTriggerDDLCommandStart for a discussion about why event * triggers are disabled in single user mode or via a GUC. We also need a @@ -1019,7 +1019,7 @@ EventTriggerTableRewrite(Node *parsetree, Oid tableOid, int reason) { List *runlist; EventTriggerData trigdata; -#if !defined(__EMSCRIPTEN__) && !defined(__wasi__) +#if !defined(__PGLITE__) /* * See EventTriggerDDLCommandStart for a discussion about why event * triggers are disabled in single user mode or via a GUC. diff --git a/src/backend/libpq/be-secure.c b/src/backend/libpq/be-secure.c index b2e9260e8b1a6..61a32b6b9db5d 100644 --- a/src/backend/libpq/be-secure.c +++ b/src/backend/libpq/be-secure.c @@ -32,7 +32,7 @@ #include "tcop/tcopprot.h" #include "utils/wait_event.h" -#if defined(__EMSCRIPTEN__) +#if defined(__PGLITE__) #include "pglite-comm.h" #endif diff --git a/src/backend/port/posix_sema.c b/src/backend/port/posix_sema.c index f7d5e2b2007f2..3803044f19891 100644 --- a/src/backend/port/posix_sema.c +++ b/src/backend/port/posix_sema.c @@ -298,7 +298,7 @@ PGSemaphoreReset(PGSemaphore sema) * There's no direct API for this in POSIX, so we have to ratchet the * semaphore down to 0 with repeated trywait's. */ -#if defined(__EMSCRIPTEN__) || defined(__wasi__) +#if defined(__PGLITE__) sem_trywait(PG_SEM_REF(sema)); return; #else diff --git a/src/backend/postmaster/checkpointer.c b/src/backend/postmaster/checkpointer.c index f8e3f4ed102c6..1f8e83a825b56 100644 --- a/src/backend/postmaster/checkpointer.c +++ b/src/backend/postmaster/checkpointer.c @@ -947,7 +947,7 @@ RequestCheckpoint(int flags) /* * If in a standalone backend, just do it ourselves. */ -#if !defined(__wasi__) && !defined(__EMSCRIPTEN__) +#if !defined(__wasi__) && !defined(__PGLITE__) if (!IsPostmasterEnvironment) #endif { diff --git a/src/backend/storage/file/fd.c b/src/backend/storage/file/fd.c index d7a35c655773d..18721abc05e02 100644 --- a/src/backend/storage/file/fd.c +++ b/src/backend/storage/file/fd.c @@ -524,7 +524,7 @@ pg_file_exists(const char *name) void pg_flush_data(int fd, off_t offset, off_t nbytes) { -#if defined(__EMSCRIPTEN__) || defined(__wasi__) +#if defined(__PGLITE__) //int res = sync_file_range(fd, offset, nbytes, SYNC_FILE_RANGE_WAIT_BEFORE | SYNC_FILE_RANGE_WRITE | SYNC_FILE_RANGE_WAIT_AFTER); (void)fsync(fd); // fprintf(stderr, "# pg_flush_data(int fd=%d, off_t offset=%lld, off_t nbytes=%lld res=%d\n", fd,offset,nbytes, res); @@ -2678,7 +2678,7 @@ OpenTransientFilePerm(const char *fileName, int fileFlags, mode_t fileMode) return -1; /* failure */ } -#if !defined(__EMSCRIPTEN__) && !defined(__wasi__) +#if !defined(__PGLITE__) /* * Routines that want to initiate a pipe stream should use OpenPipeStream * rather than plain popen(). This lets fd.c deal with freeing FDs if diff --git a/src/backend/storage/ipc/ipc.c b/src/backend/storage/ipc/ipc.c index 89f9e7355e80e..db2be0fe9a56e 100644 --- a/src/backend/storage/ipc/ipc.c +++ b/src/backend/storage/ipc/ipc.c @@ -103,7 +103,7 @@ static int on_proc_exit_index, void proc_exit(int code) { -#if defined(__EMSCRIPTEN__) || defined(__wasi__) +#if defined(__PGLITE__) if (code==66) { fprintf(stderr,"# 108:fake shutdown\n"); proc_exit_inprogress = true; @@ -405,7 +405,7 @@ before_shmem_exit(pg_on_exit_callback function, Datum arg) void on_shmem_exit(pg_on_exit_callback function, Datum arg) { -#if defined(__wasi__) || defined(__EMSCRIPTEN__) +#if defined(__PGLITE__) if (!atexit_callback_setup) { PDEBUG("# 410:" __FILE__ " on_shmem_exit(pg_on_exit_callback function, Datum arg) FIRST CALL"); if (on_shmem_exit_index >= MAX_ON_EXITS) { diff --git a/src/backend/storage/ipc/procsignal.c b/src/backend/storage/ipc/procsignal.c index f4f73b0652ab4..49422db9212b2 100644 --- a/src/backend/storage/ipc/procsignal.c +++ b/src/backend/storage/ipc/procsignal.c @@ -416,7 +416,7 @@ WaitForProcSignalBarrier(uint64 generation) (errmsg("still waiting for backend with PID %d to accept ProcSignalBarrier", (int) slot->pss_pid))); oldval = pg_atomic_read_u64(&slot->pss_barrierGeneration); -#if defined(__EMSCRIPTEN__) || defined(__wasi__) +#if defined(__PGLITE__) break; #endif } diff --git a/src/backend/storage/ipc/signalfuncs.c b/src/backend/storage/ipc/signalfuncs.c index 2db7ccfa5edb7..8df2f32997da2 100644 --- a/src/backend/storage/ipc/signalfuncs.c +++ b/src/backend/storage/ipc/signalfuncs.c @@ -98,7 +98,7 @@ pg_signal_backend(int pid, int sig) */ /* If we have setsid(), signal the backend's whole process group */ -#if defined(__EMSCRIPTEN__) || defined(__wasi__) +#if defined(__PGLITE__) # if PGDEBUG printf("# 103: FIXME: kill(pid=%d, sig=%d) ", pid, sig); # endif diff --git a/src/backend/storage/ipc/sinvaladt.c b/src/backend/storage/ipc/sinvaladt.c index 396d491204a80..1eccbe95c4fbb 100644 --- a/src/backend/storage/ipc/sinvaladt.c +++ b/src/backend/storage/ipc/sinvaladt.c @@ -288,7 +288,7 @@ SharedInvalBackendInit(bool sendOnly) * set hasMessages appropriately. */ LWLockAcquire(SInvalWriteLock, LW_EXCLUSIVE); -#if defined(__EMSCRIPTEN__) || defined(__wasi__) +#if defined(__PGLITE__) (void)oldPid; #else oldPid = stateP->procPid; diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 7f1b5faa2b713..47198a1979a59 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -307,7 +307,7 @@ InitProcess(void) elog(PANIC, "proc header uninitialized"); if (MyProc != NULL) -#if defined(__wasi__) || defined(__EMSCRIPTEN__) +#if defined(__PGLITE__) elog(WARNING, "# 309: you already exist"); #else elog(ERROR, "# 309: you already exist"); diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c index a9bfd973eb12e..c9914f965ab92 100644 --- a/src/backend/tcop/postgres.c +++ b/src/backend/tcop/postgres.c @@ -107,7 +107,7 @@ int client_connection_check_interval = 0; /* flags for non-system relation kinds to restrict use */ int restrict_nonsystem_relation_kind; -#if (defined(__EMSCRIPTEN__) || defined(__wasi__)) +#if (defined(__PGLITE__)) bool quote_all_identifiers = false; #endif // WASM diff --git a/src/backend/tcop/utility.c b/src/backend/tcop/utility.c index 1b17405ae4f9f..a06155a9b5157 100644 --- a/src/backend/tcop/utility.c +++ b/src/backend/tcop/utility.c @@ -804,7 +804,7 @@ standard_ProcessUtility(PlannedStmt *pstmt, ListenStmt *stmt = (ListenStmt *) parsetree; CheckRestrictedOperation("LISTEN"); -#if !defined(__EMSCRIPTEN__) && !defined(__wasi__) +#if !defined(__PGLITE__) /* * We don't allow LISTEN in background processes, as there is * no mechanism for them to collect NOTIFY messages, so they'd diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c index 2699e31c1e02c..73d2c000f79bb 100644 --- a/src/backend/utils/adt/ruleutils.c +++ b/src/backend/utils/adt/ruleutils.c @@ -321,7 +321,7 @@ static SPIPlanPtr plan_getviewrule = NULL; static const char *const query_getviewrule = "SELECT * FROM pg_catalog.pg_rewrite WHERE ev_class = $1 AND rulename = $2"; /* GUC parameters */ -#if !defined(__EMSCRIPTEN__) && !defined(__wasi__) +#if !defined(__PGLITE__) bool quote_all_identifiers = false; #endif diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c index dcd1ea8f050ed..db13a64fd885d 100644 --- a/src/backend/utils/error/elog.c +++ b/src/backend/utils/error/elog.c @@ -348,7 +348,7 @@ errstart(int elevel, const char *domain) ErrorData *edata; bool output_to_server; bool output_to_client = false; -#if defined(__EMSCRIPTEN__) || defined(__wasi__) +#if defined(__PGLITE__) # warning "FIXME: error levels" #else int i; @@ -506,6 +506,9 @@ errfinish(const char *filename, int lineno, const char *funcname) matches_backtrace_functions(edata->funcname)) set_backtrace(edata, 2); + #if defined(__PGLITE__) + # warning "FIXME: error levels" + #else /* * Call any context callback functions. Errors occurring in callback * functions will be treated as recursive errors --- this ensures we will @@ -515,7 +518,8 @@ errfinish(const char *filename, int lineno, const char *funcname) econtext != NULL; econtext = econtext->previous) econtext->callback(econtext->arg); - + + #endif /* * If ERROR (not more nor less) we pass it off to the current handler. * Printing it and popping the stack is the responsibility of the handler. @@ -591,7 +595,7 @@ errfinish(const char *filename, int lineno, const char *funcname) * FATAL termination. The postmaster may or may not consider this * worthy of panic, depending on which subprocess returns it. */ -#if defined(__EMSCRIPTEN__) || defined(__wasi__) +#if defined(__PGLITE__) puts("# 600: proc_exit(FATAL) ignored\r\n"); #else proc_exit(1); diff --git a/src/backend/utils/init/miscinit.c b/src/backend/utils/init/miscinit.c index 0590684a85980..15c251a9cf09c 100644 --- a/src/backend/utils/init/miscinit.c +++ b/src/backend/utils/init/miscinit.c @@ -375,7 +375,7 @@ checkDataDir(void) * * XXX can we safely enable this check on Windows? */ -#if !defined(WIN32) && !defined(__CYGWIN__) && !defined(__EMSCRIPTEN__) && !defined(__wasi__) +#if !defined(WIN32) && !defined(__CYGWIN__) && !defined(__PGLITE__) if (stat_buf.st_uid != geteuid()) ereport(FATAL, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), @@ -395,7 +395,7 @@ checkDataDir(void) * be proper support for Unix-y file permissions. Need to think of a * reasonable check to apply on Windows. */ -#if !defined(WIN32) && !defined(__CYGWIN__) && !defined(__EMSCRIPTEN__) && !defined(__wasi__) +#if !defined(WIN32) && !defined(__CYGWIN__) && !defined(__PGLITE__) if (stat_buf.st_mode & PG_MODE_MASK_GROUP) ereport(FATAL, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), @@ -416,7 +416,7 @@ checkDataDir(void) * Suppress when on Windows, because there may not be proper support for * Unix-y file permissions. */ -#if !defined(WIN32) && !defined(__CYGWIN__) && !defined(__EMSCRIPTEN__) && !defined(__wasi__) +#if !defined(WIN32) && !defined(__CYGWIN__) && !defined(__PGLITE__) SetDataDirectoryCreatePerm(stat_buf.st_mode); umask(pg_mode_mask); diff --git a/src/backend/utils/init/postinit.c b/src/backend/utils/init/postinit.c index dc94e69b2ef95..6bb83dddfb437 100644 --- a/src/backend/utils/init/postinit.c +++ b/src/backend/utils/init/postinit.c @@ -898,12 +898,12 @@ puts("# 766:"__FILE__); } else if (!IsUnderPostmaster) { -#if defined(__EMSCRIPTEN__) || defined(__wasi__) +#if defined(__PGLITE__) if (!strcmp( username , WASM_USERNAME )) { #endif InitializeSessionUserIdStandalone(); am_superuser = true; -#if defined(__EMSCRIPTEN__) || defined(__wasi__) +#if defined(__PGLITE__) } else { //puts("# 894: switching session id"); InitializeSessionUserId(username, InvalidOid, false); diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c index ea076bf59903a..990dc7a2043c6 100644 --- a/src/backend/utils/misc/guc.c +++ b/src/backend/utils/misc/guc.c @@ -2647,7 +2647,7 @@ ReportGUCOption(struct config_generic *record) pq_sendstring(&msgbuf, val); pq_endmessage(&msgbuf); -#ifndef __EMSCRIPTEN__ +#ifndef __PGLITE__ /* * We need a long-lifespan copy. If guc_strdup() fails due to OOM, * we'll set last_reported to NULL and thereby possibly make a diff --git a/src/backend/utils/misc/timeout.c b/src/backend/utils/misc/timeout.c index 980a7de8ebf8d..806d2638b73b0 100644 --- a/src/backend/utils/misc/timeout.c +++ b/src/backend/utils/misc/timeout.c @@ -116,7 +116,7 @@ static void insert_timeout(TimeoutId id, int index) { int i; -#if defined(__EMSCRIPTEN__) || defined(__wasi__) +#if defined(__PGLITE__) if (!insert_timeout_warned) //(index<0) { insert_timeout_warned = true; diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c index eb4699868b44e..e20c726b44c29 100644 --- a/src/bin/initdb/initdb.c +++ b/src/bin/initdb/initdb.c @@ -815,7 +815,7 @@ cleanup_directories_atexit(void) static char * get_id(void) { -#if !defined(__EMSCRIPTEN__) && !defined(__wasi__) +#if !defined(__PGLITE__) const char *username; #ifndef WIN32 @@ -1079,7 +1079,7 @@ set_null_conf(void) static const char * choose_dsm_implementation(void) { -#if defined(__wasi__) || defined(__EMSCRIPTEN__) +#if defined(__PGLITE__) return "posix"; #endif #if defined(HAVE_SHM_OPEN) && !defined(__sun__) @@ -1245,14 +1245,14 @@ test_specific_config_settings(int test_conns, int test_buffs) DEVNULL, DEVNULL); fflush(NULL); - #if defined(__EMSCRIPTEN__) + #if defined(__PGLITE__) // emscripten supports (some?) syscalls, but that's not actually what we want, because we want to remain inside the wasm sandbox // so just return a dummy value until we decide how to handle syscalls. // TODO: https://github.com/electric-sql/pglite/issues/798 status = 123; #else status = system(cmd.data); - #endif // #if defined(__EMSCRIPTEN__) + #endif // #if defined(__PGLITE__) termPQExpBuffer(&cmd); @@ -2653,7 +2653,7 @@ setup_bin_paths(const char *argv0) strlcpy(full_path, progname, sizeof(full_path)); if (ret == -1) -#if defined(__EMSCRIPTEN__) || defined(__wasi__) +#if defined(__PGLITE__) printf("# WARNING: program \"%s\" is needed by %s but was not found in the same directory as \"%s\"\n", "postgres", progname, full_path); #else @@ -3476,7 +3476,7 @@ printf("# 3245:" __FILE__ " calling pg_initdb_main for %s\n", progname); if (icu_rules && locale_provider != COLLPROVIDER_ICU) pg_fatal("%s cannot be specified unless locale provider \"%s\" is chosen", "--icu-rules", "icu"); -#if defined(__wasi__) || defined(__EMSCRIPTEN__) +#if defined(__PGLITE__) #pragma message "#TODO: atexit(cleanup_directories_atexit)" PDEBUG("# 3472:"__FILE__ "#TODO: atexit(cleanup_directories_atexit)"); #endif diff --git a/src/bin/pg_config/pg_config.c b/src/bin/pg_config/pg_config.c index 1fc3e6298d532..77368b8d14392 100644 --- a/src/bin/pg_config/pg_config.c +++ b/src/bin/pg_config/pg_config.c @@ -152,7 +152,7 @@ main(int argc, char **argv) if (find_my_exec(argv[0], my_exec_path) < 0) { fprintf(stderr, _("%s: could not find own program executable\n"), progname); -#if !defined(__EMSCRIPTEN__) && !defined(__wasi__) +#if !defined(__PGLITE__) exit(1); #endif } diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 22699405a2ef6..c7f853e41a845 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -69,7 +69,7 @@ #include "pg_dump.h" #include "storage/block.h" -#if defined(__EMSCRIPTEN__) +#if defined(__PGLITE__) #include #endif @@ -347,7 +347,7 @@ static bool forcePartitionRootLoad(const TableInfo *tbinfo); static void read_dump_filters(const char *filename, DumpOptions *dopt); int -#if defined(__EMSCRIPTEN__) +#if defined(__PGLITE__) EMSCRIPTEN_KEEPALIVE #endif main(int argc, char **argv) diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c index 27bdf2baf02b4..0ac1fc5dcdfe7 100644 --- a/src/bin/pg_dump/pg_dumpall.c +++ b/src/bin/pg_dump/pg_dumpall.c @@ -14,7 +14,7 @@ */ #include "postgres_fe.h" -#if !defined(__EMSCRIPTEN__) && !defined(__wasi__) +#if !defined(__PGLITE__) #ifdef quote_all_identifiers #undef quote_all_identifiers #endif diff --git a/src/bin/pg_resetwal/pg_resetwal.c b/src/bin/pg_resetwal/pg_resetwal.c index ebfe9256a819f..eccf33d7d61a8 100644 --- a/src/bin/pg_resetwal/pg_resetwal.c +++ b/src/bin/pg_resetwal/pg_resetwal.c @@ -334,7 +334,7 @@ main(int argc, char *argv[]) * -- any other user won't have sufficient permissions to modify files in * the data directory. */ -#if !defined(WIN32) && !defined(__EMSCRIPTEN__) && !defined(__wasi__) +#if !defined(WIN32) && !defined(__PGLITE__) if (geteuid() == 0) { pg_log_error("cannot be executed by \"root\""); diff --git a/src/include/bootstrap/bootstrap.h b/src/include/bootstrap/bootstrap.h index a48899dca4e40..4e0729a2888a8 100644 --- a/src/include/bootstrap/bootstrap.h +++ b/src/include/bootstrap/bootstrap.h @@ -32,7 +32,7 @@ extern PGDLLIMPORT Relation boot_reldesc; extern PGDLLIMPORT Form_pg_attribute attrtypes[MAXATTR]; extern PGDLLIMPORT int numattr; -#if defined(__EMSCRIPTEN__) || defined(__wasi__) +#if defined(__PGLITE__) int BootstrapModeMain(int argc, char *argv[], bool check_only); #else extern void BootstrapModeMain(int argc, char *argv[], bool check_only) pg_attribute_noreturn(); diff --git a/src/include/fmgr.h b/src/include/fmgr.h index 7c960bcc4af68..f4289426636a9 100644 --- a/src/include/fmgr.h +++ b/src/include/fmgr.h @@ -505,10 +505,6 @@ PG_MAGIC_FUNCTION_NAME(void) \ return &Pg_magic_data; \ } \ extern int no_such_variable -#if defined(__wasi__) && !defined(__EMSCRIPTEN__) -#undef PG_MODULE_MAGIC -#define PG_MODULE_MAGIC -#endif /*------------------------------------------------------------------------- * Support routines and macros for callers of fmgr-compatible functions diff --git a/src/include/port/sdk_port.h b/src/include/port/sdk_port.h index 7e6b178dce493..19c438aa6199a 100644 --- a/src/include/port/sdk_port.h +++ b/src/include/port/sdk_port.h @@ -1,4 +1,4 @@ -#if defined(__EMSCRIPTEN__) +#if defined(__PGLITE__) #include #elif defined(__wasi__) @@ -258,5 +258,5 @@ extern ssize_t recvfrom_bc(int socket, void *buffer, size_t length, int flags, v #endif // I_WASI #else - #error "unknown port mode should be __EMSCRIPTEN__ or __wasi__" -#endif // __EMSCRIPTEN__ + #error "unknown port mode should be __PGLITE__" +#endif // __PGLITE__ diff --git a/src/include/storage/dsm_impl.h b/src/include/storage/dsm_impl.h index 5246c84161b75..99f1b780df045 100644 --- a/src/include/storage/dsm_impl.h +++ b/src/include/storage/dsm_impl.h @@ -23,7 +23,7 @@ * Determine which dynamic shared memory implementations will be supported * on this platform, and which one will be the default. */ -#if 0 // defined(__wasi__) || defined(__EMSCRIPTEN__) +#if 0 // defined(__PGLITE__) #define DEFAULT_DYNAMIC_SHARED_MEMORY_TYPE DSM_IMPL_SYSV #define USE_DSM_SYSV extern PGDLLIMPORT int dynamic_shared_memory_type; @@ -31,7 +31,7 @@ #define PG_DYNSHMEM_DIR "/tmp/pglite" #define PG_DYNSHMEM_MMAP_FILE_PREFIX "mmap." -#elif 0 // defined(__wasi__) || defined(__EMSCRIPTEN__) +#elif 0 // defined(__PGLITE__) #define DEFAULT_DYNAMIC_SHARED_MEMORY_TYPE DSM_IMPL_MMAP #define USE_DSM_MMAP extern PGDLLIMPORT int dynamic_shared_memory_type; @@ -39,7 +39,7 @@ #define PG_DYNSHMEM_DIR "/tmp/pglite" #define PG_DYNSHMEM_MMAP_FILE_PREFIX "mmap." -#elif defined(__wasi__) || defined(__EMSCRIPTEN__) +#elif defined(__PGLITE__) #define DEFAULT_DYNAMIC_SHARED_MEMORY_TYPE DSM_IMPL_POSIX #define USE_DSM_POSIX extern PGDLLIMPORT int dynamic_shared_memory_type; @@ -63,7 +63,7 @@ # endif #define USE_DSM_MMAP -#endif /* defined(__wasi__) || defined(__EMSCRIPTEN__) */ +#endif /* defined(__PGLITE__) */ diff --git a/src/include/storage/ipc.h b/src/include/storage/ipc.h index d5aebb72dc15b..95f8010141167 100644 --- a/src/include/storage/ipc.h +++ b/src/include/storage/ipc.h @@ -64,7 +64,7 @@ typedef void (*shmem_startup_hook_type) (void); /* ipc.c */ extern PGDLLIMPORT bool proc_exit_inprogress; extern PGDLLIMPORT bool shmem_exit_inprogress; -#if defined(__EMSCRIPTEN__) || defined(__wasi__) +#if defined(__PGLITE__) extern void pg_proc_exit(int code); #else extern void proc_exit(int code) pg_attribute_noreturn(); diff --git a/src/include/utils/elog.h b/src/include/utils/elog.h index 751a6a414ec83..6d8b23882d65f 100644 --- a/src/include/utils/elog.h +++ b/src/include/utils/elog.h @@ -137,7 +137,7 @@ struct Node; * prevents gcc from making the unreachability deduction at optlevel -O0. *---------- */ -#if defined(__EMSCRIPTEN__) || defined(__wasi__) +#if defined(__PGLITE__) #define ereport_domain(elevel, domain, ...) \ do { \ pg_prevent_errno_in_scope(); \ diff --git a/src/interfaces/libpq/fe-auth.c b/src/interfaces/libpq/fe-auth.c index 48989bcaabce6..3867e1983f1c7 100644 --- a/src/interfaces/libpq/fe-auth.c +++ b/src/interfaces/libpq/fe-auth.c @@ -1169,7 +1169,7 @@ char * pg_fe_getusername(uid_t user_id, PQExpBuffer errorMessage) { char *result = NULL; -#if !defined(__EMSCRIPTEN__) && !defined(__wasi__) +#if !defined(__PGLITE__) const char *name = NULL; #ifdef WIN32 diff --git a/src/interfaces/libpq/fe-secure.c b/src/interfaces/libpq/fe-secure.c index 7f170f55730db..33e337fcbf370 100644 --- a/src/interfaces/libpq/fe-secure.c +++ b/src/interfaces/libpq/fe-secure.c @@ -45,7 +45,7 @@ #include "libpq-fe.h" #include "libpq-int.h" -#if defined(__EMSCRIPTEN__) +#if defined(__PGLITE__) #include "pglite-comm.h" #endif diff --git a/src/interfaces/libpq/legacy-pqsignal.c b/src/interfaces/libpq/legacy-pqsignal.c index 9c69f38907059..4606984a83951 100644 --- a/src/interfaces/libpq/legacy-pqsignal.c +++ b/src/interfaces/libpq/legacy-pqsignal.c @@ -36,7 +36,7 @@ * is to ensure that no in-tree code accidentally calls this version.) */ #undef pqsignal -#if !defined(__EMSCRIPTEN__) && !defined(__wasi__) +#if !defined(__PGLITE__) extern pqsigfunc pqsignal(int signo, pqsigfunc func); pqsigfunc pqsignal(int signo, pqsigfunc func) @@ -61,4 +61,4 @@ pqsignal(int signo, pqsigfunc func) return signal(signo, func); #endif } -#endif /* __EMSCRIPTEN__ || __wasi__ */ +#endif /* __PGLITE__ */ diff --git a/src/port/getpeereid.c b/src/port/getpeereid.c index 09f86bfc2c922..b2e79ec1c547e 100644 --- a/src/port/getpeereid.c +++ b/src/port/getpeereid.c @@ -32,7 +32,7 @@ int getpeereid(int sock, uid_t *uid, gid_t *gid) { -#if defined(__EMSCRIPTEN__) || defined(__wasi__) +#if defined(__PGLITE__) /* No implementation available on this platform */ errno = ENOSYS; return -1; diff --git a/wasm-build/include/sdk_port.h b/wasm-build/include/sdk_port.h index 2ceab50b00ef1..506214a121866 100644 --- a/wasm-build/include/sdk_port.h +++ b/wasm-build/include/sdk_port.h @@ -1,4 +1,4 @@ -#if defined(__EMSCRIPTEN__) +#if defined(__PGLITE__) #include #elif defined(__wasi__) @@ -258,5 +258,5 @@ extern ssize_t recvfrom_bc(int socket, void *buffer, size_t length, int flags, v #endif // I_WASI #else - #error "unknown port mode should be __EMSCRIPTEN__ or __wasi__" -#endif // __EMSCRIPTEN__ + #error "unknown port mode should be __PGLITE__" +#endif // __PGLITE__ diff --git a/wasm-build/sdk.sh b/wasm-build/sdk.sh index d0298734c3c88..292ca5a0fd3d9 100755 --- a/wasm-build/sdk.sh +++ b/wasm-build/sdk.sh @@ -98,14 +98,14 @@ else cat > /tmp/sdk/hello_em.c < #include -#if defined(__EMSCRIPTEN__) +#if defined(__PGLITE__) #include "emscripten.h" #endif #define IO ((char *)(1)) int main(int argc, char**arv){ -#if defined(__EMSCRIPTEN__) +#if defined(__PGLITE__) # if defined(__PYDK__) printf("pydk" " %d.%d.%d\n",__EMSCRIPTEN_major__, __EMSCRIPTEN_minor__, __EMSCRIPTEN_tiny__); # else