Skip to content

Commit c5418ef

Browse files
committed
add config generation for multiple PG versions
1 parent 1f95e07 commit c5418ef

13 files changed

+428
-11
lines changed

.templates/buildAddon.bat

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
@echo off
2+
3+
set LIBPG_REPO=___LIBPG_REPO___
4+
set LIBPG_COMMIT=___LIBPG_COMMIT___
5+
set LIBPG_BRANCH=___LIBPG_BRANCH___
6+
7+
:: Check if each required variable is set
8+
if "%LIBPG_REPO%"=="" (
9+
echo ERROR: LIBPG_REPO variable is not set.
10+
exit /B 1
11+
)
12+
13+
if "%LIBPG_COMMIT%"=="" (
14+
echo ERROR: LIBPG_COMMIT variable is not set.
15+
exit /B 1
16+
)
17+
18+
if "%LIBPG_BRANCH%"=="" (
19+
echo ERROR: LIBPG_BRANCH variable is not set.
20+
exit /B 1
21+
)
22+
23+
:: The environment variables must be set
24+
echo Using repository: %LIBPG_REPO%
25+
echo Using commit: %LIBPG_COMMIT%
26+
echo Using branch: %LIBPG_BRANCH%
27+
28+
setlocal enabledelayedexpansion
29+
30+
rem Remember current's parent directory and create a new, unique, temporary directory
31+
set buildDir=%cd%
32+
set projectDir=%cd%\..
33+
set tmpDir=%temp%\tmpdir.libpg_query
34+
rmdir /s /q %tmpDir%
35+
md %tmpDir%
36+
37+
38+
rem Define the make target
39+
set makeTarget=build
40+
41+
rem Change to the newly created temp directory
42+
cd /D %tmpDir%
43+
44+
45+
rem Clone the selected branch of the libpg_query Git repo
46+
git clone -b %LIBPG_BRANCH% --single-branch %LIBPG_REPO%
47+
cd libpg_query
48+
49+
rem Checkout the desired commit
50+
git checkout %LIBPG_COMMIT%
51+
52+
rem needed if being invoked from within gyp
53+
set MAKEFLAGS=
54+
set MFLAGS=
55+
56+
rem set path with Windows Developer Command Prompt
57+
echo "please ensure you are running at Windows Developer Command Prompt environments"
58+
nmake /F Makefile.msvc clean
59+
nmake /F Makefile.msvc build
60+
61+
62+
rem Terminate if build fails
63+
if %errorlevel% NEQ 0 (
64+
echo ERROR: 'nmake' command failed
65+
)
66+
67+
rem Search for pg_query.obj (libpg_query.a), error if not found
68+
for /f "delims=" %%f in ('dir /b /s pg_query.lib') do set file=%%f
69+
if not defined file (
70+
echo "ERROR: pg_query.lib not found"
71+
72+
)
73+
74+
rem Error if pg_query.h is missing
75+
for /f "delims=" %%f in ('dir /b /s pg_query.h') do set file=%%f
76+
if not defined file (
77+
echo "ERROR: pg_query.h not found"
78+
79+
)
80+
81+
rem Copy pg_query.lib to windows dir
82+
copy /Y pg_query.lib "%projectDir%\libpg_query\windows\"
83+
84+
rem Copy header
85+
copy /Y pg_query.h "%projectDir%\libpg_query\include\"
86+
87+
rem Cleanup: revert to original directory
88+
cd /D %buildDir%
89+
90+
exit /B 0

