vapoursynth: Simplify plugin loading (#332800)

This commit is contained in:
Michele Guerini Rocco 2024-10-24 10:39:26 +02:00 committed by GitHub
commit a1071d0055
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 29 additions and 53 deletions

View File

@ -1,28 +0,0 @@
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) {

View File

@ -8,7 +8,6 @@
runCommandCC,
runCommand,
vapoursynth,
writeText,
buildEnv,
zimg,
libass,
@ -29,8 +28,6 @@ stdenv.mkDerivation rec {
hash = "sha256-T2bCVNH0dLM9lFYChXzvD6AJM3xEtOVCb2tI10tIXJs=";
};
patches = [ ./nix-plugin-loader.patch ];
nativeBuildInputs = [
pkg-config
autoreconfHook
@ -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
@ -66,7 +64,6 @@ stdenv.mkDerivation rec {
lib
python3
buildEnv
writeText
runCommandCC
stdenv
runCommand
@ -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}
@ -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";

View File

@ -2,7 +2,6 @@
lib,
python3,
buildEnv,
writeText,
runCommandCC,
stdenv,
runCommand,
@ -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;
@ -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 \