Skip to content

Commit c1962cb

Browse files
committed
fix: pgroonga build on macos
1 parent 41f291e commit c1962cb

File tree

2 files changed

+41
-17
lines changed

2 files changed

+41
-17
lines changed

flake.nix

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -528,40 +528,46 @@
528528
pg_prove = pkgs.perlPackages.TAPParserSourceHandlerpgTAP;
529529
supabase-groonga = pkgs.callPackage ./nix/supabase-groonga.nix { };
530530
pg_regress = basePackages.pg_regress;
531+
tmpDirCmd = if pkgs.stdenv.isDarwin then
532+
"$(pwd)/postgres-tmp"
533+
else
534+
"mktemp -d";
531535
in
532536
pkgs.runCommand "postgres-${pgpkg.version}-check-harness"
533537
{
534538
nativeBuildInputs = with pkgs; [ coreutils bash pgpkg pg_prove pg_regress procps supabase-groonga ];
535539
} ''
536-
TMPDIR=$(mktemp -d)
540+
$WORKDIR=$(${tmpDirCmd})
537541
if [ $? -ne 0 ]; then
538542
echo "Failed to create temp directory" >&2
539543
exit 1
540544
fi
541545
546+
chmod 700 "$WORKDIR"
547+
542548
# Ensure the temporary directory is removed on exit
543-
trap 'rm -rf "$TMPDIR"' EXIT
549+
#trap 'rm -rf "$WORKDIR"' EXIT
544550
545-
export PGDATA="$TMPDIR/pgdata"
546-
export PGSODIUM_DIR="$TMPDIR/pgsodium"
551+
export PGDATA="$WORKDIR/pgdata"
552+
export PGSODIUM_DIR="$WORKDIR/pgsodium"
547553
548554
mkdir -p $PGDATA
549-
mkdir -p $TMPDIR/logfile
555+
mkdir -p $WORKDIR/logfile
550556
# Generate a random key and store it in an environment variable
551557
export PGSODIUM_KEY=$(head -c 32 /dev/urandom | od -A n -t x1 | tr -d ' \n')
552558
export GRN_PLUGINS_DIR=${supabase-groonga}/lib/groonga/plugins
553559
# Create a simple script to echo the key
554-
echo '#!/bin/sh' > $TMPDIR/getkey.sh
555-
echo 'echo $PGSODIUM_KEY' >> $TMPDIR/getkey.sh
556-
chmod +x $TMPDIR/getkey.sh
560+
echo '#!/bin/sh' > $WORKDIR/getkey.sh
561+
echo 'echo $PGSODIUM_KEY' >> $WORKDIR/getkey.sh
562+
chmod +x $WORKDIR/getkey.sh
557563
initdb --locale=C --username=supabase_admin
558564
substitute ${./nix/tests/postgresql.conf.in} $PGDATA/postgresql.conf \
559-
--subst-var-by PGSODIUM_GETKEY_SCRIPT "$TMPDIR/getkey.sh"
565+
--subst-var-by PGSODIUM_GETKEY_SCRIPT "$WORKDIR/getkey.sh"
560566
echo "listen_addresses = '*'" >> $PGDATA/postgresql.conf
561567
echo "port = 5432" >> $PGDATA/postgresql.conf
562568
echo "host all all 127.0.0.1/32 trust" >> $PGDATA/pg_hba.conf
563-
#postgres -D "$PGDATA" -k "$TMPDIR" -h localhost -p 5432 >$TMPDIR/logfile/postgresql.log 2>&1 &
564-
pg_ctl -D "$PGDATA" -l $TMPDIR/logfile/postgresql.log -o "-k $TMPDIR -p 5432" start
569+
#postgres -D "$PGDATA" -k "$WORKDIR" -h localhost -p 5432 >$WORKDIR/logfile/postgresql.log 2>&1 &
570+
pg_ctl -D "$PGDATA" -l $WORKDIR/logfile/postgresql.log -o "-k $WORKDIR -p 5432" start
565571
for i in {1..60}; do
566572
if pg_isready -h localhost -p 5432; then
567573
echo "PostgreSQL is ready"
@@ -573,14 +579,14 @@
573579
echo "PostgreSQL status:"
574580
pg_ctl -D "$PGDATA" status
575581
echo "PostgreSQL log content:"
576-
cat $TMPDIR/logfile/postgresql.log
582+
cat $WORKDIR/logfile/postgresql.log
577583
exit 1
578584
fi
579585
done
580586
createdb -p 5432 -h localhost --username=supabase_admin testing
581587
if ! psql -p 5432 -h localhost --username=supabase_admin -d testing -v ON_ERROR_STOP=1 -Xaf ${./nix/tests/prime.sql}; then
582588
echo "Error executing SQL file. PostgreSQL log content:"
583-
cat $TMPDIR/logfile/postgresql.log
589+
cat $WORKDIR/logfile/postgresql.log
584590
pg_ctl -D "$PGDATA" stop
585591
exit 1
586592
fi
@@ -598,7 +604,7 @@
598604
$(ls ${./nix/tests/sql} | sed -e 's/\..*$//' | sort )
599605
600606
pg_ctl -D "$PGDATA" stop
601-
mv $TMPDIR/logfile/postgresql.log $out
607+
mv $WORKDIR/logfile/postgresql.log $out
602608
echo ${pgpkg}
603609
'';
604610
in

