From 9242ebadc9cdcd916a29fc44d121cb8a945f1501 Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Fri, 20 Sep 2024 20:56:37 +0000 Subject: [PATCH 1/3] feat: wip plv8 update on aarch64-linux --- ...001-build-Allow-using-V8-from-system.patch | 56 +++++---- nix/ext/plv8.nix | 108 ++++-------------- 2 files changed, 50 insertions(+), 114 deletions(-) diff --git a/nix/ext/0001-build-Allow-using-V8-from-system.patch b/nix/ext/0001-build-Allow-using-V8-from-system.patch index eb5e2964f..41917b28c 100644 --- a/nix/ext/0001-build-Allow-using-V8-from-system.patch +++ b/nix/ext/0001-build-Allow-using-V8-from-system.patch @@ -1,46 +1,44 @@ diff --git a/Makefile b/Makefile -index 38879cc..6e78eeb 100644 +index a705c11..08b952b 100644 --- a/Makefile +++ b/Makefile -@@ -20,6 +20,7 @@ OBJS = $(SRCS:.cc=.o) +@@ -13,11 +13,14 @@ OBJS = $(SRCS:.cc=.o) MODULE_big = plv8-$(PLV8_VERSION) EXTENSION = plv8 - PLV8_DATA = plv8.control plv8--$(PLV8_VERSION).sql $(wildcard upgrade/*.sql) + PLV8_DATA = plv8.control plv8--$(PLV8_VERSION).sql +USE_SYSTEM_V8 = 0 - - # Platform detection -@@ -41,6 +42,7 @@ PGXS := $(shell $(PG_CONFIG) --pgxs) - PG_VERSION_NUM := $(shell cat `$(PG_CONFIG) --includedir-server`/pg_config*.h \ - | perl -ne 'print $$1 and exit if /PG_VERSION_NUM\s+(\d+)/') + ifeq ($(OS),Windows_NT) + # noop for now + else ++ ifeq ($(USE_SYSTEM_V8),0) + SHLIB_LINK += -Ldeps/v8-cmake/build ++ endif + UNAME_S := $(shell uname -s) + ifeq ($(UNAME_S),Darwin) + CCFLAGS += -stdlib=libc++ +@@ -34,6 +37,7 @@ ifeq ($(NUMPROC),0) + NUMPROC = 1 + endif +ifeq ($(USE_SYSTEM_V8),0) - AUTOV8_DIR = build/v8 - AUTOV8_OUT = build/v8/out.gn/obj - AUTOV8_STATIC_LIBS = -lv8_libplatform -lv8_libbase -@@ -66,6 +68,7 @@ v8: - make -f Makefiles/Makefile.macos v8 - endif - endif + SHLIB_LINK += -Ldeps/v8-cmake/build + + all: v8 $(OBJS) +@@ -46,11 +50,16 @@ deps/v8-cmake/build/libv8_libbase.a: + @cd deps/v8-cmake && mkdir -p build && cd build && cmake -Denable-fPIC=ON -DCMAKE_BUILD_TYPE=Release ../ && make -j $(NUMPROC) + + v8: deps/v8-cmake/build/libv8_libbase.a ++else ++all: $(OBJS) +endif # enable direct jsonb conversion by default CCFLAGS += -DJSONB_DIRECT_CONVERSION -@@ -83,6 +86,7 @@ ifdef BIGINT_GRACEFUL - endif - +ifeq ($(USE_SYSTEM_V8),0) - # We're gonna build static link. Rip it out after include Makefile - SHLIB_LINK := $(filter-out -lv8, $(SHLIB_LINK)) - -@@ -101,6 +105,7 @@ else - SHLIB_LINK += -lrt -std=c++14 - endif - endif + CCFLAGS += -Ideps/v8-cmake/v8/include -std=c++17 +endif - DATA = $(PLV8_DATA) - ifndef DISABLE_DIALECT --- -2.37.3 + ifdef EXECUTION_TIMEOUT + CCFLAGS += -DEXECUTION_TIMEOUT \ No newline at end of file diff --git a/nix/ext/plv8.nix b/nix/ext/plv8.nix index ef476f0ab..c3c9465ec 100644 --- a/nix/ext/plv8.nix +++ b/nix/ext/plv8.nix @@ -1,130 +1,70 @@ { stdenv , lib , fetchFromGitHub -, v8 +, nodejs_20 , perl , postgresql - # For test +# For test , runCommand , coreutils , gnugrep -, clang -, patchelf -, xcbuild -, darwin }: -stdenv.mkDerivation (finalAttrs: { +let + libv8 = nodejs_20.libv8; +in stdenv.mkDerivation (finalAttrs: { pname = "plv8"; - version = "3.1.5"; + version = "3.2.2"; src = fetchFromGitHub { owner = "plv8"; repo = "plv8"; rev = "v${finalAttrs.version}"; - hash = "sha256-LodC2eQJSm5fLckrjm2RuejZhmOyQMJTv9b0iPCnzKQ="; + hash = "sha256-azO33v22EF+/sTNmwswxyDR0PhrvWfTENuLu6JgSGJ0="; }; 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 [ - clang - xcbuild ]; buildInputs = [ - (v8.overrideAttrs (oldAttrs: { - version = "9.7.106.18"; - })) + libv8 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" - "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.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" + "SHLIB_LINK=-lv8" + "V8_OUTDIR=${libv8}/lib" ]; 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 - 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 = { @@ -133,9 +73,8 @@ stdenv.mkDerivation (finalAttrs: { postgresqlWithSelf = postgresql.withPackages (_: [ finalAttrs.finalPackage ]); - in - { - smoke = runCommand "plv8-smoke-test" { } '' + in { + smoke = runCommand "plv8-smoke-test" {} '' export PATH=${lib.makeBinPath [ postgresqlWithSelf coreutils @@ -195,9 +134,8 @@ stdenv.mkDerivation (finalAttrs: { meta = with lib; { description = "V8 Engine Javascript Procedural Language add-on for PostgreSQL"; homepage = "https://plv8.github.io/"; - maintainers = with maintainers; [ samrose ]; - platforms = [ "x86_64-linux" "aarch64-linux" "aarch64-darwin" ]; + maintainers = with maintainers; [ ]; + platforms = [ "x86_64-linux" "aarch64-linux" ]; license = licenses.postgresql; - #broken = postgresql.jitSupport; }; -}) +}) \ No newline at end of file From 61c6b2037804f2501a72780c6ce5543638951eff Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Fri, 20 Sep 2024 21:41:42 +0000 Subject: [PATCH 2/3] feat: bring back to 3.1.10 to both support pg 16 and retain plcoffee/plls --- ...001-build-Allow-using-V8-from-system.patch | 54 ++++++++++--------- nix/ext/plv8.nix | 16 +++--- 2 files changed, 36 insertions(+), 34 deletions(-) diff --git a/nix/ext/0001-build-Allow-using-V8-from-system.patch b/nix/ext/0001-build-Allow-using-V8-from-system.patch index 41917b28c..ab2c6f06c 100644 --- a/nix/ext/0001-build-Allow-using-V8-from-system.patch +++ b/nix/ext/0001-build-Allow-using-V8-from-system.patch @@ -1,44 +1,46 @@ diff --git a/Makefile b/Makefile -index a705c11..08b952b 100644 +index 38879cc..6e78eeb 100644 --- a/Makefile +++ b/Makefile -@@ -13,11 +13,14 @@ OBJS = $(SRCS:.cc=.o) +@@ -20,6 +20,7 @@ OBJS = $(SRCS:.cc=.o) MODULE_big = plv8-$(PLV8_VERSION) EXTENSION = plv8 PLV8_DATA = plv8.control plv8--$(PLV8_VERSION).sql +USE_SYSTEM_V8 = 0 - ifeq ($(OS),Windows_NT) - # noop for now - else -+ ifeq ($(USE_SYSTEM_V8),0) - SHLIB_LINK += -Ldeps/v8-cmake/build -+ endif - UNAME_S := $(shell uname -s) - ifeq ($(UNAME_S),Darwin) - CCFLAGS += -stdlib=libc++ -@@ -34,6 +37,7 @@ ifeq ($(NUMPROC),0) - NUMPROC = 1 - endif - -+ifeq ($(USE_SYSTEM_V8),0) - SHLIB_LINK += -Ldeps/v8-cmake/build - all: v8 $(OBJS) -@@ -46,11 +50,16 @@ deps/v8-cmake/build/libv8_libbase.a: - @cd deps/v8-cmake && mkdir -p build && cd build && cmake -Denable-fPIC=ON -DCMAKE_BUILD_TYPE=Release ../ && make -j $(NUMPROC) + # Platform detection +@@ -41,6 +42,7 @@ PGXS := $(shell $(PG_CONFIG) --pgxs) + PG_VERSION_NUM := $(shell cat `$(PG_CONFIG) --includedir-server`/pg_config*.h \ + | perl -ne 'print $$1 and exit if /PG_VERSION_NUM\s+(\d+)/') - v8: deps/v8-cmake/build/libv8_libbase.a -+else -+all: $(OBJS) ++ifeq ($(USE_SYSTEM_V8),0) + AUTOV8_DIR = build/v8 + AUTOV8_OUT = build/v8/out.gn/obj + AUTOV8_STATIC_LIBS = -lv8_libplatform -lv8_libbase +@@ -66,6 +68,7 @@ v8: + make -f Makefiles/Makefile.macos v8 + endif + endif +endif # enable direct jsonb conversion by default CCFLAGS += -DJSONB_DIRECT_CONVERSION +@@ -83,6 +86,7 @@ ifdef BIGINT_GRACEFUL + endif + +ifeq ($(USE_SYSTEM_V8),0) - CCFLAGS += -Ideps/v8-cmake/v8/include -std=c++17 + # We're gonna build static link. Rip it out after include Makefile + SHLIB_LINK := $(filter-out -lv8, $(SHLIB_LINK)) + +@@ -101,6 +105,7 @@ else + SHLIB_LINK += -lrt -std=c++14 + endif + endif +endif - ifdef EXECUTION_TIMEOUT - CCFLAGS += -DEXECUTION_TIMEOUT \ No newline at end of file + DATA = $(PLV8_DATA) + ifndef DISABLE_DIALECT +-- +2.37.3 diff --git a/nix/ext/plv8.nix b/nix/ext/plv8.nix index c3c9465ec..bf6fd96da 100644 --- a/nix/ext/plv8.nix +++ b/nix/ext/plv8.nix @@ -1,7 +1,7 @@ { stdenv , lib , fetchFromGitHub -, nodejs_20 +, v8 , perl , postgresql # For test @@ -10,17 +10,15 @@ , gnugrep }: -let - libv8 = nodejs_20.libv8; -in stdenv.mkDerivation (finalAttrs: { +stdenv.mkDerivation (finalAttrs: { pname = "plv8"; - version = "3.2.2"; + version = "3.1.10"; src = fetchFromGitHub { owner = "plv8"; repo = "plv8"; rev = "v${finalAttrs.version}"; - hash = "sha256-azO33v22EF+/sTNmwswxyDR0PhrvWfTENuLu6JgSGJ0="; + hash = "sha256-g1A/XPC0dX2360Gzvmo9/FSQnM6Wt2K4eR0pH0p9fz4="; }; patches = [ @@ -34,7 +32,7 @@ in stdenv.mkDerivation (finalAttrs: { ]; buildInputs = [ - libv8 + v8 postgresql ]; @@ -44,7 +42,7 @@ in stdenv.mkDerivation (finalAttrs: { # Nixpkgs build a v8 monolith instead of separate v8_libplatform. "USE_SYSTEM_V8=1" "SHLIB_LINK=-lv8" - "V8_OUTDIR=${libv8}/lib" + "V8_OUTDIR=${v8}/lib" ]; installFlags = [ @@ -57,6 +55,8 @@ in stdenv.mkDerivation (finalAttrs: { postPatch = '' patchShebangs ./generate_upgrade.sh + 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 " ''; postInstall = '' From ab92c985d14947d8aa326821041fa7497242e06e Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Mon, 23 Sep 2024 10:14:31 -0400 Subject: [PATCH 3/3] feat: update to latest that retain plcoffee and plls and pg16 --- nix/ext/plv8.nix | 57 ++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 53 insertions(+), 4 deletions(-) diff --git a/nix/ext/plv8.nix b/nix/ext/plv8.nix index bf6fd96da..5cb4fb67e 100644 --- a/nix/ext/plv8.nix +++ b/nix/ext/plv8.nix @@ -4,10 +4,16 @@ , v8 , perl , postgresql -# For test +# For passthru test on various systems, and local development on macos +# not we are not currently using passthru tests but retaining for possible contrib +# to nixpkgs , runCommand , coreutils , gnugrep +, clang +, xcbuild +, darwin +, patchelf }: stdenv.mkDerivation (finalAttrs: { @@ -29,11 +35,17 @@ stdenv.mkDerivation (finalAttrs: { nativeBuildInputs = [ perl + ] ++ lib.optionals stdenv.isDarwin [ + clang + xcbuild ]; buildInputs = [ v8 postgresql + ] ++ lib.optionals stdenv.isDarwin [ + darwin.apple_sdk.frameworks.CoreFoundation + darwin.apple_sdk.frameworks.Kerberos ]; buildFlags = [ "all" ]; @@ -41,10 +53,31 @@ stdenv.mkDerivation (finalAttrs: { 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=-lv8" ]; + 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" + ]); + installFlags = [ # PGXS only supports installing to postgresql prefix so we need to redirect this "DESTDIR=${placeholder "out"}" @@ -57,6 +90,11 @@ stdenv.mkDerivation (finalAttrs: { patchShebangs ./generate_upgrade.sh 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 + ''} ''; postInstall = '' @@ -65,6 +103,17 @@ stdenv.mkDerivation (finalAttrs: { # 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 = { @@ -134,8 +183,8 @@ stdenv.mkDerivation (finalAttrs: { meta = with lib; { description = "V8 Engine Javascript Procedural Language add-on for PostgreSQL"; homepage = "https://plv8.github.io/"; - maintainers = with maintainers; [ ]; - platforms = [ "x86_64-linux" "aarch64-linux" ]; + maintainers = with maintainers; [ samrose ]; + platforms = [ "x86_64-linux" "aarch64-linux" "aarch64-darwin" ]; license = licenses.postgresql; }; }) \ No newline at end of file