Skip to content

Commit e2e9f8e

Browse files
committed
feat(ci): add PostgreSQL extension builds for Linux, macOS, and Windows
Add a postgres-build matrix job that compiles the PostgreSQL extension for 5 platform/arch combinations (linux-x86_64, linux-arm64, macos-arm64, macos-x86_64, windows-x86_64) and includes them as release assets. Add postgres-package Makefile target and Windows platform support (PG_EXTENSION_LIB, -lpostgres linking).
1 parent 9882a84 commit e2e9f8e

File tree

3 files changed

+101
-11
lines changed

3 files changed

+101
-11
lines changed

.github/workflows/main.yml

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,10 +265,77 @@ jobs:
265265
docker cp test/postgresql cloudsync-postgres:/tmp/cloudsync/test/postgresql
266266
docker exec cloudsync-postgres psql -U postgres -d postgres -f /tmp/cloudsync/test/postgresql/full_test.sql
267267
268+
postgres-build:
269+
runs-on: ${{ matrix.os }}
270+
name: postgresql-${{ matrix.name }}-${{ matrix.arch }} build
271+
timeout-minutes: 15
272+
strategy:
273+
fail-fast: false
274+
matrix:
275+
include:
276+
- os: ubuntu-22.04
277+
arch: x86_64
278+
name: linux
279+
- os: ubuntu-22.04-arm
280+
arch: arm64
281+
name: linux
282+
- os: macos-15
283+
arch: arm64
284+
name: macos
285+
- os: macos-13
286+
arch: x86_64
287+
name: macos
288+
- os: windows-2022
289+
arch: x86_64
290+
name: windows
291+
292+
steps:
293+
294+
- uses: actions/checkout@v4.2.2
295+
with:
296+
submodules: true
297+
298+
- name: linux install postgresql dev headers
299+
if: matrix.name == 'linux'
300+
run: |
301+
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
302+
curl -fsSL https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/postgresql.gpg
303+
sudo apt-get update
304+
sudo apt-get install -y postgresql-server-dev-17
305+
306+
- name: macos install postgresql
307+
if: matrix.name == 'macos'
308+
run: brew install postgresql@17
309+
310+
- uses: msys2/setup-msys2@v2.27.0
311+
if: matrix.name == 'windows'
312+
with:
313+
msystem: ucrt64
314+
install: mingw-w64-ucrt-x86_64-gcc make mingw-w64-ucrt-x86_64-postgresql
315+
316+
- name: build and package postgresql extension (linux)
317+
if: matrix.name == 'linux'
318+
run: make postgres-package
319+
320+
- name: build and package postgresql extension (macos)
321+
if: matrix.name == 'macos'
322+
run: make postgres-package PG_CONFIG=$(brew --prefix postgresql@17)/bin/pg_config
323+
324+
- name: build and package postgresql extension (windows)
325+
if: matrix.name == 'windows'
326+
shell: msys2 {0}
327+
run: make postgres-package
328+
329+
- uses: actions/upload-artifact@v4.6.2
330+
with:
331+
name: cloudsync-postgresql-${{ matrix.name }}-${{ matrix.arch }}
332+
path: dist/postgresql/
333+
if-no-files-found: error
334+
268335
release:
269336
runs-on: ubuntu-22.04
270337
name: release
271-
needs: [build, postgres-test]
338+
needs: [build, postgres-test, postgres-build]
272339
if: github.ref == 'refs/heads/main'
273340

274341
env:

docker/Makefile.postgresql

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,17 @@ PG_INCLUDEDIR := $(shell $(PG_CONFIG) --includedir-server 2>/dev/null)
1414
EXTENSION = cloudsync
1515
EXTVERSION = 1.0
1616

17+
# Platform-specific PostgreSQL settings
18+
ifeq ($(OS),Windows_NT)
19+
PG_EXTENSION_LIB = $(EXTENSION).dll
20+
PG_CFLAGS = -Wall -Wextra -Wno-unused-parameter -std=c11 -O2
21+
PG_LDFLAGS = -shared -L$(shell $(PG_CONFIG) --libdir) -lpostgres
22+
else
23+
PG_EXTENSION_LIB = $(EXTENSION).so
24+
PG_CFLAGS = -fPIC -Wall -Wextra -Wno-unused-parameter -std=c11 -O2
25+
PG_LDFLAGS = -shared
26+
endif
27+
1728
# Source files - core platform-agnostic code
1829
PG_CORE_SRC = \
1930
src/cloudsync.c \
@@ -38,23 +49,24 @@ PG_OBJS = $(PG_ALL_SRC:.c=.o)
3849
# Compiler flags
3950
# Define POSIX macros as compiler flags to ensure they're defined before any includes
4051
PG_CPPFLAGS = -I$(PG_INCLUDEDIR) -Isrc -Isrc/postgresql -Imodules/fractional-indexing -DCLOUDSYNC_POSTGRESQL_BUILD -D_POSIX_C_SOURCE=200809L -D_GNU_SOURCE
41-
PG_CFLAGS = -fPIC -Wall -Wextra -Wno-unused-parameter -std=c11 -O2
4252
PG_DEBUG ?= 0
4353
ifeq ($(PG_DEBUG),1)
54+
ifeq ($(OS),Windows_NT)
55+
PG_CFLAGS = -Wall -Wextra -Wno-unused-parameter -std=c11 -g -O0 -fno-omit-frame-pointer
56+
else
4457
PG_CFLAGS = -fPIC -Wall -Wextra -Wno-unused-parameter -std=c11 -g -O0 -fno-omit-frame-pointer
4558
endif
46-
PG_LDFLAGS = -shared
59+
endif
4760

