2022-12-17 10:02:37 +00:00
|
|
|
{ lib
|
|
|
|
, stdenv
|
|
|
|
, buildPythonPackage
|
|
|
|
, isPyPy
|
|
|
|
, fetchPypi
|
|
|
|
, fetchpatch
|
|
|
|
, pytestCheckHook
|
|
|
|
, libffi
|
|
|
|
, pkg-config
|
|
|
|
, pycparser
|
|
|
|
, pythonAtLeast
|
2021-12-26 17:43:05 +00:00
|
|
|
}:
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
if isPyPy then null else buildPythonPackage rec {
|
|
|
|
pname = "cffi";
|
2022-08-12 12:06:08 +00:00
|
|
|
version = "1.15.1";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
src = fetchPypi {
|
|
|
|
inherit pname version;
|
2022-08-12 12:06:08 +00:00
|
|
|
sha256 = "sha256-1AC/uaN7E1ElPLQCZxzqfom97MKU6AFqcH9tHYrJNPk=";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
2022-12-17 10:02:37 +00:00
|
|
|
patches = [
|
|
|
|
#
|
|
|
|
# Trusts the libffi library inside of nixpkgs on Apple devices.
|
|
|
|
#
|
|
|
|
# Based on some analysis I did:
|
|
|
|
#
|
|
|
|
# https://groups.google.com/g/python-cffi/c/xU0Usa8dvhk
|
|
|
|
#
|
|
|
|
# I believe that libffi already contains the code from Apple's fork that is
|
|
|
|
# deemed safe to trust in cffi.
|
|
|
|
#
|
|
|
|
./darwin-use-libffi-closures.diff
|
2023-01-20 10:41:00 +00:00
|
|
|
(fetchpatch {
|
|
|
|
# Drop py.code usage from tests, no longer depend on the deprecated py package
|
|
|
|
url = "https://foss.heptapod.net/pypy/cffi/-/commit/9c7d865e17ec16a847090a3e0d1498b698b99756.patch";
|
|
|
|
excludes = [
|
|
|
|
"README.md"
|
|
|
|
"requirements.txt"
|
|
|
|
];
|
|
|
|
hash = "sha256-HSuLLIYXXGGCPccMNLV7o1G3ppn2P0FGCrPjqDv2e7k=";
|
|
|
|
})
|
|
|
|
(fetchpatch {
|
|
|
|
# Replace py.test usage with pytest
|
|
|
|
url = "https://foss.heptapod.net/pypy/cffi/-/commit/bd02e1b122612baa74a126e428bacebc7889e897.patch";
|
|
|
|
excludes = [
|
|
|
|
"README.md"
|
|
|
|
"requirements.txt"
|
|
|
|
];
|
|
|
|
hash = "sha256-+2daRTvxtyrCPimOEAmVbiVm1Bso9hxGbaAbd03E+ws=";
|
|
|
|
})
|
2022-12-17 10:02:37 +00:00
|
|
|
] ++ lib.optionals (pythonAtLeast "3.11") [
|
2022-12-02 08:20:57 +00:00
|
|
|
# Fix test that failed because python seems to have changed the exception format in the
|
|
|
|
# final release. This patch should be included in the next version and can be removed when
|
|
|
|
# it is released.
|
2022-12-17 10:02:37 +00:00
|
|
|
(fetchpatch {
|
|
|
|
url = "https://foss.heptapod.net/pypy/cffi/-/commit/8a3c2c816d789639b49d3ae867213393ed7abdff.diff";
|
|
|
|
sha256 = "sha256-3wpZeBqN4D8IP+47QDGK7qh/9Z0Ag4lAe+H0R5xCb1E=";
|
|
|
|
})
|
|
|
|
];
|
2022-12-02 08:20:57 +00:00
|
|
|
|
2022-04-27 09:35:20 +00:00
|
|
|
postPatch = lib.optionalString stdenv.isDarwin ''
|
2021-12-26 17:43:05 +00:00
|
|
|
# Remove setup.py impurities
|
2022-04-27 09:35:20 +00:00
|
|
|
substituteInPlace setup.py \
|
|
|
|
--replace "'-iwithsysroot/usr/include/ffi'" "" \
|
|
|
|
--replace "'/usr/include/ffi'," "" \
|
|
|
|
--replace '/usr/include/libffi' '${lib.getDev libffi}/include'
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
|
2022-12-17 10:02:37 +00:00
|
|
|
buildInputs = [ libffi ];
|
|
|
|
|
|
|
|
nativeBuildInputs = [ pkg-config ];
|
|
|
|
|
|
|
|
propagatedBuildInputs = [ pycparser ];
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
# The tests use -Werror but with python3.6 clang detects some unreachable code.
|
2023-03-04 12:14:45 +00:00
|
|
|
env.NIX_CFLAGS_COMPILE = lib.optionalString stdenv.cc.isClang
|
2021-12-26 17:43:05 +00:00
|
|
|
"-Wno-unused-command-line-argument -Wno-unreachable-code -Wno-c++11-narrowing";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2022-12-17 10:02:37 +00:00
|
|
|
doCheck = !stdenv.hostPlatform.isMusl;
|
2021-05-20 23:08:51 +00:00
|
|
|
|
2023-02-02 18:25:31 +00:00
|
|
|
nativeCheckInputs = [ pytestCheckHook ];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2023-01-20 10:41:00 +00:00
|
|
|
disabledTests = lib.optionals stdenv.isDarwin [
|
|
|
|
# AssertionError: cannot seem to get an int[10] not completely cleared
|
|
|
|
# https://foss.heptapod.net/pypy/cffi/-/issues/556
|
|
|
|
"test_ffi_new_allocator_1"
|
|
|
|
];
|
|
|
|
|
2021-01-15 22:18:51 +00:00
|
|
|
meta = with lib; {
|
2020-04-24 23:36:52 +00:00
|
|
|
maintainers = with maintainers; [ domenkozar lnl7 ];
|
|
|
|
homepage = "https://cffi.readthedocs.org/";
|
2021-02-05 17:12:51 +00:00
|
|
|
license = licenses.mit;
|
2020-04-24 23:36:52 +00:00
|
|
|
description = "Foreign Function Interface for Python calling C code";
|
|
|
|
};
|
|
|
|
}
|