Skip to content

Commit

Permalink
vapoursynth: Simplify plugin loading (#332800)
Browse files Browse the repository at this point in the history
  • Loading branch information
rnhmjoj authored Oct 24, 2024
2 parents 1dd9d10 + 1a66c5b commit a1071d0
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 53 deletions.
28 changes: 0 additions & 28 deletions pkgs/by-name/va/vapoursynth/nix-plugin-loader.patch

This file was deleted.

25 changes: 21 additions & 4 deletions pkgs/by-name/va/vapoursynth/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
runCommandCC,
runCommand,
vapoursynth,
writeText,
buildEnv,
zimg,
libass,
Expand All @@ -29,8 +28,6 @@ stdenv.mkDerivation rec {
hash = "sha256-T2bCVNH0dLM9lFYChXzvD6AJM3xEtOVCb2tI10tIXJs=";
};

patches = [ ./nix-plugin-loader.patch ];

nativeBuildInputs = [
pkg-config
autoreconfHook
Expand All @@ -53,6 +50,7 @@ stdenv.mkDerivation rec {
];

enableParallelBuilding = true;
doInstallCheck = true;

passthru = rec {
# If vapoursynth is added to the build inputs of mpv and then
Expand All @@ -66,7 +64,6 @@ stdenv.mkDerivation rec {
lib
python3
buildEnv
writeText
runCommandCC
stdenv
runCommand
Expand All @@ -83,6 +80,14 @@ stdenv.mkDerivation rec {
};
};

postPatch = ''
# Export weak symbol nixPluginDir to permit override of default plugin path
sed -E -i \
-e 's/(VS_PATH_PLUGINDIR)/(nixPluginDir ? nixPluginDir : \1)/g' \
-e '1i\extern char const __attribute__((weak)) nixPluginDir[];' \
src/core/vscore.cpp
'';

postInstall = ''
wrapProgram $out/bin/vspipe \
--prefix PYTHONPATH : $out/${python3.sitePackages}
Expand All @@ -92,6 +97,18 @@ stdenv.mkDerivation rec {
mkdir $out/lib/vapoursynth
'';

installCheckPhase = ''
runHook preInstallCheck
libv="$out/lib/libvapoursynth${stdenv.hostPlatform.extensions.sharedLibrary}"
if ! $NM -g -P "$libv" | grep -q '^nixPluginDir w'; then
echo "Weak symbol nixPluginDir is missing from $libv." >&2
exit 1
fi
runHook postInstallCheck
'';

meta = with lib; {
broken = stdenv.hostPlatform.isDarwin; # see https://github.com/NixOS/nixpkgs/pull/189446 for partial fix
description = "Video processing framework with the future in mind";
Expand Down
29 changes: 8 additions & 21 deletions pkgs/by-name/va/vapoursynth/plugin-interface.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
lib,
python3,
buildEnv,
writeText,
runCommandCC,
stdenv,
runCommand,
Expand Down Expand Up @@ -35,29 +34,19 @@ let
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"
# Override default plugin path through nixPluginDir symbol
nixPlugins =
runCommandCC "libvapoursynth-nix-plugins${ext}"
{
executable = true;
preferLocalBuild = true;
allowSubstitutes = false;
src = ''
char const nixPluginDir[] = "${pluginsEnv}/lib/vapoursynth";
'';
}
''
mkdir -p $out/lib
$CXX -std=c++17 -shared -fPIC ${source} -o "$out/lib/libvapoursynth-nix-plugins${ext}"
$CC -x c -shared -fPIC - -o "$out" <<<"$src"
'';

ext = stdenv.hostPlatform.extensions.sharedLibrary;
Expand Down Expand Up @@ -123,9 +112,7 @@ runCommand "${vapoursynth.name}-with-plugins"
${vapoursynth}/$binaryFile
done
ln -s \
${pluginLoader}/lib/libvapoursynth-nix-plugins${ext} \
$out/lib/libvapoursynth-nix-plugins${ext}
ln -s ${nixPlugins} $out/lib/libvapoursynth-nix-plugins${ext}
ln -s ${vapoursynth}/include $out/include
ln -s ${vapoursynth}/lib/vapoursynth/* $out/lib/vapoursynth
ln -s \
Expand Down

0 comments on commit a1071d0

Please sign in to comment.