4861
# Output files
49-
PG_EXTENSION_SO = $(EXTENSION).so
5062
PG_EXTENSION_SQL = src/postgresql/$(EXTENSION)--$(EXTVERSION).sql
5163
PG_EXTENSION_CONTROL = docker/postgresql/$(EXTENSION).control
5264

5365
# ============================================================================
5466
# PostgreSQL Build Targets
5567
# ============================================================================
5668

57-
.PHONY: postgres-check postgres-build postgres-install postgres-clean postgres-test \
69+
.PHONY: postgres-check postgres-build postgres-install postgres-package postgres-clean postgres-test \
5870
postgres-docker-build postgres-docker-build-asan postgres-docker-run postgres-docker-run-asan postgres-docker-stop postgres-docker-rebuild \
5971
postgres-docker-debug-build postgres-docker-debug-run postgres-docker-debug-rebuild \
6072
postgres-docker-shell postgres-dev-rebuild postgres-help unittest-pg \
@@ -78,16 +90,16 @@ postgres-build: postgres-check
7890
echo " CC $$src"; \
7991
$(CC) $(PG_CPPFLAGS) $(PG_CFLAGS) -c $$src -o $${src%.c}.o || exit 1; \
8092
done
81-
@echo "Linking $(PG_EXTENSION_SO)..."
82-
$(CC) $(PG_LDFLAGS) -o $(PG_EXTENSION_SO) $(PG_OBJS)
83-
@echo "Build complete: $(PG_EXTENSION_SO)"
93+
@echo "Linking $(PG_EXTENSION_LIB)..."
94+
$(CC) $(PG_LDFLAGS) -o $(PG_EXTENSION_LIB) $(PG_OBJS)
95+
@echo "Build complete: $(PG_EXTENSION_LIB)"
8496

8597
# Install extension to PostgreSQL
8698
postgres-install: postgres-build
8799
@echo "Installing CloudSync extension to PostgreSQL..."
88100
@echo "Installing shared library to $(PG_PKGLIBDIR)/"
89101
install -d $(PG_PKGLIBDIR)
90-
install -m 755 $(PG_EXTENSION_SO) $(PG_PKGLIBDIR)/
102+
install -m 755 $(PG_EXTENSION_LIB) $(PG_PKGLIBDIR)/
91103
@echo "Installing SQL script to $(PG_SHAREDIR)/extension/"
92104
install -d $(PG_SHAREDIR)/extension
93105
install -m 644 $(PG_EXTENSION_SQL) $(PG_SHAREDIR)/extension/
@@ -98,10 +110,21 @@ postgres-install: postgres-build
98110
@echo "To use the extension, run in psql:"
99111
@echo " CREATE EXTENSION $(EXTENSION);"
100112

113+
# Package extension files for distribution
114+
PG_DIST_DIR = dist/postgresql
115+
116+
postgres-package: postgres-build
117+
@echo "Packaging PostgreSQL extension..."
118+
@mkdir -p $(PG_DIST_DIR)
119+
cp $(PG_EXTENSION_LIB) $(PG_DIST_DIR)/
120+
cp $(PG_EXTENSION_SQL) $(PG_DIST_DIR)/
121+
cp $(PG_EXTENSION_CONTROL) $(PG_DIST_DIR)/
122+
@echo "Package ready in $(PG_DIST_DIR)/"
123+
101124
# Clean PostgreSQL build artifacts
102125
postgres-clean:
103126
@echo "Cleaning PostgreSQL build artifacts..."
104-
rm -f $(PG_OBJS) $(PG_EXTENSION_SO)
127+
rm -f $(PG_OBJS) $(PG_EXTENSION_LIB)
105128
@echo "Clean complete"
106129

107130
# Test extension (requires running PostgreSQL)

src/cloudsync.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
extern "C" {
1919
#endif
2020

21-
#define CLOUDSYNC_VERSION "0.9.202"
21+
#define CLOUDSYNC_VERSION "0.9.203"
2222
#define CLOUDSYNC_MAX_TABLENAME_LEN 512
2323

2424
#define CLOUDSYNC_VALUE_NOTSET -1

0 commit comments

Comments
 (0)