Skip to content
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
2 changes: 1 addition & 1 deletion .buildconfig
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
PG_VERSION=17.5
PG_BRANCH=REL_17_5_WASM
SDK_VERSION=3.1.74.12.0
SDK_VERSION=3.1.74.11.11
SDKROOT=/tmp/sdk
GETZIC=false
ZIC=/usr/sbin/zic
Expand Down
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,12 @@ lib*.pc
/tmp_install/
/portlock/
/dist

# emscripten build excludes
*.cjs
*.wasm
pglite.data
pglite.js
pglite.html
*.map
pglite-wasm/excluded.imports
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[submodule "pglite/pg_ivm"]
path = pglite/pg_ivm
url = https://github.com/sraoss/pg_ivm.git
[submodule "pglite/pgvector"]
path = pglite/vector
url = https://github.com/pgvector/pgvector.git
46 changes: 46 additions & 0 deletions build-pglite.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/bash

### NOTES ###
# $INSTALL_PREFIX is expected to point to the installation folder of various libraries built to wasm (see pglite-builder)
#############

# final output folder
INSTALL_FOLDER=${INSTALL_FOLDER:-"/install/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"
else
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
fi

echo "pglite: PGLITE_CFLAGS=$PGLITE_CFLAGS"

# Step 1: configure the project
LDFLAGS="-sWASM_BIGINT -sUSE_PTHREADS=0" CFLAGS="${PGLITE_CFLAGS} -sWASM_BIGINT -fpic -sENVIRONMENT=node,web,worker -sSUPPORT_LONGJMP=emscripten -DPYDK=1 -DCMA_MB=12 -Wno-declaration-after-statement -Wno-macro-redefined -Wno-unused-function -Wno-missing-prototypes -Wno-incompatible-pointer-types" emconfigure ./configure ac_cv_exeext=.cjs --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 --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; }

# Step 2: make and install all except pglite
emmake make PORTNAME=emscripten -j || { echo 'error: emmake make PORTNAME=emscripten -j' ; exit 21; }
emmake make PORTNAME=emscripten install || { echo 'error: emmake make PORTNAME=emscripten install' ; exit 22; }

# Step 3.1: make all contrib extensions - do not install
emmake make PORTNAME=emscripten LDFLAGS_SL="-sSIDE_MODULE=1" -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

# Step 4: make and dist other extensions
SAVE_PATH=$PATH
PATH=$PATH:$INSTALL_FOLDER/bin
emmake make OPTFLAGS="" PORTNAME=emscripten -j -C pglite || { echo 'error: emmake make OPTFLAGS="" PORTNAME=emscripten -j -C pglite' ; exit 41; }
emmake make OPTFLAGS="" PORTNAME=emscripten LDFLAGS_SL="-sSIDE_MODULE=1" -C pglite/ dist || { echo 'error: make OPTFLAGS="" PORTNAME=emscripten LDFLAGS_SL="-sSIDE_MODULE=1" -C pglite/ dist ' ; exit 42; }
PATH=$SAVE_PATH

# Step 5: make and install pglite
# 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 emmake make PORTNAME=emscripten -j -C src/backend/ install-pglite || { echo 'emmake make OPTFLAGS="" PORTNAME=emscripten -j -C pglite' ; exit 51; }
13 changes: 13 additions & 0 deletions build-with-docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# although we could use any path inside docker, using the same path as on the host
# allows the DWARF info (when building in DEBUG) to contain the correct file paths
DOCKER_WORKSPACE=$(pwd)

docker run $@ \
--rm \
-e DEBUG=${DEBUG:-false} \
--workdir=${DOCKER_WORKSPACE} \
-v .:${DOCKER_WORKSPACE}:rw \
-v ./dist:/install/pglite:rw \
electricsql/pglite-builder:3.1.74_1 \
./build-pglite.sh

6 changes: 6 additions & 0 deletions clean-pglite.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

emmake make -C src/backend uninstall; emmake make -C src/backend clean;
emmake make -C pglite/ clean; emmake make -C pglite/ uninstall;
emmake make -C contrib/ clean; emmake make -C contrib/ uninstall; emmake make -C pglite clean; emmake make -C pglite uninstall;
emmake make clean; emmake make uninstal
1 change: 1 addition & 0 deletions contrib/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ endif
# Missing:
# start-scripts \ (does not have a makefile)

include ./dist.mk

$(recurse)
$(recurse_always)
27 changes: 27 additions & 0 deletions contrib/dist.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# contrib/dist.mk
#
# Package each contrib extension into its own .tar.gz archive

prefix ?= /install/pglite
CONTRIB_BUILD_ROOT := /tmp/extensions/build
ARCHIVE_DIR := /install/pglite/extensions

CONTRIBS := $(SUBDIRS)

# Default target: build tarballs for all contribs
dist: $(addsuffix .tar.gz,$(CONTRIBS))

# Pattern rule: build $(EXT).tar.gz for each contrib
%.tar.gz:
@echo "=== Staging $* ==="
rm -rf $(CONTRIB_BUILD_ROOT)/$*
bash -c 'mkdir -p $(CONTRIB_BUILD_ROOT)/$*/$(prefix)/{bin,lib,share/extension,share/doc,share/postgresql/extension,share/postgresql/tsearch_data,include}'
$(MAKE) -C $* install DESTDIR=$(CONTRIB_BUILD_ROOT)/$*
@echo "=== Packaging $* ==="
mkdir -p $(ARCHIVE_DIR)
cd $(CONTRIB_BUILD_ROOT)/$*/$(prefix) && \
files=$$(find . -type f -o -type l | sed 's|^\./||') && \
tar -czf $(ARCHIVE_DIR)/$*.tar.gz $$files
# tar -C $(CONTRIB_BUILD_ROOT)/$*/$(prefix) -czf $(ARCHIVE_DIR)/$*.tar.gz .

.PHONY: dist
62 changes: 62 additions & 0 deletions docker_rc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/bin/bash

WORKSPACE=$(pwd)

echo "

SDK prepare

"

pushd /
# this is minimum required to **use** sdk on docker/debian 12, not build it
apt-get update && apt-get --yes install git wget curl lz4 xz-utils bison flex pkg-config autoconf make

if [ -f $WORKSPACE/sdk.tar.lz4 ]
then
tar xf $WORKSPACE/sdk.tar.lz4 --use-compress-program=lz4
fi

if [ -d $SDKROOT/wasisdk/upstream ]
then
echo "wasi sdk common support is already installed"
else
tar xf ${WORKSPACE}/prebuilt/wasi-sdk-25.tar.xz
fi

if [ -d $SDKROOT/wasisdk/upstream/lib ]
then
echo "wasi sdk $(arch) support is already installed"
else
pushd $SDKROOT/wasisdk
if arch|grep -q aarch64
then
wget https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-25/wasi-sdk-25.0-arm64-linux.tar.gz -O/tmp/sdk.tar.gz
else
wget https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-25/wasi-sdk-25.0-x86_64-linux.tar.gz -O/tmp/sdk.tar.gz
fi
tar xfz /tmp/sdk.tar.gz && rm /tmp/sdk.tar.gz
mv wasi-sdk-25.0-*/{bin,lib} upstream/
popd
fi

popd

echo "

Setting up SDK shell


Applying Hotfixes
------------------------------------------------------------------------------------------
"

echo "linker fix"
cp -vf hotfix/library_dylink.js ${SDKROOT}/emsdk/upstream/emscripten/src/



echo "------------------------------------------------------------------------------------------"


${SDKROOT}/wasm32-bi-emscripten-shell.sh
Loading