diff --git a/pkgs/development/python-modules/pypdfium2/default.nix b/pkgs/development/python-modules/pypdfium2/default.nix index 933302eb81e3..66cdf166a6fb 100644 --- a/pkgs/development/python-modules/pypdfium2/default.nix +++ b/pkgs/development/python-modules/pypdfium2/default.nix @@ -1,4 +1,5 @@ { + stdenv, lib, pkgs, buildPythonPackage, @@ -9,6 +10,9 @@ numpy, pillow, pytestCheckHook, + removeReferencesTo, + python, + replaceVars, }: let @@ -37,6 +41,12 @@ let hash = "sha256-3JA7cW/xaEj/DxMHEypROwrKGo7EwUEcipRqALTvydw="; }; + patches = [ + (replaceVars ./fix-cc-detection.patch { + cc = "${stdenv.cc.targetPrefix}cc"; + }) + ]; + build-system = [ setuptools-scm ]; @@ -62,6 +72,10 @@ buildPythonPackage rec { setuptools-scm ]; + nativeBuildInputs = [ + removeReferencesTo + ]; + propagatedBuildInputs = [ pdfium-binaries ]; @@ -104,6 +118,11 @@ buildPythonPackage rec { ''; env.PDFIUM_PLATFORM = "system:${pdfiumVersion}"; + # Remove references to stdenv in comments. + postInstall = '' + remove-references-to -t ${stdenv.cc.cc} $out/${python.sitePackages}/pypdfium2_raw/bindings.py + ''; + nativeCheckInputs = [ numpy pillow diff --git a/pkgs/development/python-modules/pypdfium2/fix-cc-detection.patch b/pkgs/development/python-modules/pypdfium2/fix-cc-detection.patch new file mode 100644 index 000000000000..e01cc90901f5 --- /dev/null +++ b/pkgs/development/python-modules/pypdfium2/fix-cc-detection.patch @@ -0,0 +1,25 @@ +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