15 ccVersion = lib.getVersion stdenv.cc;
20 buildPythonPackage rec {
26 inherit pname version;
27 hash = "sha256-HDnGAWwyvEjdVFYZUOvWg24WcPKuRhKPZ89J54nFKCQ=";
33 # Trusts the libffi library inside of nixpkgs on Apple devices.
35 # Based on some analysis I did:
37 # https://groups.google.com/g/python-cffi/c/xU0Usa8dvhk
39 # I believe that libffi already contains the code from Apple's fork that is
40 # deemed safe to trust in cffi.
42 ./darwin-use-libffi-closures.diff
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
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'
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 ];
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;