pdfium-binaries: refactor (#409245)

This commit is contained in:
Pol Dellaiera 2025-05-23 07:49:52 +00:00 committed by GitHub
commit 657d143faa
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 54 additions and 32 deletions

View file

@ -1,44 +1,52 @@
{ {
lib, lib,
fetchzip,
stdenv, stdenv,
fetchzip,
python3Packages, python3Packages,
withV8 ? false,
}: }:
let
stdenv.mkDerivation (finalAttrs: {
pname = "pdfium-binaries";
# also update rev of headers in python3Packages.pypdfium2 # also update rev of headers in python3Packages.pypdfium2
version = "7087"; version = "7087";
src = src =
let let
inherit (stdenv.hostPlatform) system; selectSystem =
selectSystem = attrs: attrs.${system}; attrs:
suffix = selectSystem { attrs.${stdenv.hostPlatform.system} or (throw "Unsupported system: ${stdenv.hostPlatform.system}");
system = selectSystem {
x86_64-linux = "linux-x64"; x86_64-linux = "linux-x64";
aarch64-linux = "linux-arm64"; aarch64-linux = "linux-arm64";
x86_64-darwin = "mac-x64"; x86_64-darwin = "mac-x64";
aarch64-darwin = "mac-arm64"; aarch64-darwin = "mac-arm64";
}; };
hash = selectSystem {
x86_64-linux = "sha256-zn7QlTvChQa2mQCe5K+zEGVUtuD+l/jEtlKticrrSKg=";
aarch64-linux = "sha256-080X72NNfKaanHeVtmxE/4uNV6Ue4f/1Mri/p3nOT8c=";
x86_64-darwin = "sha256-XMStU0MN9ieCrLQnQL4/jKrNWxgQl9OtZHg9EmemPhU=";
aarch64-darwin = "sha256-Q8R/p1hX6+JeVTFc6w7MC9GPNGqxlu6m+iawRIMndic=";
};
in in
fetchzip { fetchzip {
url = "https://github.com/bblanchon/pdfium-binaries/releases/download/chromium%2F${version}/pdfium-${suffix}.tgz"; url = "https://github.com/bblanchon/pdfium-binaries/releases/download/chromium%2F${finalAttrs.version}/pdfium${lib.optionalString withV8 "-v8"}-${system}.tgz";
inherit hash; hash =
if withV8 then
selectSystem {
x86_64-linux = "sha256-nKHXcBTEp165g18HLzaNGfKt8MtTYpKBGNgwIpSO0u4=";
aarch64-linux = "sha256-wip/ry42aDbyGiwYSUX8koxDuf88BLGZAmMZE0s+fL0=";
x86_64-darwin = "sha256-7pUMfNFgGqQ8Dnox57sHfrKKke+i8CGEma4tePJaTDA=";
aarch64-darwin = "sha256-o59kmTNC4nSCFLfww3E+4iIYs2kQ30yyFaX9f2Za7os=";
}
else
selectSystem {
x86_64-linux = "sha256-zn7QlTvChQa2mQCe5K+zEGVUtuD+l/jEtlKticrrSKg=";
aarch64-linux = "sha256-080X72NNfKaanHeVtmxE/4uNV6Ue4f/1Mri/p3nOT8c=";
x86_64-darwin = "sha256-XMStU0MN9ieCrLQnQL4/jKrNWxgQl9OtZHg9EmemPhU=";
aarch64-darwin = "sha256-Q8R/p1hX6+JeVTFc6w7MC9GPNGqxlu6m+iawRIMndic=";
};
stripRoot = false; stripRoot = false;
}; };
in
stdenv.mkDerivation {
pname = "pdfium-binaries";
inherit version src;
installPhase = '' installPhase = ''
runHook preInstall runHook preInstall
mkdir $out cp -r . $out
cp -r ./ $out/
runHook postInstall runHook postInstall
''; '';
@ -53,7 +61,10 @@ stdenv.mkDerivation {
meta = { meta = {
description = "Binary distribution of PDFium"; description = "Binary distribution of PDFium";
homepage = "https://github.com/bblanchon/pdfium-binaries"; homepage = "https://github.com/bblanchon/pdfium-binaries";
license = with lib.licenses; [ asl20 ]; license = with lib.licenses; [
asl20
mit
];
sourceProvenance = with lib.sourceTypes; [ binaryBytecode ]; sourceProvenance = with lib.sourceTypes; [ binaryBytecode ];
maintainers = with lib.maintainers; [ ]; maintainers = with lib.maintainers; [ ];
platforms = [ platforms = [
@ -63,4 +74,4 @@ stdenv.mkDerivation {
"x86_64-darwin" "x86_64-darwin"
]; ];
}; };
} })

View file

@ -1,10 +1,10 @@
#!/usr/bin/env nix-shell #!/usr/bin/env nix-shell
#!nix-shell -i bash -p bash nixVersions.latest curl coreutils jq common-updater-scripts #!nix-shell -i bash -p bash nix curl coreutils jq common-updater-scripts
set -eou pipefail set -eou pipefail
latestVersion=$(curl ${GITHUB_TOKEN:+-u ":$GITHUB_TOKEN"} -sL https://api.github.com/repos/bblanchon/pdfium-binaries/releases/latest | jq -r '.tag_name | ltrimstr("chromium/")') latestVersion=$(curl ${GITHUB_TOKEN:+-u ":$GITHUB_TOKEN"} -sL https://api.github.com/repos/bblanchon/pdfium-binaries/releases/latest | jq -r '.tag_name | ltrimstr("chromium/")')
currentVersion=$(nix-instantiate --eval -E "with import ./. {}; pdfium-binaries.version" | tr -d '"') currentVersion=$(nix-instantiate --eval -E "with import ./. {}; pdfium-binaries.version or (lib.getVersion pdfium-binaries)" | tr -d '"')
echo "latest version: $latestVersion" echo "latest version: $latestVersion"
echo "current version: $currentVersion" echo "current version: $currentVersion"
@ -14,13 +14,22 @@ if [[ "$latestVersion" == "$currentVersion" ]]; then
exit 0 exit 0
fi fi
for i in \ update-source-version pdfium-binaries $latestVersion || true
"x86_64-linux linux-x64" \
"aarch64-linux linux-arm64" \ for system in \
"x86_64-darwin mac-x64" \ x86_64-linux \
"aarch64-darwin mac-arm64"; do aarch64-linux \
set -- $i x86_64-darwin \
prefetch=$(nix-prefetch-url --unpack "https://github.com/bblanchon/pdfium-binaries/releases/download/chromium%2F$latestVersion/pdfium-$2.tgz") aarch64-darwin; do
hash=$(nix hash convert --hash-algo sha256 --to sri $prefetch) hash=$(nix hash convert --to sri --hash-algo sha256 $(nix-prefetch-url --unpack $(nix-instantiate --eval -E "with import ./. {}; pdfium-binaries.src.url" --system "$system" | tr -d '"')))
update-source-version pdfium-binaries $latestVersion $hash --system=$1 --ignore-same-version update-source-version pdfium-binaries $latestVersion $hash --system=$system --ignore-same-version
done
for system in \
x86_64-linux \
aarch64-linux \
x86_64-darwin \
aarch64-darwin; do
hash=$(nix hash convert --to sri --hash-algo sha256 $(nix-prefetch-url --unpack $(nix-instantiate --eval -E "with import ./. {}; pdfium-binaries-v8.src.url" --system "$system" | tr -d '"')))
update-source-version pdfium-binaries-v8 $latestVersion $hash --system=$system --ignore-same-version
done done

View file

@ -4144,6 +4144,8 @@ with pkgs;
pdfminer = with python3Packages; toPythonApplication pdfminer-six; pdfminer = with python3Packages; toPythonApplication pdfminer-six;
pdfium-binaries-v8 = pdfium-binaries.override { withV8 = true; };
pgsync = callPackage ../development/tools/database/pgsync { }; pgsync = callPackage ../development/tools/database/pgsync { };
pdsh = callPackage ../tools/networking/pdsh { pdsh = callPackage ../tools/networking/pdsh {