Skip to content

wasm 16.6 library build support #18

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

Open
wants to merge 2 commits into
base: REL_16_STABLE
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
40 changes: 20 additions & 20 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -4322,7 +4322,7 @@ else
ac_save_c_werror_flag=$ac_c_werror_flag
ac_c_werror_flag=yes
ac_cv_prog_cc_g=no
CFLAGS="-g"
CFLAGS="-g2"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */

Expand Down Expand Up @@ -4353,7 +4353,7 @@ if ac_fn_c_try_compile "$LINENO"; then :

else
ac_c_werror_flag=$ac_save_c_werror_flag
CFLAGS="-g"
CFLAGS="-g2"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */

Expand Down Expand Up @@ -4381,13 +4381,13 @@ if test "$ac_test_CFLAGS" = set; then
CFLAGS=$ac_save_CFLAGS
elif test $ac_cv_prog_cc_g = yes; then
if test "$GCC" = yes; then
CFLAGS="-g -O2"
CFLAGS="-g2 -Os"
else
CFLAGS="-g"
CFLAGS="-g2"
fi
else
if test "$GCC" = yes; then
CFLAGS="-O2"
CFLAGS="-Os"
else
CFLAGS=
fi
Expand Down Expand Up @@ -4853,7 +4853,7 @@ else
ac_save_cxx_werror_flag=$ac_cxx_werror_flag
ac_cxx_werror_flag=yes
ac_cv_prog_cxx_g=no
CXXFLAGS="-g"
CXXFLAGS="-g2"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */

Expand Down Expand Up @@ -4884,7 +4884,7 @@ if ac_fn_cxx_try_compile "$LINENO"; then :

else
ac_cxx_werror_flag=$ac_save_cxx_werror_flag
CXXFLAGS="-g"
CXXFLAGS="-g2"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */

Expand Down Expand Up @@ -4912,13 +4912,13 @@ if test "$ac_test_CXXFLAGS" = set; then
CXXFLAGS=$ac_save_CXXFLAGS
elif test $ac_cv_prog_cxx_g = yes; then
if test "$GXX" = yes; then
CXXFLAGS="-g -O2"
CXXFLAGS="-g2 -Os"
else
CXXFLAGS="-g"
CXXFLAGS="-g2"
fi
else
if test "$GXX" = yes; then
CXXFLAGS="-O2"
CXXFLAGS="-Os"
else
CXXFLAGS=
fi
Expand Down Expand Up @@ -5278,11 +5278,11 @@ elif test "${CFLAGS+set}" = set; then
elif test "$enable_coverage" = yes; then
: # no optimization by default
elif test "$GCC" = yes; then
CFLAGS="-O2"
CFLAGS="-Os"
else
# if the user selected debug mode, don't use -O
if test "$enable_debug" != yes; then
CFLAGS="-O"
CFLAGS="-Os"
fi
fi

Expand All @@ -5293,11 +5293,11 @@ elif test "${CXXFLAGS+set}" = set; then
elif test "$enable_coverage" = yes; then
: # no optimization by default
elif test "$GCC" = yes; then
CXXFLAGS="-O2"
CXXFLAGS="-Os"
else
# if the user selected debug mode, don't use -O
if test "$enable_debug" != yes; then
CXXFLAGS="-O"
CXXFLAGS="-Os"
fi
fi

Expand All @@ -5310,12 +5310,12 @@ fi
if test "$ac_env_BITCODE_CFLAGS_set" = set; then
BITCODE_CFLAGS=$ac_env_BITCODE_CFLAGS_value
else
BITCODE_CFLAGS="-O2 $BITCODE_CFLAGS"
BITCODE_CFLAGS="-Os $BITCODE_CFLAGS"
fi
if test "$ac_env_BITCODE_CXXFLAGS_set" = set; then
BITCODE_CXXFLAGS=$ac_env_BITCODE_CXXFLAGS_value
else
BITCODE_CXXFLAGS="-O2 $BITCODE_CXXFLAGS"
BITCODE_CXXFLAGS="-Os $BITCODE_CXXFLAGS"
fi

# C[XX]FLAGS we determined above will be added back at the end
Expand Down Expand Up @@ -7826,11 +7826,11 @@ fi

# supply -g if --enable-debug
if test "$enable_debug" = yes && test "$ac_cv_prog_cc_g" = yes; then
CFLAGS="$CFLAGS -g"
CFLAGS="$CFLAGS -g2"
fi

if test "$enable_debug" = yes && test "$ac_cv_prog_cxx_g" = yes; then
CXXFLAGS="$CXXFLAGS -g"
CXXFLAGS="$CXXFLAGS -g2"
fi

# enable code coverage if --enable-coverage
Expand Down Expand Up @@ -13588,7 +13588,7 @@ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
#ifdef __cplusplus
extern "C"
#endif
char uuid_export ();
extern char uuid_export ();
int
main ()
{
Expand Down Expand Up @@ -13650,7 +13650,7 @@ $as_echo "$ac_cv_lib_uuid_uuid_export" >&6; }
if test "x$ac_cv_lib_uuid_uuid_export" = xyes; then :
UUID_LIBS="-luuid"
else
as_fn_error $? "library 'ossp-uuid' or 'uuid' is required for OSSP UUID" "$LINENO" 5
ac_cv_lib_ossp_uuid_uuid_export=yes
fi

