Skip to content

Commit 16cbb4c

Browse files
authored
Merge branch 'tom/deparse-pr' into tom/deparse
2 parents d4c0438 + 03f3f15 commit 16cbb4c

28 files changed

+3358
-500
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Build Dry Run No Windows 🏗
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
build-matrix:
8+
runs-on: ${{ matrix.os }}
9+
strategy:
10+
matrix:
11+
os: [macos-latest, ubuntu-latest]
12+
steps:
13+
- name: Checkout Repository 📥
14+
uses: actions/checkout@v4
15+
16+
- name: Setup Node.js 🌐
17+
uses: actions/setup-node@v4
18+
with:
19+
node-version: '20.x'
20+
cache: 'yarn'
21+
22+
- name: Install Dependencies 🧶
23+
run: |
24+
yarn
25+
26+
- name: Save Artifacts 🏗
27+
uses: actions/upload-artifact@v4
28+
with:
29+
name: build-artifact-${{ matrix.os }}
30+
path: |
31+
${{ matrix.os == 'macos-latest' && './libpg_query/osx/libpg_query.a' ||
32+
matrix.os == 'ubuntu-latest' && './libpg_query/linux/libpg_query.a'
33+
}}
34+
35+
prepare-and-publish:
36+
needs: build-matrix # Corrected the needs to reflect the actual job name
37+
runs-on: ubuntu-latest
38+
steps:
39+
- uses: actions/checkout@v4
40+
- uses: actions/download-artifact@v4
41+
with:
42+
path: downloaded-artifacts
43+
- name: Prepare artifacts
44+
run: |
45+
# move or prepare artifacts
46+
find .
47+
# - name: Publish to NPM
48+
# run: |
49+
# # Assuming you've set up your package.json and .npmrc correctly
50+
# npm publish
51+
# env:

.github/workflows/build-dry-run.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Build Dry Run 🏗
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
build-matrix:
8+
runs-on: ${{ matrix.os }}
9+
strategy:
10+
matrix:
11+
os: [windows-latest, macos-latest, ubuntu-latest]
12+
steps:
13+
- name: Checkout Repository 📥
14+
uses: actions/checkout@v4
15+
16+
- name: Setup Node.js 🌐
17+
uses: actions/setup-node@v4
18+
with:
19+
node-version: '20.x'
20+
cache: 'yarn'
21+
22+
- name: Install Dependencies 🧶
23+
run: |
24+
yarn
25+
26+
- name: Save Artifacts 🏗
27+
uses: actions/upload-artifact@v4
28+
with:
29+
name: build-artifact-${{ matrix.os }}
30+
path: |
31+
${{ matrix.os == 'macos-latest' && './libpg_query/osx/libpg_query.a' ||
32+
matrix.os == 'ubuntu-latest' && './libpg_query/linux/libpg_query.a' ||
33+
matrix.os == 'windows-latest' && './libpg_query/windows/queryparser.lib' }}
34+
35+
prepare-and-publish:
36+
needs: build-matrix # Corrected the needs to reflect the actual job name
37+
runs-on: ubuntu-latest
38+
steps:
39+
- uses: actions/checkout@v4
40+
- uses: actions/download-artifact@v4
41+
with:
42+
path: downloaded-artifacts
43+
- name: Prepare artifacts
44+
run: |
45+
# move or prepare artifacts
46+
find .
47+
# - name: Publish to NPM
48+
# run: |
49+
# # Assuming you've set up your package.json and .npmrc correctly
50+
# npm publish
51+
# env:
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Build Wasm Linux 🧪
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
run-tests:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- name: Checkout Repository 📥
11+
uses: actions/checkout@v4
12+
13+
- name: Setup Node.js 🌐
14+
uses: actions/setup-node@v4
15+
with:
16+
node-version: '20.x'
17+
cache: 'yarn'
18+
19+
- name: Install Linux Deps 🧶
20+
run: |
21+
sudo apt-get update
22+
sudo apt-get install -y make
23+
24+
- name: Install Dependencies 🧶
25+
run: |
26+
yarn
27+
28+
- name: Test 🔍
29+
run: |
30+
yarn make:wasm
31+
yarn make build:wasm

.github/workflows/run-tests-linux.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Run Tests Linux 🧪
2+
3+
on:
4+
pull_request:
5+
types: [opened, push, reopened]
6+
workflow_dispatch:
7+
8+
jobs:
9+
run-tests:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout Repository 📥
13+
uses: actions/checkout@v4
14+
15+
- name: Setup Node.js 🌐
16+
uses: actions/setup-node@v4
17+
with:
18+
node-version: '20.x'
19+
cache: 'yarn'
20+
21+
- name: Install Dependencies 🧶
22+
run: |
23+
yarn
24+
25+
- name: Test 🔍
26+
run: yarn test

.github/workflows/run-tests-mac.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Run Tests Mac 🧪
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
run-tests:
8+
runs-on: macos-latest
9+
steps:
10+
- name: Checkout Repository 📥
11+
uses: actions/checkout@v4
12+
13+
- name: Setup Node.js 🌐
14+
uses: actions/setup-node@v4
15+
with:
16+
node-version: '20.x'
17+
cache: 'yarn'
18+
19+
- name: Install Dependencies 🧶
20+
run: |
21+
yarn
22+
23+
- name: Test 🔍
24+
run: yarn test

