-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
218 lines (185 loc) · 7.64 KB
/
Makefile
File metadata and controls
218 lines (185 loc) · 7.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
DUCKDB_VERSION := v1.2.0
EXTENSION_NAME := duckarrow
# Extract version from git tag, fall back to "dev" for local builds
EXTENSION_VERSION := $(shell git describe --tags --exact-match 2>/dev/null || echo "dev")
BUILD_DIR := build
SCRIPTS_DIR := scripts
TESTS_DIR := tests
.PHONY: all clean build deps test test-unit test-coverage test-all fmt help
.PHONY: test-load test-hardcoded test-connection test-full test-replacement-scan test-pool test-types test-edge-cases test-errors
.PHONY: build-linux-amd64 build-linux-arm64 build-darwin-amd64 build-darwin-arm64 build-windows-amd64 build-windows-arm64
.PHONY: build-linux build-darwin build-windows
# Platform detection with override support
GOOS ?= $(shell go env GOOS)
GOARCH ?= $(shell go env GOARCH)
# Derive platform string and file extension
ifeq ($(GOOS),linux)
PLATFORM := linux_$(GOARCH)
EXT := .so
else ifeq ($(GOOS),darwin)
PLATFORM := osx_$(GOARCH)
EXT := .dylib
else ifeq ($(GOOS),windows)
PLATFORM := windows_$(GOARCH)
EXT := .dll
else
# Fallback for unknown OS
PLATFORM := $(GOOS)_$(GOARCH)
EXT := .so
endif
# Platform-specific output directory to avoid collisions when building multiple platforms
OUTPUT_DIR := $(BUILD_DIR)/$(PLATFORM)
OUTPUT := $(OUTPUT_DIR)/$(EXTENSION_NAME)$(EXT)
# Default target
all: build
# Ensure dependencies and check submodule
deps:
@mkdir -p $(OUTPUT_DIR)
@if [ ! -f duckdb-go-api/duckdb.h ]; then \
echo "Error: duckdb-go-api submodule not initialized."; \
echo "Run: git submodule update --init"; \
exit 1; \
fi
go mod tidy
# Build the extension
build: deps
CGO_ENABLED=1 GOOS=$(GOOS) GOARCH=$(GOARCH) \
go build -buildmode=c-shared -ldflags="-X main.Version=$(EXTENSION_VERSION)" -o $(OUTPUT) ./
cd $(OUTPUT_DIR) && python3 ../../$(SCRIPTS_DIR)/append_extension_metadata.py \
-l $(EXTENSION_NAME)$(EXT) \
-n $(EXTENSION_NAME) \
-dv $(DUCKDB_VERSION) \
-ev $(EXTENSION_VERSION) \
-p $(PLATFORM)
@# Create symlink for test convenience (skip on Windows)
ifneq ($(GOOS),windows)
@ln -sf $(PLATFORM)/$(EXTENSION_NAME).duckdb_extension $(BUILD_DIR)/$(EXTENSION_NAME).duckdb_extension
endif
@echo "Built: $(OUTPUT_DIR)/$(EXTENSION_NAME).duckdb_extension for $(PLATFORM)"
# Platform-specific targets
# NOTE: Cross-compilation requires appropriate C toolchains:
# - Linux ARM64 from AMD64: CC=aarch64-linux-gnu-gcc
# - Windows from Linux: CC=x86_64-w64-mingw32-gcc
# - macOS: Requires osxcross or native build on macOS
# These targets work best for native builds on each platform.
build-linux-amd64:
$(MAKE) build GOOS=linux GOARCH=amd64
build-linux-arm64:
$(MAKE) build GOOS=linux GOARCH=arm64
build-darwin-amd64:
$(MAKE) build GOOS=darwin GOARCH=amd64
build-darwin-arm64:
$(MAKE) build GOOS=darwin GOARCH=arm64
build-windows-amd64:
$(MAKE) build GOOS=windows GOARCH=amd64
build-windows-arm64:
$(MAKE) build GOOS=windows GOARCH=arm64
# Convenience targets
build-linux: build-linux-amd64 build-linux-arm64
build-darwin: build-darwin-amd64 build-darwin-arm64
build-windows: build-windows-amd64 build-windows-arm64
# Test: Extension loading
test-load: build
@echo "=== Test: Extension Load ==="
duckdb -unsigned -c "LOAD './$(OUTPUT_DIR)/$(EXTENSION_NAME).duckdb_extension';" && \
echo "PASS: Extension loaded" || echo "FAIL: Extension failed to load"
# Test: Hardcoded data
test-hardcoded: build
@echo "=== Test: Hardcoded Data ==="
duckdb -unsigned < $(TESTS_DIR)/hardcoded_test.sql
# Test: Flight SQL connection
test-connection: build
@echo "=== Test: Flight SQL Connection ==="
duckdb -unsigned < $(TESTS_DIR)/connection_test.sql
# Test: Full data transfer
test-full: build
@echo "=== Test: Full Data Transfer ==="
duckdb -unsigned < $(TESTS_DIR)/full_test.sql
# Test: Replacement scan (includes validation error tests)
test-replacement-scan: build
@echo "=== Test: Replacement Scan ==="
@echo "Note: This test includes expected validation errors"
duckdb -unsigned < $(TESTS_DIR)/replacement_scan_test.sql; \
if [ $$? -eq 0 ] || [ $$? -eq 1 ]; then echo "Replacement scan tests completed (errors are expected for validation tests)"; else exit 1; fi
# Test: Connection pooling
test-pool: build
@echo "=== Test: Connection Pool ==="
@echo "Note: Compare timing - subsequent queries should be faster"
duckdb -unsigned < $(TESTS_DIR)/connection_pool_test.sql
# Run SQL integration tests (core functionality)
test: test-load test-hardcoded test-connection test-full test-replacement-scan test-pool
@echo "SQL integration tests passed!"
# Go unit tests (no server required)
test-unit:
@echo "=== Go Unit Tests ==="
go test -v -race ./internal/...
# Go tests with coverage
test-coverage:
@echo "=== Go Tests with Coverage ==="
go test -v -race -coverprofile=coverage.out ./internal/...
go tool cover -func=coverage.out
# Test: Data type conversions
test-types: build
@echo "=== Test: Data Types ==="
duckdb -unsigned < $(TESTS_DIR)/data_types_test.sql
# Test: Edge cases (large results, unicode)
test-edge-cases: build
@echo "=== Test: Edge Cases ==="
duckdb -unsigned < $(TESTS_DIR)/integration_test.sql
# Test: Error handling
# Note: This test includes expected errors, but the final recovery test must pass
test-errors: build
@echo "=== Test: Error Handling ==="
@echo "Note: Expected errors will be shown, but recovery test must pass"
duckdb -unsigned < $(TESTS_DIR)/error_handling_test.sql; \
if [ $$? -eq 0 ]; then echo "Error handling tests PASSED"; \
elif [ $$? -eq 1 ]; then echo "Error handling tests completed with expected errors"; \
else echo "Error handling tests FAILED with unexpected error"; exit 1; fi
# Full test suite (unit + all SQL tests)
test-all: test-unit test test-types test-edge-cases test-errors
@echo "All tests completed!"
# Clean build artifacts
clean:
rm -rf $(BUILD_DIR)
# Development helpers
fmt:
go fmt ./...
# Show help
help:
@echo "DuckArrow DuckDB Extension Build System"
@echo ""
@echo "Build Targets:"
@echo " build - Build the extension for current platform"
@echo " build-linux-amd64 - Build for Linux x86_64"
@echo " build-linux-arm64 - Build for Linux ARM64"
@echo " build-darwin-amd64 - Build for macOS Intel"
@echo " build-darwin-arm64 - Build for macOS Apple Silicon"
@echo " build-windows-amd64 - Build for Windows x86_64"
@echo " build-windows-arm64 - Build for Windows ARM64"
@echo " build-linux - Build for all Linux platforms"
@echo " build-darwin - Build for all macOS platforms"
@echo " build-windows - Build for all Windows platforms"
@echo ""
@echo "Test Targets:"
@echo " test - Run core SQL integration tests"
@echo " test-unit - Run Go unit tests (no server required)"
@echo " test-coverage - Run Go tests with coverage report"
@echo " test-all - Run full test suite (unit + all SQL tests)"
@echo " test-load - Test extension loading"
@echo " test-hardcoded - Test hardcoded table function"
@echo " test-connection - Test Flight SQL connection"
@echo " test-full - Test full data transfer"
@echo " test-replacement-scan - Test replacement scan (duckarrow.* syntax)"
@echo " test-pool - Test connection pooling"
@echo " test-types - Test data type conversions"
@echo " test-edge-cases - Test edge cases (large results, unicode)"
@echo " test-errors - Test error handling"
@echo ""
@echo "Other:"
@echo " clean - Remove build artifacts"
@echo " deps - Install dependencies"
@echo " fmt - Format Go code"
@echo ""
@echo "Cross-compilation note:"
@echo " Platform-specific targets require appropriate C toolchains."
@echo " For native builds, just run 'make build' on the target platform."