···11+{ lib, stdenv, fetchurl, fetchpatch
22+, autoreconfHook
33+44+, doCheck ? true # test suite depends on dejagnu which cannot be used during bootstrapping
55+, dejagnu
66+}:
77+88+stdenv.mkDerivation rec {
99+ pname = "libffi";
1010+ version = "3.3";
1111+1212+ src = fetchurl {
1313+ url = "https://github.com/libffi/libffi/releases/download/v${version}/${pname}-${version}.tar.gz";
1414+ hash = "sha256-cvunkicD3fp6Ao1ROsFahcjVTI1n9V+lpIAohdxlIFY=";
1515+ };
1616+1717+ patches = [];
1818+1919+ outputs = [ "out" "dev" "man" "info" ];
2020+2121+ configureFlags = [
2222+ "--with-gcc-arch=generic" # no detection of -march= or -mtune=
2323+ "--enable-pax_emutramp"
2424+2525+ # Causes issues in downstream packages which misuse ffi_closure_alloc
2626+ # Reenable once these issues are fixed and merged:
2727+ # https://gitlab.haskell.org/ghc/ghc/-/merge_requests/6155
2828+ # https://gitlab.gnome.org/GNOME/gobject-introspection/-/merge_requests/283
2929+ "--disable-exec-static-tramp"
3030+ ];
3131+3232+ preCheck = ''
3333+ # The tests use -O0 which is not compatible with -D_FORTIFY_SOURCE.
3434+ NIX_HARDENING_ENABLE=''${NIX_HARDENING_ENABLE/fortify/}
3535+ '';
3636+3737+ dontStrip = stdenv.hostPlatform != stdenv.buildPlatform; # Don't run the native `strip' when cross-compiling.
3838+3939+ inherit doCheck;
4040+4141+ checkInputs = [ dejagnu ];
4242+4343+ meta = with lib; {
4444+ description = "A foreign function call interface library";
4545+ longDescription = ''
4646+ The libffi library provides a portable, high level programming
4747+ interface to various calling conventions. This allows a
4848+ programmer to call any function specified by a call interface
4949+ description at run-time.
5050+5151+ FFI stands for Foreign Function Interface. A foreign function
5252+ interface is the popular name for the interface that allows code
5353+ written in one language to call code written in another
5454+ language. The libffi library really only provides the lowest,
5555+ machine dependent layer of a fully featured foreign function
5656+ interface. A layer must exist above libffi that handles type
5757+ conversions for values passed between the two languages.
5858+ '';
5959+ homepage = "http://sourceware.org/libffi/";
6060+ license = licenses.mit;
6161+ maintainers = with maintainers; [ armeenm ];
6262+ platforms = platforms.all;
6363+ };
6464+}