From 83447b6d6857d163be6caab7691b64d3590f990c Mon Sep 17 00:00:00 2001 From: Sander Date: Fri, 13 Jun 2025 01:36:23 +0200 Subject: [PATCH] varnish: fix builds of `varnish`, `varnish77`, and `varnish60` on macOS Applies several patches to get varnish to build on macOS. For `varnish77`: - Fix `endian.h` compatibility for macOS https://github.com/varnishcache/varnish-cache/pull/4339 - Fix VMOD section attribute on macOS https://github.com/varnishcache/varnish-cache/commit/a95399f5b9eda1bfdba6ee6406c30a1ed0720167.patch For `varnish60`: - Fix duplicate OS_CODE definitions on macOS https://github.com/varnishcache/varnish-cache/pull/4347 --- pkgs/servers/varnish/default.nix | 19 ++++++++ ...-fix-endian-h-compatibility-on-macos.patch | 43 +++++++++++++++++++ ...plicate-os-code-definitions-on-macos.patch | 43 +++++++++++++++++++ 3 files changed, 105 insertions(+) create mode 100644 pkgs/servers/varnish/patches/0001-fix-endian-h-compatibility-on-macos.patch create mode 100644 pkgs/servers/varnish/patches/0002-fix-duplicate-os-code-definitions-on-macos.patch diff --git a/pkgs/servers/varnish/default.nix b/pkgs/servers/varnish/default.nix index b496c0569d79..2d6930e34970 100644 --- a/pkgs/servers/varnish/default.nix +++ b/pkgs/servers/varnish/default.nix @@ -2,6 +2,7 @@ lib, stdenv, fetchurl, + fetchpatch2, pcre, pcre2, jemalloc, @@ -56,6 +57,24 @@ let buildFlags = [ "localstatedir=/var/run" ]; + patches = + lib.optionals (stdenv.isDarwin && lib.versionAtLeast version "7.7") [ + # Fix VMOD section attribute on macOS + # Unreleased commit on master + (fetchpatch2 { + url = "https://github.com/varnishcache/varnish-cache/commit/a95399f5b9eda1bfdba6ee6406c30a1ed0720167.patch"; + hash = "sha256-T7DIkmnq0O+Cr9DTJS4/rOtg3J6PloUo8jHMWoUZYYk="; + }) + # Fix endian.h compatibility on macOS + # PR: https://github.com/varnishcache/varnish-cache/pull/4339 + ./patches/0001-fix-endian-h-compatibility-on-macos.patch + ] + ++ lib.optionals (stdenv.isDarwin && lib.versionOlder version "7.6") [ + # Fix duplicate OS_CODE definitions on macOS + # PR: https://github.com/varnishcache/varnish-cache/pull/4347 + ./patches/0002-fix-duplicate-os-code-definitions-on-macos.patch + ]; + postPatch = '' substituteInPlace bin/varnishtest/vtc_main.c --replace /bin/rm "${coreutils}/bin/rm" ''; diff --git a/pkgs/servers/varnish/patches/0001-fix-endian-h-compatibility-on-macos.patch b/pkgs/servers/varnish/patches/0001-fix-endian-h-compatibility-on-macos.patch new file mode 100644 index 000000000000..1b4f3568781e --- /dev/null +++ b/pkgs/servers/varnish/patches/0001-fix-endian-h-compatibility-on-macos.patch @@ -0,0 +1,43 @@ +From 7a1c7020db85699e0693d637f6e31d49bf9ca3d0 Mon Sep 17 00:00:00 2001 +From: Rui Chen +Date: Sun, 25 May 2025 23:54:29 -0400 +Subject: [PATCH] libvarnish: Fix endian.h compatibility for macOS builds + +Signed-off-by: Rui Chen +--- + lib/libvarnish/vsha256.c | 12 ++++++++---- + 1 file changed, 8 insertions(+), 4 deletions(-) + +diff --git a/lib/libvarnish/vsha256.c b/lib/libvarnish/vsha256.c +index 29f97fe40..541b6e612 100644 +--- a/lib/libvarnish/vsha256.c ++++ b/lib/libvarnish/vsha256.c +@@ -31,7 +31,14 @@ + + #include "config.h" + +-#ifndef __DARWIN_BYTE_ORDER ++#ifdef __APPLE__ ++# include ++# include ++# define htobe32(x) OSSwapHostToBigInt32(x) ++# define htobe64(x) OSSwapHostToBigInt64(x) ++# define VBYTE_ORDER __DARWIN_BYTE_ORDER ++# define VBIG_ENDIAN __DARWIN_BIG_ENDIAN ++#else + # include + # ifdef _BYTE_ORDER + # define VBYTE_ORDER _BYTE_ORDER +@@ -43,9 +50,6 @@ + # else + # define VBIG_ENDIAN __BIG_ENDIAN + # endif +-#else +-# define VBYTE_ORDER __DARWIN_BYTE_ORDER +-# define VBIG_ENDIAN __DARWIN_BIG_ENDIAN + #endif + + #ifndef VBYTE_ORDER +-- +2.49.0 + diff --git a/pkgs/servers/varnish/patches/0002-fix-duplicate-os-code-definitions-on-macos.patch b/pkgs/servers/varnish/patches/0002-fix-duplicate-os-code-definitions-on-macos.patch new file mode 100644 index 000000000000..4153e20e08f1 --- /dev/null +++ b/pkgs/servers/varnish/patches/0002-fix-duplicate-os-code-definitions-on-macos.patch @@ -0,0 +1,43 @@ +From f56b314408d22252bf62d6cd2e098cf8139bd048 Mon Sep 17 00:00:00 2001 +From: Sander +Date: Fri, 13 Jun 2025 01:12:59 +0200 +Subject: [PATCH] build: fix duplicate OS_CODE definitions on macOS + +`TARGET_OS_MAC` and `__APPLE__` are both true on macOS, which results in +duplicate definitions for `OS_CODE`. + +Upstream removed the check for `TARGET_OS_MAC`, as well as the ancient +compat code, in +https://github.com/madler/zlib/commit/4bd9a71f3539b5ce47f0c67ab5e01f3196dc8ef9. + +This was fixed in varnish >= 7.6 as part of https://github.com/varnishcache/varnish-cache/commit/86df12b6c1ad8208899ea353fdcbea227356fcf8. +--- + lib/libvgz/zutil.h | 11 +---------- + 1 file changed, 1 insertion(+), 10 deletions(-) + +diff --git a/lib/libvgz/zutil.h b/lib/libvgz/zutil.h +index 1c80e3842..294ea2b2d 100644 +--- a/lib/libvgz/zutil.h ++++ b/lib/libvgz/zutil.h +@@ -137,17 +137,8 @@ extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */ + # endif + #endif + +-#if defined(MACOS) || defined(TARGET_OS_MAC) ++#if defined(MACOS) + # define OS_CODE 7 +-# ifndef Z_SOLO +-# if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os +-# include /* for fdopen */ +-# else +-# ifndef fdopen +-# define fdopen(fd,mode) NULL /* No fdopen() */ +-# endif +-# endif +-# endif + #endif + + #ifdef __acorn +-- +2.49.0 +