about summary refs log tree commit diff
path: root/nixpkgs/pkgs/development/libraries/libffi
diff options
context:
space:
mode:
Diffstat (limited to 'nixpkgs/pkgs/development/libraries/libffi')
-rw-r--r--nixpkgs/pkgs/development/libraries/libffi/3.3.nix69
-rw-r--r--nixpkgs/pkgs/development/libraries/libffi/default.nix79
-rw-r--r--nixpkgs/pkgs/development/libraries/libffi/fix-implicit-fun-decl.patch46
3 files changed, 194 insertions, 0 deletions
diff --git a/nixpkgs/pkgs/development/libraries/libffi/3.3.nix b/nixpkgs/pkgs/development/libraries/libffi/3.3.nix
new file mode 100644
index 000000000000..294717d1fb1c
--- /dev/null
+++ b/nixpkgs/pkgs/development/libraries/libffi/3.3.nix
@@ -0,0 +1,69 @@
+{ lib, stdenv, fetchurl, fetchpatch
+, autoreconfHook
+
+, doCheck ? true # test suite depends on dejagnu which cannot be used during bootstrapping
+, dejagnu
+}:
+
+stdenv.mkDerivation rec {
+  pname = "libffi";
+  version = "3.3";
+
+  src = fetchurl {
+    url = "https://github.com/libffi/libffi/releases/download/v${version}/${pname}-${version}.tar.gz";
+    hash = "sha256-cvunkicD3fp6Ao1ROsFahcjVTI1n9V+lpIAohdxlIFY=";
+  };
+
+  patches = [];
+
+  outputs = [ "out" "dev" "man" "info" ];
+
+  configureFlags = [
+    "--with-gcc-arch=generic" # no detection of -march= or -mtune=
+    "--enable-pax_emutramp"
+
+    # Causes issues in downstream packages which misuse ffi_closure_alloc
+    # Reenable once these issues are fixed and merged:
+    # https://gitlab.haskell.org/ghc/ghc/-/merge_requests/6155
+    # https://gitlab.gnome.org/GNOME/gobject-introspection/-/merge_requests/283
+    "--disable-exec-static-tramp"
+  ];
+
+  # with fortify3, tests fail for some reason
+  hardeningDisable = [ "fortify3" ];
+
+  preCheck = ''
+    # The tests use -O0 which is not compatible with -D_FORTIFY_SOURCE.
+    NIX_HARDENING_ENABLE=''${NIX_HARDENING_ENABLE/fortify/}
+  '';
+
+  dontStrip = stdenv.hostPlatform != stdenv.buildPlatform; # Don't run the native `strip' when cross-compiling.
+
+  inherit doCheck;
+
+  nativeCheckInputs = [ dejagnu ];
+
+  meta = with lib; {
+    description = "A foreign function call interface library";
+    longDescription = ''
+      The libffi library provides a portable, high level programming
+      interface to various calling conventions.  This allows a
+      programmer to call any function specified by a call interface
+      description at run-time.
+
+      FFI stands for Foreign Function Interface.  A foreign function
+      interface is the popular name for the interface that allows code
+      written in one language to call code written in another
+      language.  The libffi library really only provides the lowest,
+      machine dependent layer of a fully featured foreign function
+      interface.  A layer must exist above libffi that handles type
+      conversions for values passed between the two languages.
+    '';
+    homepage = "http://sourceware.org/libffi/";
+    license = licenses.mit;
+    maintainers = with maintainers; [ armeenm ];
+    platforms = platforms.all;
+    # never built on aarch64-darwin since first introduction in nixpkgs
+    broken = stdenv.isDarwin && stdenv.isAarch64;
+  };
+}
diff --git a/nixpkgs/pkgs/development/libraries/libffi/default.nix b/nixpkgs/pkgs/development/libraries/libffi/default.nix
new file mode 100644
index 000000000000..6394a35d782d
--- /dev/null
+++ b/nixpkgs/pkgs/development/libraries/libffi/default.nix
@@ -0,0 +1,79 @@
+{ lib, stdenv, fetchurl, fetchpatch
+, autoreconfHook
+
+  # test suite depends on dejagnu which cannot be used during bootstrapping
+  # dejagnu also requires tcl which can't be built statically at the moment
+, doCheck ? !(stdenv.hostPlatform.isStatic)
+, dejagnu
+, nix-update-script
+}:
+
+stdenv.mkDerivation rec {
+  pname = "libffi";
+  version = "3.4.4";
+
+  src = fetchurl {
+    url = "https://github.com/libffi/libffi/releases/download/v${version}/${pname}-${version}.tar.gz";
+    sha256 = "sha256-1mxWrSWags8qnfxAizK/XaUjcVALhHRff7i2RXEt9nY=";
+  };
+
+  # Note: this package is used for bootstrapping fetchurl, and thus
+  # cannot use fetchpatch! All mutable patches (generated by GitHub or
+  # cgit) that are needed here should be included directly in Nixpkgs as
+  # files.
+  patches = [
+    # Fix implicit function declarations (clang-16 build failure):
+    #     https://github.com/libffi/libffi/pull/764
+    ./fix-implicit-fun-decl.patch
+  ];
+
+  strictDeps = true;
+  outputs = [ "out" "dev" "man" "info" ];
+
+  enableParallelBuilding = true;
+
+  configurePlatforms = [ "build" "host" ];
+
+  configureFlags = [
+    "--with-gcc-arch=generic" # no detection of -march= or -mtune=
+    "--enable-pax_emutramp"
+  ];
+
+  preCheck = ''
+    # The tests use -O0 which is not compatible with -D_FORTIFY_SOURCE.
+    NIX_HARDENING_ENABLE=''${NIX_HARDENING_ENABLE/fortify3/}
+    NIX_HARDENING_ENABLE=''${NIX_HARDENING_ENABLE/fortify/}
+  '';
+
+  dontStrip = stdenv.hostPlatform != stdenv.buildPlatform; # Don't run the native `strip' when cross-compiling.
+
+  inherit doCheck;
+
+  nativeCheckInputs = [ dejagnu ];
+
+  passthru = {
+    updateScript = nix-update-script { };
+  };
+
+  meta = with lib; {
+    description = "A foreign function call interface library";
+    longDescription = ''
+      The libffi library provides a portable, high level programming
+      interface to various calling conventions.  This allows a
+      programmer to call any function specified by a call interface
+      description at run-time.
+
+      FFI stands for Foreign Function Interface.  A foreign function
+      interface is the popular name for the interface that allows code
+      written in one language to call code written in another
+      language.  The libffi library really only provides the lowest,
+      machine dependent layer of a fully featured foreign function
+      interface.  A layer must exist above libffi that handles type
+      conversions for values passed between the two languages.
+    '';
+    homepage = "http://sourceware.org/libffi/";
+    license = licenses.mit;
+    maintainers = with maintainers; [ matthewbauer ];
+    platforms = platforms.all;
+  };
+}
diff --git a/nixpkgs/pkgs/development/libraries/libffi/fix-implicit-fun-decl.patch b/nixpkgs/pkgs/development/libraries/libffi/fix-implicit-fun-decl.patch
new file mode 100644
index 000000000000..c0bd32d4333c
--- /dev/null
+++ b/nixpkgs/pkgs/development/libraries/libffi/fix-implicit-fun-decl.patch
@@ -0,0 +1,46 @@
+https://github.com/libffi/libffi/commit/ce077e5565366171aa1b4438749b0922fce887a4.patch
+
+From ce077e5565366171aa1b4438749b0922fce887a4 Mon Sep 17 00:00:00 2001
+From: serge-sans-paille <serge.guelton@telecom-bretagne.eu>
+Date: Thu, 2 Feb 2023 14:46:29 +0000
+Subject: [PATCH] Forward declare open_temp_exec_file (#764)
+
+It's defined in closures.c and used in tramp.c.
+Also declare it as an hidden symbol, as it should be.
+
+Co-authored-by: serge-sans-paille <sguelton@mozilla.com>
+---
+ include/ffi_common.h | 4 ++++
+ src/tramp.c          | 4 ++++
+ 2 files changed, 8 insertions(+)
+
+diff --git a/include/ffi_common.h b/include/ffi_common.h
+index 2bd31b03d..c53a79493 100644
+--- a/include/ffi_common.h
++++ b/include/ffi_common.h
+@@ -128,6 +128,10 @@ void *ffi_data_to_code_pointer (void *data) FFI_HIDDEN;
+    static trampoline. */
+ int ffi_tramp_is_present (void *closure) FFI_HIDDEN;
+ 
++/* Return a file descriptor of a temporary zero-sized file in a
++   writable and executable filesystem. */
++int open_temp_exec_file(void) FFI_HIDDEN;
++
+ /* Extended cif, used in callback from assembly routine */
+ typedef struct
+ {
+diff --git a/src/tramp.c b/src/tramp.c
+index 7e005b054..5f19b557f 100644
+--- a/src/tramp.c
++++ b/src/tramp.c
+@@ -39,6 +39,10 @@
+ #ifdef __linux__
+ #define _GNU_SOURCE 1
+ #endif
++
++#include <ffi.h>
++#include <ffi_common.h>
++
+ #include <stdio.h>
+ #include <unistd.h>
+ #include <stdlib.h>