Unverified Commit e16e4d74 authored by Michele Guerini Rocco's avatar Michele Guerini Rocco Committed by GitHub
Browse files

Merge pull request #332199 from illdefined/vapoursynth-new

vapoursynth: 65 → 69
parents 75ceabad 59545101
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -19137,6 +19137,13 @@
    githubId = 602439;
    name = "Serguei Narojnyi";
  };
  snaki = {
    email = "ek@kyouma.net";
    matrix = "@snaki:kescher.at";
    name = "emily";
    github = "snaakey";
    githubId = 38018554;
  };
  snapdgn = {
    email = "snapdgn@proton.me";
    name = "Nitish Kumar";
+80 −0
Original line number Diff line number Diff line
{ lib, mkDerivation, fetchFromGitHub, makeWrapper, runCommand
, python3, vapoursynth
, qmake, qtbase, qtwebsockets
{
  lib,
  mkDerivation,
  fetchFromGitHub,
  makeWrapper,
  runCommand,
  python3,
  vapoursynth,
  qmake,
  qtbase,
  qtwebsockets,
}:

let
@@ -16,7 +24,11 @@ let
    };

    nativeBuildInputs = [ qmake ];
    buildInputs = [ qtbase vapoursynth qtwebsockets ];
    buildInputs = [
      qtbase
      vapoursynth
      qtwebsockets
    ];

    dontWrapQtApps = true;

@@ -31,7 +43,9 @@ let
      done
    '';

    passthru = { inherit withPlugins; };
    passthru = {
      inherit withPlugins;
    };

    meta = with lib; {
      description = "Cross-platform editor for VapourSynth scripts";
@@ -42,12 +56,19 @@ let
    };
  };

  withPlugins = plugins: let
  withPlugins =
    plugins:
    let
      vapoursynthWithPlugins = vapoursynth.withPlugins plugins;
  in runCommand "${unwrapped.name}-with-plugins" {
    in
    runCommand "${unwrapped.name}-with-plugins"
      {
        nativeBuildInputs = [ makeWrapper ];
    passthru = { withPlugins = plugins': withPlugins (plugins ++ plugins'); };
  } ''
        passthru = {
          withPlugins = plugins': withPlugins (plugins ++ plugins');
        };
      }
      ''
        mkdir -p $out/bin
        for bin in vsedit{,-job-server{,-watcher}}; do
            makeWrapper ${unwrapped}/bin/$bin $out/bin/$bin \
+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) {
+64 −23
Original line number Diff line number Diff line
{ lib, stdenv, fetchFromGitHub, pkg-config, autoreconfHook, makeWrapper
, runCommandCC, runCommand, vapoursynth, writeText, buildEnv
, zimg, libass, python3, libiconv, testers
, ApplicationServices
{
  lib,
  stdenv,
  fetchFromGitHub,
  pkg-config,
  autoreconfHook,
  makeWrapper,
  runCommandCC,
  runCommand,
  vapoursynth,
  writeText,
  buildEnv,
  zimg,
  libass,
  python3,
  libiconv,
  testers,
  ApplicationServices,
}:

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
  ];
  patches = [ ./nix-plugin-loader.patch ];

  nativeBuildInputs = [ pkg-config autoreconfHook makeWrapper ];
  buildInputs = [
    zimg libass
    (python3.withPackages (ps: with ps; [ sphinx cython ]))
  ] ++ lib.optionals stdenv.isDarwin [ libiconv ApplicationServices ];
  nativeBuildInputs = [
    pkg-config
    autoreconfHook
    makeWrapper
  ];
  buildInputs =
    [
      zimg
      libass
      (python3.withPackages (
        ps: with ps; [
          sphinx
          cython
        ]
      ))
    ]
    ++ lib.optionals stdenv.isDarwin [
      libiconv
      ApplicationServices
    ];

  enableParallelBuilding = true;

@@ -35,8 +62,18 @@ stdenv.mkDerivation rec {
    inherit python3;

    withPlugins = import ./plugin-interface.nix {
      inherit lib python3 buildEnv writeText runCommandCC stdenv runCommand
        vapoursynth makeWrapper withPlugins;
      inherit
        lib
        python3
        buildEnv
        writeText
        runCommandCC
        stdenv
        runCommand
        vapoursynth
        makeWrapper
        withPlugins
        ;
    };

    tests.version = testers.testVersion {
@@ -61,7 +98,11 @@ stdenv.mkDerivation rec {
    homepage = "http://www.vapoursynth.com/";
    license = licenses.lgpl21;
    platforms = platforms.x86_64;
    maintainers = with maintainers; [ rnhmjoj sbruder ];
    maintainers = with maintainers; [
      rnhmjoj
      sbruder
      snaki
    ];
    mainProgram = "vspipe";
  };
}
+140 −0
Original line number Diff line number Diff line
{
  lib,
  python3,
  buildEnv,
  writeText,
  runCommandCC,
  stdenv,
  runCommand,
  vapoursynth,
  makeWrapper,
  withPlugins,
}:

plugins:
let
  pythonEnvironment = python3.buildEnv.override { extraLibs = plugins; };

  getRecursivePropagatedBuildInputs =
    pkgs:
    lib.flatten (
      map (
        pkg:
        let
          cleanPropagatedBuildInputs = lib.filter lib.isDerivation pkg.propagatedBuildInputs;
        in
        cleanPropagatedBuildInputs ++ (getRecursivePropagatedBuildInputs cleanPropagatedBuildInputs)
      ) pkgs
    );

  deepPlugins = lib.unique (plugins ++ (getRecursivePropagatedBuildInputs plugins));

  pluginsEnv = buildEnv {
    name = "vapoursynth-plugins-env";
    pathsToLink = [ "/lib/vapoursynth" ];
    paths = 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"
      {
        executable = true;
        preferLocalBuild = true;
        allowSubstitutes = false;
      }
      ''
        mkdir -p $out/lib
        $CXX -std=c++17 -shared -fPIC ${source} -o "$out/lib/libvapoursynth-nix-plugins${ext}"
      '';

  ext = stdenv.hostPlatform.extensions.sharedLibrary;
in
runCommand "${vapoursynth.name}-with-plugins"
  {
    nativeBuildInputs = [ makeWrapper ];
    passthru = {
      inherit python3;
      inherit (vapoursynth) src version;
      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}
  ''
Loading