python313Packages.pypdfium2: 4.30.1 -> 5.0.0

This commit is contained in:
Ihar Hrachyshka
2025-08-23 21:45:02 -04:00
parent 0a89c97fd8
commit fbf2b41342
3 changed files with 18 additions and 89 deletions

View File

@@ -8,7 +8,6 @@
stdenv.mkDerivation (finalAttrs: { stdenv.mkDerivation (finalAttrs: {
pname = "pdfium-binaries"; pname = "pdfium-binaries";
# also update rev of headers in python3Packages.pypdfium2
version = "7363"; version = "7363";
src = src =

View File

@@ -1,10 +1,9 @@
{ {
stdenv, stdenv,
lib, lib,
pkgs, pkgsCross,
buildPythonPackage, buildPythonPackage,
fetchFromGitHub, fetchFromGitHub,
fetchgit,
gitUpdater, gitUpdater,
setuptools-scm, setuptools-scm,
pdfium-binaries, pdfium-binaries,
@@ -13,22 +12,9 @@
pytestCheckHook, pytestCheckHook,
removeReferencesTo, removeReferencesTo,
python, python,
replaceVars,
}: }:
let let
pdfiumVersion = "${pdfium-binaries.version}";
headers = fetchgit {
url = "https://pdfium.googlesource.com/pdfium";
# The latest revision on the chromium/${pdfiumVersion} branch
rev = "9232d7c94a0007377a8034222f47683fe391d474";
hash = "sha256-dI3jTyVYc0EmMLHTiVjGSf3C2noS9Ru5WijEJFtiSFk=";
sparseCheckout = [
"public"
];
};
# They demand their own fork of ctypesgen # They demand their own fork of ctypesgen
ctypesgen = buildPythonPackage rec { ctypesgen = buildPythonPackage rec {
pname = "ctypesgen"; pname = "ctypesgen";
@@ -38,34 +24,26 @@ let
src = fetchFromGitHub { src = fetchFromGitHub {
owner = "pypdfium2-team"; owner = "pypdfium2-team";
repo = "ctypesgen"; repo = "ctypesgen";
rev = "848e9fbb1374f7f58a7ebf5e5da5c33292480b30"; rev = "3961621c3e057015362db82471e07f3a57822b15";
hash = "sha256-3JA7cW/xaEj/DxMHEypROwrKGo7EwUEcipRqALTvydw="; hash = "sha256-0OBY7/Zn12rG20jNYG65lANTRVRIFvE0SgUdYGFpRtU=";
}; };
patches = [
(replaceVars ./fix-cc-detection.patch {
cc = "${stdenv.cc.targetPrefix}cc";
})
];
build-system = [ build-system = [
setuptools-scm setuptools-scm
]; ];
env.SETUPTOOLS_SCM_PRETEND_VERSION = "${version}";
}; };
in in
buildPythonPackage rec { buildPythonPackage rec {
pname = "pypdfium2"; pname = "pypdfium2";
version = "4.30.1"; version = "5.0.0";
pyproject = true; pyproject = true;
src = fetchFromGitHub { src = fetchFromGitHub {
owner = "pypdfium2-team"; owner = "pypdfium2-team";
repo = "pypdfium2"; repo = "pypdfium2";
tag = version; tag = version;
hash = "sha256-v8f/XruGJYK3H9z4Q1rLg4fEnPHa8tTOlNTBMVxPEgA="; hash = "sha256-to6l8kfi6pYRs+hv+9zdxpSyhKCxX79G/EMdz6OBBaA=";
}; };
build-system = [ build-system = [
@@ -81,43 +59,19 @@ buildPythonPackage rec {
pdfium-binaries pdfium-binaries
]; ];
# Build system insists on fetching from the internet unless "cached" files preBuild = ''
# are prepared. Even then, some code patching needs to happen to make it not getVersion() {
# talk to the internet. cat ${pdfium-binaries}/VERSION | grep $1 | sed 's/.*=//'
}
# The project doesn't seem very open to allow for offline building either, export GIVEN_FULLVER="$(getVersion MAJOR).$(getVersion MINOR).$(getVersion BUILD).$(getVersion PATCH)"
# see: https://github.com/pypdfium2-team/pypdfium2/discussions/274
preBuild =
let
pdfiumLib = lib.makeLibraryPath [ pdfium-binaries ];
inputVersionFile = (pkgs.formats.json { }).generate "version.json" {
version = lib.strings.toInt pdfiumVersion;
source = "generated";
flags = [ ];
run_lds = [ pdfiumLib ];
guard_symbols = false;
};
bindingsDir = "data/bindings";
headersDir = "${bindingsDir}/headers";
versionFile = "${bindingsDir}/version.json";
in
''
# Preseed the headers and version file
mkdir -p ${bindingsDir}
cp -r ${headers}/public ${headersDir}
install -m 644 ${inputVersionFile} ${versionFile}
# Make generated bindings consider pdfium derivation path when loading dynamic libraries
substituteInPlace setupsrc/pypdfium2_setup/emplace.py \
--replace-fail 'build_pdfium_bindings(pdfium_ver, flags=flags, guard_symbols=True, run_lds=[])' \
'build_pdfium_bindings(pdfium_ver, flags=flags, guard_symbols=True, run_lds=["${pdfiumLib}"])'
# Short circuit the version pull from the internet
substituteInPlace setupsrc/pypdfium2_setup/packaging_base.py \
--replace-fail 'PdfiumVer.to_full(build)._asdict()' \
'{"major": 133, "minor": 0, "build": ${pdfiumVersion}, "patch": 1}'
''; '';
env.PDFIUM_PLATFORM = "system:${pdfiumVersion}";
env = {
PDFIUM_PLATFORM = "system-search:${pdfium-binaries.version}";
PDFIUM_HEADERS = "${pdfium-binaries}/include";
PDFIUM_BINARY = "${pdfium-binaries}/lib/libpdfium${stdenv.targetPlatform.extensions.sharedLibrary}";
CPP = "${stdenv.cc.targetPrefix}cpp";
};
# Remove references to stdenv in comments. # Remove references to stdenv in comments.
postInstall = '' postInstall = ''
@@ -138,6 +92,7 @@ buildPythonPackage rec {
updateScript = gitUpdater { updateScript = gitUpdater {
allowedVersions = "^[.0-9]+$"; allowedVersions = "^[.0-9]+$";
}; };
tests.cross = pkgsCross.aarch64-multiplatform.python3Packages.pypdfium2;
}; };
meta = { meta = {

View File

@@ -1,25 +0,0 @@
diff --git a/src/ctypesgen/__main__.py b/src/ctypesgen/__main__.py
index 23ee014..2d0cfc1 100644
--- a/src/ctypesgen/__main__.py
+++ b/src/ctypesgen/__main__.py
@@ -89,17 +89,9 @@ def main_impl(args, cmd_str):
assert _is_relative_to(args.output, args.linkage_anchor)
if args.cpp:
- assert shutil.which(args.cpp[0]), f"Given pre-processor {args.cpp[0]!r} is not available."
- else:
- if shutil.which("gcc"):
- args.cpp = ["gcc", "-E"]
- elif shutil.which("cpp"):
- args.cpp = ["cpp"]
- elif shutil.which("clang"):
- args.cpp = ["clang", "-E"]
- else:
- raise RuntimeError("C pre-processor auto-detection failed: neither gcc nor clang available.")
-
+ print("cpp argument ignored for nix build")
+ args.cpp = ["@cc@", "-E"]
+
# Important: must not use +=, this would mutate the original object, which is problematic when default=[] is used and ctypesgen called repeatedly from within python
args.compile_libdirs = args.compile_libdirs + args.universal_libdirs
args.runtime_libdirs = args.runtime_libdirs + args.universal_libdirs