nixpkgs/pkgs/tools/graphics/pngquant/default.nix
6t8k ef0b88ac3c
pngquant: 2.17.0 -> 3.0.3
https://github.com/kornelski/pngquant/blob/3.0.3/CHANGELOG

Since 3.0.0, pngquant uses libimagequant 4.x, which is a Rust rewrite,
and and switches the build system from make to Cargo. The `pngquant`
executable is now a Rust wrapper around `pngquant.c`, which in turn
interfaces with libimagequant via the `imagequant_sys` crate, which
exports a C API.[1] The CLI seems unchanged.

Upstream lacks a Cargo.lock[2], so I generated one and patched it in.

Set `doCheck = false;` as there are no Rust-based tests. `test/` was
previously part of the make-based workflow (which is gone with pngquant
3.x) and looks like it isn't meant for pngquant 3.x anyway (as `test.sh`
executes `$BIN --version 2>&1 | fgrep 2.`).

`$ nix build .#pkgsCross.raspberryPi.pngquant` succeeds[3]; remove the
workaround originally introduced in [4].

Notes on dependencies:

- While nixpkgs package libimagequant on its own, pngquant depends on a
  specific vendored version

- pngquant 3.x depends on the libpng-sys and lcms2-sys crates, which
  provide bindings to the respective C libraries. If those are not
  provided by the system at build time, vendored versions of them will
  be built and statically linked; libpng 1.6.37 and LCMS 2.15,
  respectively

[1] See also: https://github.com/kornelski/pngquant/issues/368#issuecomment-1542507114
[2] See also: https://github.com/kornelski/pngquant/issues/347
[3] New SSE flag decision logic: https://github.com/kornelski/pngquant/blob/3.0.3/rust/build.rs#L31
[4] https://github.com/NixOS/nixpkgs/pull/145672
2023-11-17 00:51:57 +01:00

42 lines
1.1 KiB
Nix

{ lib, rustPlatform, fetchFromGitHub, pkg-config, libpng, zlib, lcms2 }:
rustPlatform.buildRustPackage rec {
pname = "pngquant";
version = "3.0.3";
outputs = [ "out" "man" ];
src = fetchFromGitHub {
owner = "kornelski";
repo = "pngquant";
rev = version;
hash = "sha256-u2zEp9Llo+c/+1QGW4V4r40KQn/ATHCTEsrpy7bRf/I=";
fetchSubmodules = true;
};
cargoHash = "sha256-mZpg6BRpsvEiMsS6ZJzVYg6wXHLb3Cf72sK1yzTF8y4=";
cargoPatches = [
# https://github.com/kornelski/pngquant/issues/347
./add-Cargo.lock.patch
];
nativeBuildInputs = [ pkg-config ];
buildInputs = [ libpng zlib lcms2 ];
doCheck = false; # Has no Rust-based tests
postInstall = ''
install -Dpm0444 pngquant.1 $man/share/man/man1/pngquant.1
'';
meta = with lib; {
homepage = "https://pngquant.org/";
description = "A tool to convert 24/32-bit RGBA PNGs to 8-bit palette with alpha channel preserved";
changelog = "https://github.com/kornelski/pngquant/raw/${version}/CHANGELOG";
platforms = platforms.unix;
license = with licenses; [ gpl3Plus hpnd bsd2 ];
mainProgram = "pngquant";
maintainers = [ ];
};
}