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 6 commits into
base: REL_17_STABLE
Choose a base branch
from
Draft
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
@@ -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
@@ -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
2 changes: 1 addition & 1 deletion contrib/xml2/Makefile
Original file line number Diff line number Diff line change
@@ -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
38 changes: 36 additions & 2 deletions src/backend/Makefile
Original file line number Diff line number Diff line change
@@ -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

@@ -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)

@@ -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 $@ $@.wasi
touch $@
endif

ifeq ($(PORTNAME), cygwin)

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

#if !defined(__EMSCRIPTEN__)
if (debugmessage)
{
if (allequalimage)
@@ -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
@@ -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
@@ -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
@@ -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
4 changes: 4 additions & 0 deletions src/backend/access/transam/xlogarchive.c
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions src/backend/bootstrap/bootstrap.c
Original file line number Diff line number Diff line change
@@ -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;
@@ -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
}


4 changes: 2 additions & 2 deletions src/backend/catalog/index.c
Original file line number Diff line number Diff line change
@@ -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",
@@ -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
6 changes: 3 additions & 3 deletions src/backend/commands/collationcmds.c
Original file line number Diff line number Diff line change
@@ -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;
3 changes: 2 additions & 1 deletion src/backend/commands/dbcommands.c
Original file line number Diff line number Diff line change
@@ -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.
*/
33 changes: 25 additions & 8 deletions src/backend/commands/event_trigger.c
Original file line number Diff line number Diff line change
@@ -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:
@@ -744,6 +745,10 @@ EventTriggerDDLCommandStart(Node *parsetree)
*/
if (!IsUnderPostmaster || !event_triggers)
return;
#else
if (!event_triggers)
return;
#endif

runlist = EventTriggerCommonSetup(parsetree,
EVT_DDLCommandStart,
@@ -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
@@ -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
@@ -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
@@ -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",
@@ -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
2 changes: 1 addition & 1 deletion src/backend/libpq/auth.c
Original file line number Diff line number Diff line change
@@ -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)
20 changes: 14 additions & 6 deletions src/backend/libpq/be-fsstubs.c
Original file line number Diff line number Diff line change
@@ -150,8 +150,12 @@ be_lo_close(PG_FUNCTION_ARGS)
*
*****************************************************************************/

#if defined(__EMSCRIPTEN__) || defined(__wasi__)
static int
#else
int
lo_read(int fd, char *buf, int len)
#endif
lo_read3(int fd, char *buf, int len)
{
int status;
LargeObjectDesc *lobj;
@@ -178,8 +182,12 @@ lo_read(int fd, char *buf, int len)
return status;
}

#if defined(__EMSCRIPTEN__) || defined(__wasi__)
static int
#else
int
lo_write(int fd, const char *buf, int len)
#endif
lo_write3(int fd, const char *buf, int len)
{
int status;
LargeObjectDesc *lobj;
@@ -190,7 +198,7 @@ lo_write(int fd, const char *buf, int len)
errmsg("invalid large-object descriptor: %d", fd)));
lobj = cookies[fd];

/* see comment in lo_read() */
/* see comment in lo_read3() */
if ((lobj->flags & IFS_WRLOCK) == 0)
ereport(ERROR,
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
@@ -365,7 +373,7 @@ be_loread(PG_FUNCTION_ARGS)
len = 0;

retval = (bytea *) palloc(VARHDRSZ + len);
totalread = lo_read(fd, VARDATA(retval), len);
totalread = lo_read3(fd, VARDATA(retval), len);
SET_VARSIZE(retval, totalread + VARHDRSZ);

PG_RETURN_BYTEA_P(retval);
@@ -382,7 +390,7 @@ be_lowrite(PG_FUNCTION_ARGS)
PreventCommandIfReadOnly("lowrite()");

bytestowrite = VARSIZE_ANY_EXHDR(wbuf);
totalwritten = lo_write(fd, VARDATA_ANY(wbuf), bytestowrite);
totalwritten = lo_write3(fd, VARDATA_ANY(wbuf), bytestowrite);
PG_RETURN_INT32(totalwritten);
}

@@ -560,7 +568,7 @@ lo_truncate_internal(int32 fd, int64 len)
errmsg("invalid large-object descriptor: %d", fd)));
lobj = cookies[fd];

/* see comment in lo_read() */
/* see comment in lo_read3() */
if ((lobj->flags & IFS_WRLOCK) == 0)
ereport(ERROR,
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
Loading