Skip to content

Commit c24701f

Browse files
authored
Merge pull request #177 from constructive-io/fix/v13-build-from-source
fix(v13): build PG13 WASM from source in CI
2 parents b0af47e + 555e166 commit c24701f

2 files changed

Lines changed: 58 additions & 32 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,7 @@ jobs:
5151
run: pnpm install
5252

5353
- name: Build WASM 🏗
54-
run: |
55-
if [ "${{ matrix.package.name }}" = "v13" ]; then
56-
# Download prebuilt WASM for v13 since it can't build in CI
57-
mkdir -p wasm
58-
curl -o v13.tgz "https://registry.npmjs.org/@libpg-query/v13/-/v13-13.5.7.tgz"
59-
tar -xzf v13.tgz --strip-components=1 package/wasm
60-
rm v13.tgz
61-
else
62-
pnpm run build
63-
fi
54+
run: pnpm run build
6455
working-directory: ${{ matrix.package.path }}
6556

6657
- name: Upload WASM Artifacts 📦
Lines changed: 57 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,59 @@
1-
--- a/Makefile
2-
+++ b/Makefile
3-
@@ -36,6 +36,11 @@ OBJ_FILES := $(filter-out $(NOT_OBJ_FILES), $(SRC_FILES:.c=.o))
4-
override CFLAGS += -g -I. -I./vendor -I./src/postgres/include -Wall -Wno-unused-function -Wno-unused-value -Wno-unused-variable -fno-strict-aliasing -fwrapv -fPIC
1+
Backport of the PostgreSQL 14 s_lock.h fallback that uses __sync_lock_test_and_set()
2+
when there is no platform-specific TAS. PG13 has none for wasm32, so without this
3+
Emscripten hits "#error PostgreSQL does not have native spinlock support".
4+
5+
diff --git a/src/postgres/include/storage/s_lock.h b/src/postgres/include/storage/s_lock.h
6+
index 6b368a5..d8d0bff 100644
7+
--- a/src/postgres/include/storage/s_lock.h
8+
+++ b/src/postgres/include/storage/s_lock.h
9+
@@ -748,6 +748,50 @@ tas(volatile slock_t *lock)
10+
typedef unsigned char slock_t;
11+
#endif
512

6-
override PG_CONFIGURE_FLAGS += -q --without-readline --without-zlib
713
+
8-
+# Disable spinlocks when building with Emscripten
9-
+ifdef EMSCRIPTEN
10-
+override PG_CONFIGURE_FLAGS += --disable-spinlocks
11-
+endif
12-
13-
override TEST_CFLAGS += -I. -I./vendor -g
14-
override TEST_LDFLAGS += -pthread
15-
@@ -149,6 +154,9 @@ extract_source: $(PGDIR)
16-
echo "#undef LOCALE_T_IN_XLOCALE" >> ./src/postgres/include/pg_config.h
17-
echo "#undef WCSTOMBS_L_IN_XLOCALE" >> ./src/postgres/include/pg_config.h
18-
# Support 32-bit systems without reconfiguring
19-
+ifdef EMSCRIPTEN
20-
+ echo "#undef HAVE_SPINLOCKS" >> ./src/postgres/include/pg_config.h
21-
+endif
22-
echo "#undef PG_INT128_TYPE" >> ./src/postgres/include/pg_config.h
23-
# Support gcc earlier than 4.6.0 without reconfiguring
24-
echo "#undef HAVE__STATIC_ASSERT" >> ./src/postgres/include/pg_config.h
14+
+/*
15+
+ * If we have no platform-specific knowledge, but we found that the compiler
16+
+ * provides __sync_lock_test_and_set(), use that. Prefer the int-width
17+
+ * version over the char-width version if we have both, on the rather dubious
18+
+ * grounds that that's known to be more likely to work in the ARM ecosystem.
19+
+ * (But we dealt with ARM above.)
20+
+ */
21+
+#if !defined(HAS_TEST_AND_SET)
22+
+
23+
+#if defined(HAVE_GCC__SYNC_INT32_TAS)
24+
+#define HAS_TEST_AND_SET
25+
+
26+
+#define TAS(lock) tas(lock)
27+
+
28+
+typedef int slock_t;
29+
+
30+
+static __inline__ int
31+
+tas(volatile slock_t *lock)
32+
+{
33+
+ return __sync_lock_test_and_set(lock, 1);
34+
+}
35+
+
36+
+#define S_UNLOCK(lock) __sync_lock_release(lock)
37+
+
38+
+#elif defined(HAVE_GCC__SYNC_CHAR_TAS)
39+
+#define HAS_TEST_AND_SET
40+
+
41+
+#define TAS(lock) tas(lock)
42+
+
43+
+typedef char slock_t;
44+
+
45+
+static __inline__ int
46+
+tas(volatile slock_t *lock)
47+
+{
48+
+ return __sync_lock_test_and_set(lock, 1);
49+
+}
50+
+
51+
+#define S_UNLOCK(lock) __sync_lock_release(lock)
52+
+
53+
+#endif /* HAVE_GCC__SYNC_INT32_TAS */
54+
+
55+
+#endif /* !defined(HAS_TEST_AND_SET) */
56+
+
57+
/*
58+
* Default implementation of S_UNLOCK() for gcc/icc.
59+
*

0 commit comments

Comments
 (0)