Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,18 @@ jobs:
- if: ${{ startsWith(matrix.os, 'windows') }}
run: pip.exe install setuptools
- if: ${{ startsWith(matrix.os, 'macos') }}
run: brew install python-setuptools
run: brew install python-setuptools icu4c
- if: ${{ !startsWith(matrix.os, 'windows') && !startsWith(matrix.os, 'macos') }}
run: python3 -m pip install setuptools
- if: ${{ startsWith(matrix.os, 'ubuntu') && matrix.node < 25 }}
run: |
sudo apt update
sudo apt install -y gcc-10 g++-10 libreadline-dev libncurses5-dev
sudo apt install -y gcc-10 g++-10 libreadline-dev libncurses5-dev libicu-dev
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-10 100 --slave /usr/bin/g++ g++ /usr/bin/g++-10 --slave /usr/bin/gcov gcov /usr/bin/gcov-10
- if: ${{ startsWith(matrix.os, 'ubuntu') && matrix.node >= 25 }}
run: |
sudo apt update
sudo apt install -y gcc-11 g++-11 libreadline-dev libncurses5-dev
sudo apt install -y gcc-11 g++-11 libreadline-dev libncurses5-dev libicu-dev
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 100 --slave /usr/bin/g++ g++ /usr/bin/g++-11 --slave /usr/bin/gcov gcov /usr/bin/gcov-11
- run: npm install --ignore-scripts
- run: npm run build-debug
Expand Down Expand Up @@ -93,13 +93,13 @@ jobs:
with:
bun-version: ${{ matrix.bun }}
- if: ${{ startsWith(matrix.os, 'macos') }}
run: brew install python-setuptools
run: brew install python-setuptools icu4c
- if: ${{ !startsWith(matrix.os, 'macos') }}
run: python3 -m pip install setuptools
- if: ${{ startsWith(matrix.os, 'ubuntu') }}
run: |
sudo apt update
sudo apt install -y gcc-10 g++-10 libreadline-dev libncurses5-dev
sudo apt install -y gcc-10 g++-10 libreadline-dev libncurses5-dev libicu-dev
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-10 100 --slave /usr/bin/g++ g++ /usr/bin/g++-10 --slave /usr/bin/gcov gcov /usr/bin/gcov-10
- run: bun install --ignore-scripts
- run: bun run build-debug
Expand Down Expand Up @@ -163,7 +163,7 @@ jobs:
- if: ${{ startsWith(matrix.os, 'windows') }}
run: pip.exe install setuptools
- if: ${{ startsWith(matrix.os, 'macos') }}
run: brew install python-setuptools
run: brew install python-setuptools icu4c
- run: npm install --ignore-scripts
- run: ${{ env.NODE_BUILD_CMD_LEGACY }} -u ${{ secrets.GITHUB_TOKEN }}
- run: ${{ env.NODE_BUILD_CMD_MODERN }} -u ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -182,6 +182,7 @@ jobs:
needs: test
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- run: apt-get update && apt-get install -y libicu-dev
- run: npm install --ignore-scripts
- run: ${{ env.NODE_BUILD_CMD_LEGACY }} -u ${{ secrets.GITHUB_TOKEN }}

Expand All @@ -193,6 +194,7 @@ jobs:
needs: test
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- run: apt-get update && apt-get install -y libicu-dev
- run: npm install --ignore-scripts
- run: ${{ env.NODE_BUILD_CMD_MODERN }} -u ${{ secrets.GITHUB_TOKEN }}

