This commit is contained in:
Choi138 2026-08-14 22:42:45 +09:00 committed by GitHub
commit e41be9b599
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 53 additions and 12 deletions

View File

@ -8,8 +8,9 @@ Build & install to `~/.hermes/lib/`:
./build.sh
Uses the system `sqlite3ext.h` when available, else the vendored copy in
`vendor/` — no libsqlite3-dev required.
Uses the vendored public-domain SQLite extension headers in `vendor/`, so no
libsqlite3-dev package is required and SDK headers that disable loadable
extensions cannot break the build.
Once the extension is installed, the next `SessionDB` open creates the
`messages_fts_cjk` index (external-content, tool rows excluded — same v23

View File

@ -1,19 +1,20 @@
#!/bin/bash
# Build libfts5_cjk.so and install to ~/.hermes/lib/ (or $1).
#
# Uses the system sqlite3ext.h when present, else the vendored copy in
# vendor/ (public-domain SQLite amalgamation headers) so the build works
# without libsqlite3-dev installed.
# Uses the vendored public-domain SQLite extension headers. Some platforms
# ship a sqlite3ext.h that exists but deliberately defines
# SQLITE_OMIT_LOAD_EXTENSION (notably the macOS SDK), which makes a simple
# header-presence probe produce a shared object with unresolved symbols.
set -euo pipefail
cd "$(dirname "$0")"
CFLAGS_EXTRA=""
if ! echo '#include <sqlite3ext.h>' | gcc -E -xc - >/dev/null 2>&1; then
CFLAGS_EXTRA="-Ivendor"
fi
gcc -shared -fPIC -O2 -Wall -Wextra $CFLAGS_EXTRA fts5_cjk.c -o libfts5_cjk.so
dest="${1:-$HOME/.hermes/lib}"
mkdir -p "$dest"
install -m 0644 libfts5_cjk.so "$dest/libfts5_cjk.so"
compiler="${CC:-gcc}"
tmp_output="$(mktemp "$dest/.libfts5_cjk.XXXXXX")"
trap 'rm -f "$tmp_output"' EXIT
"$compiler" -shared -fPIC -O2 -Wall -Wextra -Ivendor \
fts5_cjk.c -o "$tmp_output"
install -m 0644 "$tmp_output" "$dest/libfts5_cjk.so"
echo "installed: $dest/libfts5_cjk.so"

View File

@ -4,6 +4,7 @@ Builds the loadable tokenizer from native/fts5_cjk/fts5_cjk.c on the fly;
skips when no C toolchain / extension loading is available.
"""
import os
import shutil
import sqlite3
import subprocess
@ -16,6 +17,7 @@ from hermes_state import FTS_CJK_STALE_KEY, SessionDB
REPO = Path(__file__).resolve().parent.parent
SRC = REPO / "native" / "fts5_cjk" / "fts5_cjk.c"
VENDOR = REPO / "native" / "fts5_cjk" / "vendor"
BUILD = REPO / "native" / "fts5_cjk" / "build.sh"
@pytest.fixture(scope="session")
@ -43,6 +45,43 @@ def cjk_so(tmp_path_factory):
return out
def test_build_script_installs_loadable_extension(tmp_path):
bash = shutil.which("bash")
if shutil.which("gcc") is None or bash is None:
pytest.skip("no C toolchain / bash")
# Emulate a system header that preprocesses successfully but disables the
# loadable-extension API. The build must prefer -Ivendor over CPATH.
hostile_include = tmp_path / "host-include"
hostile_include.mkdir()
vendored_ext = VENDOR / "sqlite3ext.h"
(hostile_include / "sqlite3ext.h").write_text(
"#define SQLITE_OMIT_LOAD_EXTENSION 1\n"
f'#include "{vendored_ext.as_posix()}"\n',
encoding="utf-8",
)
env = os.environ.copy()
env["CPATH"] = str(hostile_include)
dest = tmp_path / "lib"
subprocess.run(
[bash, str(BUILD), str(dest)],
check=True,
capture_output=True,
text=True,
env=env,
)
installed = dest / "libfts5_cjk.so"
assert installed.is_file()
probe = sqlite3.connect(":memory:")
try:
probe.enable_load_extension(True)
probe.load_extension(str(installed))
finally:
probe.close()
@pytest.fixture()
def db(cjk_so, tmp_path, monkeypatch):
monkeypatch.setenv("HERMES_FTS5_CJK_SO", str(cjk_so))