.templates/buildAddon.sh

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#!/usr/bin/env bash
2+
3+
LIBPG_REPO=___LIBPG_REPO___
4+
LIBPG_COMMIT=___LIBPG_COMMIT___
5+
LIBPG_BRANCH=___LIBPG_BRANCH___
6+
7+
# Check if variables are set and exit if not
8+
if [ -z "$LIBPG_COMMIT" ]; then
9+
echo "ERROR: LIBPG_COMMIT variable is not set."
10+
exit 1
11+
fi
12+
13+
if [ -z "$LIBPG_BRANCH" ]; then
14+
echo "ERROR: LIBPG_BRANCH variable is not set."
15+
exit 1
16+
fi
17+
18+
if [ -z "$LIBPG_REPO" ]; then
19+
echo "ERROR: LIBPG_REPO variable is not set."
20+
exit 1
21+
fi
22+
23+
# Remember current directory and create a new, unique, temporary directory
24+
rDIR=$(pwd)
25+
tmpDir=$(mktemp -d 2>/dev/null || mktemp -d -t 'tmpdir.XXXX')
26+
27+
# Define the make target
28+
makeTarget=build
29+
30+
# Change to the newly created temp directory
31+
cd "$tmpDir"
32+
33+
# Clone the selected branch of the libpg_query Git repo
34+
git clone -b $LIBPG_BRANCH --single-branch $LIBPG_REPO
35+
cd libpg_query
36+
37+
# Checkout the desired commit
38+
git checkout $LIBPG_COMMIT
39+
40+
# needed if being invoked from within gyp
41+
unset MAKEFLAGS
42+
unset MFLAGS
43+
44+
# Adaptively build for macOS or Linux
45+
if [ "$(uname)" == "Darwin" ]; then
46+
make CFLAGS='-mmacosx-version-min=10.7' PG_CFLAGS='-mmacosx-version-min=10.7' $makeTarget
47+
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
48+
make CFLAGS='' PG_CFLAGS='' $makeTarget
49+
fi
50+
51+
# Terminate if build fails
52+
if [ $? -ne 0 ]; then
53+
echo "ERROR: 'make' command failed";
54+
exit 1;
55+
fi
56+
57+
# Search for libpg_query.a, error if not found
58+
file=$(ls | grep 'libpg_query.a')
59+
if [ ! $file ]; then
60+
echo "ERROR: libpg_query.a not found";
61+
exit 1;
62+
fi
63+
64+
# Error if pg_query.h is missing
65+
file=$(ls | grep 'pg_query.h')
66+
if [ ! $file ]; then
67+
echo "ERROR: pg_query.h not found";
68+
exit 1;
69+
fi
70+
71+
# Copy queryparser.cc, binding.gyp to current directory
72+
if [ "$(uname)" == "Darwin" ]; then
73+
cp $(pwd)/libpg_query.a $rDIR/libpg_query/osx/
74+
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
75+
cp $(pwd)/libpg_query.a $rDIR/libpg_query/linux/
76+
fi
77+
78+
# Copy header
79+
cp $(pwd)/pg_query.h $rDIR/libpg_query/include/
80+
cp $(pwd)/protobuf/*.proto $rDIR/libpg_query/protobuf/
81+
82+
# Cleanup: revert to original directory and remove the temp
83+
cd "$rDIR"
84+
rm -rf "$tmpDir"

.yamlize/versions/14-latest.yaml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
env:
2+
JOB: pg-14
3+
LIBPG_REPO: https://github.com/pganalyze/libpg_query.git
4+
LIBPG_COMMIT: 1577ef7c6c349542149e34ffbfafc244ab942ec6
5+
LIBPG_BRANCH: 14-latest
6+
PGSQL_TYPES: 14.0.0
7+
OPERATION_SYSYTEMS: [linux,mac]

.yamlize/versions/15-latest.yaml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
env:
2+
JOB: pg-15
3+
LIBPG_REPO: https://github.com/pganalyze/libpg_query.git
4+
LIBPG_COMMIT: db39825bc7c1ddd45962ec6a626d740b7f8f027a
5+
LIBPG_BRANCH: 15-latest
6+
PGSQL_TYPES: 15.0.2
7+
OPERATION_SYSYTEMS: [linux,mac]

.yamlize/versions/16-latest.yaml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
env:
2+
JOB: pg-16
3+
LIBPG_REPO: https://github.com/pganalyze/libpg_query.git
4+
LIBPG_COMMIT: 1ec38940e5c6f09a4c1d17a46d839a881c4f2db7
5+
LIBPG_BRANCH: 16-latest
6+
PGSQL_TYPES: 16.0.0
7+
OPERATION_SYSYTEMS: [linux,mac,win]

package.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
"clean:wasm": "yarn make:wasm clean",
4141
"clean-cache:wasm": "yarn make:wasm clean-cache",
4242
"workflows": "node script/workflows.js",
43+
"build:generate": "node script/utils/generate.js",
4344
"test": "mocha --timeout 5000",
4445
"binary:build": "node-pre-gyp rebuild package",
4546
"binary:publish": "AWS_PROFILE=supabase-dev node-pre-gyp publish"
@@ -54,14 +55,15 @@
5455
"@yamlize/cli": "^0.8.0",
5556
"chai": "^3.5.0",
5657
"emnapi": "^0.43.1",
58+
"js-yaml": "^4.1.0",
5759
"lodash": "^4.17.15",
5860
"mocha": "^5.2.0",
5961
"rimraf": "5.0.0"
6062
},
6163
"dependencies": {
6264
"@emnapi/runtime": "^0.43.1",
6365
"@mapbox/node-pre-gyp": "^1.0.8",
64-
"@pgsql/types": "^15.0.1",
66+
"@pgsql/types": "15.0.2",
6567
"node-addon-api": "^7.0.0",
6668
"node-gyp": "^10.0.1"
6769
},
@@ -80,4 +82,4 @@
8082
"host": "https://supabase-public-artifacts-bucket.s3.amazonaws.com",
8183
"remote_path": "./libpg-query-node/"
8284
}
83-
}
85+
}

script/buildAddon.bat

+27-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,30 @@
1+
:: this file is auto-generated, use "yarn build:generate <env>" to rebuild with an env (e.g., pg-15)
12
@echo off
23

3-
set commit=db39825bc7c1ddd45962ec6a626d740b7f8f027a
4-
set branch=15-latest
4+
set LIBPG_REPO=https://github.com/pganalyze/libpg_query.git
5+
set LIBPG_COMMIT=db39825bc7c1ddd45962ec6a626d740b7f8f027a
6+
set LIBPG_BRANCH=15-latest
7+
8+
:: Check if each required variable is set
9+
if "%LIBPG_REPO%"=="" (
10+
echo ERROR: LIBPG_REPO variable is not set.
11+
exit /B 1
12+
)
13+
14+
if "%LIBPG_COMMIT%"=="" (
15+
echo ERROR: LIBPG_COMMIT variable is not set.
16+
exit /B 1
17+
)
18+
19+
if "%LIBPG_BRANCH%"=="" (
20+
echo ERROR: LIBPG_BRANCH variable is not set.
21+
exit /B 1
22+
)
23+
24+
:: The environment variables must be set
25+
echo Using repository: %LIBPG_REPO%
26+
echo Using commit: %LIBPG_COMMIT%
27+
echo Using branch: %LIBPG_BRANCH%
528

629
setlocal enabledelayedexpansion
730

@@ -21,11 +44,11 @@ cd /D %tmpDir%
2144

2245

2346
rem Clone the selected branch of the libpg_query Git repo
24-
git clone -b %branch% --single-branch https://github.com/pganalyze/libpg_query.git
47+
git clone -b %LIBPG_BRANCH% --single-branch %LIBPG_REPO%
2548
cd libpg_query
2649

2750
rem Checkout the desired commit
28-
git checkout %commit%
51+
git checkout %LIBPG_COMMIT%
2952

3053
rem needed if being invoked from within gyp
3154
set MAKEFLAGS=

script/buildAddon.sh

+23-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,25 @@
11
#!/usr/bin/env bash
2+
# this file is auto-generated, use "yarn build:generate <env>" to rebuild with an env (e.g., pg-15)
23

3-
# Set the desired commit hash and branch
4-
commit=db39825bc7c1ddd45962ec6a626d740b7f8f027a
5-
branch=15-latest
4+
LIBPG_REPO=https://github.com/pganalyze/libpg_query.git
5+
LIBPG_COMMIT=db39825bc7c1ddd45962ec6a626d740b7f8f027a
6+
LIBPG_BRANCH=15-latest
7+
8+
# Check if variables are set and exit if not
9+
if [ -z "$LIBPG_COMMIT" ]; then
10+
echo "ERROR: LIBPG_COMMIT variable is not set."
11+
exit 1
12+
fi
13+
14+
if [ -z "$LIBPG_BRANCH" ]; then
15+
echo "ERROR: LIBPG_BRANCH variable is not set."
16+
exit 1
17+
fi
18+
19+
if [ -z "$LIBPG_REPO" ]; then
20+
echo "ERROR: LIBPG_REPO variable is not set."
21+
exit 1
22+
fi
623

724
# Remember current directory and create a new, unique, temporary directory
825
rDIR=$(pwd)
@@ -15,11 +32,11 @@ makeTarget=build
1532
cd "$tmpDir"
1633

1734
# Clone the selected branch of the libpg_query Git repo
18-
git clone -b $branch --single-branch https://github.com/pganalyze/libpg_query.git
35+
git clone -b $LIBPG_BRANCH --single-branch $LIBPG_REPO
1936
cd libpg_query
2037

2138
# Checkout the desired commit
22-
git checkout $commit
39+
git checkout $LIBPG_COMMIT
2340

2441
# needed if being invoked from within gyp
2542
unset MAKEFLAGS
@@ -61,6 +78,7 @@ fi
6178

6279
# Copy header
6380
cp $(pwd)/pg_query.h $rDIR/libpg_query/include/
81+
cp $(pwd)/protobuf/*.proto $rDIR/libpg_query/protobuf/
6482

6583
# Cleanup: revert to original directory and remove the temp
6684
cd "$rDIR"

script/env.generated.json

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"JOB": "pg-15",
3+
"LIBPG_REPO": "https://github.com/pganalyze/libpg_query.git",
4+
"LIBPG_COMMIT": "db39825bc7c1ddd45962ec6a626d740b7f8f027a",
5+
"LIBPG_BRANCH": "15-latest",
6+
"PGSQL_TYPES": "15.0.2",
7+
"OPERATION_SYSYTEMS": [
8+
"linux",
9+
"mac"
10+
]
11+
}

script/utils/config.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
const path = require('path');
2+
const rootDir = path.join(__dirname, '/../../');
3+
module.exports.rootDir = rootDir;
4+
module.exports.templatesDir = path.join(rootDir, '.templates');
5+
module.exports.yamlizeDir = path.join(rootDir, '.yamlize');
6+
module.exports.configDir = path.join(rootDir, '.yamlize/versions');

0 commit comments

Comments
 (0)