Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 6 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -417,8 +417,12 @@
fi
done
createdb -p 5432 -h localhost testing
psql -p 5432 -h localhost -d testing -Xaf ${./nix/tests/prime.sql}

if ! psql -p 5432 -h localhost -d testing -v ON_ERROR_STOP=1 -Xaf ${./nix/tests/prime.sql}; then
echo "Error executing SQL file. PostgreSQL log content:"
cat $TMPDIR/logfile/postgresql.log
pg_ctl -D "$PGDATA" stop
exit 1
fi
pg_prove -p 5432 -h localhost -d testing ${sqlTests}/*.sql

mkdir -p $out/regression_output
Expand Down
85 changes: 66 additions & 19 deletions nix/ext/plv8.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
, runCommand
, coreutils
, gnugrep
, gcc
, clang
, patchelf
, xcbuild
, darwin
}:

stdenv.mkDerivation (finalAttrs: {
pname = "plv8";
# plv8 latest is https://github.com/plv8/plv8/releases/tag/v3.2.2
# FIXME we need to increment this build toward 3.2.2
# 3.1.7 is the highest version that can be built with pg 16
version = "3.1.5";

src = fetchFromGitHub {
Expand All @@ -26,58 +26,105 @@ stdenv.mkDerivation (finalAttrs: {
};

patches = [
# Allow building with system v8.
# https://github.com/plv8/plv8/pull/505 (rejected)
./0001-build-Allow-using-V8-from-system.patch
];

nativeBuildInputs = [
perl
] ++ lib.optionals stdenv.isDarwin [
gcc
clang
xcbuild
];

buildInputs = [
v8
(v8.overrideAttrs (oldAttrs: {
version = "9.7.106.18";
}))
postgresql
] ++ lib.optionals stdenv.isDarwin [
darwin.apple_sdk.frameworks.CoreFoundation
darwin.apple_sdk.frameworks.Kerberos
];

buildFlags = [ "all" ];

makeFlags = [
# Nixpkgs build a v8 monolith instead of separate v8_libplatform.
"USE_SYSTEM_V8=1"
"SHLIB_LINK=-lv8"
"V8_OUTDIR=${v8}/lib"
"PG_CONFIG=${postgresql}/bin/pg_config"
] ++ lib.optionals stdenv.isDarwin [
"CC=${clang}/bin/clang"
"CXX=${clang}/bin/clang++"
"SHLIB_LINK=-L${v8}/lib -lv8_monolith -Wl,-rpath,${v8}/lib"
] ++ lib.optionals (!stdenv.isDarwin) [
"SHLIB_LINK=-L${v8}/lib -lv8_monolith -Wl,-rpath,${v8}/lib"
];
NIX_LDFLAGS = lib.optionalString (stdenv.isDarwin && stdenv.isAarch64)
"-undefined dynamic_lookup";

NIX_CFLAGS_COMPILE = lib.optionals (stdenv.isDarwin && stdenv.isAarch64) [
NIX_LDFLAGS = (lib.optionals stdenv.isDarwin [
"-L${postgresql}/lib"
"-L${v8}/lib"
"-lv8_monolith"
"-lpq"
"-lpgcommon"
"-lpgport"
"-F${darwin.apple_sdk.frameworks.CoreFoundation}/Library/Frameworks"
"-framework" "CoreFoundation"
"-F${darwin.apple_sdk.frameworks.Kerberos}/Library/Frameworks"
"-framework" "Kerberos"
"-undefined" "dynamic_lookup"
"-flat_namespace"
]) ++ (lib.optionals (!stdenv.isDarwin) [
"-L${postgresql}/lib"
"-L${v8}/lib"
"-lv8_monolith"
"-lpq"
"-lpgcommon"
"-lpgport"
]);

NIX_CFLAGS_COMPILE = [
"-I${v8}/include"
"-I${postgresql}/include"
"-I${postgresql}/include/server"
"-I${postgresql}/include/internal"
];

installFlags = [
# PGXS only supports installing to postgresql prefix so we need to redirect this
"DESTDIR=${placeholder "out"}"
];

# No configure script.
dontConfigure = true;

postPatch = ''
patchShebangs ./generate_upgrade.sh
# https://github.com/plv8/plv8/pull/506
substituteInPlace generate_upgrade.sh \
--replace " 2.3.10 " " 2.3.10 2.3.11 2.3.12 2.3.13 2.3.14 2.3.15 "

${lib.optionalString stdenv.isDarwin ''
# Replace g++ with clang++ in Makefile
sed -i 's/g++/clang++/g' Makefile
''}
'';

preBuild = lib.optionalString stdenv.isDarwin ''
export CC=${clang}/bin/clang
export CXX=${clang}/bin/clang++
'';

postInstall = ''
# Move the redirected to proper directory.
# There appear to be no references to the install directories
# so changing them does not cause issues.
mv "$out/nix/store"/*/* "$out"
rmdir "$out/nix/store"/* "$out/nix/store" "$out/nix"

${lib.optionalString stdenv.isDarwin ''
install_name_tool -add_rpath "${v8}/lib" $out/lib/plv8-${finalAttrs.version}.so
install_name_tool -add_rpath "${postgresql}/lib" $out/lib/plv8-${finalAttrs.version}.so
install_name_tool -add_rpath "${stdenv.cc.cc.lib}/lib" $out/lib/plv8-${finalAttrs.version}.so
install_name_tool -change @rpath/libv8_monolith.dylib ${v8}/lib/libv8_monolith.dylib $out/lib/plv8-${finalAttrs.version}.so
''}

${lib.optionalString (!stdenv.isDarwin) ''
${patchelf}/bin/patchelf --set-rpath "${v8}/lib:${postgresql}/lib:${stdenv.cc.cc.lib}/lib" $out/lib/plv8-${finalAttrs.version}.so
''}
'';

passthru = {
Expand Down
Loading
Loading