Skip to content

Commit

Permalink
libavif: build gdk-pixbuf loader and thumbnailer
Browse files Browse the repository at this point in the history
AOMediaCodec/libavif#182
AOMediaCodec/libavif#977

Mostly mirrors webp-pixbuf-loader.

Also use prefixed names for `loaders.cache` so that users can install
multiple loaders in a profile without collisions, and move
`bin/webp-thumbnailer` to `libexec/gdk-pixbuf-thumbnailer-webp` (and
similarly for avif).
  • Loading branch information
mkg20001 authored and ncfavier committed Jul 25, 2023
1 parent 4b7ad2c commit a38770b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 8 deletions.
5 changes: 3 additions & 2 deletions pkgs/development/libraries/gdk-pixbuf/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,9 @@ stdenv.mkDerivation (finalAttrs: {
pkg-config = testers.testMetaPkgConfig finalAttrs.finalPackage;
};

# gdk_pixbuf_moduledir variable from gdk-pixbuf-2.0.pc
moduleDir = "lib/gdk-pixbuf-2.0/2.10.0/loaders";
# gdk_pixbuf_binarydir and gdk_pixbuf_moduledir variables from gdk-pixbuf-2.0.pc
binaryDir = "lib/gdk-pixbuf-2.0/2.10.0";
moduleDir = "${finalAttrs.passthru.binaryDir}/loaders";
};

meta = with lib; {
Expand Down
28 changes: 28 additions & 0 deletions pkgs/development/libraries/libavif/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,15 @@
, libjpeg
, dav1d
, libyuv
, gdk-pixbuf
, makeWrapper
}:

let
gdkPixbufModuleDir = "${placeholder "out"}/${gdk-pixbuf.moduleDir}";
gdkPixbufModuleFile = "${placeholder "out"}/${gdk-pixbuf.binaryDir}/avif-loaders.cache";
in

stdenv.mkDerivation rec {
pname = "libavif";
version = "0.11.1";
Expand All @@ -29,14 +36,18 @@ stdenv.mkDerivation rec {
"-DAVIF_CODEC_DAV1D=ON" # best decoder (fast)
"-DAVIF_CODEC_AOM_DECODE=OFF"
"-DAVIF_BUILD_APPS=ON"
"-DAVIF_BUILD_GDK_PIXBUF=ON"
];

nativeBuildInputs = [
cmake
pkg-config
gdk-pixbuf
makeWrapper
];

buildInputs = [
gdk-pixbuf
libaom
zlib
libpng
Expand All @@ -45,6 +56,23 @@ stdenv.mkDerivation rec {
libyuv
];

postPatch = ''
substituteInPlace contrib/gdk-pixbuf/avif.thumbnailer.in \
--replace '@CMAKE_INSTALL_FULL_BINDIR@/gdk-pixbuf-thumbnailer' "$out/libexec/gdk-pixbuf-thumbnailer-avif"
'';

env.PKG_CONFIG_GDK_PIXBUF_2_0_GDK_PIXBUF_MODULEDIR = gdkPixbufModuleDir;

postInstall = ''
GDK_PIXBUF_MODULEDIR=${gdkPixbufModuleDir} \
GDK_PIXBUF_MODULE_FILE=${gdkPixbufModuleFile} \
gdk-pixbuf-query-loaders --update-cache
mkdir -p "$out/bin"
makeWrapper ${gdk-pixbuf}/bin/gdk-pixbuf-thumbnailer "$out/libexec/gdk-pixbuf-thumbnailer-avif" \
--set GDK_PIXBUF_MODULE_FILE ${gdkPixbufModuleFile}
'';

meta = with lib; {
description = "C implementation of the AV1 Image File Format";
longDescription = ''
Expand Down
9 changes: 3 additions & 6 deletions pkgs/development/libraries/webp-pixbuf-loader/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@

let
inherit (gdk-pixbuf) moduleDir;

# turning lib/gdk-pixbuf-#.#/#.#.#/loaders into lib/gdk-pixbuf-#.#/#.#.#/loaders.cache
# removeSuffix is just in case moduleDir gets a trailing slash
loadersPath = (lib.strings.removeSuffix "/" gdk-pixbuf.moduleDir) + ".cache";
loadersPath = "${gdk-pixbuf.binaryDir}/webp-loaders.cache";
in
stdenv.mkDerivation rec {
pname = "webp-pixbuf-loader";
Expand Down Expand Up @@ -47,7 +44,7 @@ stdenv.mkDerivation rec {
postPatch = ''
# It looks for gdk-pixbuf-thumbnailer in this package's bin rather than the gdk-pixbuf bin. We need to patch that.
substituteInPlace webp-pixbuf.thumbnailer.in \
--replace "@bindir@/gdk-pixbuf-thumbnailer" "$out/bin/webp-thumbnailer"
--replace "@bindir@/gdk-pixbuf-thumbnailer" "$out/libexec/gdk-pixbuf-thumbnailer-webp"
'';

postInstall = ''
Expand All @@ -58,7 +55,7 @@ stdenv.mkDerivation rec {
# It assumes gdk-pixbuf-thumbnailer can find the webp loader in the loaders.cache referenced by environment variable, breaking containment.
# So we replace it with a wrapped executable.
mkdir -p "$out/bin"
makeWrapper "${gdk-pixbuf}/bin/gdk-pixbuf-thumbnailer" "$out/bin/webp-thumbnailer" \
makeWrapper "${gdk-pixbuf}/bin/gdk-pixbuf-thumbnailer" "$out/libexec/gdk-pixbuf-thumbnailer-webp" \
--set GDK_PIXBUF_MODULE_FILE "$out/${loadersPath}"
'';

Expand Down

0 comments on commit a38770b

Please sign in to comment.