Expand All @@ -204,7 +206,7 @@ jobs:
needs: test
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- run: apk add build-base git python3 py3-setuptools libstdc++ readline-dev ncurses-dev --update-cache
- run: apk add build-base git python3 py3-setuptools libstdc++ readline-dev ncurses-dev icu-dev icu-static --update-cache
- run: npm install --ignore-scripts
- run: ${{ env.NODE_BUILD_CMD_LEGACY }} -u ${{ secrets.GITHUB_TOKEN }}
- run: ${{ env.NODE_BUILD_CMD_MODERN }} -u ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -225,7 +227,7 @@ jobs:
- uses: docker/setup-qemu-action@c7c53464625b32c7a7e944ae62b3e17d2b600130 # v3
- run: |
docker run --rm -v $(pwd):/tmp/project --entrypoint /bin/sh --platform linux/${{ matrix.arch }} node:20-alpine -c "\
apk add build-base git python3 py3-setuptools libstdc++ readline-dev ncurses-dev --update-cache && \
apk add build-base git python3 py3-setuptools libstdc++ readline-dev ncurses-dev icu-dev icu-static --update-cache && \
cd /tmp/project && \
npm install --ignore-scripts && \
${{ env.NODE_BUILD_CMD_LEGACY }} -u ${{ secrets.GITHUB_TOKEN }} && \
Expand All @@ -247,6 +249,7 @@ jobs:
- uses: docker/setup-qemu-action@c7c53464625b32c7a7e944ae62b3e17d2b600130 # v3
- run: |
docker run --rm -v $(pwd):/tmp/project --entrypoint /bin/sh --platform linux/${{ matrix.arch }} node:20-bullseye -c "\
apt-get update && apt-get install -y libicu-dev && \
cd /tmp/project && \
npm install --ignore-scripts && \
${{ env.NODE_BUILD_CMD_LEGACY }} -u ${{ secrets.GITHUB_TOKEN }}"
Expand All @@ -267,6 +270,7 @@ jobs:
- uses: docker/setup-qemu-action@c7c53464625b32c7a7e944ae62b3e17d2b600130 # v3
- run: |
docker run --rm -v $(pwd):/tmp/project --entrypoint /bin/sh --platform linux/${{ matrix.arch }} node:20-bookworm -c "\
apt-get update && apt-get install -y libicu-dev && \
cd /tmp/project && \
npm install --ignore-scripts && \
${{ env.NODE_BUILD_CMD_MODERN }} -u ${{ secrets.GITHUB_TOKEN }}"
13 changes: 13 additions & 0 deletions binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@
},
},
'conditions': [
# ICU is statically linked into the SQLite static library on
# non-Windows; the final .node must resolve its ICU symbols. (See
# deps/sqlite3.gyp for why Windows is excluded.)
['OS != "win"', {
'libraries': ['<!@(node deps/icu.js libs)'],
}],
['OS=="linux"', {
'ldflags': [
'-Wl,-Bsymbolic',
Expand Down Expand Up @@ -69,6 +75,13 @@
'defines': ['HAVE_EDITLINE=1'],
'libraries': ['-ledit', '-lncurses'],
}],
# Unicode-aware LIKE/upper()/lower() via the bundled ICU extension,
# statically linked. Excluded on Windows (see deps/sqlite3.gyp).
['OS != "win"', {
'defines': ['SQLITE_ENABLE_ICU'],
'include_dirs': ['<!@(node deps/icu.js include)'],
'libraries': ['<!@(node deps/icu.js libs)'],
}],
Comment thread
arv marked this conversation as resolved.
Comment thread
arv marked this conversation as resolved.
],
'configurations': {
'Debug': {
Expand Down
122 changes: 122 additions & 0 deletions deps/icu.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
'use strict';

// ===
// ICU discovery helper for node-gyp — STATIC linking.
//
// Defining SQLITE_ENABLE_ICU compiles SQLite's bundled ICU extension (already
// present in the amalgamation, guarded by #ifdef SQLITE_ENABLE_ICU) and
// auto-registers Unicode-aware LIKE/upper()/lower()/REGEXP on every
// connection. That code calls into ICU.
//
// We link ICU *statically* so the prebuilt .node binaries stay self-contained:
// zero-cache ships them via prebuild-install onto runtime images (e.g. Alpine)
// that do not have ICU installed, and a dynamic NEEDED libicu*.so.<ver> would
// fail to load there (and couples the binary to one ICU soname). Static
// linking embeds ICU into the binary instead.
//
// Usage:
// node icu.js include -> the ICU include directory (for #include <unicode/...>)
// node icu.js libs -> newline-separated linker inputs: full paths to the
// ICU static archives, then the C++ runtime / system
// libraries those archives require.
//
// Discovery order: pkg-config (Linux/Alpine) -> Homebrew icu4c (macOS) ->
// common system locations. Set ICU_ROOT to override (expects ICU_ROOT/lib and
// ICU_ROOT/include).
//
// ICU is not enabled on Windows (see deps/sqlite3.gyp), so this script only
// ever runs on macOS and Linux.
// ===

const {execSync} = require('child_process');
const fs = require('fs');
const path = require('path');

const isMac = process.platform === 'darwin';

function run(cmd) {
try {
return execSync(cmd, {stdio: ['ignore', 'pipe', 'ignore']}).toString().trim();
} catch {
return '';
}
}

function firstDir(candidates) {
return candidates.find(p => p && fs.existsSync(p)) || '';
}

// Locate the ICU lib and include directories. Returns {libDir, includeDir}.
function locate() {
if (process.env.ICU_ROOT) {
const root = process.env.ICU_ROOT;
return {libDir: path.join(root, 'lib'), includeDir: path.join(root, 'include')};
}

// pkg-config (Debian's libicu-dev and Alpine's icu-dev ship icu-i18n.pc).
const pcLibDir = run('pkg-config --variable=libdir icu-i18n');
const pcIncDir = run('pkg-config --variable=includedir icu-i18n');
if (pcLibDir && fs.existsSync(pcLibDir)) {
Comment thread
arv marked this conversation as resolved.
Outdated
Comment thread
arv marked this conversation as resolved.
Outdated
return {libDir: pcLibDir, includeDir: pcIncDir};
}

// Homebrew icu4c (macOS, keg-only so not on default search paths).
if (isMac) {
let prefix = run('brew --prefix icu4c');
if (!prefix || !fs.existsSync(prefix)) {
prefix = firstDir(['/opt/homebrew/opt/icu4c', '/usr/local/opt/icu4c']);
}
if (prefix) {
return {libDir: path.join(prefix, 'lib'), includeDir: path.join(prefix, 'include')};
}
}

// Common system locations (Debian multiarch, Alpine, manual installs).
const libDir = firstDir([
'/usr/lib/x86_64-linux-gnu',
'/usr/lib/aarch64-linux-gnu',
'/usr/lib/arm-linux-gnueabihf',
'/usr/lib',
'/usr/local/lib',
]);
const includeDir = firstDir(['/usr/include', '/usr/local/include']);
return {libDir, includeDir};
}

// ICU static archives, in dependency order (i18n -> uc -> data).
const ARCHIVE_NAMES = ['libicui18n', 'libicuuc', 'libicudata'];

function libsOutput(loc) {
const out = [];
for (const name of ARCHIVE_NAMES) {
const full = loc.libDir && path.join(loc.libDir, name + '.a');
if (full && fs.existsSync(full)) {
out.push(full);
} else {
// Fall back to a normal library reference so local dev without the
// static archives still builds (dynamically). Prebuild CI installs the
// static libs, so this path is not taken for shipped binaries.
process.stderr.write(
`deps/icu.js: static archive ${name}.a not found in ${loc.libDir || '(unknown)'}; ` +
`falling back to dynamic linking for ${name}\n`,
);
out.push('-l' + name.replace(/^lib/, ''));
}
}
Comment thread
arv marked this conversation as resolved.
Outdated
Comment thread
arv marked this conversation as resolved.
Outdated
// C++ runtime + system libraries required by ICU's (C++) static archives.
if (isMac) {
out.push('-lc++');
} else {
out.push('-lstdc++', '-lm', '-lpthread', '-ldl');
}
return out;
}

const mode = process.argv[2];
const loc = locate();

if (mode === 'include') {
process.stdout.write(loc.includeDir || '');
} else {
process.stdout.write(libsOutput(loc).join('\n'));
}
11 changes: 10 additions & 1 deletion deps/sqlite3.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,16 @@
# This is currently required by better-sqlite3.
'SQLITE_ENABLE_COLUMN_METADATA',
],
}]
}],
# Unicode-aware LIKE/upper()/lower() via SQLite's bundled ICU extension,
# statically linked so the prebuilt binaries stay self-contained.
# Not enabled on Windows yet: static ICU there means building it from
# source (vcpkg), which is impractically slow in CI. Windows therefore
# keeps SQLite's ASCII-only LIKE for now.
['OS != "win"', {
'defines': ['SQLITE_ENABLE_ICU'],
Comment thread
arv marked this conversation as resolved.
'include_dirs': ['<!@(node icu.js include)'],
}],
],
'configurations': {
'Debug': {
Expand Down
Loading