Skip to content

Commit

Permalink
phps: Factor out prev.lib
Browse files Browse the repository at this point in the history
Makes the code slightly cleaner.
  • Loading branch information
jtojnar authored and drupol committed Jan 23, 2025
1 parent f0cc17b commit 249bd98
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions pkgs/phps.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,18 @@ let

libxml2_12 = prev.callPackage ./libxml2/2.12.nix { };

inherit (prev) lib;

_mkArgs =
args:

let
libxml2 = if prev.lib.versionAtLeast args.version "8.1" then prev.libxml2 else libxml2_12;
libxml2 = if lib.versionAtLeast args.version "8.1" then prev.libxml2 else libxml2_12;

# Use a consistent libxml2 version.
libxslt = prev.libxslt.override { inherit libxml2; };

pcre2 = if prev.lib.versionAtLeast args.version "7.3" then prev.pcre2 else prev.pcre;
pcre2 = if lib.versionAtLeast args.version "7.3" then prev.pcre2 else prev.pcre;
in
{
inherit packageOverrides libxml2 pcre2;
Expand All @@ -29,20 +31,20 @@ let
{
patches =
attrs.patches or [ ]
++ prev.lib.optionals (prev.lib.versions.majorMinor args.version == "5.6") [
++ lib.optionals (lib.versions.majorMinor args.version == "5.6") [
# Patch to make it build with autoconf >= 2.72
# Source: https://aur.archlinux.org/packages/php56-ldap?all_deps=1#comment-954506
./patches/php56-autoconf.patch
]
++ prev.lib.optionals (prev.lib.versions.majorMinor args.version == "7.2") [
++ lib.optionals (lib.versions.majorMinor args.version == "7.2") [
# Building the bundled intl extension fails on Mac OS.
# See https://bugs.php.net/bug.php?id=76826 for more information.
(prev.pkgs.fetchurl {
url = "https://bugs.php.net/patch-display.php?bug_id=76826&patch=bug76826.poc.0.patch&revision=1538723399&download=1";
hash = "sha256-6JoyxVir3AG3VC6Q0uKrfb/ZFjs9/db+uZg3ssBdqzw=";
})
]
++ prev.lib.optionals (prev.lib.versionOlder args.version "7.4") [
++ lib.optionals (lib.versionOlder args.version "7.4") [
# Handle macos versions that don't start with 10.* in libtool.
# https://github.com/php/php-src/commit/d016434ad33284dfaceb8d233351d34356566d7d
(prev.pkgs.fetchpatch {
Expand All @@ -56,32 +58,32 @@ let

configureFlags =
attrs.configureFlags
++ prev.lib.optionals (prev.lib.versionOlder args.version "7.4") [
++ lib.optionals (lib.versionOlder args.version "7.4") [
# phar extension’s build system expects hash or it will degrade.
"--enable-hash"

"--enable-libxml"
"--with-libxml-dir=${libxml2.dev}"
]
++ prev.lib.optionals (prev.lib.versions.majorMinor args.version == "7.3") [
++ lib.optionals (lib.versions.majorMinor args.version == "7.3") [
# Force use of pkg-config.
# https://github.com/php/php-src/blob/php-7.3.33/ext/pcre/config0.m4#L14
"--with-pcre-regex=/usr"
]
++ prev.lib.optionals (prev.lib.versionOlder args.version "7.3") [
++ lib.optionals (lib.versionOlder args.version "7.3") [
# Only PCRE 1 supported and no pkg-config.
"--with-pcre-regex=${prev.pcre.dev}"
"PCRE_LIBDIR=${prev.pcre}"
];

buildInputs =
attrs.buildInputs
++ prev.lib.optionals (prev.lib.versionOlder args.version "7.1") [
++ lib.optionals (lib.versionOlder args.version "7.1") [
prev.libxcrypt
];

preConfigure =
prev.lib.optionalString (prev.lib.versionOlder args.version "7.4") ''
lib.optionalString (lib.versionOlder args.version "7.4") ''
# Workaround “configure: error: Your system does not support systemd.”
# caused by PHP build system expecting PKG_CONFIG variable to contain
# an absolute path on PHP ≤ 7.4.
Expand All @@ -94,14 +96,14 @@ let
''
+ attrs.preConfigure;
}
// prev.lib.optionalAttrs (prev.stdenv.cc.isClang) {
// lib.optionalAttrs (prev.stdenv.cc.isClang) {
# Downgrade the following errors to warnings. `-Wint-conversion` only affects PHP 7.3.
NIX_CFLAGS_COMPILE =
(attrs.NIX_CFLAGS_COMPILE or "")
+ prev.lib.optionalString (prev.lib.versionOlder args.version "8.2") " -Wno-compare-distinct-pointer-types -Wno-implicit-const-int-float-conversion -Wno-deprecated-declarations -Wno-incompatible-function-pointer-types -Wno-incompatible-pointer-types-discards-qualifiers"
+ prev.lib.optionalString (prev.lib.versionOlder args.version "8.0") " -Wno-implicit-int -Wno-implicit-function-declaration"
+ prev.lib.optionalString (
prev.lib.versionAtLeast args.version "7.3" && prev.lib.versionOlder args.version "7.4"
+ lib.optionalString (lib.versionOlder args.version "8.2") " -Wno-compare-distinct-pointer-types -Wno-implicit-const-int-float-conversion -Wno-deprecated-declarations -Wno-incompatible-function-pointer-types -Wno-incompatible-pointer-types-discards-qualifiers"
+ lib.optionalString (lib.versionOlder args.version "8.0") " -Wno-implicit-int -Wno-implicit-function-declaration"
+ lib.optionalString (
lib.versionAtLeast args.version "7.3" && lib.versionOlder args.version "7.4"
) " -Wno-int-conversion";
};

Expand All @@ -113,13 +115,13 @@ let
prevArgs:

# Only pass these attributes if the package function actually expects them.
prev.lib.filterAttrs (key: _v: builtins.hasAttr key prevArgs) {
lib.filterAttrs (key: _v: builtins.hasAttr key prevArgs) {
inherit libxml2 libxslt pcre2;

# For passing pcre2 to stuff called with callPackage in php-packages.nix.
pkgs =
prev
// (prev.lib.makeScope prev.newScope (self: {
// (lib.makeScope prev.newScope (self: {
inherit libxml2 libxslt pcre2;
}));
}
Expand Down

0 comments on commit 249bd98

Please sign in to comment.