about summary refs log tree commit diff
path: root/nixpkgs/pkgs/development/libraries/vapoursynth/plugin-interface.nix
diff options
context:
space:
mode:
authorAlyssa Ross <hi@alyssa.is>2021-04-09 18:28:16 +0000
committerAlyssa Ross <hi@alyssa.is>2021-04-12 18:46:15 +0000
commitfd2e737e0678ee7d8081baef05b305146a2c0034 (patch)
treeac3e9b27576a0382335532d126f9a66d486bc638 /nixpkgs/pkgs/development/libraries/vapoursynth/plugin-interface.nix
parentcc207d720b6aa836e256c1ee9842bc739e630a8a (diff)
parent9e377a6ce42dccd9b624ae4ce8f978dc892ba0e2 (diff)
downloadnixlib-fd2e737e0678ee7d8081baef05b305146a2c0034.tar
nixlib-fd2e737e0678ee7d8081baef05b305146a2c0034.tar.gz
nixlib-fd2e737e0678ee7d8081baef05b305146a2c0034.tar.bz2
nixlib-fd2e737e0678ee7d8081baef05b305146a2c0034.tar.lz
nixlib-fd2e737e0678ee7d8081baef05b305146a2c0034.tar.xz
nixlib-fd2e737e0678ee7d8081baef05b305146a2c0034.tar.zst
nixlib-fd2e737e0678ee7d8081baef05b305146a2c0034.zip
Merge remote-tracking branch 'nixpkgs/nixos-unstable'
Diffstat (limited to 'nixpkgs/pkgs/development/libraries/vapoursynth/plugin-interface.nix')
-rw-r--r--nixpkgs/pkgs/development/libraries/vapoursynth/plugin-interface.nix112
1 files changed, 112 insertions, 0 deletions
diff --git a/nixpkgs/pkgs/development/libraries/vapoursynth/plugin-interface.nix b/nixpkgs/pkgs/development/libraries/vapoursynth/plugin-interface.nix
new file mode 100644
index 000000000000..55b2b03c893e
--- /dev/null
+++ b/nixpkgs/pkgs/development/libraries/vapoursynth/plugin-interface.nix
@@ -0,0 +1,112 @@
+{ lib, python3, buildEnv, writeText, runCommandCC, stdenv, runCommand
+, vapoursynth, makeWrapper, withPlugins }:
+
+plugins: let
+  pythonEnvironment = python3.buildEnv.override {
+    extraLibs = plugins;
+  };
+
+  getRecursivePropagatedBuildInputs = pkgs: lib.flatten
+    (map
+      (pkg: pkg.propagatedBuildInputs ++ (getRecursivePropagatedBuildInputs pkg.propagatedBuildInputs))
+      pkgs);
+
+  deepPlugins = plugins ++ (getRecursivePropagatedBuildInputs plugins);
+
+  pluginsEnv = buildEnv {
+    name = "vapoursynth-plugins-env";
+    pathsToLink = [ "/lib/vapoursynth" ];
+    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}
+      }
+    '';
+  in
+  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}"
+  '';
+
+  ext = stdenv.targetPlatform.extensions.sharedLibrary;
+in
+runCommand "${vapoursynth.name}-with-plugins" {
+  nativeBuildInputs = [ makeWrapper ];
+  passthru = {
+    inherit python3;
+    withPlugins = plugins': withPlugins (plugins ++ plugins');
+  };
+} ''
+  mkdir -p \
+    $out/bin \
+    $out/lib/pkgconfig \
+    $out/lib/vapoursynth \
+    $out/${python3.sitePackages}
+
+  for textFile in \
+      lib/pkgconfig/vapoursynth{,-script}.pc \
+      lib/libvapoursynth.la \
+      lib/libvapoursynth-script.la \
+      ${python3.sitePackages}/vapoursynth.la
+  do
+      substitute ${vapoursynth}/$textFile $out/$textFile \
+          --replace "${vapoursynth}" "$out"
+  done
+
+  for binaryPlugin in ${pluginsEnv}/lib/vapoursynth/*; do
+      ln -s $binaryPlugin $out/''${binaryPlugin#"${pluginsEnv}/"}
+  done
+
+  for pythonPlugin in ${pythonEnvironment}/${python3.sitePackages}/*; do
+      ln -s $pythonPlugin $out/''${pythonPlugin#"${pythonEnvironment}/"}
+  done
+
+  for binaryFile in \
+      lib/libvapoursynth${ext} \
+      lib/libvapoursynth-script${ext}.0.0.0
+  do
+    old_rpath=$(patchelf --print-rpath ${vapoursynth}/$binaryFile)
+    new_rpath="$old_rpath:$out/lib"
+    patchelf \
+        --set-rpath "$new_rpath" \
+        --output $out/$binaryFile \
+        ${vapoursynth}/$binaryFile
+    patchelf \
+        --add-needed libvapoursynth-nix-plugins${ext} \
+        $out/$binaryFile
+  done
+
+  for binaryFile in \
+      ${python3.sitePackages}/vapoursynth${ext} \
+      bin/.vspipe-wrapped
+  do
+      old_rpath=$(patchelf --print-rpath ${vapoursynth}/$binaryFile)
+      new_rpath="''${old_rpath//"${vapoursynth}"/"$out"}"
+      patchelf \
+          --set-rpath "$new_rpath" \
+          --output $out/$binaryFile \
+          ${vapoursynth}/$binaryFile
+  done
+
+  ln -s \
+      ${pluginLoader}/lib/libvapoursynth-nix-plugins${ext} \
+      $out/lib/libvapoursynth-nix-plugins${ext}
+  ln -s ${vapoursynth}/include $out/include
+  ln -s ${vapoursynth}/lib/vapoursynth/* $out/lib/vapoursynth
+  ln -s \
+      libvapoursynth-script${ext}.0.0.0 \
+      $out/lib/libvapoursynth-script${ext}
+  ln -s \
+      libvapoursynth-script${ext}.0.0.0 \
+      $out/lib/libvapoursynth-script${ext}.0
+
+  makeWrapper $out/bin/.vspipe-wrapped $out/bin/vspipe \
+      --prefix PYTHONPATH : $out/${python3.sitePackages}
+''