From 9170adc70f9004a1b46788012f83047ee42e91bf Mon Sep 17 00:00:00 2001 From: Mike Burgh Date: Sat, 6 Jun 2026 08:08:11 +1000 Subject: [PATCH 1/5] ci: upload prebuild before verify; add Electron runtime deps for Linux verify --- .../build-better-sqlite3-electron.yml | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/.github/workflows/build-better-sqlite3-electron.yml b/.github/workflows/build-better-sqlite3-electron.yml index 99c7877..7deed63 100644 --- a/.github/workflows/build-better-sqlite3-electron.yml +++ b/.github/workflows/build-better-sqlite3-electron.yml @@ -64,6 +64,15 @@ jobs: ARCH: ${{ matrix.arch }} run: npx prebuild -r electron -t "$ELECTRON" --arch "$ARCH" --include-regex 'better_sqlite3.node$' + # Upload before verify so a successful build always yields an artifact, + # even if the Electron launch in CI is flaky. + - name: Upload prebuild artifact + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 + with: + name: bsmc-${{ matrix.platform }}-${{ matrix.arch }} + path: package/prebuilds/*.tar.gz + if-no-files-found: error + - name: Install Electron for verification shell: bash working-directory: package @@ -76,7 +85,11 @@ jobs: shell: bash working-directory: package run: | - sudo apt-get update && sudo apt-get install -y xvfb + sudo apt-get update + sudo apt-get install -y xvfb libnss3 libatk1.0-0t64 libatk-bridge2.0-0t64 \ + libcups2t64 libgtk-3-0t64 libgbm1 libasound2t64 libxshmfence1 libdrm2 \ + libxcomposite1 libxdamage1 libxfixes3 libxrandr2 libxkbcommon0 \ + libpango-1.0-0 libpangocairo-1.0-0 libcairo2 libgdk-pixbuf-2.0-0 || true out=$(xvfb-run -a ./node_modules/.bin/electron ../.github/scripts/verify-bsmc.js "$PWD" 2>&1) || true echo "$out" echo "$out" | grep -q "VERIFY_OK" || { echo "verification failed"; exit 1; } @@ -89,10 +102,3 @@ jobs: out=$(./node_modules/.bin/electron ../.github/scripts/verify-bsmc.js "$PWD" 2>&1) || true echo "$out" echo "$out" | grep -q "VERIFY_OK" || { echo "verification failed"; exit 1; } - - - name: Upload prebuild artifact - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 - with: - name: bsmc-${{ matrix.platform }}-${{ matrix.arch }} - path: package/prebuilds/*.tar.gz - if-no-files-found: error From 910a80d385ea163f9764c1a750cda238e784a5b8 Mon Sep 17 00:00:00 2001 From: Mike Burgh Date: Sat, 6 Jun 2026 08:13:58 +1000 Subject: [PATCH 2/5] ci: disable Electron SUID sandbox in Linux verify (CI has no root-owned chrome-sandbox) --- .github/workflows/build-better-sqlite3-electron.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/build-better-sqlite3-electron.yml b/.github/workflows/build-better-sqlite3-electron.yml index 7deed63..5d8659e 100644 --- a/.github/workflows/build-better-sqlite3-electron.yml +++ b/.github/workflows/build-better-sqlite3-electron.yml @@ -84,6 +84,8 @@ jobs: if: matrix.platform == 'linux' shell: bash working-directory: package + env: + ELECTRON_DISABLE_SANDBOX: '1' run: | sudo apt-get update sudo apt-get install -y xvfb libnss3 libatk1.0-0t64 libatk-bridge2.0-0t64 \ From 9177ca11edbe3265341ecd1f0a4e369b94164493 Mon Sep 17 00:00:00 2001 From: Mike Burgh Date: Sat, 6 Jun 2026 08:19:07 +1000 Subject: [PATCH 3/5] ci: robustly resolve Database export in verify harness --- .github/scripts/verify-bsmc.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/.github/scripts/verify-bsmc.js b/.github/scripts/verify-bsmc.js index d24d0da..381f376 100644 --- a/.github/scripts/verify-bsmc.js +++ b/.github/scripts/verify-bsmc.js @@ -16,8 +16,14 @@ app.commandLine.appendSwitch('no-sandbox'); app.whenReady().then(() => { let encFile; try { - const pkgDir = process.argv[2]; - const Database = require(pkgDir); + const pkgDir = process.argv[2] || process.cwd(); + const mod = require(pkgDir); + const Database = typeof mod === 'function' ? mod : mod && (mod.default || mod.Database); + if (typeof Database !== 'function') { + throw new Error( + `export is not a constructor: typeof=${typeof mod} keys=${mod && Object.keys(mod)} path=${pkgDir}`, + ); + } const db = new Database(':memory:'); db.exec('CREATE TABLE t(a INTEGER, b TEXT)'); From f98b26fc94f4ee73feda6eafd858c3bcfe5ea501 Mon Sep 17 00:00:00 2001 From: Mike Burgh Date: Sat, 6 Jun 2026 08:25:27 +1000 Subject: [PATCH 4/5] ci: resolve better-sqlite3 entry via manifest (avoid sibling package.json collision) --- .github/scripts/verify-bsmc.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/.github/scripts/verify-bsmc.js b/.github/scripts/verify-bsmc.js index 381f376..bff0601 100644 --- a/.github/scripts/verify-bsmc.js +++ b/.github/scripts/verify-bsmc.js @@ -17,12 +17,13 @@ app.whenReady().then(() => { let encFile; try { const pkgDir = process.argv[2] || process.cwd(); - const mod = require(pkgDir); - const Database = typeof mod === 'function' ? mod : mod && (mod.default || mod.Database); + // require(pkgDir) mis-resolves to /package.json (Node's LOAD_AS_FILE matches the + // sibling package.json before the package/ directory), so resolve via the package manifest. + const pkgJson = require(path.join(pkgDir, 'package.json')); + const entry = require(path.join(pkgDir, pkgJson.main || 'lib/index.js')); + const Database = typeof entry === 'function' ? entry : entry && (entry.default || entry.Database); if (typeof Database !== 'function') { - throw new Error( - `export is not a constructor: typeof=${typeof mod} keys=${mod && Object.keys(mod)} path=${pkgDir}`, - ); + throw new Error(`export is not a constructor: typeof=${typeof entry} path=${pkgDir}`); } const db = new Database(':memory:'); From 4ace03a552561c8fc59f6cc5df28998e49152d7c Mon Sep 17 00:00:00 2001 From: Mike Burgh Date: Sat, 6 Jun 2026 08:33:54 +1000 Subject: [PATCH 5/5] ci: MSVC shim for __builtin_frame_address (Electron 42 V8 14 Windows build) --- .github/scripts/patch-bsmc-v8-14.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/.github/scripts/patch-bsmc-v8-14.js b/.github/scripts/patch-bsmc-v8-14.js index 1eed9fd..7fa1c8b 100644 --- a/.github/scripts/patch-bsmc-v8-14.js +++ b/.github/scripts/patch-bsmc-v8-14.js @@ -80,6 +80,29 @@ replaceOnce( } } +// 4) Windows/MSVC only: V8 14's cppgc/heap.h uses __builtin_frame_address(0) (a Clang/GCC +// builtin) unconditionally; MSVC lacks it. Shim it to _AddressOfReturnAddress() (the MSVC +// stack-address intrinsic V8 itself uses elsewhere) before any V8 header is included. The +// only compiled TU is src/better_sqlite3.cpp, so prepending there covers everything. +// Guarded to MSVC-non-clang, so it is a no-op on the macOS/Linux (clang/gcc) builds. +{ + const file = path.join(pkg, 'src/better_sqlite3.cpp'); + const marker = '/* dbcode: MSVC __builtin_frame_address shim */'; + let c = fs.readFileSync(file, 'utf8'); + if (c.includes(marker)) { + console.log('SKIP (already patched) src/better_sqlite3.cpp: MSVC frame-address shim'); + } else { + const shim = + marker + + '\n#if defined(_MSC_VER) && !defined(__clang__)\n' + + '#include \n' + + '#define __builtin_frame_address(x) _AddressOfReturnAddress()\n' + + '#endif\n'; + fs.writeFileSync(file, shim + c); + console.log('OK src/better_sqlite3.cpp: MSVC frame-address shim'); + } +} + if (failed) { process.exit(1); }