fi
Expand Down
4 changes: 2 additions & 2 deletions contrib/pgstattuple/pgstatindex.c
Original file line number Diff line number Diff line change
Expand Up @@ -656,9 +656,9 @@ pgstathashindex(PG_FUNCTION_ARGS)
stats.unused_pages++;
else if (PageGetSpecialSize(page) !=
MAXALIGN(sizeof(HashPageOpaqueData)))
ereport(ERROR,
ereport(WARNING,
(errcode(ERRCODE_INDEX_CORRUPTED),
errmsg("index \"%s\" contains corrupted page at block %u",
errmsg("# 661(FATAL block=%d): index \"%s\" contains corrupted page at block %u", blkno,
RelationGetRelationName(rel),
BufferGetBlockNumber(buf))));
else
Expand Down
2 changes: 1 addition & 1 deletion contrib/xml2/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ DATA = xml2--1.1.sql xml2--1.0--1.1.sql
PGFILEDESC = "xml2 - XPath querying and XSLT"

REGRESS = xml2

PG_CFLAGS=$(shell xml2-config --cflags)
SHLIB_LINK += $(filter -lxslt, $(LIBS)) -lxml2

ifdef USE_PGXS
Expand Down
32 changes: 31 additions & 1 deletion src/Makefile.shlib
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,33 @@ ifeq ($(SHLIB_EXPORTS),)
override CXXFLAGS += $(CXXFLAGS_SL_MODULE)
endif

ifeq ($(PORTNAME), emscripten)
LINK.shared = emsdk-shared
ifdef soname
# emscripten uses unversioned shared libraries
shlib = $(shlib_bare)
soname = $(shlib_bare)
endif
BUILD.exports = ( echo '{ global:'; $(AWK) '/^[^\#]/ {printf "%s;\n",$$1}' $<; echo ' local: *; };' ) >$@
exports_file = $(SHLIB_EXPORTS:%.txt=%.list)
# ifneq (,$(exports_file))
# LINK.shared += -Wl,--version-script=$(exports_file)
# endif
endif

ifeq ($(PORTNAME), wasi)
LINK.shared = wasi-shared
ifdef soname
# emscripten uses unversioned shared libraries
shlib = $(shlib_bare)
soname = $(shlib_bare)
endif
BUILD.exports = ( echo '{ global:'; $(AWK) '/^[^\#]/ {printf "%s;\n",$$1}' $<; echo ' local: *; };' ) >$@
exports_file = $(SHLIB_EXPORTS:%.txt=%.list)
# ifneq (,$(exports_file))
# LINK.shared += -Wl,--version-script=$(exports_file)
# endif
endif

##
## BUILD
Expand All @@ -248,8 +275,11 @@ all-lib: lib$(NAME).pc
endif

all-static-lib: $(stlib)

ifdef wasi
all-shared-lib: all-static-lib
else
all-shared-lib: $(shlib)
endif

# In this rule, "touch $@" works around a problem on some platforms wherein
# ar updates the library file's mod time with a value calculated to
Expand Down
22 changes: 20 additions & 2 deletions src/backend/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@ LOCALOBJS += utils/probes.o
endif
endif

OBJS = \
ONLYOBJS = \
$(LOCALOBJS) \
$(SUBDIROBJS) \
$(SUBDIROBJS)
OBJS = \
$(ONLYOBJS) \
$(top_builddir)/src/common/libpgcommon_srv.a \
$(top_builddir)/src/port/libpgport_srv.a

Expand All @@ -60,6 +62,7 @@ override LDFLAGS := $(LDFLAGS) $(LDFLAGS_EX) $(LDFLAGS_EX_BE)

all: submake-libpgport submake-catalog-headers submake-utils-headers postgres $(POSTGRES_IMP)

ifneq ($(PORTNAME), emscripten)
ifneq ($(PORTNAME), cygwin)
ifneq ($(PORTNAME), win32)
ifneq ($(PORTNAME), aix)
Expand All @@ -70,6 +73,21 @@ postgres: $(OBJS)
endif
endif
endif
endif

ifeq ($(PORTNAME), emscripten)
AR ?= llvm-ar
LIBPGLITE ?= $(top_builddir)/libpglite.a
LIBPG = $(top_builddir)/libpostgres.a
PGLITE = $(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)/libpglite.o -Wl,--whole-archive $(PGLITE)
$(AR) rcs $(LIBPGLITE) $(top_builddir)/libpglite.o
COPTS="$(LOPTS)" $(CC) $(MAIN_MODULE) $(CFLAGS) $(LDFLAGS) -o $@ $(LIBPGLITE) $(top_builddir)/libpgmain.a $(LIBS)
endif

ifeq ($(PORTNAME), cygwin)

Expand Down
4 changes: 2 additions & 2 deletions src/backend/access/nbtree/nbtutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -2732,7 +2732,7 @@ _bt_allequalimage(Relation rel, bool debugmessage)
break;
}
}

