about summary refs log tree commit diff
path: root/pkgs/top-level/php-packages.nix
diff options
context:
space:
mode:
authortalyz <kim.lindberger@gmail.com>2020-03-24 19:30:18 +0100
committerElis Hirwing <elis@hirwing.se>2020-04-03 10:11:13 +0200
commit282337799b08844c145c295110f20025541f829a (patch)
tree5ef0cedc3b2d1d767fddbf5c99478003e3789eff /pkgs/top-level/php-packages.nix
parentda8ca2be2ffd5964684fa81b953f933c9beaa7ed (diff)
downloadnixlib-282337799b08844c145c295110f20025541f829a.tar
nixlib-282337799b08844c145c295110f20025541f829a.tar.gz
nixlib-282337799b08844c145c295110f20025541f829a.tar.bz2
nixlib-282337799b08844c145c295110f20025541f829a.tar.lz
nixlib-282337799b08844c145c295110f20025541f829a.tar.xz
nixlib-282337799b08844c145c295110f20025541f829a.tar.zst
nixlib-282337799b08844c145c295110f20025541f829a.zip
php: Build an even slimmer base
This moves yet more extensions from the base build to
phpPackages.ext. Some of the extensions are a bit quirky and need
patching for this to work, most notably mysqlnd and opcache.

Two new parameters are introduced for mkExtension - internalDeps and
postPhpize. internalDeps is used to specify which other internal
extensions the current extension depends on, in order to provide them
at build time. postPhpize is for when patches and quirks need to be
applied after running phpize.

Patch notes:

- For opcache, older versions of PHP have a bug where header files are
  included in the wrong order.

- For mysqlnd, the config.h is never included, so we include it in the
  main header file, mysqlnd.h. Also, the configure script doesn't add
  the necessary library link flags, so we add them to the variable
  configure should have added them to.
Diffstat (limited to 'pkgs/top-level/php-packages.nix')
-rw-r--r--pkgs/top-level/php-packages.nix128
1 files changed, 111 insertions, 17 deletions
diff --git a/pkgs/top-level/php-packages.nix b/pkgs/top-level/php-packages.nix
index ab0abf7b26bb..c819a33b620f 100644
--- a/pkgs/top-level/php-packages.nix
+++ b/pkgs/top-level/php-packages.nix
@@ -1,8 +1,9 @@
-{ stdenv, lib, pkgs, fetchgit, php, autoconf, pkgconfig, re2c
+{ stdenv, lib, pkgs, fetchgit, php, autoconf, pkgconfig, re2c, gettext
 , bzip2, curl, libxml2, openssl, gmp, icu, oniguruma, libsodium, html-tidy
 , libzip, zlib, pcre, pcre2, libxslt, aspell, openldap, cyrus_sasl, uwimap
 , pam, libiconv, enchant1, libXpm, gd, libwebp, libjpeg, libpng, freetype
-, libffi, freetds, postgresql, sqlite, recode, net-snmp, unixODBC }:
+, libffi, freetds, postgresql, sqlite, net-snmp, unixODBC, libedit, readline
+}:
 
 let
   self = with self; {
@@ -709,6 +710,8 @@ let
     mkExtension = {
       name
       , configureFlags ? [ "--enable-${name}" ]
+      , internalDeps ? []
+      , postPhpize ? ""
       , buildInputs ? []
       , zendExtension ? false
       , ...
@@ -720,10 +723,24 @@ let
 
       enableParallelBuilding = true;
       nativeBuildInputs = [ php autoconf pkgconfig re2c ];
-      inherit configureFlags buildInputs zendExtension;
-
-      preConfigure = "phpize";
-
+      inherit configureFlags internalDeps buildInputs zendExtension;
+
+      preConfigure = ''
+        nullglobRestore=$(shopt -p nullglob)
+        shopt -u nullglob   # To make ?-globbing work
+
+        # Some extensions have a config0.m4 or config9.m4
+        if [ -f config?.m4 ]; then
+          mv config?.m4 config.m4
+        fi
+
+        $nullglobRestore
+        phpize
+        ${postPhpize}
+        ${lib.concatMapStringsSep "\n"
+          (dep: "mkdir -p ext; ln -s ../../${dep} ext/")
+          internalDeps}
+      '';
       installPhase = ''
         mkdir -p $out/lib/php/extensions
         cp modules/${name}.so $out/lib/php/extensions/ext-${name}.so
@@ -779,6 +796,10 @@ let
           "--enable-gd-jis-conv"
         ];
         enable = lib.versionOlder php.version "7.4"; }
