Skip to content

Instantly share code, notes, and snippets.

@hamjin
Last active January 5, 2025 01:10
Show Gist options
  • Save hamjin/fd2ca2d3b91fcb2d9cedebab579def5f to your computer and use it in GitHub Desktop.
Save hamjin/fd2ca2d3b91fcb2d9cedebab579def5f to your computer and use it in GitHub Desktop.
Build Angie with Tongsuo, XQUIC, Brotli, ZSTD, Clang, LLD and ThinLTO
#!/bin/bash
export SSL_QUIC_PREFIX="$HOME/.local/babassl"
export SSL_FEATURES="--api=1.1.1 no-legacy no-tests no-external-tests no-trace no-unit-test zlib enable-weak-ssl-ciphers enable-ssl3 enable-ct enable-ktls enable-ntls enable-sm2 enable-sm4 enable-sm3 enable-optimize-chacha-choose enable-ec_nistp_64_gcc_128 enable-ec_sm2p_64_gcc_128 enable-zuc enable-bulletproofs enable-sm2_threshold enable-ec_elgamal enable-twisted_ec_elgamal enable-cert-compression -DOPENSSL_TLS_SECURITY_LEVEL=0"
export SSL_CFLAGS="-O3 -march=haswell -mtune=haswell -mavx2 -funroll-loops -D_FORTIFY_SOURCE=2 -fPIC -pipe -flto=thin"
export SSL_LINKER_FLAGS="-fuse-ld=lld -fintegrated-as -static -ljemalloc -Wl,-z,relro,-z,now,--lto-O3,-O3,--as-needed"
## deps
# sudo apt install libatomic-ops-dev libperl-dev
apk add build-base cmake clang lld llvm pcre2-dev perl-dev zstd-dev zstd-static libatomic libatomic_ops-dev libatomic_ops-static jemalloc-static zlib-dev zlib-static linux-headers
## Tongsuo
git clone --depth 1 --recurse-submodules https://github.com/Tongsuo-Project/Tongsuo.git
cd Tongsuo
./config CC=clang --prefix="$SSL_QUIC_PREFIX" $SSL_FEATURES $SSL_CFLAGS $SSL_LINKER_FLAGS
make -j clean && make -j && make -j install
cd ..
## xquic
git clone --depth 1 --recurse-submodules https://github.com/hamjin/xquic.git
cd xquic
cmake -B build --fresh -Wno-error=deprecated -Wno-deprecated -DBUILD_SHARED_LIBS=OFF \
-DCMAKE_C_COMPILER="clang" -DCMAKE_CXX_COMPILER="clang++" -DCMAKE_LINKER_TYPE="LLD" \
-DCMAKE_C_FLAGS="$SSL_CFLAGS" -DCMAKE_CXX_FLAGS="$SSL_CFLAGS" \
-DXQC_SUPPORT_SENDMMSG_BUILD=ON -DXQC_ENABLE_BBR2=ON -DXQC_ENABLE_RENO=ON -DXQC_ENABLE_MP_INTEROP=ON -DXQC_ENABLE_UNLIMITED=ON \
-DXQC_ENABLE_COPA=ON -DXQC_COMPAT_DUPLICATE=ON -DXQC_ENABLE_FEC=ON -DXQC_ENABLE_XOR=ON -DXQC_ENABLE_RSC=1 -DXQC_ENABLE_PKM=ON \
-DSSL_TYPE="babassl" -DSSL_PATH="$SSL_QUIC_PREFIX" -DSSL_INC_PATH="$SSL_QUIC_PREFIX/include" \
-DSSL_LIB_PATH="$SSL_QUIC_PREFIX/lib64/libssl.a;$SSL_QUIC_PREFIX/lib64/libcrypto.a" \
.
cmake --build build -j --clean-first
# mv build/libxquic-static.a build/libxquic.a
# mv build/libxquic.so build/libxquicbak.so
cd ..
## ngx_brotli
git clone --depth 1 --recurse-submodules https://github.com/google/ngx_brotli.git ngx_brotli
cd ngx_brotli
cmake -B deps/brotli/out --fresh -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF \
-DCMAKE_C_COMPILER="clang" -DCMAKE_CXX_COMPILER="clang++" -DCMAKE_LINKER_TYPE="LLD" \
-DCMAKE_C_FLAGS="$SSL_CFLAGS" \
-DCMAKE_INSTALL_PREFIX=./installed deps/brotli
cmake --build deps/brotli/out -j --clean-first --config Release --target brotlienc
cd ..
## ngx_zstd
git clone --depth 1 --recurse-submodules https://github.com/tokers/zstd-nginx-module.git ngx_zstd
## angie
git clone --depth 1 --branch xquic_tongsuo --recurse-submodules https://github.com/hamjin/angie.git
cd angie
./configure --prefix=/usr/local/angie --http-log-path=/var/log/angie/access.log --error-log-path=/var/log/angie/error.log --lock-path=/var/lock/angie.lock --pid-path=/run/angie.pid \
--with-xquic-inc="../xquic/include" --with-xquic-lib="../xquic/build" \
--with-cc="clang" --with-cc-opt="$SSL_CFLAGS -I$SSL_QUIC_PREFIX/include" --with-ld-opt="$SSL_LINKER_FLAGS -L$SSL_QUIC_PREFIX/lib64 -Wl,-s" \
--with-select_module --with-poll_module --with-threads --with-file-aio \
--with-pcre --with-pcre-jit --with-libatomic \
--with-http_ssl_module --with-ntls --with-http_v2_module \
--with-http_realip_module --with-http_gunzip_module --with-http_gzip_static_module \
--with-stream --with-stream_ssl_module \
--add-module=../ngx_brotli --add-module=../ngx_zstd \
--add-module=modules/ngx_http_xquic_module --with-debug
make -j
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment