www-nginx/ngx-brotli: move old to 1.0.0_rc_p20231109, use system libbrotlienc

This imports a patch[1] from upstream GitHub PR. The patch links to the
system Brotli lib using pkgconfig.

Since the system Brotli lib is used in favour of the bundled Brotli lib,
the commit drops bundled Brotli from the package.

Many thanks to Mikel Olasagasti Uranga for writing the patch[1].

[1]: https://github.com/google/ngx_brotli/pull/172

Closes: https://bugs.gentoo.org/959780
Signed-off-by: Zurab Kvachadze <zurabid2016@gmail.com>
Part-of: https://github.com/gentoo/gentoo/pull/42955
Closes: https://github.com/gentoo/gentoo/pull/42955
Signed-off-by: Sam James <sam@gentoo.org>
This commit is contained in:
Zurab Kvachadze
2025-07-11 00:17:46 +02:00
committed by Sam James
parent 3de03b7a1e
commit 4b7bb29ace
3 changed files with 109 additions and 10 deletions

View File

@@ -1,2 +1 @@
DIST brotli-ed738e842d2fbdf2d6459e39267a633c4a9b2f5d.tar.gz 512305 BLAKE2B b646e4565386870443d006a97a13b295c2c66de448e501f809700c303bb3daf5e4f84a2dacec16c43a534879243e4cda9292072630f13d5f7ca54f2c4372e560 SHA512 f493e7f15ca2804ae8715e48bdc954680f527533e684ec3762a7d49d05890915194289ed948c8cce95644274e1dcab952dcfbc84c0108aaf79f35f20270ffe6a
DIST ngx-brotli-a71f9312c2deb28875acc7bacfdd5695a111aa53.tar.gz 16387 BLAKE2B 2883711581ff5073f8e6451078c046f70323e1c893c3b70f8feb1abfc6ccb420ddb5f5d3b5131eb127538cf9b0cd0d9843d450cacd49b7fc7dfeb0a8c8865de8 SHA512 62a904f1a8e63e169cf09517189d65dd9ee1a6cca2a8461bc4ea29d72f97b940048e34f8dcc4a332785ab603be79f1830e371d920f06bdaa460d7e57915cafdc

View File

