Skip to content

Commit a45bb2a

Browse files
committed
feat: support multiple versions of the pgroonga extension
Build multiple versions of the pgroonga extension on different PostgreSQL versions. Add test for the extensions and their upgrade on PostgreSQL 15 and 17.
1 parent a720562 commit a45bb2a

File tree

10 files changed

+523
-118
lines changed

10 files changed

+523
-118
lines changed

nix/ext/pgroonga.nix

Lines changed: 0 additions & 95 deletions
This file was deleted.

nix/ext/pgroonga/default.nix

Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
{
2+
lib,
3+
stdenv,
4+
fetchurl,
5+
pkg-config,
6+
postgresql,
7+
msgpack-c,
8+
callPackage,
9+
mecab,
10+
makeWrapper,
11+
xxHash,
12+
buildEnv,
13+
}:
14+
let
15+
pname = "pgroonga";
16+
17+
# Load version configuration from external file
18+
allVersions = (builtins.fromJSON (builtins.readFile ../versions.json)).${pname};
19+
20+
# Filter versions compatible with current PostgreSQL version
21+
supportedVersions = lib.filterAttrs (
22+
_: value: builtins.elem (lib.versions.major postgresql.version) value.postgresql
23+
) allVersions;
24+
25+
# Derived version information
26+
versions = lib.naturalSort (lib.attrNames supportedVersions);
27+
latestVersion = lib.last versions;
28+
numberOfVersions = builtins.length versions;
29+
packages = builtins.attrValues (
30+
lib.mapAttrs (name: value: build name value.hash) supportedVersions
31+
);
32+
33+
# List of C extensions to be included in the build
34+
cExtensions = [
35+
"pgroonga"
36+
"pgroonga_database"
37+
];
38+
39+
# Build function for individual versions
40+
build =
41+
version: hash:
42+
let
43+
supabase-groonga = callPackage ./supabase-groonga-14.0.5.nix { };
44+
mecab-naist-jdic = callPackage ../mecab-naist-jdic { };
45+
in
46+
stdenv.mkDerivation rec {
47+
inherit pname version;
48+
49+
src = fetchurl {
50+
url = "https://packages.groonga.org/source/${pname}/${pname}-${version}.tar.gz";
51+
inherit hash;
52+
};
53+
nativeBuildInputs = [
54+
pkg-config
55+
makeWrapper
56+
];
57+
58+
buildInputs = [
59+
postgresql
60+
msgpack-c
61+
supabase-groonga
62+
mecab
63+
] ++ lib.optionals stdenv.isDarwin [ xxHash ];
64+
65+
propagatedBuildInputs = [
66+
supabase-groonga
67+
mecab-naist-jdic
68+
];
69+
configureFlags = [
70+
"--with-mecab=${mecab}"
71+
"--enable-mecab"
72+
"--with-groonga=${supabase-groonga}"
73+
"--with-groonga-plugin-dir=${supabase-groonga}/lib/groonga/plugins"
74+
];
75+
76+
makeFlags = [
77+
"HAVE_MSGPACK=1"
78+
"MSGPACK_PACKAGE_NAME=msgpack-c"
79+
"HAVE_MECAB=1"
80+
];
81+
82+
NIX_CFLAGS_COMPILE = lib.optionalString stdenv.isDarwin (
83+
builtins.concatStringsSep " " [
84+
"-Wno-error=incompatible-function-pointer-types"
85+
"-Wno-error=format"
86+
"-Wno-format"
87+
"-I${supabase-groonga}/include/groonga"
88+
"-I${xxHash}/include"
89+
"-DPGRN_VERSION=\"${version}\""
90+
]
91+
);
92+
93+
preConfigure = ''
94+
export GROONGA_LIBS="-L${supabase-groonga}/lib -lgroonga"
95+
export GROONGA_CFLAGS="-I${supabase-groonga}/include"
96+
export MECAB_CONFIG="${mecab}/bin/mecab-config"
97+
export MECAB_DICDIR="${mecab-naist-jdic}/lib/mecab/dic/naist-jdic"
98+
${lib.optionalString stdenv.isDarwin ''
99+
export CPPFLAGS="-I${supabase-groonga}/include/groonga -I${xxHash}/include -DPGRN_VERSION=\"${version}\""
100+
export CFLAGS="-I${supabase-groonga}/include/groonga -I${xxHash}/include -DPGRN_VERSION=\"${version}\""
101+
export PG_CPPFLAGS="-Wno-error=incompatible-function-pointer-types -Wno-error=format"
102+
''}
103+
'';
104+
105+
installPhase = ''
106+
runHook preInstall
107+
108+
mkdir -p $out/{lib,share/postgresql/extension}
109+
110+
for ext in ${lib.concatStringsSep " " cExtensions}; do
111+
# Install shared library with version suffix
112+
mv $ext${postgresql.dlSuffix} $out/lib/$ext-${version}${postgresql.dlSuffix}
113+
114+
# Create version-specific control file
115+
sed -e "/^default_version =/d" \
116+
-e "s|^module_pathname = .*|module_pathname = '\$libdir/$ext'|" \
117+
$ext.control > $out/share/postgresql/extension/$ext--${version}.control
118+
119+
# Copy SQL file to install the specific version
120+
cp data/$ext--${version}.sql $out/share/postgresql/extension
121+
122+
# Create versioned control file with modified module path
123+
sed -e "/^default_version =/d" \
124+
-e "s|^module_pathname = .*|module_pathname = '\$libdir/$ext'|" \
125+
$ext.control > $out/share/postgresql/extension/$ext--${version}.control
126+
127+
# For the latest version, create default control file and symlink and copy SQL upgrade scripts
128+
if [[ "${version}" == "${latestVersion}" ]]; then
129+
{
130+
echo "default_version = '${version}'"
131+
cat $out/share/postgresql/extension/$ext--${version}.control
132+
} > $out/share/postgresql/extension/$ext.control
133+
ln -sfn $ext-${version}${postgresql.dlSuffix} $out/lib/$ext${postgresql.dlSuffix}
134+
cp data/$ext--*--*.sql $out/share/postgresql/extension
135+
fi
136+
done
137+
'';
138+
139+
meta = with lib; {
140+
description = "A PostgreSQL extension to use Groonga as the index";
141+
longDescription = ''
142+
PGroonga is a PostgreSQL extension to use Groonga as the index.
143+
PostgreSQL supports full text search against languages that use only alphabet and digit.
144+
It means that PostgreSQL doesn't support full text search against Japanese, Chinese and so on.
145+
You can use super fast full text search feature against all languages by installing PGroonga into your PostgreSQL.
146+
'';
147+
homepage = "https://pgroonga.github.io/";
148+
changelog = "https://github.com/pgroonga/pgroonga/releases/tag/${version}";
149+
license = licenses.postgresql;
150+
inherit (postgresql.meta) platforms;
151+
};
152+
};
153+
in
154+
buildEnv {
155+
name = pname;
156+
paths = packages;
157+
158+
pathsToLink = [
159+
"/lib"
160+
"/share/postgresql/extension"
161+
];
162+
postBuild = ''
163+
# Verify all expected library files are present
164+
expectedFiles=${toString ((numberOfVersions + 1) * (builtins.length cExtensions))}
165+
actualFiles=$(ls -l $out/lib/${pname}*${postgresql.dlSuffix} | wc -l)
166+
167+
if [[ "$actualFiles" != "$expectedFiles" ]]; then
168+
echo "Error: Expected $expectedFiles library files, found $actualFiles"
169+
echo "Files found:"
170+
ls -la $out/lib/*${postgresql.dlSuffix} || true
171+
exit 1
172+
fi
173+
'';
174+
175+
passthru = {
176+
inherit versions numberOfVersions;
177+
pname = "${pname}-all";
178+
version =
179+
"multi-" + lib.concatStringsSep "-" (map (v: lib.replaceStrings [ "." ] [ "-" ] v) versions);
180+
};
181+
}
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()
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}")

0 commit comments

Comments
 (0)