Commit 3d87b65e authored by Mikael Voss's avatar Mikael Voss
Browse files

vapoursynth: 65 -> 69

parent 1201f432
Loading
Loading
Loading
Loading
+0 −74
Original line number Diff line number Diff line
From 439e2effe1cc372925daf6d5c28569663ffb93ed Mon Sep 17 00:00:00 2001
From: Tadeo Kondrak <me@tadeo.ca>
Date: Mon, 25 Jan 2021 11:17:44 -0700
Subject: [PATCH] Call weak function to allow adding preloaded plugins after
 compile

---
 src/core/vscore.cpp | 19 +++++++++++++++++++
 src/core/vscore.h   |  5 +++++
 2 files changed, 24 insertions(+)

diff --git a/src/core/vscore.cpp b/src/core/vscore.cpp
index f8e69062..4ce4c623 100644
--- a/src/core/vscore.cpp
+++ b/src/core/vscore.cpp
@@ -1791,6 +1791,20 @@ void VSCore::destroyFilterInstance(VSNode *node) {
     freeDepth--;
 }
 
+extern "C" {
+void __attribute__((weak)) VSLoadPluginsNix(void (*load)(void *data, const char *path), void *data);
+
+struct VSLoadPluginsNixCallbackData {
+    VSCore *core;
+    const char *filter;
+};
+
+static void VSLoadPluginsNixCallback(void *data, const char *path) {
+    auto callbackData = static_cast<VSLoadPluginsNixCallbackData *>(data);
+    callbackData->core->loadAllPluginsInPath(path, callbackData->filter);
+}
+}
+
 VSCore::VSCore(int flags) :
     numFilterInstances(1),
     numFunctionInstances(0),
@@ -1918,6 +1932,11 @@ VSCore::VSCore(int flags) :
     } // If neither exists, an empty string will do.
 #endif
 
+    if (VSLoadPluginsNix != nullptr) {
+        VSLoadPluginsNixCallbackData data{this, filter.c_str()};
+        VSLoadPluginsNix(VSLoadPluginsNixCallback, &data);
+    }
+
     VSMap *settings = readSettings(configFile);
     const char *error = vs_internal_vsapi.mapGetError(settings);
     if (error) {
diff --git a/src/core/vscore.h b/src/core/vscore.h
index 2ce0f56b..2982b133 100644
--- a/src/core/vscore.h
+++ b/src/core/vscore.h
@@ -985,6 +985,9 @@ public:
     std::string getV3ArgString() const;
 };
 
+extern "C" {
+static void VSLoadPluginsNixCallback(void *data, const char *path);
+}
 
 struct VSPlugin {
     friend struct VSPluginFunction;
@@ -1140,6 +1143,8 @@ public:
 
     explicit VSCore(int flags);
     void freeCore();
+
+    friend void VSLoadPluginsNixCallback(void *data, const char *path);
 };
 
 #endif // VSCORE_H
-- 
2.32.0
+3 −3
Original line number Diff line number Diff line
@@ -6,17 +6,17 @@

stdenv.mkDerivation rec {
  pname = "vapoursynth";
  version = "65";
  version = "69";

  src = fetchFromGitHub {
    owner  = "vapoursynth";
    repo   = "vapoursynth";
    rev    = "R${version}";
    sha256 = "sha256-HrTXhRoKSFeLXYQM7W2FvYf7yCD1diSZGtPop9urrSk=";
    hash   = "sha256-T2bCVNH0dLM9lFYChXzvD6AJM3xEtOVCb2tI10tIXJs=";
  };

  patches = [
    ./0001-Call-weak-function-to-allow-adding-preloaded-plugins.patch
    ./nix-plugin-loader.patch
  ];

  nativeBuildInputs = [ pkg-config autoreconfHook makeWrapper ];
+28 −0
Original line number Diff line number Diff line
diff --git a/src/core/vscore.cpp b/src/core/vscore.cpp
index 73e2eafc..66a01326 100644
--- a/src/core/vscore.cpp
+++ b/src/core/vscore.cpp
@@ -1779,6 +1779,12 @@ void VSCore::isPortableInit() {
 }
 #endif
 
+void __attribute__((weak)) VSLoadPluginsNix(void (*load)(VSCore *core, const std::filesystem::path &), VSCore *);
+
+static void VSLoadPluginsNixCallback(VSCore *core, const std::filesystem::path &path) {
+    core->loadAllPluginsInPath(path);
+}
+
 VSCore::VSCore(int flags) :
     numFilterInstances(1),
     numFunctionInstances(0),
@@ -1890,6 +1896,10 @@ VSCore::VSCore(int flags) :
 #endif
     }
 
+    if (VSLoadPluginsNix != nullptr) {
+        VSLoadPluginsNix(VSLoadPluginsNixCallback, this);
+    };
+
     VSMap *settings = readSettings(configFile);
     const char *error = vs_internal_vsapi.mapGetError(settings);
     if (error) {
+23 −14
Original line number Diff line number Diff line
@@ -20,20 +20,29 @@ plugins: let
    paths = deepPlugins;
  };

  pluginLoader = let
    source = writeText "vapoursynth-nix-plugins.c" ''
      void VSLoadPluginsNix(void (*load)(void *data, const char *path), void *data) {
      ${lib.concatMapStringsSep "" (path: "load(data, \"${path}/lib/vapoursynth\");") deepPlugins}
  pluginLoader =
    let
      source = writeText "vapoursynth-nix-plugins.cpp" ''
        #include <filesystem>

        struct VSCore;

        void VSLoadPluginsNix(void (*load)(VSCore *, const std::filesystem::path &), VSCore *core) {
        ${lib.concatMapStrings (
          path: ''load(core, std::filesystem::u8path("${path}/lib/vapoursynth"));''
        ) deepPlugins}
        }
      '';
    in
  runCommandCC "vapoursynth-plugin-loader" {
    runCommandCC "vapoursynth-plugin-loader"
      {
        executable = true;
        preferLocalBuild = true;
        allowSubstitutes = false;
  } ''
      }
      ''
        mkdir -p $out/lib
    $CC -shared -fPIC ${source} -o "$out/lib/libvapoursynth-nix-plugins${ext}"
        $CXX -std=c++17 -shared -fPIC ${source} -o "$out/lib/libvapoursynth-nix-plugins${ext}"
      '';

  ext = stdenv.hostPlatform.extensions.sharedLibrary;