+      { name = "gettext";
+        buildInputs = [ gettext ];
+        postPhpize = ''substituteInPlace configure --replace 'as_fn_error $? "Cannot locate header file libintl.h" "$LINENO" 5' ':' '';
+        configureFlags = "--with-gettext=${gettext}"; }
       { name = "gmp";
         buildInputs = [ gmp ];
         configureFlags = [ "--with-gmp=${gmp.dev}" ]; }
@@ -804,29 +825,96 @@ let
           "LDAP_LIBDIR=${openldap.out}/lib"
         ] ++ lib.optional stdenv.isLinux "--with-ldap-sasl=${cyrus_sasl.dev}"; }
       { name = "mbstring"; buildInputs = [ oniguruma ]; }
-      { name = "mysqli"; configureFlags = [ "--with-mysqli=mysqlnd" "--with-mysql-sock=/run/mysqld/mysqld.sock" ]; }
+      { name = "mysqli";
+        internalDeps = [ "mysqlnd" ];
+        configureFlags = [ "--with-mysqli=mysqlnd" "--with-mysql-sock=/run/mysqld/mysqld.sock" ]; }
+      { name = "mysqlnd";
+        buildInputs = [ zlib openssl ];
+        # The configure script doesn't correctly add library link
+        # flags, so we add them to the variable used by the Makefile
+        # when linking.
+        MYSQLND_SHARED_LIBADD = "-lssl -lcrypto -lz";
+        # The configure script builds a config.h which is never
+        # included. Let's include it in the main header file
+        # included by all .c-files.
+        patches = [
+          (pkgs.writeText "mysqlnd_config.patch" ''
+            --- a/mysqlnd.h
+            +++ b/mysqlnd.h
+            @@ -1,3 +1,6 @@
+            +#ifdef HAVE_CONFIG_H
+            +#include "config.h"
+            +#endif
+             /*
+               +----------------------------------------------------------------------+
+               | Copyright (c) The PHP Group                                          |
+          '')
+        ];
+        postPhpize = lib.optionalString (lib.versionOlder php.version "7.4") ''
+          substituteInPlace configure --replace '$OPENSSL_LIBDIR' '${openssl}/lib' \
+                                      --replace '$OPENSSL_INCDIR' '${openssl.dev}/include'
+        ''; }
       # oci8 (7.4, 7.3, 7.2)
       # odbc (7.4, 7.3, 7.2)
-      { name = "opcache"; buildInputs = [ pcre' ]; zendExtension = true; }
+      { name = "opcache";
+        buildInputs = [ pcre' ];
+        # HAVE_OPCACHE_FILE_CACHE is defined in config.h, which is
+        # included from ZendAccelerator.h, but ZendAccelerator.h is
+        # included after the ifdef...
+        patches = lib.optional (lib.versionOlder php.version "7.4") [
+          (pkgs.writeText "zend_file_cache_config.patch" ''
+            --- a/zend_file_cache.c
+            +++ b/zend_file_cache.c
+            @@ -27,9 +27,9 @@
+             #include "ext/standard/md5.h"
+             #endif
+
+            +#include "ZendAccelerator.h"
+             #ifdef HAVE_OPCACHE_FILE_CACHE
+
+            -#include "ZendAccelerator.h"
+             #include "zend_file_cache.h"
+             #include "zend_shared_alloc.h"
+             #include "zend_accelerator_util_funcs.h"
+          '') ];
+        zendExtension = true; }
+      { name = "openssl";
+        buildInputs = [ openssl ];
+        configureFlags = [ "--with-openssl" ]; }
       { name = "pcntl"; }
       { name = "pdo"; }
       { name = "pdo_dblib";
+        internalDeps = [ "pdo" ];
         configureFlags = [ "--with-pdo-dblib=${freetds}" ];
         # Doesn't seem to work on darwin.
         enable = (!stdenv.isDarwin); }
       # pdo_firebird (7.4, 7.3, 7.2)
-      { name = "pdo_mysql"; configureFlags = [ "--with-pdo-mysql=mysqlnd" ]; }
+      { name = "pdo_mysql";
+        internalDeps = [ "mysqlnd" "pdo" ];
+        configureFlags = [ "--with-pdo-mysql=mysqlnd" ]; }
       # pdo_oci (7.4, 7.3, 7.2)
-      { name = "pdo_odbc"; configureFlags = [ "--with-pdo-odbc=unixODBC,${unixODBC}" ]; }
-      { name = "pdo_pgsql"; configureFlags = [ "--with-pdo-pgsql=${postgresql}" ]; }
-      { name = "pdo_sqlite"; buildInputs = [ sqlite ]; configureFlags = [ "--with-pdo-sqlite=${sqlite.dev}" ]; }
-      { name = "pgsql"; buildInputs = [ pcre' ]; configureFlags = [ "--with-pgsql=${postgresql}" ]; }
+      { name = "pdo_odbc";
+        internalDeps = [ "pdo" ];
+        configureFlags = [ "--with-pdo-odbc=unixODBC,${unixODBC}" ]; }
+      { name = "pdo_pgsql";
+        internalDeps = [ "pdo" ];
+        configureFlags = [ "--with-pdo-pgsql=${postgresql}" ]; }
+      { name = "pdo_sqlite";
+        internalDeps = [ "pdo" ];
+        buildInputs = [ sqlite ];
+        configureFlags = [ "--with-pdo-sqlite=${sqlite.dev}" ]; }
+      { name = "pgsql";
+        buildInputs = [ pcre' ];
+        configureFlags = [ "--with-pgsql=${postgresql}" ]; }
       { name = "posix"; }
       { name = "pspell"; configureFlags = [ "--with-pspell=${aspell}" ]; }
-      { name = "recode";
-        configureFlags = [ "--with-recode=${recode}" ];
-        # Removed in php 7.4.
-        enable = lib.versionOlder php.version "7.4"; }
+      { name = "readline";
+        buildInputs = [ libedit readline ];
+        configureFlags = [ "--with-readline=${readline.dev}" ];
+        postPhpize = lib.optionalString (lib.versionOlder php.version "7.4") ''
+          substituteInPlace configure --replace 'as_fn_error $? "Please reinstall libedit - I cannot find readline.h" "$LINENO" 5' ':'
+        ''; }
+      # recode (7.3, 7.2)
       { name = "session"; }
       { name = "shmop"; }
       { name = "simplexml";
@@ -846,6 +934,7 @@ let
           ++ lib.optional (lib.versionOlder php.version "7.4") [ "--with-libxml-dir=${libxml2.dev}" ]; }
       { name = "sockets"; }
       { name = "sodium"; buildInputs = [ libsodium ]; }
+      { name = "sqlite3"; buildInputs = [ sqlite ]; }
       { name = "sysvmsg"; }
       { name = "sysvsem"; }
       { name = "sysvshm"; }
@@ -853,6 +942,7 @@ let
       { name = "tokenizer"; }
       { name = "wddx";
         buildInputs = [ libxml2 ];
+        internalDeps = [ "session" ];
         configureFlags = [ "--enable-wddx" "--with-libxml-dir=${libxml2.dev}" ];
         # Removed in php 7.4.
         enable = lib.versionOlder php.version "7.4"; }
@@ -882,6 +972,10 @@ let
         configureFlags = [ "--with-zip" ]
           ++ lib.optional (lib.versionOlder php.version "7.4") [ "--with-zlib-dir=${zlib.dev}" ]
           ++ lib.optional (lib.versionOlder php.version "7.3") [ "--with-libzip" ]; }
+      { name = "zlib";
+        buildInputs = [ zlib ];
+        configureFlags = [ "--with-zlib" ]
+          ++ lib.optional (lib.versionOlder php.version "7.4") [ "--with-zlib-dir=${zlib.dev}" ]; }
     ];
 
     # Convert the list of attrs: