1{ stdenv, buildPythonPackage, isPyPy, fetchPypi, libffi, pycparser, pytest }:
2
3if isPyPy then null else buildPythonPackage rec {
4 pname = "cffi";
5 version = "1.13.2";
6
7 src = fetchPypi {
8 inherit pname version;
9 sha256 = "599a1e8ff057ac530c9ad1778293c665cb81a791421f46922d80a86473c13346";
10 };
11
12 outputs = [ "out" "dev" ];
13
14 propagatedBuildInputs = [ libffi pycparser ];
15 checkInputs = [ pytest ];
16
17 # On Darwin, the cffi tests want to hit libm a lot, and look for it in a global
18 # impure search path. It's obnoxious how much repetition there is, and how difficult
19 # it is to get it to search somewhere else (since we do actually have a libm symlink in libSystem)
20 prePatch = stdenv.lib.optionalString stdenv.isDarwin ''
21 substituteInPlace testing/cffi0/test_parsing.py \
22 --replace 'lib_m = "m"' 'lib_m = "System"' \
23 --replace '"libm" in name' '"libSystem" in name'
24 substituteInPlace testing/cffi0/test_unicode_literals.py --replace 'lib_m = "m"' 'lib_m = "System"'
25 substituteInPlace testing/cffi0/test_zdistutils.py --replace 'self.lib_m = "m"' 'self.lib_m = "System"'
26 substituteInPlace testing/cffi1/test_recompiler.py --replace 'lib_m = "m"' 'lib_m = "System"'
27 substituteInPlace testing/cffi0/test_function.py --replace "lib_m = 'm'" "lib_m = 'System'"
28 substituteInPlace testing/cffi0/test_verify.py --replace "lib_m = ['m']" "lib_m = ['System']"
29 '';
30
31 # The tests use -Werror but with python3.6 clang detects some unreachable code.
32 NIX_CFLAGS_COMPILE = stdenv.lib.optionalString stdenv.cc.isClang
33 "-Wno-unused-command-line-argument -Wno-unreachable-code";
34
35 doCheck = !stdenv.hostPlatform.isMusl && !stdenv.isDarwin; # TODO: Investigate
36 checkPhase = ''
37 py.test -k "not test_char_pointer_conversion"
38 '';
39
40 meta = with stdenv.lib; {
41 maintainers = with maintainers; [ domenkozar lnl7 ];
42 homepage = https://cffi.readthedocs.org/;
43 license = with licenses; [ mit ];
44 description = "Foreign Function Interface for Python calling C code";
45 };
46}