Skip to content

fix(v13): build PG13 WASM from source in CI - #177

Merged
pyramation merged 1 commit into
mainfrom
fix/v13-build-from-source
Oct 22, 2026
Merged

pyramation merged 1 commit into
mainfrom
fix/v13-build-from-source

Conversation

@pyramation

Copy link
Copy Markdown
Collaborator

Summary

CI has never built v13. It downloaded the prebuilt @libpg-query/[email protected] WASM, which has Emscripten's default 64 KiB stack and traps on SELECT 1+1+… with 1000 terms. This PR makes v13 build from source like 14–18 do.

Root cause. PG13's src/postgres/include/storage/s_lock.h has no test-and-set (TAS) for wasm32, so the build stops at:

./src/postgres/include/storage/s_lock.h:946:2: error: PostgreSQL does not have native spinlock support on this platform.  To continue the compilation, rerun configure using --disable-spinlocks.

The old emscripten_disable_spinlocks.patch only added --disable-spinlocks and #undef HAVE_SPINLOCKS to libpg_query's configure and extract_source steps. make build never runs those steps; it uses the pg_config.h already checked in, which still has HAVE_SPINLOCKS 1.

PG14 added a generic fallback, which is why 14–18 build fine: if nothing else defined HAS_TEST_AND_SET, it uses __sync_lock_test_and_set() when HAVE_GCC__SYNC_INT32_TAS / HAVE_GCC__SYNC_CHAR_TAS is set. PG13's pg_config.h already defines both of those. This PR's patch backports that block into PG13's s_lock.h, word for word from PG14.

Changes

  • versions/13/patches/emscripten_disable_spinlocks.patch: the content is replaced with the s_lock.h backport. The filename stays the same, so the template and Makefile need no changes and copy:templates produces no diff.
  • .github/workflows/ci.yml: the v13 tarball download is removed; every version now runs pnpm run build.

Verified locally (Linux, Docker, cd versions/13 && pnpm run build from an empty .cache, about 35–40 s):

emsdk wasm sha256 pnpm test
6.0.13 (untagged emscripten/emsdk, what main uses) c568fa4c…d67a 41/41 pass
6.0.3 (#174's pin) c81f444c…8708 41/41 pass, two clean builds gave identical bytes
  • On 10 sample statements the parse output is identical to the published [email protected] (DDL, CTE, window, plpgsql function, GRANT, COPY…).
  • Left-deep 1+1+… chains: 1000 and 5000 terms parse; 20000 terms gives a clean RangeError (published 13.7.3 behaves the same). The CI prebuilt 13.5.7 traps at 1000 (table index is out of bounds).

Conflicts with #173, which edits the same v13 CI step. Whichever merges second just deletes the if v13 branch.

Link to Devin session: https://app.devin.ai/sessions/46dadacb8a2045eab1b68b35e90ad8de
Open in Devin Desktop: https://app.devin.ai/desktop/session/46dadacb8a2045eab1b68b35e90ad8de?variant=devin
Requested by: @pyramation

PG13's s_lock.h has no TAS for wasm32, so Emscripten stopped at
'#error PostgreSQL does not have native spinlock support'. The old patch
only added --disable-spinlocks / '#undef HAVE_SPINLOCKS' to configure and
extract_source steps that 'make build' never runs. Backport PG14's generic
__sync_lock_test_and_set() fallback instead, and drop CI's download of the
prebuilt @libpg-query/[email protected] WASM.
@devin-ai-integration

Copy link
Copy Markdown

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@pyramation
pyramation marked this pull request as ready for review October 22, 2026 23:23
@tenki-reviewer

tenki-reviewer Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Review complete. No issues found — approved ✅.


This PR makes PostgreSQL 13 buildable under Emscripten by backporting the upstream __sync_lock_test_and_set-based TAS spinlock fallback into versions/13/patches/emscripten_disable_spinlocks.patch, removing the #error path when --disable-spinlocks is used on wasm32. The CI workflow is updated to build all supported versions from source, dropping the prebuilt v13 WASM download and eliminating that supply-chain fetch. | Files | Change | | --- | --- | | versions/13/patches/emscripten_disable_spinlocks.patch | Backports the wasm32 spinlock fallback (__sync_lock_test_and_set / __sync_lock_release) so PG13 builds with --disable-spinlocks. | | .github/workflows/ci.yml | Builds v13 WASM from source with the new patch instead of fetching prebuilt artifacts. | No blocking issues were identified; the verified scan found no defects in either change.

Reviewed commit: 555e166

@pyramation
pyramation merged commit c24701f into main Oct 22, 2026
59 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant