Skip to content

Commit 98951d6

Browse files
authored
python3Packages.pypdfium2: fix cross, reduce closure size (#396787)
2 parents e7e6e9d + a2882f7 commit 98951d6

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

pkgs/development/python-modules/pypdfium2/default.nix

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
stdenv,
23
lib,
34
pkgs,
45
buildPythonPackage,
@@ -9,6 +10,9 @@
910
numpy,
1011
pillow,
1112
pytestCheckHook,
13+
removeReferencesTo,
14+
python,
15+
replaceVars,
1216
}:
1317

1418
let
@@ -37,6 +41,12 @@ let
3741
hash = "sha256-3JA7cW/xaEj/DxMHEypROwrKGo7EwUEcipRqALTvydw=";
3842
};
3943

44+
patches = [
45+
(replaceVars ./fix-cc-detection.patch {
46+
cc = "${stdenv.cc.targetPrefix}cc";
47+
})
48+
];
49+
4050
build-system = [
4151
setuptools-scm
4252
];
@@ -62,6 +72,10 @@ buildPythonPackage rec {
6272
setuptools-scm
6373
];
6474

75+
nativeBuildInputs = [
76+
removeReferencesTo
77+
];
78+
6579
propagatedBuildInputs = [
6680
pdfium-binaries
6781
];
@@ -104,6 +118,11 @@ buildPythonPackage rec {
104118
'';
105119
env.PDFIUM_PLATFORM = "system:${pdfiumVersion}";
106120

121+
# Remove references to stdenv in comments.
122+
postInstall = ''
123+
remove-references-to -t ${stdenv.cc.cc} $out/${python.sitePackages}/pypdfium2_raw/bindings.py
124+
'';
125+
107126
nativeCheckInputs = [
108127
numpy
109128
pillow
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
diff --git a/src/ctypesgen/__main__.py b/src/ctypesgen/__main__.py
2+
index 23ee014..2d0cfc1 100644
3+
--- a/src/ctypesgen/__main__.py
4+
+++ b/src/ctypesgen/__main__.py
5+
@@ -89,17 +89,9 @@ def main_impl(args, cmd_str):
6+
assert _is_relative_to(args.output, args.linkage_anchor)
7+
8+
if args.cpp:
9+
- assert shutil.which(args.cpp[0]), f"Given pre-processor {args.cpp[0]!r} is not available."
10+
- else:
11+
- if shutil.which("gcc"):
12+
- args.cpp = ["gcc", "-E"]
13+
- elif shutil.which("cpp"):
14+
- args.cpp = ["cpp"]
15+
- elif shutil.which("clang"):
16+
- args.cpp = ["clang", "-E"]
17+
- else:
18+
- raise RuntimeError("C pre-processor auto-detection failed: neither gcc nor clang available.")
19+
-
20+
+ print("cpp argument ignored for nix build")
21+
+ args.cpp = ["@cc@", "-E"]
22+
+
23+
# Important: must not use +=, this would mutate the original object, which is problematic when default=[] is used and ctypesgen called repeatedly from within python
24+
args.compile_libdirs = args.compile_libdirs + args.universal_libdirs
25+
args.runtime_libdirs = args.runtime_libdirs + args.universal_libdirs

0 commit comments

Comments
 (0)