diff --git a/PUBLISH.md b/PUBLISH.md index fedc2e2..deab377 100644 --- a/PUBLISH.md +++ b/PUBLISH.md @@ -1,5 +1,31 @@ # Publishing Guide +## Keeping the C source in sync + +Each `versions//package.json` pins its libpg_query source in `x-publish` +(`libpgQueryRepo`, `libpgQueryTag`, `libpgQueryCommit`), and the Docker build uses +`emscripten/emsdk:6.0.3`. Every generated Makefile and the protobufs come from those pins, +and the pins ship in the published package.json. + +To move a version to new C code, do all of this in one commit: + +```bash +# 1. edit x-publish.libpgQueryCommit (full 40-char SHA) in versions//package.json +pnpm copy:templates # regenerate the Makefiles +pnpm fetch:protos # protos//pg_query.proto at the new commit +pnpm build:types && pnpm build:enums +cd versions/ && pnpm build && pnpm test +``` + +If you skip the build when publishing, `versions//wasm/` must have been built after the +last pin change, or the package will name one commit and ship another. After publishing, +`npm view libpg-query@pg x-publish` should show the commit you expect. + +`publish:pkg` also writes `x-publish.wasmSha256`, the sha256 of `wasm/libpg-query.wasm` and +`wasm/libpg-query.js`, into the published package.json. To verify a release, check out the +`gitHead` it was published from, run `pnpm wasm:build` in `versions/`, and compare +`sha256sum wasm/libpg-query.*` with `npm view libpg-query@ x-publish.wasmSha256`. + ## Automated Publishing (Recommended) ### Version Packages (libpg-query) @@ -14,7 +40,7 @@ This interactive script will: - Ask if you want to skip the build step (useful if already built) - Always run tests (even if build is skipped) - Publish each selected version -- Optionally promote pg17 to latest +- Optionally promote pg17 to latest (`latest` is currently pg18; to keep it there, answer no) ### Types Packages ```bash @@ -56,16 +82,6 @@ PARSER_BUILD_TYPE=full pnpm run publish:parser PARSER_BUILD_TYPE=lts pnpm run publish:parser ``` -#### Latest Only (version 17) -```bash -PARSER_BUILD_TYPE=latest pnpm run publish:parser -``` - -#### Legacy Build (versions 13-15) -```bash -PARSER_BUILD_TYPE=legacy pnpm run publish:parser -``` - This command will: - Navigate to the parser directory - Build the parser with the specified configuration @@ -241,19 +257,15 @@ pnpm publish The parser package is now a simple distribution package that copies pre-built WASM files. No TypeScript compilation needed! #### Available Build Types: -- **full**: All versions (13, 14, 15, 16, 17) - Default -- **lts**: LTS versions only (16, 17) -- **latest**: Latest version only (17) -- **legacy**: Legacy versions (13, 14, 15) +- **full**: All versions (13, 14, 15, 16, 17, 18) - Default +- **lts**: LTS versions only (15, 16, 17, 18) ```bash # Full build (default) npm run build -# Specific builds +# LTS build npm run build:lts -npm run build:latest -npm run build:legacy # Or using environment variable PARSER_BUILD_TYPE=lts npm run build @@ -275,11 +287,11 @@ The templates automatically adjust to include only the versions specified in the **Important**: Before building the parser package, ensure that the version packages are built first: ```bash # Build all version packages first -pnpm build # builds libpg-query versions +pnpm build:versions # Then build the parser with desired configuration cd parser -npm run build:lts # or build:full, build:latest, etc. +npm run build:lts # or build:full ``` ### Types Bundling @@ -299,10 +311,6 @@ npm publish # Publish LTS version with lts tag npm run build:lts npm publish --tag lts - -# Publish legacy version with legacy tag -npm run build:legacy -npm publish --tag legacy ``` ### What it does @@ -318,12 +326,6 @@ npm publish --tag legacy # Install latest (full build) npm install @pgsql/parser -# Install LTS version -npm install @pgsql/parser@lts - -# Install legacy version -npm install @pgsql/parser@legacy - # Use version-specific imports: # import { parse } from '@pgsql/parser/v17' # import { parse } from '@pgsql/parser/v16' diff --git a/REPO_NOTES.md b/REPO_NOTES.md index 4ba54e9..8d8e035 100644 --- a/REPO_NOTES.md +++ b/REPO_NOTES.md @@ -6,9 +6,9 @@ Versions with `x-publish.fullApi: true` (currently 18) are generated from the full-API templates in `templates/full/` and export the full API (parse, parsePlPgSQL, scan, fingerprint, normalize + sync variants); the other versions use the slim (parse-only) templates. -āš ļø Note: the Makefiles for 15/17/18 have been hand-edited to point at -constructive-io/libpg_query branches; `copy:templates` regenerates Makefiles -with the pganalyze repo URL, so re-apply the repo override if you regenerate. +Each version's libpg_query source (repo, branch/tag and exact commit) comes from +`x-publish` in its package.json, so `copy:templates` regenerates every Makefile +as-is — 15/17/18 point at constructive-io/libpg_query branches, pinned by commit. ## Code Duplication šŸ“‹ @@ -21,7 +21,7 @@ with the pganalyze repo URL, so re-apply the repo override if you regenerate. - `versions/*/src/index.ts` are nearly identical except for version numbers - `versions/*/src/wasm_wrapper.c` are identical - `versions/*/Makefile` differ only in: - - `LIBPG_QUERY_TAG` version + - `LIBPG_QUERY_REPO` / `LIBPG_QUERY_TAG` / `LIBPG_QUERY_COMMIT` - Version 13 has an extra emscripten patch ## Consistency Issues šŸ”§ diff --git a/package.json b/package.json index df537e2..b259f9b 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,6 @@ "build:parser": "pnpm --filter @pgsql/parser build", "build:parser:lts": "PARSER_BUILD_TYPE=lts pnpm --filter @pgsql/parser build", "build:parser:full": "PARSER_BUILD_TYPE=full pnpm --filter @pgsql/parser build", - "build:parser:legacy": "PARSER_BUILD_TYPE=legacy pnpm --filter @pgsql/parser build", "test:parser": "pnpm --filter @pgsql/parser test", "publish:parser": "pnpm --filter @pgsql/parser publish" }, diff --git a/scripts/copy-templates.js b/scripts/copy-templates.js index 6d8d312..c2c9c56 100755 --- a/scripts/copy-templates.js +++ b/scripts/copy-templates.js @@ -28,24 +28,27 @@ function loadVersionConfigs() { console.log(`Found ${packageFiles.length} package.json files\n`); packageFiles.forEach(packageFile => { - try { - const packageData = JSON.parse(fs.readFileSync(packageFile, 'utf8')); - const version = packageData['x-publish']?.pgVersion; - const libpgQueryTag = packageData['x-publish']?.libpgQueryTag; - const fullApi = packageData['x-publish']?.fullApi === true; - - if (version && libpgQueryTag) { - configs[version] = { - tag: libpgQueryTag, - hasEmscriptenPatch: version === '13', // Only version 13 needs the patch - fullApi - }; - console.log(` Version ${version}: tag ${libpgQueryTag}${fullApi ? ' (full API)' : ''}`); - } else { - console.warn(` Warning: Missing x-publish data in ${packageFile}`); + const packageData = JSON.parse(fs.readFileSync(packageFile, 'utf8')); + const version = packageData['x-publish']?.pgVersion; + const libpgQueryTag = packageData['x-publish']?.libpgQueryTag; + const libpgQueryRepo = packageData['x-publish']?.libpgQueryRepo; + const libpgQueryCommit = packageData['x-publish']?.libpgQueryCommit; + const fullApi = packageData['x-publish']?.fullApi === true; + + if (version && libpgQueryTag) { + if (!libpgQueryRepo || !/^[0-9a-f]{40}$/.test(libpgQueryCommit || '')) { + throw new Error(`${packageFile}: x-publish needs libpgQueryRepo and a full 40-char libpgQueryCommit`); } - } catch (error) { - console.error(` Error reading ${packageFile}: ${error.message}`); + configs[version] = { + tag: libpgQueryTag, + repo: libpgQueryRepo, + commit: libpgQueryCommit, + hasEmscriptenPatch: version === '13', // Only version 13 needs the patch + fullApi + }; + console.log(` Version ${version}: ${libpgQueryTag} @ ${libpgQueryCommit.slice(0, 7)}${fullApi ? ' (full API)' : ''}`); + } else { + console.warn(` Warning: Missing x-publish data in ${packageFile}`); } }); @@ -106,6 +109,8 @@ function copyTemplates() { // Process Makefile template const makefileTemplate = fs.readFileSync(path.join(templatesDir, 'Makefile.template'), 'utf8'); let makefileContent = makefileTemplate.replace(/{{VERSION_TAG}}/g, config.tag); + makefileContent = makefileContent.replace(/{{LIBPG_QUERY_REPO}}/g, config.repo); + makefileContent = makefileContent.replace(/{{LIBPG_QUERY_COMMIT}}/g, config.commit); makefileContent = makefileContent.replace( /{{EXPORTED_FUNCTIONS}}/g, config.fullApi ? FULL_EXPORTED_FUNCTIONS : SLIM_EXPORTED_FUNCTIONS @@ -132,7 +137,7 @@ function copyTemplates() { // Write Makefile with header fs.writeFileSync(path.join(versionDir, 'Makefile'), MAKEFILE_HEADER + makefileContent); - console.log(` āœ“ Generated Makefile with tag ${config.tag}`); + console.log(` āœ“ Generated Makefile with ${config.tag} @ ${config.commit.slice(0, 7)}`); } console.log('\nāœ… Template copying completed!'); diff --git a/scripts/fetch-protos.js b/scripts/fetch-protos.js index 646130a..fcec6a2 100644 --- a/scripts/fetch-protos.js +++ b/scripts/fetch-protos.js @@ -18,7 +18,9 @@ function getVersionMappings() { pgVersion: pkg['x-publish'].pgVersion, packageVersion: pkg.version, distTag: pkg['x-publish'].distTag, - libpgQueryTag: pkg['x-publish'].libpgQueryTag + libpgQueryTag: pkg['x-publish'].libpgQueryTag, + libpgQueryRepo: pkg['x-publish'].libpgQueryRepo, + libpgQueryCommit: pkg['x-publish'].libpgQueryCommit }); } } @@ -27,24 +29,24 @@ function getVersionMappings() { return mappings; } -// Download file from URL +// Download file from URL; dest is only written after a complete 200 response function downloadFile(url, dest) { return new Promise((resolve, reject) => { - const file = fs.createWriteStream(dest); console.log('Downloading', url, 'to', dest); https.get(url, (response) => { - if (response.statusCode === 200) { - response.pipe(file); - file.on('finish', () => { - file.close(); - resolve(); - }); - } else { + if (response.statusCode !== 200) { + response.resume(); reject(new Error(`HTTP ${response.statusCode}: ${response.statusMessage}`)); + return; } - }).on('error', (err) => { - reject(err); - }); + const chunks = []; + response.on('data', (chunk) => chunks.push(chunk)); + response.on('end', () => { + fs.writeFileSync(dest, Buffer.concat(chunks)); + resolve(); + }); + response.on('error', reject); + }).on('error', reject); }); } @@ -61,7 +63,7 @@ async function fetchProtos() { console.log('Fetching protobuf files for all versions...\n'); for (const mapping of mappings) { - const { pgVersion, libpgQueryTag } = mapping; + const { pgVersion, libpgQueryTag, libpgQueryRepo, libpgQueryCommit } = mapping; const versionDir = path.join(protosDir, pgVersion); // Create version directory @@ -69,11 +71,12 @@ async function fetchProtos() { fs.mkdirSync(versionDir, { recursive: true }); } - // Use the libpgQueryTag from the Makefile - const url = `https://raw.githubusercontent.com/pganalyze/libpg_query/refs/tags/${libpgQueryTag}/protobuf/pg_query.proto`; + // The same repo and commit the WASM is built from + const repoPath = new URL(libpgQueryRepo).pathname.replace(/^\/|\.git$/g, ''); + const url = `https://raw.githubusercontent.com/${repoPath}/${libpgQueryCommit}/protobuf/pg_query.proto`; const destPath = path.join(versionDir, 'pg_query.proto'); - console.log(`Fetching protobuf for PostgreSQL ${pgVersion} with tag ${libpgQueryTag}...`); + console.log(`Fetching protobuf for PostgreSQL ${pgVersion} from ${repoPath} ${libpgQueryTag} @ ${libpgQueryCommit.slice(0, 7)}...`); try { await downloadFile(url, destPath); @@ -82,6 +85,7 @@ async function fetchProtos() { console.log(` Saved to: ${destPath}\n`); } catch (error) { console.log(`āŒ Failed to fetch protobuf for PostgreSQL ${pgVersion}: ${error.message}\n`); + process.exitCode = 1; } } @@ -90,7 +94,10 @@ async function fetchProtos() { // Run the script if (require.main === module) { - fetchProtos().catch(console.error); + fetchProtos().catch((error) => { + console.error(error); + process.exitCode = 1; + }); } module.exports = { fetchProtos, getVersionMappings }; \ No newline at end of file diff --git a/scripts/publish-single-version.js b/scripts/publish-single-version.js index 4dc0b50..09de5d5 100644 --- a/scripts/publish-single-version.js +++ b/scripts/publish-single-version.js @@ -2,6 +2,7 @@ const fs = require('fs'); const path = require('path'); +const crypto = require('crypto'); const { execSync } = require('child_process'); const pkgPath = path.join(process.cwd(), 'package.json'); @@ -22,7 +23,22 @@ if (!original.name || !original.version) { process.exit(1); } -const modified = { ...original, name: publishName }; +// Hashes of the Emscripten outputs, so anyone can rebuild from the x-publish pins and compare. +const wasmSha256 = {}; +for (const file of ['wasm/libpg-query.wasm', 'wasm/libpg-query.js']) { + const filePath = path.join(process.cwd(), file); + if (!fs.existsSync(filePath)) { + console.error(`āŒ ${file} not found; build this version first.`); + process.exit(1); + } + wasmSha256[file] = crypto.createHash('sha256').update(fs.readFileSync(filePath)).digest('hex'); +} + +const modified = { + ...original, + name: publishName, + 'x-publish': { ...publishMeta, wasmSha256 } +}; try { console.log(`šŸ“¦ Publishing ${publishName}@${original.version} with tag '${distTag}'...`); diff --git a/templates/Makefile.template b/templates/Makefile.template index 340d51f..952520d 100644 --- a/templates/Makefile.template +++ b/templates/Makefile.template @@ -1,8 +1,18 @@ WASM_OUT_DIR := wasm WASM_OUT_NAME := libpg-query WASM_MODULE_NAME := PgQueryModule -LIBPG_QUERY_REPO := https://github.com/pganalyze/libpg_query.git + +# WASM memory configuration (bytes). Override on the make command line for +# low-memory variants, e.g. `make build WASM_INITIAL_MEMORY=33554432` (32MiB). +WASM_INITIAL_MEMORY ?= 134217728 +WASM_MAXIMUM_MEMORY ?= 1073741824 +WASM_STACK_SIZE ?= 33554432 + +# libpg_query source, pinned to an exact commit so a release can be rebuilt +# byte-for-byte. Set in package.json `x-publish` and applied by copy:templates. +LIBPG_QUERY_REPO := {{LIBPG_QUERY_REPO}} LIBPG_QUERY_TAG := {{VERSION_TAG}} +LIBPG_QUERY_COMMIT := {{LIBPG_QUERY_COMMIT}} CACHE_DIR := .cache @@ -25,7 +35,7 @@ endif PLATFORM_ARCH := $(PLATFORM)-$(ARCH) SRC_FILES := src/wasm_wrapper.c -LIBPG_QUERY_DIR := $(CACHE_DIR)/$(PLATFORM_ARCH)/libpg_query/$(LIBPG_QUERY_TAG) +LIBPG_QUERY_DIR := $(CACHE_DIR)/$(PLATFORM_ARCH)/libpg_query/$(LIBPG_QUERY_COMMIT) LIBPG_QUERY_ARCHIVE := $(LIBPG_QUERY_DIR)/libpg_query.a LIBPG_QUERY_HEADER := $(LIBPG_QUERY_DIR)/pg_query.h CXXFLAGS := -O3 -flto @@ -36,15 +46,18 @@ else $(error Native builds are no longer supported. Use EMSCRIPTEN=1 for WASM builds only.) endif -# Clone libpg_query source (lives in CACHE_DIR) -$(LIBPG_QUERY_DIR): - mkdir -p $(CACHE_DIR) - git clone -b $(LIBPG_QUERY_TAG) --single-branch $(LIBPG_QUERY_REPO) $(LIBPG_QUERY_DIR) {{#USE_EMSCRIPTEN_PATCH}} +# Applied in the same step as the clone, so a failed patch removes the clone. ifdef EMSCRIPTEN - cd $(LIBPG_QUERY_DIR); patch -p1 < $(shell pwd)/patches/emscripten_disable_spinlocks.patch +LIBPG_QUERY_PATCH := && patch -d $(LIBPG_QUERY_DIR) -p1 < $(CURDIR)/patches/emscripten_disable_spinlocks.patch endif -{{/USE_EMSCRIPTEN_PATCH}} + +{{/USE_EMSCRIPTEN_PATCH}}# Clone libpg_query source (lives in CACHE_DIR) +$(LIBPG_QUERY_DIR): + mkdir -p $(CACHE_DIR) + git clone -b $(LIBPG_QUERY_TAG) --single-branch $(LIBPG_QUERY_REPO) $(LIBPG_QUERY_DIR) && \ + git -C $(LIBPG_QUERY_DIR) -c advice.detachedHead=false checkout $(LIBPG_QUERY_COMMIT) $(LIBPG_QUERY_PATCH) || \ + { rm -rf $(LIBPG_QUERY_DIR); exit 1; } $(LIBPG_QUERY_HEADER): $(LIBPG_QUERY_DIR) @@ -71,9 +84,9 @@ ifdef EMSCRIPTEN -sMODULARIZE=1 \ -sEXPORT_ES6=0 \ -sALLOW_MEMORY_GROWTH=1 \ - -sINITIAL_MEMORY=134217728 \ - -sMAXIMUM_MEMORY=1073741824 \ - -sSTACK_SIZE=33554432 \ + -sINITIAL_MEMORY=$(WASM_INITIAL_MEMORY) \ + -sMAXIMUM_MEMORY=$(WASM_MAXIMUM_MEMORY) \ + -sSTACK_SIZE=$(WASM_STACK_SIZE) \ -lpg_query \ -o $@ \ $(SRC_FILES) diff --git a/templates/README.md b/templates/README.md index e507db5..fc78842 100644 --- a/templates/README.md +++ b/templates/README.md @@ -28,7 +28,9 @@ This script will: The following placeholders are used in template files: -- `{{VERSION_TAG}}` - The libpg_query version tag (e.g., "14-3.0.0") +- `{{LIBPG_QUERY_REPO}}` - The libpg_query git repository to clone +- `{{VERSION_TAG}}` - The libpg_query branch or tag to clone (e.g., "14-3.0.0") +- `{{LIBPG_QUERY_COMMIT}}` - The exact commit checked out after cloning - `{{#USE_EMSCRIPTEN_PATCH}}...{{/USE_EMSCRIPTEN_PATCH}}` - Conditional block for version-specific patches (currently only used in version 13) ## Version-Specific Configurations @@ -40,13 +42,18 @@ The `scripts/copy-templates.js` script automatically reads version-specific conf "publishName": "libpg-query", "pgVersion": "15", "distTag": "pg15", - "libpgQueryTag": "15-4.2.4" + "libpgQueryRepo": "https://github.com/constructive-io/libpg_query.git", + "libpgQueryTag": "fix/negative-int-pg15", + "libpgQueryCommit": "ae10504217b703340b5632f6345fe1e83d61485c" } ``` The script uses: - `pgVersion` to identify the PostgreSQL version -- `libpgQueryTag` for the {{VERSION_TAG}} placeholder replacement +- `libpgQueryRepo`, `libpgQueryTag` and `libpgQueryCommit` for the source placeholders. The commit + is required (a full 40-character SHA): the build checks it out after cloning, so a branch moving + upstream cannot change what a rebuild produces. To pick up new libpg_query changes, bump the commit + and re-run `npm run copy:templates`. - Version 13 automatically gets the emscripten patch applied ## Important Notes diff --git a/versions/13/Makefile b/versions/13/Makefile index 4ace118..47cdf4d 100644 --- a/versions/13/Makefile +++ b/versions/13/Makefile @@ -6,8 +6,18 @@ WASM_OUT_DIR := wasm WASM_OUT_NAME := libpg-query WASM_MODULE_NAME := PgQueryModule + +# WASM memory configuration (bytes). Override on the make command line for +# low-memory variants, e.g. `make build WASM_INITIAL_MEMORY=33554432` (32MiB). +WASM_INITIAL_MEMORY ?= 134217728 +WASM_MAXIMUM_MEMORY ?= 1073741824 +WASM_STACK_SIZE ?= 33554432 + +# libpg_query source, pinned to an exact commit so a release can be rebuilt +# byte-for-byte. Set in package.json `x-publish` and applied by copy:templates. LIBPG_QUERY_REPO := https://github.com/pganalyze/libpg_query.git LIBPG_QUERY_TAG := 13-2.2.0 +LIBPG_QUERY_COMMIT := 1097b2c33e54a37c0d2c0f2d498c7d1cf967eae9 CACHE_DIR := .cache @@ -30,7 +40,7 @@ endif PLATFORM_ARCH := $(PLATFORM)-$(ARCH) SRC_FILES := src/wasm_wrapper.c -LIBPG_QUERY_DIR := $(CACHE_DIR)/$(PLATFORM_ARCH)/libpg_query/$(LIBPG_QUERY_TAG) +LIBPG_QUERY_DIR := $(CACHE_DIR)/$(PLATFORM_ARCH)/libpg_query/$(LIBPG_QUERY_COMMIT) LIBPG_QUERY_ARCHIVE := $(LIBPG_QUERY_DIR)/libpg_query.a LIBPG_QUERY_HEADER := $(LIBPG_QUERY_DIR)/pg_query.h CXXFLAGS := -O3 -flto @@ -41,13 +51,17 @@ else $(error Native builds are no longer supported. Use EMSCRIPTEN=1 for WASM builds only.) endif +# Applied in the same step as the clone, so a failed patch removes the clone. +ifdef EMSCRIPTEN +LIBPG_QUERY_PATCH := && patch -d $(LIBPG_QUERY_DIR) -p1 < $(CURDIR)/patches/emscripten_disable_spinlocks.patch +endif + # Clone libpg_query source (lives in CACHE_DIR) $(LIBPG_QUERY_DIR): mkdir -p $(CACHE_DIR) - git clone -b $(LIBPG_QUERY_TAG) --single-branch $(LIBPG_QUERY_REPO) $(LIBPG_QUERY_DIR) -ifdef EMSCRIPTEN - cd $(LIBPG_QUERY_DIR); patch -p1 < $(shell pwd)/patches/emscripten_disable_spinlocks.patch -endif + git clone -b $(LIBPG_QUERY_TAG) --single-branch $(LIBPG_QUERY_REPO) $(LIBPG_QUERY_DIR) && \ + git -C $(LIBPG_QUERY_DIR) -c advice.detachedHead=false checkout $(LIBPG_QUERY_COMMIT) $(LIBPG_QUERY_PATCH) || \ + { rm -rf $(LIBPG_QUERY_DIR); exit 1; } $(LIBPG_QUERY_HEADER): $(LIBPG_QUERY_DIR) @@ -74,9 +88,9 @@ ifdef EMSCRIPTEN -sMODULARIZE=1 \ -sEXPORT_ES6=0 \ -sALLOW_MEMORY_GROWTH=1 \ - -sINITIAL_MEMORY=134217728 \ - -sMAXIMUM_MEMORY=1073741824 \ - -sSTACK_SIZE=33554432 \ + -sINITIAL_MEMORY=$(WASM_INITIAL_MEMORY) \ + -sMAXIMUM_MEMORY=$(WASM_MAXIMUM_MEMORY) \ + -sSTACK_SIZE=$(WASM_STACK_SIZE) \ -lpg_query \ -o $@ \ $(SRC_FILES) diff --git a/versions/13/package.json b/versions/13/package.json index 1b39e21..f0dd5bd 100644 --- a/versions/13/package.json +++ b/versions/13/package.json @@ -13,7 +13,9 @@ "publishName": "libpg-query", "pgVersion": "13", "distTag": "pg13", - "libpgQueryTag": "13-2.2.0" + "libpgQueryRepo": "https://github.com/pganalyze/libpg_query.git", + "libpgQueryTag": "13-2.2.0", + "libpgQueryCommit": "1097b2c33e54a37c0d2c0f2d498c7d1cf967eae9" }, "files": [ "wasm/*" @@ -23,7 +25,7 @@ "build:js": "node scripts/build.js", "build": "pnpm clean && pnpm wasm:build && pnpm build:js", "publish:pkg": "node ../../scripts/publish-single-version.js", - "wasm:make": "docker run --rm -v $(pwd):/src -u $(id -u):$(id -g) -e EMSCRIPTEN=1 emscripten/emsdk emmake make", + "wasm:make": "docker run --rm -v $(pwd):/src -u $(id -u):$(id -g) -e EMSCRIPTEN=1 emscripten/emsdk:6.0.3 emmake make", "wasm:build": "pnpm wasm:make build", "wasm:rebuild": "pnpm wasm:make rebuild", "wasm:clean": "pnpm wasm:make clean", diff --git a/versions/14/Makefile b/versions/14/Makefile index 1d9b073..5fe746c 100644 --- a/versions/14/Makefile +++ b/versions/14/Makefile @@ -6,8 +6,18 @@ WASM_OUT_DIR := wasm WASM_OUT_NAME := libpg-query WASM_MODULE_NAME := PgQueryModule + +# WASM memory configuration (bytes). Override on the make command line for +# low-memory variants, e.g. `make build WASM_INITIAL_MEMORY=33554432` (32MiB). +WASM_INITIAL_MEMORY ?= 134217728 +WASM_MAXIMUM_MEMORY ?= 1073741824 +WASM_STACK_SIZE ?= 33554432 + +# libpg_query source, pinned to an exact commit so a release can be rebuilt +# byte-for-byte. Set in package.json `x-publish` and applied by copy:templates. LIBPG_QUERY_REPO := https://github.com/pganalyze/libpg_query.git LIBPG_QUERY_TAG := 14-3.0.0 +LIBPG_QUERY_COMMIT := 397cbb9c1b188b8a5c6e1a9633461b2d01903abc CACHE_DIR := .cache @@ -30,7 +40,7 @@ endif PLATFORM_ARCH := $(PLATFORM)-$(ARCH) SRC_FILES := src/wasm_wrapper.c -LIBPG_QUERY_DIR := $(CACHE_DIR)/$(PLATFORM_ARCH)/libpg_query/$(LIBPG_QUERY_TAG) +LIBPG_QUERY_DIR := $(CACHE_DIR)/$(PLATFORM_ARCH)/libpg_query/$(LIBPG_QUERY_COMMIT) LIBPG_QUERY_ARCHIVE := $(LIBPG_QUERY_DIR)/libpg_query.a LIBPG_QUERY_HEADER := $(LIBPG_QUERY_DIR)/pg_query.h CXXFLAGS := -O3 -flto @@ -44,7 +54,9 @@ endif # Clone libpg_query source (lives in CACHE_DIR) $(LIBPG_QUERY_DIR): mkdir -p $(CACHE_DIR) - git clone -b $(LIBPG_QUERY_TAG) --single-branch $(LIBPG_QUERY_REPO) $(LIBPG_QUERY_DIR) + git clone -b $(LIBPG_QUERY_TAG) --single-branch $(LIBPG_QUERY_REPO) $(LIBPG_QUERY_DIR) && \ + git -C $(LIBPG_QUERY_DIR) -c advice.detachedHead=false checkout $(LIBPG_QUERY_COMMIT) $(LIBPG_QUERY_PATCH) || \ + { rm -rf $(LIBPG_QUERY_DIR); exit 1; } $(LIBPG_QUERY_HEADER): $(LIBPG_QUERY_DIR) @@ -71,9 +83,9 @@ ifdef EMSCRIPTEN -sMODULARIZE=1 \ -sEXPORT_ES6=0 \ -sALLOW_MEMORY_GROWTH=1 \ - -sINITIAL_MEMORY=134217728 \ - -sMAXIMUM_MEMORY=1073741824 \ - -sSTACK_SIZE=33554432 \ + -sINITIAL_MEMORY=$(WASM_INITIAL_MEMORY) \ + -sMAXIMUM_MEMORY=$(WASM_MAXIMUM_MEMORY) \ + -sSTACK_SIZE=$(WASM_STACK_SIZE) \ -lpg_query \ -o $@ \ $(SRC_FILES) diff --git a/versions/14/package.json b/versions/14/package.json index 0149a88..d8dabe8 100644 --- a/versions/14/package.json +++ b/versions/14/package.json @@ -13,7 +13,9 @@ "publishName": "libpg-query", "pgVersion": "14", "distTag": "pg14", - "libpgQueryTag": "14-3.0.0" + "libpgQueryRepo": "https://github.com/pganalyze/libpg_query.git", + "libpgQueryTag": "14-3.0.0", + "libpgQueryCommit": "397cbb9c1b188b8a5c6e1a9633461b2d01903abc" }, "files": [ "wasm/*" @@ -23,7 +25,7 @@ "build:js": "node scripts/build.js", "build": "pnpm clean && pnpm wasm:build && pnpm build:js", "publish:pkg": "node ../../scripts/publish-single-version.js", - "wasm:make": "docker run --rm -v $(pwd):/src -u $(id -u):$(id -g) emscripten/emsdk emmake make", + "wasm:make": "docker run --rm -v $(pwd):/src -u $(id -u):$(id -g) emscripten/emsdk:6.0.3 emmake make", "wasm:build": "pnpm wasm:make build", "wasm:rebuild": "pnpm wasm:make rebuild", "wasm:clean": "pnpm wasm:make clean", diff --git a/versions/15/Makefile b/versions/15/Makefile index 68777d3..a16a538 100644 --- a/versions/15/Makefile +++ b/versions/15/Makefile @@ -6,10 +6,18 @@ WASM_OUT_DIR := wasm WASM_OUT_NAME := libpg-query WASM_MODULE_NAME := PgQueryModule -# LIBPG_QUERY_REPO := https://github.com/pganalyze/libpg_query.git -# LIBPG_QUERY_TAG := 15-4.2.4 + +# WASM memory configuration (bytes). Override on the make command line for +# low-memory variants, e.g. `make build WASM_INITIAL_MEMORY=33554432` (32MiB). +WASM_INITIAL_MEMORY ?= 134217728 +WASM_MAXIMUM_MEMORY ?= 1073741824 +WASM_STACK_SIZE ?= 33554432 + +# libpg_query source, pinned to an exact commit so a release can be rebuilt +# byte-for-byte. Set in package.json `x-publish` and applied by copy:templates. LIBPG_QUERY_REPO := https://github.com/constructive-io/libpg_query.git LIBPG_QUERY_TAG := fix/negative-int-pg15 +LIBPG_QUERY_COMMIT := ae10504217b703340b5632f6345fe1e83d61485c CACHE_DIR := .cache @@ -32,7 +40,7 @@ endif PLATFORM_ARCH := $(PLATFORM)-$(ARCH) SRC_FILES := src/wasm_wrapper.c -LIBPG_QUERY_DIR := $(CACHE_DIR)/$(PLATFORM_ARCH)/libpg_query/$(LIBPG_QUERY_TAG) +LIBPG_QUERY_DIR := $(CACHE_DIR)/$(PLATFORM_ARCH)/libpg_query/$(LIBPG_QUERY_COMMIT) LIBPG_QUERY_ARCHIVE := $(LIBPG_QUERY_DIR)/libpg_query.a LIBPG_QUERY_HEADER := $(LIBPG_QUERY_DIR)/pg_query.h CXXFLAGS := -O3 -flto @@ -46,7 +54,9 @@ endif # Clone libpg_query source (lives in CACHE_DIR) $(LIBPG_QUERY_DIR): mkdir -p $(CACHE_DIR) - git clone -b $(LIBPG_QUERY_TAG) --single-branch $(LIBPG_QUERY_REPO) $(LIBPG_QUERY_DIR) + git clone -b $(LIBPG_QUERY_TAG) --single-branch $(LIBPG_QUERY_REPO) $(LIBPG_QUERY_DIR) && \ + git -C $(LIBPG_QUERY_DIR) -c advice.detachedHead=false checkout $(LIBPG_QUERY_COMMIT) $(LIBPG_QUERY_PATCH) || \ + { rm -rf $(LIBPG_QUERY_DIR); exit 1; } $(LIBPG_QUERY_HEADER): $(LIBPG_QUERY_DIR) @@ -73,9 +83,9 @@ ifdef EMSCRIPTEN -sMODULARIZE=1 \ -sEXPORT_ES6=0 \ -sALLOW_MEMORY_GROWTH=1 \ - -sINITIAL_MEMORY=134217728 \ - -sMAXIMUM_MEMORY=1073741824 \ - -sSTACK_SIZE=33554432 \ + -sINITIAL_MEMORY=$(WASM_INITIAL_MEMORY) \ + -sMAXIMUM_MEMORY=$(WASM_MAXIMUM_MEMORY) \ + -sSTACK_SIZE=$(WASM_STACK_SIZE) \ -lpg_query \ -o $@ \ $(SRC_FILES) diff --git a/versions/15/package.json b/versions/15/package.json index a5e9d87..9b6e82a 100644 --- a/versions/15/package.json +++ b/versions/15/package.json @@ -13,7 +13,9 @@ "publishName": "libpg-query", "pgVersion": "15", "distTag": "pg15", - "libpgQueryTag": "15-4.2.4" + "libpgQueryRepo": "https://github.com/constructive-io/libpg_query.git", + "libpgQueryTag": "fix/negative-int-pg15", + "libpgQueryCommit": "ae10504217b703340b5632f6345fe1e83d61485c" }, "files": [ "wasm/*" @@ -23,7 +25,7 @@ "build:js": "node scripts/build.js", "build": "pnpm clean && pnpm wasm:build && pnpm build:js", "publish:pkg": "node ../../scripts/publish-single-version.js", - "wasm:make": "docker run --rm -v $(pwd):/src -u $(id -u):$(id -g) emscripten/emsdk emmake make", + "wasm:make": "docker run --rm -v $(pwd):/src -u $(id -u):$(id -g) emscripten/emsdk:6.0.3 emmake make", "wasm:build": "pnpm wasm:make build", "wasm:rebuild": "pnpm wasm:make rebuild", "wasm:clean": "pnpm wasm:make clean", diff --git a/versions/16/Makefile b/versions/16/Makefile index 6bd9e62..05e7e6f 100644 --- a/versions/16/Makefile +++ b/versions/16/Makefile @@ -6,8 +6,18 @@ WASM_OUT_DIR := wasm WASM_OUT_NAME := libpg-query WASM_MODULE_NAME := PgQueryModule + +# WASM memory configuration (bytes). Override on the make command line for +# low-memory variants, e.g. `make build WASM_INITIAL_MEMORY=33554432` (32MiB). +WASM_INITIAL_MEMORY ?= 134217728 +WASM_MAXIMUM_MEMORY ?= 1073741824 +WASM_STACK_SIZE ?= 33554432 + +# libpg_query source, pinned to an exact commit so a release can be rebuilt +# byte-for-byte. Set in package.json `x-publish` and applied by copy:templates. LIBPG_QUERY_REPO := https://github.com/pganalyze/libpg_query.git LIBPG_QUERY_TAG := 16-5.2.0 +LIBPG_QUERY_COMMIT := fce106abf41205e5d0db47bea7de44ad1e36f7a5 CACHE_DIR := .cache @@ -30,7 +40,7 @@ endif PLATFORM_ARCH := $(PLATFORM)-$(ARCH) SRC_FILES := src/wasm_wrapper.c -LIBPG_QUERY_DIR := $(CACHE_DIR)/$(PLATFORM_ARCH)/libpg_query/$(LIBPG_QUERY_TAG) +LIBPG_QUERY_DIR := $(CACHE_DIR)/$(PLATFORM_ARCH)/libpg_query/$(LIBPG_QUERY_COMMIT) LIBPG_QUERY_ARCHIVE := $(LIBPG_QUERY_DIR)/libpg_query.a LIBPG_QUERY_HEADER := $(LIBPG_QUERY_DIR)/pg_query.h CXXFLAGS := -O3 -flto @@ -44,7 +54,9 @@ endif # Clone libpg_query source (lives in CACHE_DIR) $(LIBPG_QUERY_DIR): mkdir -p $(CACHE_DIR) - git clone -b $(LIBPG_QUERY_TAG) --single-branch $(LIBPG_QUERY_REPO) $(LIBPG_QUERY_DIR) + git clone -b $(LIBPG_QUERY_TAG) --single-branch $(LIBPG_QUERY_REPO) $(LIBPG_QUERY_DIR) && \ + git -C $(LIBPG_QUERY_DIR) -c advice.detachedHead=false checkout $(LIBPG_QUERY_COMMIT) $(LIBPG_QUERY_PATCH) || \ + { rm -rf $(LIBPG_QUERY_DIR); exit 1; } $(LIBPG_QUERY_HEADER): $(LIBPG_QUERY_DIR) @@ -71,9 +83,9 @@ ifdef EMSCRIPTEN -sMODULARIZE=1 \ -sEXPORT_ES6=0 \ -sALLOW_MEMORY_GROWTH=1 \ - -sINITIAL_MEMORY=134217728 \ - -sMAXIMUM_MEMORY=1073741824 \ - -sSTACK_SIZE=33554432 \ + -sINITIAL_MEMORY=$(WASM_INITIAL_MEMORY) \ + -sMAXIMUM_MEMORY=$(WASM_MAXIMUM_MEMORY) \ + -sSTACK_SIZE=$(WASM_STACK_SIZE) \ -lpg_query \ -o $@ \ $(SRC_FILES) diff --git a/versions/16/package.json b/versions/16/package.json index 5940431..63ae279 100644 --- a/versions/16/package.json +++ b/versions/16/package.json @@ -13,7 +13,9 @@ "publishName": "libpg-query", "pgVersion": "16", "distTag": "pg16", - "libpgQueryTag": "16-5.2.0" + "libpgQueryRepo": "https://github.com/pganalyze/libpg_query.git", + "libpgQueryTag": "16-5.2.0", + "libpgQueryCommit": "fce106abf41205e5d0db47bea7de44ad1e36f7a5" }, "files": [ "wasm/*" @@ -23,7 +25,7 @@ "build:js": "node scripts/build.js", "build": "pnpm clean && pnpm wasm:build && pnpm build:js", "publish:pkg": "node ../../scripts/publish-single-version.js", - "wasm:make": "docker run --rm -v $(pwd):/src -u $(id -u):$(id -g) emscripten/emsdk emmake make", + "wasm:make": "docker run --rm -v $(pwd):/src -u $(id -u):$(id -g) emscripten/emsdk:6.0.3 emmake make", "wasm:build": "pnpm wasm:make build", "wasm:rebuild": "pnpm wasm:make rebuild", "wasm:clean": "pnpm wasm:make clean", diff --git a/versions/17/Makefile b/versions/17/Makefile index 2d091cb..747eb3f 100644 --- a/versions/17/Makefile +++ b/versions/17/Makefile @@ -6,10 +6,18 @@ WASM_OUT_DIR := wasm WASM_OUT_NAME := libpg-query WASM_MODULE_NAME := PgQueryModule -# LIBPG_QUERY_REPO := https://github.com/pganalyze/libpg_query.git -# LIBPG_QUERY_TAG := 17-6.1.0 + +# WASM memory configuration (bytes). Override on the make command line for +# low-memory variants, e.g. `make build WASM_INITIAL_MEMORY=33554432` (32MiB). +WASM_INITIAL_MEMORY ?= 134217728 +WASM_MAXIMUM_MEMORY ?= 1073741824 +WASM_STACK_SIZE ?= 33554432 + +# libpg_query source, pinned to an exact commit so a release can be rebuilt +# byte-for-byte. Set in package.json `x-publish` and applied by copy:templates. LIBPG_QUERY_REPO := https://github.com/constructive-io/libpg_query.git LIBPG_QUERY_TAG := 17-constructive +LIBPG_QUERY_COMMIT := 1ade880fd1bbc6e89c33ea2424ddc366c41c1408 CACHE_DIR := .cache @@ -32,7 +40,7 @@ endif PLATFORM_ARCH := $(PLATFORM)-$(ARCH) SRC_FILES := src/wasm_wrapper.c -LIBPG_QUERY_DIR := $(CACHE_DIR)/$(PLATFORM_ARCH)/libpg_query/$(LIBPG_QUERY_TAG) +LIBPG_QUERY_DIR := $(CACHE_DIR)/$(PLATFORM_ARCH)/libpg_query/$(LIBPG_QUERY_COMMIT) LIBPG_QUERY_ARCHIVE := $(LIBPG_QUERY_DIR)/libpg_query.a LIBPG_QUERY_HEADER := $(LIBPG_QUERY_DIR)/pg_query.h CXXFLAGS := -O3 -flto @@ -46,7 +54,9 @@ endif # Clone libpg_query source (lives in CACHE_DIR) $(LIBPG_QUERY_DIR): mkdir -p $(CACHE_DIR) - git clone -b $(LIBPG_QUERY_TAG) --single-branch $(LIBPG_QUERY_REPO) $(LIBPG_QUERY_DIR) + git clone -b $(LIBPG_QUERY_TAG) --single-branch $(LIBPG_QUERY_REPO) $(LIBPG_QUERY_DIR) && \ + git -C $(LIBPG_QUERY_DIR) -c advice.detachedHead=false checkout $(LIBPG_QUERY_COMMIT) $(LIBPG_QUERY_PATCH) || \ + { rm -rf $(LIBPG_QUERY_DIR); exit 1; } $(LIBPG_QUERY_HEADER): $(LIBPG_QUERY_DIR) @@ -73,9 +83,9 @@ ifdef EMSCRIPTEN -sMODULARIZE=1 \ -sEXPORT_ES6=0 \ -sALLOW_MEMORY_GROWTH=1 \ - -sINITIAL_MEMORY=134217728 \ - -sMAXIMUM_MEMORY=1073741824 \ - -sSTACK_SIZE=33554432 \ + -sINITIAL_MEMORY=$(WASM_INITIAL_MEMORY) \ + -sMAXIMUM_MEMORY=$(WASM_MAXIMUM_MEMORY) \ + -sSTACK_SIZE=$(WASM_STACK_SIZE) \ -lpg_query \ -o $@ \ $(SRC_FILES) diff --git a/versions/17/package.json b/versions/17/package.json index c8685ca..0b1e159 100644 --- a/versions/17/package.json +++ b/versions/17/package.json @@ -13,7 +13,9 @@ "publishName": "libpg-query", "pgVersion": "17", "distTag": "pg17", - "libpgQueryTag": "17-6.1.0" + "libpgQueryRepo": "https://github.com/constructive-io/libpg_query.git", + "libpgQueryTag": "17-constructive", + "libpgQueryCommit": "1ade880fd1bbc6e89c33ea2424ddc366c41c1408" }, "files": [ "wasm/*" @@ -23,7 +25,7 @@ "build:js": "node scripts/build.js", "build": "pnpm clean && pnpm wasm:build && pnpm build:js", "publish:pkg": "node ../../scripts/publish-single-version.js", - "wasm:make": "docker run --rm -v $(pwd):/src -u $(id -u):$(id -g) emscripten/emsdk emmake make", + "wasm:make": "docker run --rm -v $(pwd):/src -u $(id -u):$(id -g) emscripten/emsdk:6.0.3 emmake make", "wasm:build": "pnpm wasm:make build", "wasm:rebuild": "pnpm wasm:make rebuild", "wasm:clean": "pnpm wasm:make clean", diff --git a/versions/18/Makefile b/versions/18/Makefile index d1b233b..c0c91c2 100644 --- a/versions/18/Makefile +++ b/versions/18/Makefile @@ -12,10 +12,12 @@ WASM_MODULE_NAME := PgQueryModule WASM_INITIAL_MEMORY ?= 134217728 WASM_MAXIMUM_MEMORY ?= 1073741824 WASM_STACK_SIZE ?= 33554432 -# LIBPG_QUERY_REPO := https://github.com/pganalyze/libpg_query.git -# LIBPG_QUERY_TAG := 18.0.0 + +# libpg_query source, pinned to an exact commit so a release can be rebuilt +# byte-for-byte. Set in package.json `x-publish` and applied by copy:templates. LIBPG_QUERY_REPO := https://github.com/constructive-io/libpg_query.git LIBPG_QUERY_TAG := 18-constructive +LIBPG_QUERY_COMMIT := b0f5f331dc50d69597ec610de7b21afa47a66808 CACHE_DIR := .cache @@ -38,7 +40,7 @@ endif PLATFORM_ARCH := $(PLATFORM)-$(ARCH) SRC_FILES := src/wasm_wrapper.c -LIBPG_QUERY_DIR := $(CACHE_DIR)/$(PLATFORM_ARCH)/libpg_query/$(LIBPG_QUERY_TAG) +LIBPG_QUERY_DIR := $(CACHE_DIR)/$(PLATFORM_ARCH)/libpg_query/$(LIBPG_QUERY_COMMIT) LIBPG_QUERY_ARCHIVE := $(LIBPG_QUERY_DIR)/libpg_query.a LIBPG_QUERY_HEADER := $(LIBPG_QUERY_DIR)/pg_query.h CXXFLAGS := -O3 -flto @@ -52,7 +54,9 @@ endif # Clone libpg_query source (lives in CACHE_DIR) $(LIBPG_QUERY_DIR): mkdir -p $(CACHE_DIR) - git clone -b $(LIBPG_QUERY_TAG) --single-branch $(LIBPG_QUERY_REPO) $(LIBPG_QUERY_DIR) + git clone -b $(LIBPG_QUERY_TAG) --single-branch $(LIBPG_QUERY_REPO) $(LIBPG_QUERY_DIR) && \ + git -C $(LIBPG_QUERY_DIR) -c advice.detachedHead=false checkout $(LIBPG_QUERY_COMMIT) $(LIBPG_QUERY_PATCH) || \ + { rm -rf $(LIBPG_QUERY_DIR); exit 1; } $(LIBPG_QUERY_HEADER): $(LIBPG_QUERY_DIR) diff --git a/versions/18/package.json b/versions/18/package.json index 45802db..f928280 100644 --- a/versions/18/package.json +++ b/versions/18/package.json @@ -13,7 +13,9 @@ "publishName": "libpg-query", "pgVersion": "18", "distTag": "pg18", + "libpgQueryRepo": "https://github.com/constructive-io/libpg_query.git", "libpgQueryTag": "18-constructive", + "libpgQueryCommit": "b0f5f331dc50d69597ec610de7b21afa47a66808", "fullApi": true }, "files": [ @@ -24,7 +26,7 @@ "build:js": "node scripts/build.js", "build": "pnpm clean && pnpm wasm:build && pnpm build:js", "publish:pkg": "node ../../scripts/publish-single-version.js", - "wasm:make": "docker run --rm -v $(pwd):/src -u $(id -u):$(id -g) emscripten/emsdk emmake make", + "wasm:make": "docker run --rm -v $(pwd):/src -u $(id -u):$(id -g) emscripten/emsdk:6.0.3 emmake make", "wasm:build": "pnpm wasm:make build", "wasm:rebuild": "pnpm wasm:make rebuild", "wasm:clean": "pnpm wasm:make clean",