@@ -0,0 +1,103 @@
From 0b42e57bb6fa4e039585f1ebac8584b8d45b7a2a Mon Sep 17 00:00:00 2001
From: Mikel Olasagasti Uranga <mikel@olasagasti.info>
Date: Wed, 16 Apr 2025 23:50:52 +0200
Subject: [PATCH] filter/config: restore "systemfirst, bundledfallback" Brotli detection
63ca02a made the bundled submodule mandatory by hardcoding
deps/brotli and linking the objects produced in ../out. This broke
distribution builds that are required to link against the shared
libbrotli already shipped by the system.
This change brings back the original behaviour while integrating
`pkg-config`:
* Detect a system installation with `pkg-config libbrotlienc`;
if found, use the reported cflags/libs and compile only the NGINX
wrapper source.
* If no suitable system copy exists, fall back to the bundled
git submodule exactly as before.
* Abort early with a clear error message when neither flavour is
available, including instructions to initialise the submodule.
No commandline flags are needed for the common case; packagers simply
omit the submodule and let `pkg-config` do the work, while end users
who prefer the bundled copy keep the submodule checked out.
Fixes: 63ca02a (“filter: require bundled Brotli out/ artifacts”)
Signed-off-by: Mikel Olasagasti Uranga <mikel@olasagasti.info>
---
filter/config | 50 +++++++++++++++++++++++++++++++++++---------------
1 file changed, 35 insertions(+), 15 deletions(-)
diff --git a/filter/config b/filter/config
index 167e1d2..98b2504 100644
--- a/filter/config
+++ b/filter/config
@@ -42,31 +42,51 @@ fi
ngx_module_type=HTTP_FILTER
ngx_module_name=ngx_http_brotli_filter_module
-brotli="$ngx_addon_dir/deps/brotli/c"
-if [ ! -f "$brotli/include/brotli/encode.h" ]; then
-cat << END
+use_system_brotli=no
+brotli_prefix=""
+
+if pkg-config --exists libbrotlienc 2>/dev/null ; then
+ brotli_prefix=$(pkg-config --variable=prefix libbrotlienc)
+ if [ -f "$brotli_prefix/include/brotli/encode.h" ]; then
+ use_system_brotli=yes
+ fi
+fi
+
+if [ "$use_system_brotli" = no ]; then
+ brotli="$ngx_addon_dir/deps/brotli/c"
+ if [ ! -f "$brotli/include/brotli/encode.h" ]; then
+cat <<END
-$0: error: \
-Brotli library is missing from the $brotli directory.
+$0: error:
+Brotli library not found neither a system installation detected
+(tried \`pkg-config libbrotlienc\`) nor the bundled submodule present.
-Please make sure that the git submodule has been checked out:
+If you want to use the bundled copy, run:
cd $ngx_addon_dir && git submodule update --init && cd $PWD
END
- exit 1
+ exit 1
+ fi
fi
-BROTLI_OUTPUT_DIRECTORY="$brotli/../out"
-BROTLI_ENC_H="$brotli/include/brotli/encode.h \
- $brotli/include/brotli/port.h \
- $brotli/include/brotli/types.h"
+ngx_module_srcs="$BROTLI_MODULE_SRC_DIR/ngx_http_brotli_filter_module.c"
+if [ "$use_system_brotli" = yes ]; then
+ ngx_module_incs="$(pkg-config --cflags-only-I libbrotlienc)"
+ ngx_module_libs="$(pkg-config --libs libbrotlienc) -lm"
+ ngx_module_deps=""
+else
+ BROTLI_OUTPUT_DIRECTORY="$brotli/../out"
+ BROTLI_ENC_H="$brotli/include/brotli/encode.h \
+ $brotli/include/brotli/port.h \
+ $brotli/include/brotli/types.h"
+
+ ngx_module_incs="$brotli/include"
+ ngx_module_deps="$BROTLI_ENC_H"
+ ngx_module_libs="-L$BROTLI_OUTPUT_DIRECTORY -lbrotlienc -lbrotlicommon -lm"
+fi
-ngx_module_incs="$brotli/include"
-ngx_module_deps="$BROTLI_ENC_H"
-ngx_module_srcs="$BROTLI_MODULE_SRC_DIR/ngx_http_brotli_filter_module.c"
-ngx_module_libs="-L$BROTLI_OUTPUT_DIRECTORY -lbrotlienc -lbrotlicommon -lm"
ngx_module_order="$ngx_module_name \
ngx_pagespeed \
ngx_http_postpone_filter_module \

View File

@@ -4,8 +4,6 @@
EAPI=8
NGX_BROTLI_P="ngx-brotli-a71f9312c2deb28875acc7bacfdd5695a111aa53"
# A submodule.
BROTLI_P="brotli-ed738e842d2fbdf2d6459e39267a633c4a9b2f5d"
MY_PN="${PN//-/_}"
NGINX_MOD_S="${WORKDIR}/${MY_PN}-${NGX_BROTLI_P#ngx-brotli-}"
@@ -15,17 +13,16 @@ DESCRIPTION="NGINX module for Brotli compression"
HOMEPAGE="https://github.com/google/ngx_brotli"
SRC_URI="
https://github.com/google/ngx_brotli/archive/${NGX_BROTLI_P#ngx-brotli-}.tar.gz -> ${NGX_BROTLI_P}.tar.gz
https://github.com/google/brotli/archive/${BROTLI_P#brotli-}.tar.gz -> ${BROTLI_P}.tar.gz
"
LICENSE="BSD-2"
SLOT="0"
KEYWORDS="~amd64 ~arm64"
src_unpack() {
nginx-module_src_unpack
BDEPEND="virtual/pkgconfig"
DEPEND="app-arch/brotli:="
RDEPEND="${DEPEND}"
# Move the submodule to its place.
rmdir "${NGINX_MOD_S}/deps/brotli" || die "rmdir failed"
mv "./${BROTLI_P}" "${NGINX_MOD_S}/deps/brotli" || die "mv failed"
}
PATCHES=(
"${FILESDIR}/${PN}-1.0.0_rc_p20231109-use-system-brotli.patch"
)