Skip to content

Commit 22b1691

Browse files
stevencowlesclaude
andauthored
Complete JIT dependency fix for v0.2.2 (#11)
* Complete JIT dependency bundling for v0.2.2 Extend JIT fix to bundle complete LLVM dependency chain: - Bundle libLLVM.dylib (main LLVM library) - Bundle libz3.4.15.dylib (Z3 SMT solver - LLVM dependency) - Bundle libzstd.1.dylib (Zstandard compression - LLVM dependency) - Fix all hardcoded homebrew paths using install_name_tool - Update library IDs for portable @loader_path resolution Add comprehensive JIT compilation tests: - Test JIT parameter availability - Test JIT enable/disable functionality - Test actual JIT compilation with complex queries - Validate complete JIT workflow end-to-end This fixes the remaining JIT compilation issues where basic setup worked but actual compilation failed due to missing transitive dependencies. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * Fix ARM64 LLVM JIT compatibility on macOS Resolves "Unsupported stack probing method" error on ARM64 by ensuring PostgreSQL uses matching Clang and LLVM versions from Homebrew. - Add CLANG environment variable pointing to Homebrew LLVM Clang - Ensure LLVM_CONFIG and CLANG are from same installation - Fixes version mismatch between system Clang and Homebrew LLVM - Resolves ARM64-specific JIT compilation crashes Based on research of LLVM issue #95804 and PostgreSQL build requirements. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 6c833ec commit 22b1691

File tree

2 files changed

+107
-7
lines changed

2 files changed

+107
-7
lines changed

Makefile

Lines changed: 54 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ else ifeq ($(VARIANT),full)
5858
BREW_PREFIX := $(shell brew --prefix)
5959
ICU_PREFIX := $(BREW_PREFIX)/opt/icu4c
6060
LLVM_PREFIX := $(BREW_PREFIX)/opt/llvm
61-
CONFIGURE_FLAGS = --prefix=$(PREFIX) --with-openssl --with-icu --with-lz4 --with-zstd --with-libxml --with-llvm --with-uuid=e2fs --disable-nls CFLAGS="-Wno-unguarded-availability-new" --with-includes="$(BREW_PREFIX)/include:$(ICU_PREFIX)/include:$(LLVM_PREFIX)/include" --with-libraries="$(BREW_PREFIX)/lib:$(ICU_PREFIX)/lib:$(LLVM_PREFIX)/lib"
61+
CONFIGURE_FLAGS = --prefix=$(PREFIX) --with-openssl --with-icu --with-lz4 --with-zstd --with-libxml --with-llvm --with-uuid=e2fs --disable-nls CFLAGS="-Wno-unguarded-availability-new" --with-includes="$(BREW_PREFIX)/include:$(ICU_PREFIX)/include:$(LLVM_PREFIX)/include" --with-libraries="$(BREW_PREFIX)/lib:$(ICU_PREFIX)/lib:$(LLVM_PREFIX)/lib" LLVM_CONFIG="$(LLVM_PREFIX)/bin/llvm-config" CLANG="$(LLVM_PREFIX)/bin/clang"
6262
else ifeq ($(PLATFORM),linux)
6363
CONFIGURE_FLAGS = --prefix=$(PREFIX) --with-openssl --with-icu --with-lz4 --with-zstd --with-libxml --with-llvm --with-uuid=e2fs --disable-nls
6464
else ifeq ($(PLATFORM),win32)
@@ -92,7 +92,11 @@ extract:
9292
configure:
9393
@echo "⚙️ Configuring PostgreSQL build..."
9494
ifeq ($(PLATFORM),darwin)
95-
cd $(POSTGRES_SRC) && PKG_CONFIG_PATH="$(ICU_PREFIX)/lib/pkgconfig:$(BREW_PREFIX)/lib/pkgconfig" LLVM_CONFIG="$(LLVM_PREFIX)/bin/llvm-config" ./configure $(CONFIGURE_FLAGS)
95+
ifeq ($(VARIANT),full)
96+
cd $(POSTGRES_SRC) && PKG_CONFIG_PATH="$(ICU_PREFIX)/lib/pkgconfig:$(BREW_PREFIX)/lib/pkgconfig" LLVM_CONFIG="$(LLVM_PREFIX)/bin/llvm-config" CLANG="$(LLVM_PREFIX)/bin/clang" ./configure $(CONFIGURE_FLAGS)
97+
else
98+
cd $(POSTGRES_SRC) && PKG_CONFIG_PATH="$(BREW_PREFIX)/lib/pkgconfig" ./configure $(CONFIGURE_FLAGS)
99+
endif
96100
else
97101
cd $(POSTGRES_SRC) && ./configure $(CONFIGURE_FLAGS)
98102
endif
@@ -128,18 +132,62 @@ bundle-deps:
128132
@echo "📦 Bundling runtime dependencies..."
129133
ifeq ($(VARIANT),full)
130134
ifeq ($(PLATFORM),darwin)
131-
@echo " 🔗 Bundling LLVM libraries for JIT support..."
135+
@echo " 🔗 Bundling LLVM and dependencies for JIT support..."
136+
137+
# Bundle LLVM library
132138
@if [ -f "$(LLVM_PREFIX)/lib/libLLVM.dylib" ]; then \
133139
cp "$(LLVM_PREFIX)/lib/libLLVM.dylib" "$(PREFIX)/lib/"; \
134140
echo " ✅ Bundled libLLVM.dylib"; \
135141
else \
136-
echo " ⚠️ Warning: libLLVM.dylib not found at $(LLVM_PREFIX)/lib/"; \
142+
echo " ❌ Error: libLLVM.dylib not found at $(LLVM_PREFIX)/lib/"; \
143+
exit 1; \
144+
fi
145+
146+
# Bundle Z3 SMT solver library (LLVM dependency)
147+
@if [ -f "$(BREW_PREFIX)/opt/z3/lib/libz3.dylib" ]; then \
148+
cp "$(BREW_PREFIX)/opt/z3/lib/libz3.dylib" "$(PREFIX)/lib/"; \
149+
echo " ✅ Bundled libz3.dylib"; \
150+
elif [ -f "$(BREW_PREFIX)/opt/z3/lib/libz3.4.15.dylib" ]; then \
151+
cp "$(BREW_PREFIX)/opt/z3/lib/libz3.4.15.dylib" "$(PREFIX)/lib/"; \
152+
echo " ✅ Bundled libz3.4.15.dylib"; \
153+
else \
154+
echo " ❌ Error: libz3 not found at $(BREW_PREFIX)/opt/z3/lib/"; \
155+
exit 1; \
156+
fi
157+
158+
# Bundle Zstandard compression library (LLVM dependency)
159+
@if [ -f "$(BREW_PREFIX)/opt/zstd/lib/libzstd.1.dylib" ]; then \
160+
cp "$(BREW_PREFIX)/opt/zstd/lib/libzstd.1.dylib" "$(PREFIX)/lib/"; \
161+
echo " ✅ Bundled libzstd.1.dylib"; \
162+
else \
163+
echo " ❌ Error: libzstd.1.dylib not found at $(BREW_PREFIX)/opt/zstd/lib/"; \
164+
exit 1; \
137165
fi
138-
@echo " 🔧 Fixing library paths for bundled dependencies..."
166+
167+
@echo " 🔧 Fixing library paths for JIT dependencies..."
168+
169+
# Fix llvmjit.dylib -> libLLVM.dylib path
139170
@if [ -f "$(PREFIX)/lib/llvmjit.dylib" ] && [ -f "$(PREFIX)/lib/libLLVM.dylib" ]; then \
140171
install_name_tool -change "$(LLVM_PREFIX)/lib/libLLVM.dylib" "@loader_path/libLLVM.dylib" "$(PREFIX)/lib/llvmjit.dylib"; \
141-
echo " ✅ Fixed llvmjit.dylib library path"; \
172+
echo " ✅ Fixed llvmjit.dylib -> libLLVM.dylib path"; \
173+
fi
174+
175+
# Fix libLLVM.dylib paths to its dependencies
176+
@if [ -f "$(PREFIX)/lib/libLLVM.dylib" ]; then \
177+
install_name_tool -id "@loader_path/libLLVM.dylib" "$(PREFIX)/lib/libLLVM.dylib"; \
178+
if [ -f "$(PREFIX)/lib/libz3.dylib" ]; then \
179+
install_name_tool -change "$(BREW_PREFIX)/opt/z3/lib/libz3.dylib" "@loader_path/libz3.dylib" "$(PREFIX)/lib/libLLVM.dylib"; \
180+
elif [ -f "$(PREFIX)/lib/libz3.4.15.dylib" ]; then \
181+
install_name_tool -change "$(BREW_PREFIX)/opt/z3/lib/libz3.4.15.dylib" "@loader_path/libz3.4.15.dylib" "$(PREFIX)/lib/libLLVM.dylib"; \
182+
fi; \
183+
if [ -f "$(PREFIX)/lib/libzstd.1.dylib" ]; then \
184+
install_name_tool -change "$(BREW_PREFIX)/opt/zstd/lib/libzstd.1.dylib" "@loader_path/libzstd.1.dylib" "$(PREFIX)/lib/libLLVM.dylib"; \
185+
fi; \
186+
echo " ✅ Fixed libLLVM.dylib dependency paths"; \
142187
fi
188+
189+
@echo " 🎯 JIT dependency bundling complete"
190+
143191
else
144192
@echo " ℹ️ Dependency bundling not implemented for $(PLATFORM)"
145193
endif

test-binaries.sh

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,59 @@ FROM test_vectors
9494
ORDER BY distance;
9595
"
9696

97-
# Test 7: Clean shutdown
97+
# Test 7: JIT functionality (full variant only)
98+
if [ "$VARIANT" = "full" ]; then
99+
echo "🔬 Testing JIT compilation (full variant)..."
100+
101+
# Test basic JIT availability
102+
echo " Testing JIT availability..."
103+
${POSTGRES_DIR}/bin/psql -p ${TEST_PORT} -d template1 -U ${USER} -c "SHOW jit;" || {
104+
echo "❌ ERROR: JIT parameter not available"
105+
exit 1
106+
}
107+
108+
# Test JIT can be enabled without errors
109+
echo " Testing JIT enable/disable..."
110+
${POSTGRES_DIR}/bin/psql -p ${TEST_PORT} -d template1 -U ${USER} -c "SET jit = on;" || {
111+
echo "❌ ERROR: Failed to enable JIT"
112+
exit 1
113+
}
114+
115+
# Test JIT with actual compilation (force low cost threshold)
116+
echo " Testing JIT compilation with complex query..."
117+
${POSTGRES_DIR}/bin/psql -p ${TEST_PORT} -d template1 -U ${USER} -c "
118+
SET jit = on;
119+
SET jit_above_cost = 0;
120+
SET jit_optimize_above_cost = 0;
121+
SET jit_inline_above_cost = 0;
122+
123+
-- Create larger dataset for JIT to kick in
124+
CREATE TABLE jit_test AS
125+
SELECT i as id, random() as value, 'test_' || i as name
126+
FROM generate_series(1, 1000) i;
127+
128+
-- Complex query that should trigger JIT
129+
SELECT COUNT(*), AVG(value), MIN(value), MAX(value)
130+
FROM jit_test
131+
WHERE value > 0.5 AND id % 3 = 0
132+
GROUP BY (id / 100)::int
133+
HAVING COUNT(*) > 5;
134+
135+
DROP TABLE jit_test;
136+
" || {
137+
echo "❌ ERROR: JIT compilation failed"
138+
exit 1
139+
}
140+
141+
echo " ✅ JIT functionality working correctly"
142+
143+
elif [ "$VARIANT" = "lite" ]; then
144+
echo "ℹ️ Skipping JIT test (lite variant - JIT not available)"
145+
else
146+
echo "⚠️ Unknown variant: $VARIANT - skipping JIT test"
147+
fi
148+
149+
# Test 8: Clean shutdown
98150
echo "🛑 Testing server shutdown..."
99151
${POSTGRES_DIR}/bin/pg_ctl -D ${TEST_DIR}/data stop
100152

0 commit comments

Comments
 (0)