Skip to content

Commit 5961293

Browse files
samroseolirice
andauthored
Sam/pgroonga deps (#1105)
* feat: rebasing * feat: supabase-groonga and mod pgroonga * feat: resolving conflicts * feat: merge conflicts * feat: TokenMecab now working with pgroonga * chore: rm comment * chore: no postFixup needed * test: smoke test of pgroonga with mecab * fix: additional fixes to the build/install process in ami groonga plugins dir must be set as env var for TokenMecab to work * fix: need to tmp refer to this branch for testing * chore: bump version for actual release + rm wrapper not needed * pgroonga mecab test (#1156) * add mecab test * add mecab test --------- Co-authored-by: Sam Rose <[email protected]> Co-authored-by: Oliver Rice <[email protected]>
1 parent 6e17f0b commit 5961293

12 files changed

+386
-15
lines changed

ansible/tasks/stage2-setup-postgres.yml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,13 @@
1313
- name: Install pg_prove from nix binary cache
1414
become: yes
1515
shell: |
16-
sudo -u postgres bash -c ". /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh && nix profile install github:supabase/postgres/sam/2-stage-ami-nix#pg_prove"
16+
sudo -u postgres bash -c ". /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh && nix profile install github:supabase/postgres/{{ git_commit_sha }}#pg_prove"
17+
when: stage2_nix
18+
19+
- name: Install supabase-groonga from nix binary cache
20+
become: yes
21+
shell: |
22+
sudo -u postgres bash -c ". /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh && nix profile install github:supabase/postgres/sam/pgroonga-deps#supabase-groonga"
1723
when: stage2_nix
1824

1925
- name: Set ownership and permissions for /etc/ssl/private
@@ -220,3 +226,9 @@
220226
# script is expected to be placed by finalization tasks for different target platforms
221227
line: pgsodium.getkey_script= '{{ pg_bindir }}/pgsodium_getkey.sh'
222228
when: stage2_nix
229+
230+
- name: Append GRN_PLUGINS_DIR to /etc/environment.d/postgresql.env
231+
ansible.builtin.lineinfile:
232+
path: /etc/environment.d/postgresql.env
233+
line: 'GRN_PLUGINS_DIR=/var/lib/postgresql/.nix-profile/lib/groonga/plugins'
234+
become: yes

flake.nix

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@
7777
postgresql = pkgs.postgresql.postgresql_15;
7878
sfcgal = pkgs.callPackage ./nix/ext/sfcgal/sfcgal.nix { };
7979
pg_regress = pkgs.callPackage ./nix/ext/pg_regress.nix { inherit postgresql; };
80-
80+
supabase-groonga = pkgs.callPackage ./nix/supabase-groonga.nix { };
81+
mecab-naist-jdic = pkgs.callPackage ./nix/ext/mecab-naist-jdic/default.nix { };
8182
# Our list of PostgreSQL extensions which come from upstream Nixpkgs.
8283
# These are maintained upstream and can easily be used here just by
8384
# listing their name. Anytime the version of nixpkgs is upgraded, these
@@ -284,6 +285,7 @@
284285
# name in 'nix flake show' in order to make sure exactly what name you
285286
# want.
286287
basePackages = {
288+
supabase-groonga = supabase-groonga;
287289
# PostgreSQL versions.
288290
psql_15 = makePostgres "15";
289291
#psql_16 = makePostgres "16";
@@ -315,6 +317,8 @@
315317
platforms = platforms.all;
316318
};
317319
};
320+
mecab_naist_jdic = mecab-naist-jdic;
321+
supabase_groonga = supabase-groonga;
318322
# Start a version of the server.
319323
start-server =
320324
let
@@ -377,8 +381,10 @@
377381
--subst-var-by 'PG_HBA' "$out/etc/postgresql/pg_hba.conf" \
378382
--subst-var-by 'PG_IDENT' "$out/etc/postgresql/pg_ident.conf" \
379383
--subst-var-by 'LOCALES' '${localeArchive}' \
380-
--subst-var-by 'EXTENSION_CUSTOM_SCRIPTS_DIR' "$out/extension-custom-scripts"
381-
384+
--subst-var-by 'EXTENSION_CUSTOM_SCRIPTS_DIR' "$out/extension-custom-scripts" \
385+
--subst-var-by 'MECAB_LIB' '${basePackages.psql_15.exts.pgroonga}/lib/groonga/plugins/tokenizers/tokenizer_mecab.so' \
386+
--subst-var-by 'GROONGA_DIR' '${supabase-groonga}'
387+
382388
chmod +x $out/bin/start-postgres-server
383389
'';
384390

@@ -448,10 +454,11 @@
448454
let
449455
sqlTests = ./nix/tests/smoke;
450456
pg_prove = pkgs.perlPackages.TAPParserSourceHandlerpgTAP;
457+
supabase-groonga = pkgs.callPackage ./nix/supabase-groonga.nix { };
451458
in
452459
pkgs.runCommand "postgres-${pgpkg.version}-check-harness"
453460
{
454-
nativeBuildInputs = with pkgs; [ coreutils bash pgpkg pg_prove pg_regress procps ];
461+
nativeBuildInputs = with pkgs; [ coreutils bash pgpkg pg_prove pg_regress procps supabase-groonga ];
455462
} ''
456463
TMPDIR=$(mktemp -d)
457464
if [ $? -ne 0 ]; then
@@ -469,7 +476,7 @@
469476
mkdir -p $TMPDIR/logfile
470477
# Generate a random key and store it in an environment variable
471478
export PGSODIUM_KEY=$(head -c 32 /dev/urandom | od -A n -t x1 | tr -d ' \n')
472-
479+
export GRN_PLUGINS_DIR=${supabase-groonga}/lib/groonga/plugins
473480
# Create a simple script to echo the key
474481
echo '#!/bin/sh' > $TMPDIR/getkey.sh
475482
echo 'echo $PGSODIUM_KEY' >> $TMPDIR/getkey.sh
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Do not use vendored libraries
2+
3+
--- a/vendor/CMakeLists.txt
4+
+++ b/vendor/CMakeLists.txt
5+
@@ -14,10 +14,7 @@
6+
# License along with this library; if not, write to the Free Software
7+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
8+
9+
add_subdirectory(onigmo)
10+
-add_subdirectory(mruby)
11+
-add_subdirectory(mecab)
12+
-add_subdirectory(message_pack)
13+
if(GRN_WITH_MRUBY)
14+
add_subdirectory(groonga-log)
15+
endif()

nix/ext/mecab-naist-jdic/default.nix

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{ lib, stdenv, fetchurl, mecab }:
2+
3+
stdenv.mkDerivation rec {
4+
pname = "mecab-naist-jdic";
5+
version = "0.6.3b-20111013";
6+
7+
src = fetchurl {
8+
url = "https://github.com/supabase/mecab-naist-jdic/raw/main/mecab-naist-jdic-${version}.tar.gz";
9+
sha256 = "sha256-yzdwDcmne5U/K/OxW0nP7NZ4SFMKLPirywm1lMpWKMw=";
10+
};
11+
12+
buildInputs = [ mecab ];
13+
14+
configureFlags = [
15+
"--with-charset=utf8"
16+
];
17+
18+
buildPhase = ''
19+
runHook preBuild
20+
make
21+
${mecab}/libexec/mecab/mecab-dict-index -d . -o . -f UTF-8 -t utf-8
22+
runHook postBuild
23+
'';
24+
25+
installPhase = ''
26+
runHook preInstall
27+
28+
mkdir -p $out/lib/mecab/dic/naist-jdic
29+
cp *.dic *.bin *.def $out/lib/mecab/dic/naist-jdic/
30+
31+
runHook postInstall
32+
'';
33+
34+
meta = with lib; {
35+
description = "Naist Japanese Dictionary for MeCab";
36+
homepage = "https://taku910.github.io/mecab/";
37+
license = licenses.gpl2;
38+
platforms = platforms.unix;
39+
maintainers = with maintainers; [ samrose ];
40+
};
41+
}

nix/ext/pgroonga.nix

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,47 @@
1-
{ lib, stdenv, fetchurl, pkg-config, postgresql, msgpack-c, groonga }:
2-
1+
{ lib, stdenv, fetchurl, pkg-config, postgresql, msgpack-c, callPackage, mecab, makeWrapper }:
2+
let
3+
supabase-groonga = callPackage ../supabase-groonga.nix { };
4+
in
35
stdenv.mkDerivation rec {
46
pname = "pgroonga";
57
version = "3.0.7";
6-
78
src = fetchurl {
89
url = "https://packages.groonga.org/source/${pname}/${pname}-${version}.tar.gz";
910
sha256 = "sha256-iF/zh4zDDpAw5fxW1WG8i2bfPt4VYsnYArwOoE/lwgM=";
1011
};
11-
12-
nativeBuildInputs = [ pkg-config ];
13-
buildInputs = [ postgresql msgpack-c groonga ];
12+
nativeBuildInputs = [ pkg-config makeWrapper ];
13+
buildInputs = [ postgresql msgpack-c supabase-groonga mecab ];
14+
propagatedBuildInputs = [ supabase-groonga ];
15+
configureFlags = [
16+
"--with-mecab=${mecab}"
17+
"--enable-mecab"
18+
"--with-groonga=${supabase-groonga}"
19+
"--with-groonga-plugin-dir=${supabase-groonga}/lib/groonga/plugins"
20+
];
1421

1522
makeFlags = [
1623
"HAVE_MSGPACK=1"
1724
"MSGPACK_PACKAGE_NAME=msgpack-c"
25+
"HAVE_MECAB=1"
1826
];
1927

28+
preConfigure = ''
29+
export GROONGA_LIBS="-L${supabase-groonga}/lib -lgroonga"
30+
export GROONGA_CFLAGS="-I${supabase-groonga}/include"
31+
export MECAB_CONFIG="${mecab}/bin/mecab-config"
32+
'';
33+
2034
installPhase = ''
35+
mkdir -p $out/lib $out/share/postgresql/extension $out/bin
2136
install -D pgroonga${postgresql.dlSuffix} -t $out/lib/
2237
install -D pgroonga.control -t $out/share/postgresql/extension
2338
install -D data/pgroonga-*.sql -t $out/share/postgresql/extension
24-
2539
install -D pgroonga_database${postgresql.dlSuffix} -t $out/lib/
2640
install -D pgroonga_database.control -t $out/share/postgresql/extension
2741
install -D data/pgroonga_database-*.sql -t $out/share/postgresql/extension
42+
43+
echo "Debug: Groonga plugins directory contents:"
44+
ls -l ${supabase-groonga}/lib/groonga/plugins/tokenizers/
2845
'';
2946

3047
meta = with lib; {
@@ -41,4 +58,4 @@ stdenv.mkDerivation rec {
4158
platforms = postgresql.meta.platforms;
4259
maintainers = with maintainers; [ samrose ];
4360
};
44-
}
61+
}

nix/ext/use-system-groonga.patch

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
diff --git a/CMakeLists.txt b/CMakeLists.txt
2+
index 33b34477..f4ffefe5 100644
3+
--- a/CMakeLists.txt
4+
+++ b/CMakeLists.txt
5+
@@ -12,7 +12,6 @@ if(MSVC_VERSION LESS 1800)
6+
message(FATAL_ERROR "PGroonga supports only MSVC 2013 or later")
7+
endif()
8+
9+
-add_subdirectory(vendor/groonga)
10+
11+
set(PGRN_POSTGRESQL_DIR "${CMAKE_INSTALL_PREFIX}"
12+
CACHE PATH "PostgreSQL binary directory")
13+
@@ -52,8 +51,6 @@ string(REGEX REPLACE "([0-9]+)\\.([0-9]+)\\.([0-9]+)" "\\3"
14+
string(REGEX REPLACE ".*comment = '([^']+)'.*" "\\1"
15+
PGRN_DESCRIPTION "${PGRN_CONTROL}")
16+
17+
-file(READ "${CMAKE_CURRENT_SOURCE_DIR}/vendor/groonga/bundled_message_pack_version"
18+
- PGRN_BUNDLED_MESSAGE_PACK_VERSION)
19+
string(STRIP
20+
"${PGRN_BUNDLED_MESSAGE_PACK_VERSION}"
21+
PGRN_BUNDLED_MESSAGE_PACK_VERSION)

nix/fix-cmake-install-path.patch

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Fix CMake install path
2+
3+
--- a/CMakeLists.txt
4+
+++ b/CMakeLists.txt
5+
@@ -1141,11 +1141,11 @@
6+
7+
set(prefix "${CMAKE_INSTALL_PREFIX}")
8+
set(exec_prefix "\${prefix}")
9+
-set(bindir "\${exec_prefix}/${CMAKE_INSTALL_BINDIR}")
10+
-set(sbindir "\${exec_prefix}/${CMAKE_INSTALL_SBINDIR}")
11+
-set(libdir "\${prefix}/${CMAKE_INSTALL_LIBDIR}")
12+
-set(includedir "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}")
13+
-set(datarootdir "\${prefix}/${CMAKE_INSTALL_DATAROOTDIR}")
14+
+set(bindir "${CMAKE_INSTALL_FULL_BINDIR}")
15+
+set(sbindir "${CMAKE_INSTALL_FULL_SBINDIR}")
16+
+set(libdir "${CMAKE_INSTALL_FULL_LIBDIR}")
17+
+set(includedir "${CMAKE_INSTALL_FULL_INCLUDEDIR}")
18+
+set(datarootdir "${CMAKE_INSTALL_FULL_DATAROOTDIR}")
19+
set(datadir "\${datarootdir}")
20+
set(expanded_pluginsdir "${GRN_PLUGINS_DIR}")
21+
set(GRN_EXPANDED_DEFAULT_DOCUMENT_ROOT "${GRN_DEFAULT_DOCUMENT_ROOT}")

nix/supabase-groonga.nix

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
{ lib, stdenv, cmake, fetchurl, kytea, msgpack-c, mecab, pkg-config, rapidjson
2+
, testers, xxHash, zstd, postgresqlPackages, makeWrapper, suggestSupport ? false
3+
, zeromq, libevent, openssl, lz4Support ? false, lz4, zlibSupport ? true, zlib
4+
, writeShellScriptBin, callPackage }:
5+
let mecab-naist-jdic = callPackage ./ext/mecab-naist-jdic { };
6+
in stdenv.mkDerivation (finalAttrs: {
7+
pname = "supabase-groonga";
8+
version = "14.0.5";
9+
src = fetchurl {
10+
url =
11+
"https://packages.groonga.org/source/groonga/groonga-${finalAttrs.version}.tar.gz";
12+
hash = "sha256-y4UGnv8kK0z+br8wXpPf57NMXkdEJHcLCuTvYiubnIc=";
13+
};
14+
patches =
15+
[ ./fix-cmake-install-path.patch ./do-not-use-vendored-libraries.patch ];
16+
nativeBuildInputs = [ cmake pkg-config makeWrapper ];
17+
buildInputs = [ rapidjson xxHash zstd mecab kytea msgpack-c ]
18+
++ lib.optionals lz4Support [ lz4 ] ++ lib.optional zlibSupport [ zlib ]
19+
++ lib.optionals suggestSupport [ zeromq libevent ];
20+
cmakeFlags = [
21+
"-DWITH_MECAB=ON"
22+
"-DMECAB_DICDIR=${mecab-naist-jdic}/lib/mecab/dic/naist-jdic"
23+
"-DMECAB_CONFIG=${mecab}/bin/mecab-config"
24+
"-DENABLE_MECAB_TOKENIZER=ON"
25+
"-DMECAB_INCLUDE_DIR=${mecab}/include"
26+
"-DMECAB_LIBRARY=${mecab}/lib/libmecab.so"
27+
"-DGROONGA_ENABLE_TOKENIZER_MECAB=YES"
28+
"-DGRN_WITH_MECAB=YES"
29+
];
30+
preConfigure = ''
31+
export MECAB_DICDIR=${mecab-naist-jdic}/lib/mecab/dic/naist-jdic
32+
echo "MeCab dictionary directory is: $MECAB_DICDIR"
33+
'';
34+
buildPhase = ''
35+
cmake --build . -- VERBOSE=1
36+
grep -i mecab CMakeCache.txt || (echo "MeCab not detected in CMake cache" && exit 1)
37+
echo "CMake cache contents related to MeCab:"
38+
grep -i mecab CMakeCache.txt
39+
'';
40+
41+
# installPhase = ''
42+
# mkdir -p $out/bin $out/lib/groonga/plugins
43+
# cp -r lib/groonga/plugins/* $out/lib/groonga/plugins
44+
# cp -r bin/* $out/bin
45+
# echo "Installed Groonga plugins:"
46+
# ls -l $out/lib/groonga/plugins
47+
# '';
48+
49+
postInstall = ''
50+
echo "Searching for MeCab-related files:"
51+
find $out -name "*mecab*"
52+
53+
echo "Checking Groonga plugins directory:"
54+
ls -l $out/lib/groonga/plugins
55+
56+
echo "Wrapping Groonga binary:"
57+
wrapProgram $out/bin/groonga \
58+
--set GRN_PLUGINS_DIR $out/lib/groonga/plugins
59+
60+
'';
61+
env.NIX_CFLAGS_COMPILE =
62+
lib.optionalString zlibSupport "-I${zlib.dev}/include";
63+
64+
meta = with lib; {
65+
homepage = "https://groonga.org/";
66+
description = "Open-source fulltext search engine and column store";
67+
license = licenses.lgpl21;
68+
maintainers = [ maintainers.samrose ];
69+
platforms = platforms.all;
70+
longDescription = ''
71+
Groonga is an open-source fulltext search engine and column store.
72+
It lets you write high-performance applications that requires fulltext search.
73+
'';
74+
};
75+
})

0 commit comments

Comments
 (0)