Skip to content

Commit 83447b6

Browse files
committed
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 varnishcache/varnish-cache#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 varnishcache/varnish-cache#4347
1 parent ec57efa commit 83447b6

File tree

3 files changed

+105
-0
lines changed

3 files changed

+105
-0
lines changed

pkgs/servers/varnish/default.nix

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
lib,
33
stdenv,
44
fetchurl,
5+
fetchpatch2,
56
pcre,
67
pcre2,
78
jemalloc,
@@ -56,6 +57,24 @@ let
5657

5758
buildFlags = [ "localstatedir=/var/run" ];
5859

60+
patches =
61+
lib.optionals (stdenv.isDarwin && lib.versionAtLeast version "7.7") [
62+
# Fix VMOD section attribute on macOS
63+
# Unreleased commit on master
64+
(fetchpatch2 {
65+
url = "https://github.com/varnishcache/varnish-cache/commit/a95399f5b9eda1bfdba6ee6406c30a1ed0720167.patch";
66+
hash = "sha256-T7DIkmnq0O+Cr9DTJS4/rOtg3J6PloUo8jHMWoUZYYk=";
67+
})
68+
# Fix endian.h compatibility on macOS
69+
# PR: https://github.com/varnishcache/varnish-cache/pull/4339
70+
./patches/0001-fix-endian-h-compatibility-on-macos.patch
71+
]
72+
++ lib.optionals (stdenv.isDarwin && lib.versionOlder version "7.6") [
73+
# Fix duplicate OS_CODE definitions on macOS
74+
# PR: https://github.com/varnishcache/varnish-cache/pull/4347
75+
./patches/0002-fix-duplicate-os-code-definitions-on-macos.patch
76+
];
77+
5978
postPatch = ''
6079
substituteInPlace bin/varnishtest/vtc_main.c --replace /bin/rm "${coreutils}/bin/rm"
6180
'';
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
From 7a1c7020db85699e0693d637f6e31d49bf9ca3d0 Mon Sep 17 00:00:00 2001
2+
From: Rui Chen <rui@chenrui.dev>
3+
Date: Sun, 25 May 2025 23:54:29 -0400
4+
Subject: [PATCH] libvarnish: Fix endian.h compatibility for macOS builds
5+
6+
Signed-off-by: Rui Chen <rui@chenrui.dev>
7+
---
8+
lib/libvarnish/vsha256.c | 12 ++++++++----
9+
1 file changed, 8 insertions(+), 4 deletions(-)
10+
11+
diff --git a/lib/libvarnish/vsha256.c b/lib/libvarnish/vsha256.c
12+
index 29f97fe40..541b6e612 100644
13+
--- a/lib/libvarnish/vsha256.c
14+
+++ b/lib/libvarnish/vsha256.c
15+
@@ -31,7 +31,14 @@
16+
17+
#include "config.h"
18+
19+
-#ifndef __DARWIN_BYTE_ORDER
20+
+#ifdef __APPLE__
21+
+# include <machine/endian.h>
22+
+# include <libkern/OSByteOrder.h>
23+
+# define htobe32(x) OSSwapHostToBigInt32(x)
24+
+# define htobe64(x) OSSwapHostToBigInt64(x)
25+
+# define VBYTE_ORDER __DARWIN_BYTE_ORDER
26+
+# define VBIG_ENDIAN __DARWIN_BIG_ENDIAN
27+
+#else
28+
# include <endian.h>
29+
# ifdef _BYTE_ORDER
30+
# define VBYTE_ORDER _BYTE_ORDER
31+
@@ -43,9 +50,6 @@
32+
# else
33+
# define VBIG_ENDIAN __BIG_ENDIAN
34+
# endif
35+
-#else
36+
-# define VBYTE_ORDER __DARWIN_BYTE_ORDER
37+
-# define VBIG_ENDIAN __DARWIN_BIG_ENDIAN
38+
#endif
39+
40+
#ifndef VBYTE_ORDER
41+
--
42+
2.49.0
43+
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
From f56b314408d22252bf62d6cd2e098cf8139bd048 Mon Sep 17 00:00:00 2001
2+
From: Sander <hey@sandydoo.me>
3+
Date: Fri, 13 Jun 2025 01:12:59 +0200
4+
Subject: [PATCH] build: fix duplicate OS_CODE definitions on macOS
5+
6+
`TARGET_OS_MAC` and `__APPLE__` are both true on macOS, which results in
7+
duplicate definitions for `OS_CODE`.
8+
9+
Upstream removed the check for `TARGET_OS_MAC`, as well as the ancient
10+
compat code, in
11+
https://github.com/madler/zlib/commit/4bd9a71f3539b5ce47f0c67ab5e01f3196dc8ef9.
12+
13+
This was fixed in varnish >= 7.6 as part of https://github.com/varnishcache/varnish-cache/commit/86df12b6c1ad8208899ea353fdcbea227356fcf8.
14+
---
15+
lib/libvgz/zutil.h | 11 +----------
16+
1 file changed, 1 insertion(+), 10 deletions(-)
17+
18+
diff --git a/lib/libvgz/zutil.h b/lib/libvgz/zutil.h
19+
index 1c80e3842..294ea2b2d 100644
20+
--- a/lib/libvgz/zutil.h
21+
+++ b/lib/libvgz/zutil.h
22+
@@ -137,17 +137,8 @@ extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
23+
# endif
24+
#endif
25+
26+
-#if defined(MACOS) || defined(TARGET_OS_MAC)
27+
+#if defined(MACOS)
28+
# define OS_CODE 7
29+
-# ifndef Z_SOLO
30+
-# if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
31+
-# include <unix.h> /* for fdopen */
32+
-# else
33+
-# ifndef fdopen
34+
-# define fdopen(fd,mode) NULL /* No fdopen() */
35+
-# endif
36+
-# endif
37+
-# endif
38+
#endif
39+
40+
#ifdef __acorn
41+
--
42+
2.49.0
43+

0 commit comments

Comments
 (0)