evcc: 0.131.4 -> 0.131.5
[NixPkgs.git] / pkgs / development / python-modules / cffi / default.nix
blobcd0e1c143a7f6763bf36b2f187cfe06120610d01
2   lib,
3   stdenv,
4   buildPythonPackage,
5   isPyPy,
6   fetchPypi,
7   setuptools,
8   pytestCheckHook,
9   libffi,
10   pkg-config,
11   pycparser,
14 let
15   ccVersion = lib.getVersion stdenv.cc;
17 if isPyPy then
18   null
19 else
20   buildPythonPackage rec {
21     pname = "cffi";
22     version = "1.17.1";
23     pyproject = true;
25     src = fetchPypi {
26       inherit pname version;
27       hash = "sha256-HDnGAWwyvEjdVFYZUOvWg24WcPKuRhKPZ89J54nFKCQ=";
28     };
30     patches =
31       [
32         #
33         # Trusts the libffi library inside of nixpkgs on Apple devices.
34         #
35         # Based on some analysis I did:
36         #
37         #   https://groups.google.com/g/python-cffi/c/xU0Usa8dvhk
38         #
39         # I believe that libffi already contains the code from Apple's fork that is
40         # deemed safe to trust in cffi.
41         #
42         ./darwin-use-libffi-closures.diff
43       ]
44       ++ lib.optionals (stdenv.cc.isClang && (ccVersion == "boot" || lib.versionAtLeast ccVersion "13")) [
45         # -Wnull-pointer-subtraction is enabled with -Wextra. Suppress it to allow the following tests
46         # to run and pass when cffi is built with newer versions of clang (including the bootstrap tools clang on Darwin):
47         # - testing/cffi1/test_verify1.py::test_enum_usage
48         # - testing/cffi1/test_verify1.py::test_named_pointer_as_argument
49         ./clang-pointer-substraction-warning.diff
50       ];
52     postPatch = lib.optionalString stdenv.hostPlatform.isDarwin ''
53       # Remove setup.py impurities
54       substituteInPlace setup.py \
55         --replace "'-iwithsysroot/usr/include/ffi'" "" \
56         --replace "'/usr/include/ffi'," "" \
57         --replace '/usr/include/libffi' '${lib.getDev libffi}/include'
58     '';
60     nativeBuildInputs = [ pkg-config ];
62     build-system = [ setuptools ];
64     buildInputs = [ libffi ];
66     dependencies = [ pycparser ];
68     # The tests use -Werror but with python3.6 clang detects some unreachable code.
69     env.NIX_CFLAGS_COMPILE = lib.optionalString stdenv.cc.isClang "-Wno-unused-command-line-argument -Wno-unreachable-code -Wno-c++11-narrowing";
71     doCheck = !stdenv.hostPlatform.isMusl;
73     nativeCheckInputs = [ pytestCheckHook ];
75     meta = with lib; {
76       changelog = "https://github.com/python-cffi/cffi/releases/tag/v${version}";
77       description = "Foreign Function Interface for Python calling C code";
78       downloadPage = "https://github.com/python-cffi/cffi";
79       homepage = "https://cffi.readthedocs.org/";
80       license = licenses.mit;
81       maintainers = teams.python.members;
82     };
83   }