From 63ca02abdcf79c9e788d2eedcc388d2335902e52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wyatt=20O=CA=BCDay?= Date: Thu, 7 Sep 2023 06:38:47 -0400 Subject: [PATCH] Fix broken brotli build (upstream brotli dropped makefile support and sources.lst file) (#150) * Fix config file to no longer depend on a sources.lst file. * Fix readme to show how to build with latest brotli. Also make the build files real-life with optimizations (so everyone doesn't have to search for the best way to compile things). * Fix typo * Cleanup config file to not depend on out-of-date libs * Remove unused variables. --- README.md | 30 +++++++++++++++++++++++------- filter/config | 31 ++++--------------------------- 2 files changed, 27 insertions(+), 34 deletions(-) diff --git a/README.md b/README.md index 80428e9..a618b18 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,6 @@ ngx_brotli is a set of two nginx modules: - ngx_brotli filter module - used to compress responses on-the-fly, - ngx_brotli static module - used to serve pre-compressed files. -[![TravisCI Build Status](https://travis-ci.org/google/ngx_brotli.svg?branch=master)](https://travis-ci.org/google/ngx_brotli) ## Table of Contents @@ -37,6 +36,29 @@ Both Brotli library and nginx module are under active development. ## Installation +### Statically compiled + +Checkout the latest `ngx_brotli` and build the dependencies: + +``` +git clone --recurse-submodules -j8 https://github.com/google/ngx_brotli +cd ngx_brotli/deps/brotli +mkdir out && cd out +cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF -DCMAKE_C_FLAGS="-Ofast -m64 -march=native -mtune=native -flto -funroll-loops -ffunction-sections -fdata-sections -Wl,--gc-sections" -DCMAKE_CXX_FLAGS="-Ofast -m64 -march=native -mtune=native -flto -funroll-loops -ffunction-sections -fdata-sections -Wl,--gc-sections" -DCMAKE_INSTALL_PREFIX=./installed .. +cmake --build . --config Release --target brotlienc +cd ../../../.. +``` + + + $ cd nginx-1.x.x + $ export CFLAGS="-m64 -march=native -mtune=native -Ofast -flto -funroll-loops -ffunction-sections -fdata-sections -Wl,--gc-sections" + $ export LDFLAGS="-m64 -Wl,-s -Wl,-Bsymbolic -Wl,--gc-sections" + $ ./configure --add-module=/path/to/ngx_brotli + $ make && make install + +This will compile the module directly into Nginx. + + ### Dynamically loaded $ cd nginx-1.x.x @@ -51,13 +73,7 @@ load_module modules/ngx_http_brotli_filter_module.so; load_module modules/ngx_http_brotli_static_module.so; ``` -### Statically compiled - $ cd nginx-1.x.x - $ ./configure --add-module=/path/to/ngx_brotli - $ make && make install - -This will compile the module directly into Nginx. ## Configuration directives diff --git a/filter/config b/filter/config index 9c27fc7..5f2eb39 100644 --- a/filter/config +++ b/filter/config @@ -43,12 +43,6 @@ 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 - brotli="/usr/local" -fi -if [ ! -f "$brotli/include/brotli/encode.h" ]; then - brotli="/usr" -fi if [ ! -f "$brotli/include/brotli/encode.h" ]; then cat << END @@ -63,33 +57,16 @@ END exit 1 fi -BROTLI_LISTS_FILE="$brotli/../scripts/sources.lst" - -if [ -f "$BROTLI_LISTS_FILE" ]; then - -BROTLI_LISTS=`cat "$BROTLI_LISTS_FILE" | grep -v "#" | tr '\n' '#' | \ - sed 's/\\\\#//g' | tr -s ' ' '+' | tr -s '#' ' ' | \ - sed 's/+c/+$brotli/g' | sed 's/+=+/=/g'` -for ITEM in ${BROTLI_LISTS}; do - VAR=`echo $ITEM | sed 's/=.*//'` - VAL=`echo $ITEM | sed 's/.*=//' | tr '+' ' '` - eval ${VAR}=\"$VAL\" -done - -else # BROTLI_LISTS_FILE - +BROTLI_OUTPUT_DIRECTORY="$brotli/../out" BROTLI_ENC_H="$brotli/include/brotli/encode.h \ $brotli/include/brotli/port.h \ $brotli/include/brotli/types.h" -BROTLI_ENC_LIB="-lbrotlienc" -fi ngx_module_incs="$brotli/include" -ngx_module_deps="$BROTLI_COMMON_H $BROTLI_ENC_H" -ngx_module_srcs="$BROTLI_COMMON_C $BROTLI_ENC_C \ - $BROTLI_MODULE_SRC_DIR/ngx_http_brotli_filter_module.c" -ngx_module_libs="$BROTLI_ENC_LIB -lm" +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 \