Skip to content

Commit 55e28d7

Browse files
committed
build config
1 parent 5ea5ded commit 55e28d7

16 files changed

+590
-408
lines changed

.templates/buildAddon.bat

Lines changed: 90 additions & 0 deletions
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

Lines changed: 84 additions & 0 deletions
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"

.templates/protogen.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
const { exec } = require('child_process');
2+
3+
// Configuration Variables
4+
const branchName = '___LIBPG_BRANCH___';
5+
const protoUrl = `https://raw.githubusercontent.com/pganalyze/libpg_query/${branchName}/protobuf/pg_query.proto`;
6+
const inFile = 'libpg_query/protobuf/pg_query.proto';
7+
const outFile = 'proto.js';
8+
9+
const protogenCmd = [
10+
'pg-proto-parser',
11+
'protogen',
12+
'--protoUrl',
13+
protoUrl,
14+
'--inFile',
15+
inFile,
16+
'--outFile',
17+
outFile,
18+
'--originalPackageName',
19+
'protobufjs/minimal',
20+
'--newPackageName',
21+
'@launchql/protobufjs/minimal'
22+
];
23+
24+
// Step 2: Generate proto.js using pbjs (Assuming pbjs is installed and accessible)
25+
function generateProtoJS(callback) {
26+
exec(protogenCmd.join(' '), (error, stdout, stderr) => {
27+
if (error) {
28+
console.error(`Error during code generation: ${error.message}`);
29+
return;
30+
}
31+
console.log('Generated proto.js from proto file.');
32+
callback();
33+
});
34+
}
35+
36+
generateProtoJS(() => {
37+
console.log('all done 🎉');
38+
});

.yamlize/versions/14-latest.yaml

Lines changed: 7 additions & 0 deletions
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

Lines changed: 7 additions & 0 deletions
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

Lines changed: 7 additions & 0 deletions
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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,11 @@
4141
"clean:wasm": "yarn make:wasm clean",
4242
"clean-cache:wasm": "yarn make:wasm clean-cache",
4343
"workflows": "node script/workflows.js",
44+
"build:generate": "node script/utils/generate.js",
4445
"test": "mocha --timeout 5000",
4546
"binary:build": "node-pre-gyp rebuild package",
4647
"binary:publish": "AWS_PROFILE=supabase-dev node-pre-gyp publish"
47-
},
48+
},
4849
"author": "Dan Lynch <[email protected]> (http://github.com/pyramation)",
4950
"license": "LICENSE IN LICENSE",
5051
"repository": {
@@ -64,7 +65,8 @@
6465
"@emnapi/runtime": "^0.43.1",
6566
"@launchql/protobufjs": "7.2.6",
6667
"@mapbox/node-pre-gyp": "^1.0.8",
67-
"@pgsql/types": "^15.0.1",
68+
"@pgsql/types": "15.0.1",
69+
"js-yaml": "^4.1.0",
6870
"node-addon-api": "^7.0.0",
6971
"node-gyp": "^10.0.1"
7072
},
@@ -83,4 +85,4 @@
8385
"host": "https://supabase-public-artifacts-bucket.s3.amazonaws.com",
8486
"remote_path": "./libpg-query-node/"
8587
}
86-
}
88+
}

script/buildAddon.bat

Lines changed: 27 additions & 4 deletions
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

Lines changed: 22 additions & 5 deletions
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

script/env.generated.json

Lines changed: 11 additions & 0 deletions
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.1",
7+
"OPERATION_SYSYTEMS": [
8+
"linux",
9+
"mac"
10+
]
11+
}

script/protogen.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
1-
const https = require('https');
2-
const fs = require('fs');
1+
// this file is auto-generated, use "yarn build:generate <env>" to rebuild with an env (e.g., pg-15)
32
const { exec } = require('child_process');
43

5-
if (typeof process.argv[2] !== 'string') {
6-
throw new Error('branchName not provided');
7-
}
8-
94
// Configuration Variables
10-
const branchName = process.argv[2];
5+
const branchName = '15-latest';
116
const protoUrl = `https://raw.githubusercontent.com/pganalyze/libpg_query/${branchName}/protobuf/pg_query.proto`;
127
const inFile = 'libpg_query/protobuf/pg_query.proto';
138
const outFile = 'proto.js';

script/utils/config.js

Lines changed: 6 additions & 0 deletions
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)