···1+{ lib, stdenv, fetchurl, fetchpatch
2+, autoreconfHook
3+4+, doCheck ? true # test suite depends on dejagnu which cannot be used during bootstrapping
5+, dejagnu
6+}:
7+8+stdenv.mkDerivation rec {
9+ pname = "libffi";
10+ version = "3.3";
11+12+ src = fetchurl {
13+ url = "https://github.com/libffi/libffi/releases/download/v${version}/${pname}-${version}.tar.gz";
14+ hash = "sha256-cvunkicD3fp6Ao1ROsFahcjVTI1n9V+lpIAohdxlIFY=";
15+ };
16+17+ patches = [];
18+19+ outputs = [ "out" "dev" "man" "info" ];
20+21+ configureFlags = [
22+ "--with-gcc-arch=generic" # no detection of -march= or -mtune=
23+ "--enable-pax_emutramp"
24+25+ # Causes issues in downstream packages which misuse ffi_closure_alloc
26+ # Reenable once these issues are fixed and merged:
27+ # https://gitlab.haskell.org/ghc/ghc/-/merge_requests/6155
28+ # https://gitlab.gnome.org/GNOME/gobject-introspection/-/merge_requests/283
29+ "--disable-exec-static-tramp"
30+ ];
31+32+ preCheck = ''
33+ # The tests use -O0 which is not compatible with -D_FORTIFY_SOURCE.
34+ NIX_HARDENING_ENABLE=''${NIX_HARDENING_ENABLE/fortify/}
35+ '';
36+37+ dontStrip = stdenv.hostPlatform != stdenv.buildPlatform; # Don't run the native `strip' when cross-compiling.
38+39+ inherit doCheck;
40+41+ checkInputs = [ dejagnu ];
42+43+ meta = with lib; {
44+ description = "A foreign function call interface library";
45+ longDescription = ''
46+ The libffi library provides a portable, high level programming
47+ interface to various calling conventions. This allows a
48+ programmer to call any function specified by a call interface
49+ description at run-time.
50+51+ FFI stands for Foreign Function Interface. A foreign function
52+ interface is the popular name for the interface that allows code
53+ written in one language to call code written in another
54+ language. The libffi library really only provides the lowest,
55+ machine dependent layer of a fully featured foreign function
56+ interface. A layer must exist above libffi that handles type
57+ conversions for values passed between the two languages.
58+ '';
59+ homepage = "http://sourceware.org/libffi/";
60+ license = licenses.mit;
61+ maintainers = with maintainers; [ armeenm ];
62+ platforms = platforms.all;
63+ };
64+}