.github/workflows/run-tests-win.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Run Tests Windows 🧪
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
run-tests:
8+
runs-on: windows-latest
9+
steps:
10+
- name: Checkout Repository 📥
11+
uses: actions/checkout@v4
12+
13+
- name: Setup Node.js 🌐
14+
uses: actions/setup-node@v4
15+
with:
16+
node-version: '20.x'
17+
cache: 'yarn'
18+
19+
- name: Install Dependencies 🧶
20+
run: |
21+
yarn
22+
23+
- name: Test 🔍
24+
run: yarn test

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,7 @@ npm-debug.log
55
libpg_query/**/*.a
66
libpg_query/**/*.h
77
libpg_query/**/*.proto
8+
wasm/libpg-query.js
9+
*.wasm
10+
.cache
11+
libpg_query/windows/*.lib

.travis.yml

Lines changed: 0 additions & 13 deletions
This file was deleted.

Makefile

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
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 := 16-5.1.0
6+
CACHE_DIR := .cache
7+
8+
OS ?= $(shell uname -s)
9+
ARCH ?= $(shell uname -m)
10+
11+
ifdef EMSCRIPTEN
12+
PLATFORM := emscripten
13+
else ifeq ($(OS),Darwin)
14+
PLATFORM := darwin
15+
else ifeq ($(OS),Linux)
16+
PLATFORM := linux
17+
else
18+
$(error Unsupported platform: $(OS))
19+
endif
20+
21+
ifdef EMSCRIPTEN
22+
ARCH := wasm
23+
endif
24+
25+
PLATFORM_ARCH := $(PLATFORM)-$(ARCH)
26+
SRC_FILES := $(wildcard src/*.cc)
27+
LIBPG_QUERY_DIR := $(CACHE_DIR)/$(PLATFORM_ARCH)/libpg_query/$(LIBPG_QUERY_TAG)
28+
LIBPG_QUERY_ARCHIVE := $(LIBPG_QUERY_DIR)/libpg_query.a
29+
LIBPG_QUERY_HEADER := $(LIBPG_QUERY_DIR)/pg_query.h
30+
CXXFLAGS := -O3
31+
32+
ifdef EMSCRIPTEN
33+
OUT_FILES := $(foreach EXT,.js .wasm,$(WASM_OUT_DIR)/$(WASM_OUT_NAME)$(EXT))
34+
else
35+
OUT_FILES := build/Release/queryparser.node $(wildcard build/*)
36+
endif
37+
38+
# Clone libpg_query source (lives in CACHE_DIR)
39+
$(LIBPG_QUERY_DIR):
40+
mkdir -p $(CACHE_DIR)
41+
git clone -b $(LIBPG_QUERY_TAG) --single-branch $(LIBPG_QUERY_REPO) $(LIBPG_QUERY_DIR)
42+
43+
$(LIBPG_QUERY_HEADER): $(LIBPG_QUERY_DIR)
44+
45+
# Build libpg_query
46+
$(LIBPG_QUERY_ARCHIVE): $(LIBPG_QUERY_DIR)
47+
cd $(LIBPG_QUERY_DIR); $(MAKE) build
48+
49+
# Build libpg-query-node (based on platform)
50+
$(OUT_FILES): $(LIBPG_QUERY_ARCHIVE) $(LIBPG_QUERY_HEADER) $(SRC_FILES)
51+
ifdef EMSCRIPTEN
52+
@ $(CXX) \
53+
$(CXXFLAGS) \
54+
-DNAPI_HAS_THREADS \
55+
-I$(LIBPG_QUERY_DIR) \
56+
-I./node_modules/emnapi/include \
57+
-I./node_modules/node-addon-api \
58+
-L./node_modules/emnapi/lib/wasm32-emscripten \
59+
-L$(LIBPG_QUERY_DIR) \
60+
--js-library=./node_modules/emnapi/dist/library_napi.js \
61+
-sEXPORTED_FUNCTIONS="['_malloc','_free','_napi_register_wasm_v1','_node_api_module_get_api_version_v1']" \
62+
-sEXPORT_NAME="$(WASM_MODULE_NAME)" \
63+
-sENVIRONMENT="web" \
64+
-sMODULARIZE=1 \
65+
-sEXPORT_ES6=1 \
66+
-fexceptions \
67+
-lpg_query \
68+
-lemnapi-basic \
69+
-o $@ \
70+
$(SRC_FILES)
71+
else
72+
# if not wasm, defer to node-gyp
73+
yarn rebuild
74+
endif
75+
76+
# Commands
77+
build: $(OUT_FILES)
78+
79+
build-cache: $(LIBPG_QUERY_ARCHIVE) $(LIBPG_QUERY_HEADER)
80+
81+
rebuild: clean build
82+
83+
rebuild-cache: clean-cache build-cache
84+
85+
clean:
86+
-@ rm -r $(OUT_FILES) > /dev/null 2>&1
87+
88+
clean-cache:
89+
-@ rm -rf $(LIBPG_QUERY_DIR)
90+
91+
.PHONY: build build-cache rebuild rebuild-cache clean clean-cache

0 commit comments

Comments
 (0)