Unverified Commit a80572c4 authored by dotlambda's avatar dotlambda Committed by GitHub
Browse files

python313Packages.pypdfium2: 4.30.1 -> 5.0.0 (#436330)

parents 69ec38cc fbf2b413
Loading
Loading
Loading
Loading
+9 −10
Original line number Diff line number Diff line
@@ -8,8 +8,7 @@

stdenv.mkDerivation (finalAttrs: {
  pname = "pdfium-binaries";
  # also update rev of headers in python3Packages.pypdfium2
  version = "7087";
  version = "7363";

  src =
    let
@@ -28,17 +27,17 @@ stdenv.mkDerivation (finalAttrs: {
      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=";
            x86_64-linux = "sha256-KbAJUdbT3XjLs68y4xwEG5w8o/89epkXSCKpQsyuNec=";
            aarch64-linux = "sha256-zvaTKszH5yT1afzs0W3LV1caN6gaCIJiKIh9bElfI48=";
            x86_64-darwin = "sha256-xGnmndTkYSIGn44Y4cfYW36QmkVAOhgIlcsWaRYFbCk=";
            aarch64-darwin = "sha256-NYY/YIVtSux4B6UZb7kkZs+GzxXNopmvtknw/HhVEQs=";
          }
        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=";
            x86_64-linux = "sha256-mlSmVeE1oDQ1OlW8K7EXk51r7GCbDXH2l/tbat2aiB0=";
            aarch64-linux = "sha256-YiCMdwQ2Y0F120iKW3ZkxJKvDgP/vpPw1ItmRnsnz9U=";
            x86_64-darwin = "sha256-I2fWQC+GKzZwqTPwXkl9vDJ/HIH3GKzD+kNaUDcNKuw=";
            aarch64-darwin = "sha256-AhYAr5SySWJO3jbvs+DvEZ/WaCJ+KhxpFVyOVsJxuXE=";
          };
      stripRoot = false;
    };
+18 −63
Original line number Diff line number Diff line
{
  stdenv,
  lib,
  pkgs,
  pkgsCross,
  buildPythonPackage,
  fetchFromGitHub,
  fetchgit,
  gitUpdater,
  setuptools-scm,
  pdfium-binaries,
@@ -13,22 +12,9 @@
  pytestCheckHook,
  removeReferencesTo,
  python,
  replaceVars,
}:

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
  ctypesgen = buildPythonPackage rec {
    pname = "ctypesgen";
@@ -38,34 +24,26 @@ let
    src = fetchFromGitHub {
      owner = "pypdfium2-team";
      repo = "ctypesgen";
      rev = "848e9fbb1374f7f58a7ebf5e5da5c33292480b30";
      hash = "sha256-3JA7cW/xaEj/DxMHEypROwrKGo7EwUEcipRqALTvydw=";
      rev = "3961621c3e057015362db82471e07f3a57822b15";
      hash = "sha256-0OBY7/Zn12rG20jNYG65lANTRVRIFvE0SgUdYGFpRtU=";
    };

    patches = [
      (replaceVars ./fix-cc-detection.patch {
        cc = "${stdenv.cc.targetPrefix}cc";
      })
    ];

    build-system = [
      setuptools-scm
    ];

    env.SETUPTOOLS_SCM_PRETEND_VERSION = "${version}";
  };

in
buildPythonPackage rec {
  pname = "pypdfium2";
  version = "4.30.1";
  version = "5.0.0";
  pyproject = true;

  src = fetchFromGitHub {
    owner = "pypdfium2-team";
    repo = "pypdfium2";
    tag = version;
    hash = "sha256-v8f/XruGJYK3H9z4Q1rLg4fEnPHa8tTOlNTBMVxPEgA=";
    hash = "sha256-to6l8kfi6pYRs+hv+9zdxpSyhKCxX79G/EMdz6OBBaA=";
  };

  build-system = [
@@ -81,43 +59,19 @@ buildPythonPackage rec {
    pdfium-binaries
  ];

  # Build system insists on fetching from the internet unless "cached" files
  # are prepared. Even then, some code patching needs to happen to make it not
  # talk to the internet.
  preBuild = ''
    getVersion() {
      cat ${pdfium-binaries}/VERSION | grep $1 | sed 's/.*=//'
    }
    export GIVEN_FULLVER="$(getVersion MAJOR).$(getVersion MINOR).$(getVersion BUILD).$(getVersion PATCH)"
  '';

  # The project doesn't seem very open to allow for offline building either,
  # 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;
  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";
  };
      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}";

  # Remove references to stdenv in comments.
  postInstall = ''
@@ -138,6 +92,7 @@ buildPythonPackage rec {
    updateScript = gitUpdater {
      allowedVersions = "^[.0-9]+$";
    };
    tests.cross = pkgsCross.aarch64-multiplatform.python3Packages.pypdfium2;
  };

  meta = {
+0 −25
Original line number Diff line number Diff line
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
+9 −0
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@
  lib,
  buildPythonPackage,
  fetchFromGitHub,
  fetchpatch,
  setuptools,
  setuptools-scm,
  pillow,
@@ -22,6 +23,14 @@ buildPythonPackage rec {
    hash = "sha256-B8jrFQh5swDMfYjdMcY0Hh2VAzknDwarDKVAML6F2r4=";
  };

  patches = [
    # fix compatibility with pypdfium2 5.x: https://github.com/miikanissi/zebrafy/pull/20
    (fetchpatch {
      url = "https://github.com/miikanissi/zebrafy/pull/20/commits/cc15c4a28d9e8aec022d22397ff752600b9ede52.patch";
      hash = "sha256-KAjfKPqmTvfoQN7YPLayPyq2sueDASyU/lMCgLCl1RU=";
    })
  ];

  build-system = [
    setuptools
    setuptools-scm