Skip to content

Commit 05bf47d

Browse files
committed
WIP plpgsql wasm build
1 parent b3082d8 commit 05bf47d

File tree

5 files changed

+22
-13
lines changed

5 files changed

+22
-13
lines changed

src/Makefile.shlib

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,13 @@ ifeq ($(PORTNAME), darwin)
122122
ifneq ($(SO_MAJOR_VERSION), 0)
123123
version_link = -compatibility_version $(SO_MAJOR_VERSION) -current_version $(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
124124
endif
125-
LINK.shared = $(COMPILER) -dynamiclib -install_name '$(libdir)/lib$(NAME).$(SO_MAJOR_VERSION)$(DLSUFFIX)' $(version_link) $(exported_symbols_list) -multiply_defined suppress
125+
LINK.shared = $(COMPILER) -dynamiclib -install_name '$(libdir)/lib$(NAME).$(SO_MAJOR_VERSION)$(DLSUFFIX)' $(version_link) $(exported_symbols_list)
126126
shlib = lib$(NAME).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)$(DLSUFFIX)
127127
shlib_major = lib$(NAME).$(SO_MAJOR_VERSION)$(DLSUFFIX)
128128
else
129129
# loadable module
130130
DLSUFFIX = .so
131-
LINK.shared = $(COMPILER) -bundle -multiply_defined suppress
131+
LINK.shared = $(COMPILER) -bundle
132132
endif
133133
BUILD.exports = $(AWK) '/^[^\#]/ {printf "_%s\n",$$1}' $< >$@
134134
exports_file = $(SHLIB_EXPORTS:%.txt=%.list)

src/backend/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ ifneq ($(PORTNAME), win32)
6363
ifneq ($(PORTNAME), aix)
6464

6565
postgres: $(OBJS)
66-
$(CC) $(CFLAGS) $(call expand_subsys,$^) $(LDFLAGS) $(LDFLAGS_EX) $(export_dynamic) $(LIBS) -s FORCE_FILESYSTEM=1 -s ASYNCIFY=1 -lnodefs.js -lproxyfs.js -lidbfs.js -o $@
66+
$(CC) $(CFLAGS) $(call expand_subsys,$^) $(LDFLAGS) $(LDFLAGS_EX) $(export_dynamic) $(LIBS) -sMAIN_MODULE=2 -sEXPORTED_FUNCTIONS=_main,_await_query -sFORCE_FILESYSTEM=1 -sASYNCIFY=1 -lnodefs.js -lproxyfs.js -lidbfs.js -o $@
6767
endif
6868
endif
6969
endif

src/include/fmgr.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@
1515
*
1616
*-------------------------------------------------------------------------
1717
*/
18+
19+
#ifdef EMSCRIPTEN
20+
#include <emscripten.h>
21+
#endif
22+
1823
#ifndef FMGR_H
1924
#define FMGR_H
2025

@@ -416,7 +421,7 @@ typedef const Pg_finfo_record *(*PGFInfoFunction) (void);
416421
extern Datum funcname(PG_FUNCTION_ARGS); \
417422
extern PGDLLEXPORT const Pg_finfo_record * CppConcat(pg_finfo_,funcname)(void); \
418423
const Pg_finfo_record * \
419-
CppConcat(pg_finfo_,funcname) (void) \
424+
EMSCRIPTEN_KEEPALIVE CppConcat(pg_finfo_,funcname) (void) \
420425
{ \
421426
static const Pg_finfo_record my_finfo = { 1 }; \
422427
return &my_finfo; \

src/makefiles/Makefile.darwin

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ DLSUFFIX = .so
55
# env var name to use in place of LD_LIBRARY_PATH
66
ld_library_path_var = DYLD_LIBRARY_PATH
77

8-
ifdef PGXS
9-
BE_DLLLIBS = -bundle_loader $(bindir)/postgres
10-
else
11-
BE_DLLLIBS = -bundle_loader $(top_builddir)/src/backend/postgres
12-
endif
8+
# ifdef PGXS
9+
# BE_DLLLIBS = -bundle_loader $(bindir)/postgres
10+
# else
11+
# BE_DLLLIBS = -bundle_loader $(top_builddir)/src/backend/postgres
12+
# endif
1313

1414
# Rule for building a shared library from a single .o file
1515
%.so: %.o

src/pl/plpgsql/src/pl_handler.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727
#include "utils/syscache.h"
2828
#include "utils/varlena.h"
2929

30+
#ifdef EMSCRIPTEN
31+
#include <emscripten.h>
32+
#endif
33+
3034
static bool plpgsql_extra_checks_check_hook(char **newvalue, void **extra, GucSource source);
3135
static void plpgsql_extra_warnings_assign_hook(const char *newvalue, void *extra);
3236
static void plpgsql_extra_errors_assign_hook(const char *newvalue, void *extra);
@@ -142,7 +146,7 @@ plpgsql_extra_errors_assign_hook(const char *newvalue, void *extra)
142146
* DO NOT make this static nor change its name!
143147
*/
144148
void
145-
_PG_init(void)
149+
EMSCRIPTEN_KEEPALIVE _PG_init(void)
146150
{
147151
/* Be sure we do initialization only once (should be redundant now) */
148152
static bool inited = false;
@@ -219,7 +223,7 @@ _PG_init(void)
219223
PG_FUNCTION_INFO_V1(plpgsql_call_handler);
220224

221225
Datum
222-
plpgsql_call_handler(PG_FUNCTION_ARGS)
226+
EMSCRIPTEN_KEEPALIVE plpgsql_call_handler(PG_FUNCTION_ARGS)
223227
{
224228
bool nonatomic;
225229
PLpgSQL_function *func;
@@ -312,7 +316,7 @@ plpgsql_call_handler(PG_FUNCTION_ARGS)
312316
PG_FUNCTION_INFO_V1(plpgsql_inline_handler);
313317

314318
Datum
315-
plpgsql_inline_handler(PG_FUNCTION_ARGS)
319+
EMSCRIPTEN_KEEPALIVE plpgsql_inline_handler(PG_FUNCTION_ARGS)
316320
{
317321
LOCAL_FCINFO(fake_fcinfo, 0);
318322
InlineCodeBlock *codeblock = castNode(InlineCodeBlock, DatumGetPointer(PG_GETARG_DATUM(0)));
@@ -439,7 +443,7 @@ plpgsql_inline_handler(PG_FUNCTION_ARGS)
439443
PG_FUNCTION_INFO_V1(plpgsql_validator);
440444

441445
Datum
442-
plpgsql_validator(PG_FUNCTION_ARGS)
446+
EMSCRIPTEN_KEEPALIVE plpgsql_validator(PG_FUNCTION_ARGS)
443447
{
444448
Oid funcoid = PG_GETARG_OID(0);
445449
HeapTuple tuple;

0 commit comments

Comments
 (0)