Skip to content

wasm 17.4 library build support #20

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

Draft
wants to merge 8 commits into
base: REL_17_STABLE
Choose a base branch
from
Draft
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
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,10 @@ lib*.pc
/Release/
/tmp_install/
/portlock/

# libpglite
/configure
/src/Makefile.shlib
/src/backend/commands/async.c
/src/bin/initdb/initdb.c
/src/bin/pg_verifybackup/pg_verifybackup.c
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
38 changes: 36 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)

Expand All @@ -68,6 +71,37 @@ postgres: $(OBJS)

endif
endif
endif

ifeq ($(PORTNAME), emscripten)
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) -o $@ $(LIBPGCORE) $(top_builddir)/libpgmain.a $(LIBS)
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 $@ [email protected]
touch $@
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 @@ -5163,7 +5163,7 @@ _bt_allequalimage(Relation rel, bool debugmessage)
break;
}
}

#if !defined(__EMSCRIPTEN__)
if (debugmessage)
{
if (allequalimage)
Expand All @@ -5173,6 +5173,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 @@ -1761,6 +1761,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 @@ -2804,7 +2805,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 @@ -5211,7 +5214,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 @@ -32,6 +32,10 @@
#include "storage/fd.h"
#include "storage/ipc.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
9 changes: 9 additions & 0 deletions src/backend/bootstrap/bootstrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,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 @@ -365,7 +369,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 @@ -2967,7 +2967,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 @@ -2979,7 +2979,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 @@ -1651,8 +1651,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__) || defined(__wasi__)
HandleNotifyInterrupt();
#else
if (SendProcSignal(pid, PROCSIG_NOTIFY_INTERRUPT, procnos[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 @@ -868,14 +868,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
3 changes: 2 additions & 1 deletion src/backend/commands/dbcommands.c
Original file line number Diff line number Diff line change
Expand Up @@ -1834,8 +1834,9 @@ 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__)
WaitForProcSignalBarrier(EmitProcSignalBarrier(PROCSIGNAL_BARRIER_SMGRRELEASE));

#endif
/*
* Remove all tablespace subdirs belonging to the database.
*/
Expand Down
33 changes: 25 additions & 8 deletions src/backend/commands/event_trigger.c
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,7 @@ EventTriggerDDLCommandStart(Node *parsetree)
List *runlist;
EventTriggerData trigdata;

#if !defined(__EMSCRIPTEN__) && !defined(__wasi__)
/*
* Event Triggers are completely disabled in standalone mode. There are
* (at least) two reasons for this:
Expand All @@ -744,6 +745,10 @@ EventTriggerDDLCommandStart(Node *parsetree)
*/
if (!IsUnderPostmaster || !event_triggers)
return;
#else
if (!event_triggers)
return;
#endif

runlist = EventTriggerCommonSetup(parsetree,
EVT_DDLCommandStart,
Expand Down Expand Up @@ -773,14 +778,17 @@ EventTriggerDDLCommandEnd(Node *parsetree)
{
List *runlist;
EventTriggerData trigdata;

#if !defined(__EMSCRIPTEN__) && !defined(__wasi__)
/*
* See EventTriggerDDLCommandStart for a discussion about why event
* triggers are disabled in single user mode or via GUC.
*/
if (!IsUnderPostmaster || !event_triggers)
return;

#else
if (!event_triggers)
return;
#endif
/*
* Also do nothing if our state isn't set up, which it won't be if there
* weren't any relevant event triggers at the start of the current DDL
Expand Down Expand Up @@ -821,14 +829,17 @@ EventTriggerSQLDrop(Node *parsetree)
{
List *runlist;
EventTriggerData trigdata;

#if !defined(__EMSCRIPTEN__) && !defined(__wasi__)
/*
* See EventTriggerDDLCommandStart for a discussion about why event
* triggers are disabled in single user mode or via a GUC.
*/
if (!IsUnderPostmaster || !event_triggers)
return;

#else
if (!event_triggers)
return;
#endif
/*
* Use current state to determine whether this event fires at all. If
* there are no triggers for the sql_drop event, then we don't have
Expand Down Expand Up @@ -894,7 +905,7 @@ EventTriggerOnLogin(void)
{
List *runlist;
EventTriggerData trigdata;

#if !defined(__EMSCRIPTEN__) && !defined(__wasi__)
/*
* See EventTriggerDDLCommandStart for a discussion about why event
* triggers are disabled in single user mode or via a GUC. We also need a
Expand All @@ -903,7 +914,10 @@ EventTriggerOnLogin(void)
if (!IsUnderPostmaster || !event_triggers ||
!OidIsValid(MyDatabaseId) || !MyDatabaseHasLoginEventTriggers)
return;

#else
if (!event_triggers || !OidIsValid(MyDatabaseId) || !MyDatabaseHasLoginEventTriggers)
return;
#endif
StartTransactionCommand();
runlist = EventTriggerCommonSetup(NULL,
EVT_Login, "login",
Expand Down Expand Up @@ -1005,14 +1019,17 @@ EventTriggerTableRewrite(Node *parsetree, Oid tableOid, int reason)
{
List *runlist;
EventTriggerData trigdata;

#if !defined(__EMSCRIPTEN__) && !defined(__wasi__)
/*
* See EventTriggerDDLCommandStart for a discussion about why event
* triggers are disabled in single user mode or via a GUC.
*/
if (!IsUnderPostmaster || !event_triggers)
return;

#else
if (!event_triggers)
return;
#endif
/*
* Also do nothing if our state isn't set up, which it won't be if there
* weren't any relevant event triggers at the start of the current DDL
Expand Down
2 changes: 1 addition & 1 deletion src/backend/libpq/auth.c
Original file line number Diff line number Diff line change
Expand Up @@ -1875,7 +1875,7 @@ auth_peer(hbaPort *port)
return STATUS_ERROR;
}

#ifndef WIN32
#if !defined(WIN32) && !defined(__wasi__)
errno = 0; /* clear errno before call */
pw = getpwuid(uid);
if (!pw)
Expand Down
Loading