#if !defined(__EMSCRIPTEN__)
if (debugmessage)
{
if (allequalimage)
Expand All @@ -2742,6 +2742,6 @@ _bt_allequalimage(Relation rel, bool debugmessage)
elog(DEBUG1, "index \"%s\" cannot use deduplication",
RelationGetRelationName(rel));
}

#endif
return allequalimage;
}
6 changes: 6 additions & 0 deletions src/backend/access/transam/xact.c
Original file line number Diff line number Diff line change
Expand Up @@ -1740,6 +1740,7 @@ RecordTransactionAbort(bool isSubXact)
if (TransactionIdDidCommit(xid))
elog(PANIC, "cannot abort transaction %u, it was already committed",
xid);
else elog(WARNING, "# 1743: aborting transaction %u", xid);

/*
* Are we using the replication origins feature? Or, in other words, are
Expand Down Expand Up @@ -2748,7 +2749,9 @@ 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__)
sigprocmask(SIG_SETMASK, &UnBlockSig, NULL);
#endif

/*
* check the current transaction state
Expand Down Expand Up @@ -5107,7 +5110,10 @@ 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__)
sigprocmask(SIG_SETMASK, &UnBlockSig, NULL);
#endif


/*
* check the current transaction state
Expand Down
4 changes: 4 additions & 0 deletions src/backend/access/transam/xlogarchive.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
#include "storage/ipc.h"
#include "storage/lwlock.h"

#if defined(__wasi__)
#define system(cmd) system_wasi(cmd)
#endif

/*
* Attempt to retrieve the specified file from off-line archival storage.
* If successful, fill "path" with its complete path (note that this will be
Expand Down
11 changes: 10 additions & 1 deletion src/backend/bootstrap/bootstrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,11 @@ 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__)
void
#else
int
#endif
BootstrapModeMain(int argc, char *argv[], bool check_only)
{
int i;
Expand Down Expand Up @@ -353,7 +357,7 @@ BootstrapModeMain(int argc, char *argv[], bool check_only)
*/
if (pg_link_canary_is_frontend())
elog(ERROR, "backend is incorrectly linked to frontend functions");

puts("# 360: InitPostgres(boot): " __FILE__ );
InitPostgres(NULL, InvalidOid, NULL, InvalidOid, false, false, NULL);

/* Initialize stuff for bootstrap-file processing */
Expand All @@ -378,7 +382,12 @@ BootstrapModeMain(int argc, char *argv[], bool check_only)

/* Clean up and exit */
cleanup();
#if !defined(__EMSCRIPTEN__) && !defined(__wasi__)
proc_exit(0);
#else
puts("# 338 cleanup(boot): " __FILE__);
return 0;
#endif
}


Expand Down
4 changes: 2 additions & 2 deletions src/backend/catalog/index.c
Original file line number Diff line number Diff line change
Expand Up @@ -2993,7 +2993,7 @@ index_build(Relation heapRelation,
indexInfo->ii_ParallelWorkers =
plan_create_index_workers(RelationGetRelid(heapRelation),
RelationGetRelid(indexRelation));

#if !defined(__EMSCRIPTEN__)
if (indexInfo->ii_ParallelWorkers == 0)
ereport(DEBUG1,
(errmsg_internal("building index \"%s\" on table \"%s\" serially",
Expand All @@ -3005,7 +3005,7 @@ index_build(Relation heapRelation,
RelationGetRelationName(indexRelation),
RelationGetRelationName(heapRelation),
indexInfo->ii_ParallelWorkers)));

#endif
/*
* Switch to the table owner's userid, so that any index functions are run
* as that user. Also lock down security-restricted operations and
Expand Down
4 changes: 4 additions & 0 deletions src/backend/commands/async.c
Original file line number Diff line number Diff line change
Expand Up @@ -1700,8 +1700,12 @@ SignalBackends(void)
* NotifyQueueLock; which is unlikely but certainly possible. So we
* just log a low-level debug message if it happens.
*/
#if defined(__EMSCRIPTEN__)
HandleNotifyInterrupt();
#else
if (SendProcSignal(pid, PROCSIG_NOTIFY_INTERRUPT, ids[i]) < 0)
elog(DEBUG3, "could not signal backend with PID %d: %m", pid);
#endif
}

pfree(pids);
Expand Down
6 changes: 3 additions & 3 deletions src/backend/commands/collationcmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -828,14 +828,14 @@ pg_import_system_collations(PG_FUNCTION_ARGS)
maxaliases = 100;
aliases = (CollAliasData *) palloc(maxaliases * sizeof(CollAliasData));
naliases = 0;

locale_a_handle = OpenPipeStream("locale -a", "r");
if (locale_a_handle == NULL)
if (locale_a_handle == NULL) {
puts("======================== ERROR ================");
ereport(ERROR,
(errcode_for_file_access(),
errmsg("could not execute command \"%s\": %m",
"locale -a")));

}
while (fgets(localebuf, sizeof(localebuf), locale_a_handle))
{
size_t len;
Expand Down
Loading