|
1 | | -WASM_OUT_DIR := wasm |
2 | | -WASM_OUT_NAME := libpg-query |
3 | | -WASM_MODULE_NAME := PgQueryModule |
4 | | -LIBPG_QUERY_REPO := https://github.com/pganalyze/libpg_query.git |
5 | | -LIBPG_QUERY_TAG := 17-6.1.0 |
| 1 | +.PHONY: install build clean test pg17-full pg17 |
6 | 2 |
|
7 | | -CACHE_DIR := .cache |
| 3 | +# Default target |
| 4 | +all: install build |
8 | 5 |
|
9 | | -OS ?= $(shell uname -s) |
10 | | -ARCH ?= $(shell uname -m) |
| 6 | +# Install dependencies in both packages |
| 7 | +install: |
| 8 | + cd pg17-full && yarn install |
| 9 | + cd pg17 && yarn install |
11 | 10 |
|
12 | | -ifdef EMSCRIPTEN |
13 | | -PLATFORM := emscripten |
14 | | -else ifeq ($(OS),Darwin) |
15 | | -PLATFORM := darwin |
16 | | -else ifeq ($(OS),Linux) |
17 | | -PLATFORM := linux |
18 | | -else |
19 | | -$(error Unsupported platform: $(OS)) |
20 | | -endif |
21 | | - |
22 | | -ifdef EMSCRIPTEN |
23 | | -ARCH := wasm |
24 | | -endif |
25 | | - |
26 | | -PLATFORM_ARCH := $(PLATFORM)-$(ARCH) |
27 | | -SRC_FILES := src/wasm_wrapper.c |
28 | | -LIBPG_QUERY_DIR := $(CACHE_DIR)/$(PLATFORM_ARCH)/libpg_query/$(LIBPG_QUERY_TAG) |
29 | | -LIBPG_QUERY_ARCHIVE := $(LIBPG_QUERY_DIR)/libpg_query.a |
30 | | -LIBPG_QUERY_HEADER := $(LIBPG_QUERY_DIR)/pg_query.h |
31 | | -CXXFLAGS := -O3 |
32 | | - |
33 | | -ifdef EMSCRIPTEN |
34 | | -OUT_FILES := $(foreach EXT,.js .wasm,$(WASM_OUT_DIR)/$(WASM_OUT_NAME)$(EXT)) |
35 | | -else |
36 | | -$(error Native builds are no longer supported. Use EMSCRIPTEN=1 for WASM builds only.) |
37 | | -endif |
38 | | - |
39 | | -# Clone libpg_query source (lives in CACHE_DIR) |
40 | | -$(LIBPG_QUERY_DIR): |
41 | | - mkdir -p $(CACHE_DIR) |
42 | | - git clone -b $(LIBPG_QUERY_TAG) --single-branch $(LIBPG_QUERY_REPO) $(LIBPG_QUERY_DIR) |
43 | | - |
44 | | -$(LIBPG_QUERY_HEADER): $(LIBPG_QUERY_DIR) |
45 | | - |
46 | | -# Build libpg_query |
47 | | -$(LIBPG_QUERY_ARCHIVE): $(LIBPG_QUERY_DIR) |
48 | | - cd $(LIBPG_QUERY_DIR); $(MAKE) build |
49 | | - |
50 | | -# Build libpg-query-node WASM module |
51 | | -$(OUT_FILES): $(LIBPG_QUERY_ARCHIVE) $(LIBPG_QUERY_HEADER) $(SRC_FILES) |
52 | | -ifdef EMSCRIPTEN |
53 | | - $(CC) \ |
54 | | - -v \ |
55 | | - $(CXXFLAGS) \ |
56 | | - -I$(LIBPG_QUERY_DIR) \ |
57 | | - -I$(LIBPG_QUERY_DIR)/vendor \ |
58 | | - -L$(LIBPG_QUERY_DIR) \ |
59 | | - -sEXPORTED_FUNCTIONS="['_malloc','_free','_wasm_parse_query','_wasm_parse_query_protobuf','_wasm_get_protobuf_len','_wasm_deparse_protobuf','_wasm_parse_plpgsql','_wasm_fingerprint','_wasm_normalize_query','_wasm_scan','_wasm_parse_query_detailed','_wasm_free_detailed_result','_wasm_free_string']" \ |
60 | | - -sEXPORTED_RUNTIME_METHODS="['lengthBytesUTF8','stringToUTF8','UTF8ToString','HEAPU8','HEAPU32']" \ |
61 | | - -sEXPORT_NAME="$(WASM_MODULE_NAME)" \ |
62 | | - -sENVIRONMENT="web,node" \ |
63 | | - -sMODULARIZE=1 \ |
64 | | - -sEXPORT_ES6=1 \ |
65 | | - -sALLOW_MEMORY_GROWTH=1 \ |
66 | | - -lpg_query \ |
67 | | - -o $@ \ |
68 | | - $(SRC_FILES) |
69 | | -else |
70 | | -$(error Native builds are no longer supported. Use EMSCRIPTEN=1 for WASM builds only.) |
71 | | -endif |
72 | | - |
73 | | -# Commands |
74 | | -build: $(OUT_FILES) |
75 | | - |
76 | | -build-cache: $(LIBPG_QUERY_ARCHIVE) $(LIBPG_QUERY_HEADER) |
77 | | - |
78 | | -rebuild: clean build |
79 | | - |
80 | | -rebuild-cache: clean-cache build-cache |
| 11 | +# Build both packages |
| 12 | +build: |
| 13 | + cd pg17-full && yarn build |
| 14 | + cd pg17 && yarn build |
81 | 15 |
|
| 16 | +# Clean both packages |
82 | 17 | clean: |
83 | | - -@ rm -r $(OUT_FILES) > /dev/null 2>&1 |
| 18 | + cd pg17-full && yarn clean || true |
| 19 | + cd pg17 && yarn clean || true |
| 20 | + |
| 21 | +# Test both packages |
| 22 | +test: |
| 23 | + cd pg17-full && yarn test |
| 24 | + cd pg17 && yarn test |
84 | 25 |
|
85 | | -clean-cache: |
86 | | - -@ rm -rf $(LIBPG_QUERY_DIR) |
| 26 | +# Individual package targets |
| 27 | +pg17-full: |
| 28 | + cd pg17-full && yarn && yarn build |
87 | 29 |
|
88 | | -.PHONY: build build-cache rebuild rebuild-cache clean clean-cache |
| 30 | +pg17: |
| 31 | + cd pg17 && yarn && yarn build |
0 commit comments