-
Notifications
You must be signed in to change notification settings - Fork 10
Switch to vanilla emsdk for building pglite #48
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
Changes from all commits
886505c
36b927c
215a815
fade3ec
c5a5f65
bcd2f02
122f9a2
028308b
0e1db80
9fa09a0
6541d5d
d7749a5
b985c21
e9c60b5
f7ec38e
9597bfc
e60c392
65bab4c
af07854
e7f8119
8cd846b
8423bd0
33f6845
f845c70
7988c02
5bb401e
6b1cee5
2903579
92f8d2d
2d8c092
e20fdfc
a71c738
e27aa64
5cd4ec4
af29813
748baf9
69aaa2f
255b176
5f13b0c
d61bb93
06ff639
0e39ce0
9831559
51362b0
198584c
37f87e2
cb90be0
006e994
e12fdb2
276830e
a547de7
15d97a6
0158114
4283594
16d77dc
50f6e84
4d01da5
1566fea
5d369de
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 |
| 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; } | ||
| 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 | ||
|
|
| 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 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -90,6 +90,7 @@ endif | |
| # Missing: | ||
| # start-scripts \ (does not have a makefile) | ||
|
|
||
| include ./dist.mk | ||
|
|
||
| $(recurse) | ||
| $(recurse_always) | ||
| 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 | ||
|
Comment on lines
+6
to
+7
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hard coded final paths ... not great! |
||
|
|
||
| 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 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| localhost:5432:postgres:password:md532e12f215ba27cb750c9e093ce4b5127 | ||
| localhost:5432:postgres:postgres:md53175bce1d3201d16594cebf9d7eb3f9d | ||
| localhost:5432:postgres:login:md5d5745f9425eceb269f9fe01d0bef06ff |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| password |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| ARG EMSDK_VER=3.1.74 | ||
| ARG BUILDPLATFORM | ||
| # we only need to build on one platform, since we're interested in the WASM output | ||
| # building on the native (BUILDPLATFORM) is much faster, so use that | ||
| # remove "-arm64" suffix if building on x86_64 | ||
| FROM --platform=$BUILDPLATFORM emscripten/emsdk:${EMSDK_VER}-arm64 AS builder | ||
|
|
||
| ENV LLVM_NM=/emsdk/upstream/bin/llvm-nm | ||
|
|
||
| RUN apt update && apt upgrade -y && apt install -y \ | ||
| xz-utils autoconf libtool automake pkgconf bison flex | ||
|
|
||
| SHELL ["/bin/bash", "-c"] | ||
|
|
||
| RUN mkdir -p /install/libs /install/exports | ||
|
|
||
| WORKDIR /install/libs | ||
|
|
||
| # zlib CAN be installed by using the emsdk like this | ||
| # RUN embuilder --pic --verbose build zlib | ||
|
|
||
| WORKDIR /src | ||
|
|
||
| # ENV EMCC_COMMON_FLAGS="-fPIC -sWASM_BIGINT -sMIN_SAFARI_VERSION=150000 -D__PYDK__=1 -O2 -m32 -D_FILE_OFFSET_BITS=64 -sSUPPORT_LONGJMP=emscripten -mno-bulk-memory -mnontrapping-fptoint -mno-reference-types -mno-sign-ext -mno-extended-const -mno-atomics -mno-tail-call -mno-multivalue -mno-relaxed-simd -mno-simd128 -mno-multimemory -mno-exception-handling -Wno-unused-command-line-argument -Wno-unreachable-code-fallthrough -Wno-unused-function -Wno-invalid-noreturn -Wno-declaration-after-statement -Wno-invalid-noreturn" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess I wanted to look more into each of these flags to see if it makes sense to add them to libs and/or pglite. |
||
| ENV EMCC_COMMON_FLAGS="-O2 -fPIC" | ||
|
|
||
| WORKDIR /src | ||
| RUN curl -L https://www.zlib.net/zlib-1.3.1.tar.gz | tar -xz | ||
| WORKDIR /src/zlib-1.3.1 | ||
| RUN CFLAGS="${EMCC_COMMON_FLAGS}" CXXFLAGS="${EMCC_COMMON_FLAGS}" emconfigure ./configure --static --prefix=/install/libs | ||
| RUN emmake make -j && emmake make install | ||
| RUN ${LLVM_NM} /install/libs/lib/libz.a | awk '$2 ~ /^[TDB]$/ {print $3}' | sed '/^$/d' | sort -u > /install/exports/libz.exports | ||
|
|
||
| WORKDIR /src | ||
| RUN curl -L https://gitlab.gnome.org/GNOME/libxml2/-/archive/v2.14.5/libxml2-v2.14.5.tar.gz | tar -xz | ||
| WORKDIR /src/libxml2-v2.14.5 | ||
| RUN ./autogen.sh --with-python=no | ||
| RUN CFLAGS="${EMCC_COMMON_FLAGS}" CXXFLAGS="${EMCC_COMMON_FLAGS}" emconfigure ./configure --enable-shared=no --enable-static=yes --with-python=no --prefix=/install/libs | ||
| RUN emmake make -j && emmake make install | ||
| # extract exported symbols - useful for passing them to emscripten as EXPORTED_FUNCTIONS | ||
| RUN ${LLVM_NM} /install/libs/lib/libxml2.a | awk '$2 ~ /^[TDB]$/ {print $3}' | sed '/^$/d' | sort -u > /install/exports/libxml2.exports | ||
|
|
||
| WORKDIR /src | ||
| RUN curl -L https://gitlab.gnome.org/GNOME/libxslt/-/archive/v1.1.43/libxslt-v1.1.43.tar.gz | tar -xz | ||
| WORKDIR /src/libxslt-v1.1.43 | ||
| RUN ./autogen.sh --with-python=no | ||
| RUN CFLAGS="${EMCC_COMMON_FLAGS}" CXXFLAGS="${EMCC_COMMON_FLAGS}" emconfigure ./configure --enable-shared=no --enable-static=yes --with-python=no --prefix=/install/libs --with-libxml-src=/src/libxml2-v2.14.5/ --with-pic=yes | ||
| RUN emmake make -j && emmake make install | ||
| # extract exported symbols - useful for passing them to emscripten as EXPORTED_FUNCTIONS | ||
| RUN ${LLVM_NM} /install/libs/lib/libxslt.a | awk '$2 ~ /^[TDB]$/ {print $3}' | sed '/^$/d' | sort -u > /install/exports/libxslt.exports | ||
|
|
||
| WORKDIR /src | ||
| RUN curl -L https://github.com/openssl/openssl/releases/download/openssl-3.0.17/openssl-3.0.17.tar.gz | tar xz | ||
| WORKDIR /src/openssl-3.0.17 | ||
| RUN emconfigure ./Configure no-tests linux-generic64 --prefix=/install/libs | ||
| RUN sed -i 's|^CROSS_COMPILE.*$|CROSS_COMPILE=|g' Makefile # see https://github.com/emscripten-core/emscripten/issues/19597#issue-1754476454 | ||
| RUN emmake make -j && emmake make install | ||
| # extract exported symbols - useful for passing them to emscripten as EXPORTED_FUNCTIONS | ||
| RUN ${LLVM_NM} /install/libs/lib/libssl.a | awk '$2 ~ /^[TDB]$/ {print $3}' | sed '/^$/d' | sort -u > /install/exports/libssl.exports | ||
|
|
||
| WORKDIR /src | ||
| RUN curl -L ftp://ftp.ossp.org/pkg/lib/uuid/uuid-1.6.2.tar.gz | tar xz | ||
| WORKDIR /src/uuid-1.6.2 | ||
| RUN CFLAGS="${EMCC_COMMON_FLAGS}" CXXFLAGS="${EMCC_COMMON_FLAGS}" emconfigure ./configure --build=aarch64-unknown-linux-gnu --enable-shared=no --enable-static=yes --with-perl=no --with-perl-compat=no --prefix=/install/libs --with-php=no --with-pic=yes | ||
| RUN emmake make -j && emmake make install || true # install tries to strip the wasm, but it doesnt recognize the format, so ignore atm | ||
| WORKDIR /install/libs/lib | ||
| RUN ln -s libuuid.a libossp-uuid.a # contrib extensions use -lossp-uuid | ||
| RUN ${LLVM_NM} /install/libs/lib/libossp-uuid.a | awk '$2 ~ /^[TDB]$/ {print $3}' | sed '/^$/d' | sort -u > /install/exports/libossp-uuid.exports | ||
|
|
||
| ARG TARGETARCH | ||
| FROM emscripten/emsdk:${EMSDK_VER} AS base-amd64 | ||
| FROM emscripten/emsdk:${EMSDK_VER}-arm64 AS base-arm64 | ||
| FROM base-${TARGETARCH} AS runner | ||
|
|
||
| RUN apt update && apt upgrade -y && apt install -y \ | ||
| xz-utils autoconf libtool automake pkgconf bison flex | ||
|
|
||
| # this is where the libraries will be installed and subsequently where the LIBS and INCLUDES can be found | ||
| ARG INSTALL_PREFIX=/install/libs | ||
| ENV INSTALL_PREFIX=${INSTALL_PREFIX} | ||
|
|
||
| ARG LIB_EXPORTS_DIR=/install/exports | ||
| ENV LIB_EXPORTS_DIR=${LIB_EXPORTS_DIR} | ||
|
|
||
| COPY --from=builder /install/libs ${INSTALL_PREFIX} | ||
| COPY --from=builder /install/exports ${LIB_EXPORTS_DIR} | ||
|
|
||
| # needed in building pglite.wasm | ||
| ENV LLVM_NM=/emsdk/upstream/bin/llvm-nm | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| __indirect_function_table | ||
| invoke_di | ||
| invoke_didi | ||
| invoke_dii | ||
| invoke_i | ||
| invoke_ii | ||
| invoke_iii | ||
| invoke_iiii | ||
| invoke_iiiii | ||
| invoke_iiiiii | ||
| invoke_iiiiiii | ||
| invoke_iiiiiiii | ||
| invoke_iij | ||
| invoke_ij | ||
| invoke_ijj | ||
| invoke_j | ||
| invoke_ji | ||
| invoke_jiiiii | ||
| invoke_v | ||
| invoke_vi | ||
| invoke_vii | ||
| invoke_viii | ||
| invoke_viiidi | ||
| invoke_viiii | ||
| invoke_viiiii | ||
| invoke_viiiiii | ||
| invoke_viiiiii | ||
| invoke_viiiiiiii | ||
| invoke_viiiiiiiii | ||
| invoke_viiji | ||
| invoke_vij | ||
| invoke_vijiiidjiiii |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| close | ||
| fcntl | ||
| free | ||
| get_buffer_addr | ||
| get_buffer_size | ||
| get_channel | ||
| getpid | ||
| gettimeofday | ||
| gmtime | ||
| interactive_one | ||
| interactive_read | ||
| interactive_write | ||
| ioctl | ||
| isalnum | ||
| isxdigit | ||
| lowerstr | ||
| main | ||
| malloc | ||
| memcmp | ||
| memcpy | ||
| memset | ||
| nanosleep | ||
| open | ||
| pgl_backend | ||
| pgl_initdb | ||
| pgl_shutdown | ||
| rand | ||
| read | ||
| readstoplist | ||
| realloc | ||
| searchstoplist | ||
| socket | ||
| srand | ||
| strcmp | ||
| strftime | ||
| strlen | ||
| strtoul | ||
| use_wire |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,6 +26,10 @@ | |
| #include <unistd.h> /* chdir */ | ||
| #include <sys/stat.h> /* mkdir */ | ||
|
|
||
| #if defined(__EMSCRIPTEN__) | ||
| #include <emscripten.h> | ||
| #endif | ||
|
|
||
| // globals | ||
|
|
||
|
|
||
|
|
@@ -482,7 +486,8 @@ __attribute__ ((export_name("pgl_backend"))) | |
| #else | ||
| remove(IDB_PIPE_BOOT); | ||
| #endif | ||
| stdin = fdopen(saved_stdin, "r"); | ||
| // tdrz: I've commented this out!!! | ||
| // stdin = fdopen(saved_stdin, "r"); | ||
|
Comment on lines
+489
to
+490
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why was this even needed? |
||
|
|
||
| PDEBUG("# 479: initdb faking shutdown to complete WAL/OID states"); | ||
| pg_proc_exit(66); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| # Packages other extensions into individual tar.gz archives | ||
|
|
||
| top_builddir = .. | ||
| include $(top_builddir)/src/Makefile.global | ||
|
|
||
| SUBDIRS = \ | ||
| pg_ivm \ | ||
| vector | ||
|
|
||
| prefix ?= /install/pglite | ||
| EXTENSIONS_BUILD_ROOT := /tmp/extensions/build | ||
| ARCHIVE_DIR := /install/pglite/extensions | ||
|
|
||
| EXTENSIONS := $(SUBDIRS) | ||
|
|
||
| # Default target: build tarballs for all contribs | ||
| dist: $(addsuffix .tar.gz,$(EXTENSIONS)) | ||
|
|
||
| # Pattern rule: build $(EXT).tar.gz for each extra extension | ||
| %.tar.gz: | ||
| @echo "=== Staging $* ===" | ||
| rm -rf $(EXTENSIONS_BUILD_ROOT)/$* | ||
| bash -c 'mkdir -p $(EXTENSIONS_BUILD_ROOT)/$*/$(prefix)/{bin,lib,share/extension,share/doc,share/postgresql/extension,share/postgresql/tsearch_data,include}' | ||
| $(MAKE) -C $* install DESTDIR=$(EXTENSIONS_BUILD_ROOT)/$* | ||
| @echo "=== Packaging $* ===" | ||
| mkdir -p $(ARCHIVE_DIR) | ||
| cd $(EXTENSIONS_BUILD_ROOT)/$*/$(prefix) && \ | ||
| files=$$(find . -type f -o -type l | sed 's|^\./||') && \ | ||
| tar -czf $(ARCHIVE_DIR)/$*.tar.gz $$files | ||
| # tar -C $(EXTENSIONS_BUILD_ROOT)/$*/$(prefix) -czf $(ARCHIVE_DIR)/$*.tar.gz . | ||
|
|
||
| .PHONY: dist | ||
|
|
||
|
|
||
| $(recurse) |
Uh oh!
There was an error while loading. Please reload this page.