nix/ext/pgroonga.nix

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{ lib, stdenv, fetchurl, pkg-config, postgresql, msgpack-c, callPackage, mecab, makeWrapper }:
1+
{ lib, stdenv, fetchurl, pkg-config, postgresql, msgpack-c, callPackage, mecab, makeWrapper, xxHash }:
22
let
33
supabase-groonga = callPackage ../supabase-groonga.nix { };
44
in
@@ -10,7 +10,11 @@ stdenv.mkDerivation rec {
1010
sha256 = "sha256-iF/zh4zDDpAw5fxW1WG8i2bfPt4VYsnYArwOoE/lwgM=";
1111
};
1212
nativeBuildInputs = [ pkg-config makeWrapper ];
13-
buildInputs = [ postgresql msgpack-c supabase-groonga mecab ];
13+
14+
buildInputs = [ postgresql msgpack-c supabase-groonga mecab ] ++ lib.optionals stdenv.isDarwin [
15+
xxHash
16+
];
17+
1418
propagatedBuildInputs = [ supabase-groonga ];
1519
configureFlags = [
1620
"--with-mecab=${mecab}"
@@ -19,16 +23,30 @@ stdenv.mkDerivation rec {
1923
"--with-groonga-plugin-dir=${supabase-groonga}/lib/groonga/plugins"
2024
];
2125

22-
makeFlags = [
26+
makeFlags = [
2327
"HAVE_MSGPACK=1"
2428
"MSGPACK_PACKAGE_NAME=msgpack-c"
2529
"HAVE_MECAB=1"
2630
];
2731

32+
NIX_CFLAGS_COMPILE = lib.optionalString stdenv.isDarwin (builtins.concatStringsSep " " [
33+
"-Wno-error=incompatible-function-pointer-types"
34+
"-Wno-error=format"
35+
"-Wno-format"
36+
"-I${supabase-groonga}/include/groonga"
37+
"-I${xxHash}/include"
38+
"-DPGRN_VERSION=\"${version}\""
39+
]);
40+
2841
preConfigure = ''
2942
export GROONGA_LIBS="-L${supabase-groonga}/lib -lgroonga"
3043
export GROONGA_CFLAGS="-I${supabase-groonga}/include"
3144
export MECAB_CONFIG="${mecab}/bin/mecab-config"
45+
${lib.optionalString stdenv.isDarwin ''
46+
export CPPFLAGS="-I${supabase-groonga}/include/groonga -I${xxHash}/include -DPGRN_VERSION=\"${version}\""
47+
export CFLAGS="-I${supabase-groonga}/include/groonga -I${xxHash}/include -DPGRN_VERSION=\"${version}\""
48+
export PG_CPPFLAGS="-Wno-error=incompatible-function-pointer-types -Wno-error=format"
49+
''}
3250
'';
3351

3452
installPhase = ''

0 commit comments

Comments
 (0)