14 if isPyPy then null else buildPythonPackage rec {
20 inherit pname version;
21 hash = "sha256-vLPvQ+WGZbvaL7GYaY/K5ndkg+DEpjGqVkeAbCXgLMA=";
26 # Trusts the libffi library inside of nixpkgs on Apple devices.
28 # Based on some analysis I did:
30 # https://groups.google.com/g/python-cffi/c/xU0Usa8dvhk
32 # I believe that libffi already contains the code from Apple's fork that is
33 # deemed safe to trust in cffi.
35 ./darwin-use-libffi-closures.diff
36 ] ++ lib.optionals (stdenv.cc.isClang && lib.versionAtLeast (lib.getVersion stdenv.cc) "13") [
37 # -Wnull-pointer-subtraction is enabled with -Wextra. Suppress it to allow the following tests
38 # to run and pass when cffi is built with newer versions of clang:
39 # - testing/cffi1/test_verify1.py::test_enum_usage
40 # - testing/cffi1/test_verify1.py::test_named_pointer_as_argument
41 ./clang-pointer-substraction-warning.diff
44 postPatch = lib.optionalString stdenv.isDarwin ''
45 # Remove setup.py impurities
46 substituteInPlace setup.py \
47 --replace "'-iwithsysroot/usr/include/ffi'" "" \
48 --replace "'/usr/include/ffi'," "" \
49 --replace '/usr/include/libffi' '${lib.getDev libffi}/include'
61 propagatedBuildInputs = [
65 # The tests use -Werror but with python3.6 clang detects some unreachable code.
66 env.NIX_CFLAGS_COMPILE = lib.optionalString stdenv.cc.isClang
67 "-Wno-unused-command-line-argument -Wno-unreachable-code -Wno-c++11-narrowing";
69 doCheck = !stdenv.hostPlatform.isMusl;
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;