FROM docker.io/library/alpine:3.24

RUN sed -i 's|dl-cdn.alpinelinux.org|mirrors.ustc.edu.cn|g' /etc/apk/repositories \
    && apk add --no-cache \
        autoconf \
        automake \
        build-base \
        bzip2 \
        ca-certificates \
        cmake \
        coreutils \
        curl \
        git \
        libtool \
        linux-headers \
        ninja \
        perl \
        pkgconf \
        tar \
        xz

RUN git config --global url."https://wangguofang.net/github.com/".insteadOf "https://github.com/"

RUN curl --fail --location --output boost.tar.bz2 \
        https://mirrors.aliyun.com/blfs/conglomeration/boost/boost_1_83_0.tar.bz2 \
    && mkdir src \
    && tar --extract --bzip2 --file=boost.tar.bz2 --directory=src --strip-components=1 \
    && rm boost.tar.bz2 \
    && cd src \
    && ./bootstrap.sh --prefix=/usr/local \
    && ./b2 --jobs="$(nproc)" \
        --with-atomic \
        --with-chrono \
        --with-context \
        --with-date_time \
        --with-filesystem \
        --with-program_options \
        --with-regex \
        --with-system \
        --with-thread \
        cflags=-fPIC \
        cxxflags=-fPIC \
        link=static \
        pch=off \
        runtime-link=shared \
        threading=multi \
        variant=release \
        install \
    && cd .. \
    && rm -rf src

RUN git clone --branch=openssl-3.0.15 --depth=1 https://github.com/openssl/openssl.git src \
    && cd src \
    && ./Configure --prefix=/usr/local --libdir=lib no-shared no-tests -fPIC \
    && make --jobs="$(nproc)" \
    && make install_sw \
    && cd .. \
    && rm -rf src

RUN git clone --branch=release-2.1.12-stable --depth=1 https://github.com/libevent/libevent.git src \
    && cmake -G Ninja -S src -B build -DCMAKE_BUILD_TYPE=Release \
        -DCMAKE_POLICY_VERSION_MINIMUM=3.5 \
        -DCMAKE_POSITION_INDEPENDENT_CODE=ON \
        -DEVENT__DISABLE_BENCHMARK=ON \
        -DEVENT__DISABLE_REGRESS=ON \
        -DEVENT__DISABLE_SAMPLES=ON \
        -DEVENT__DISABLE_TESTS=ON \
        -DEVENT__LIBRARY_TYPE=STATIC \
    && cmake --build build --parallel "$(nproc)" --target install \
    && rm -rf build src

RUN git clone --branch=v1.5.7 --depth=1 https://github.com/facebook/zstd.git src \
    && cmake -G Ninja -S src/build/cmake -B build -DCMAKE_BUILD_TYPE=Release \
        -DCMAKE_POLICY_VERSION_MINIMUM=3.5 \
        -DCMAKE_POSITION_INDEPENDENT_CODE=ON \
        -DZSTD_BUILD_CONTRIB=OFF \
        -DZSTD_BUILD_PROGRAMS=OFF \
        -DZSTD_BUILD_SHARED=OFF \
        -DZSTD_BUILD_STATIC=ON \
        -DZSTD_BUILD_TESTS=OFF \
    && cmake --build build --parallel "$(nproc)" --target install \
    && rm -rf build src

RUN git clone --branch=v1.3.1 --depth=1 https://github.com/madler/zlib.git src \
    && cd src \
    && CFLAGS=-fPIC ./configure --prefix=/usr/local --static \
    && make --jobs="$(nproc)" \
    && make install \
    && cd .. \
    && rm -rf src

RUN git clone --branch=v3.21.12 --depth=1 https://github.com/protocolbuffers/protobuf.git src \
    && cmake -G Ninja -S src -B build -Dprotobuf_BUILD_TESTS=OFF \
        -Dprotobuf_BUILD_SHARED_LIBS=OFF \
        -Dprotobuf_WITH_ZLIB=ON \
        -DCMAKE_BUILD_TYPE=Release \
        -DCMAKE_POLICY_VERSION_MINIMUM=3.5 \
        -DBUILD_SHARED_LIBS=OFF \
        -DCMAKE_POSITION_INDEPENDENT_CODE=ON \
    && cmake --build build --parallel "$(nproc)" --target install \
    && rm -rf build src

RUN git clone --branch=REL_2_0_5 --depth=1 https://gitee.com/mirrors/log4cplus.git src \
    && git -C src submodule update --init --depth=1 threadpool \
    && cmake -G Ninja -S src -B build -DCMAKE_BUILD_TYPE=Release \
        -DCMAKE_POLICY_VERSION_MINIMUM=3.5 \
        -DBUILD_SHARED_LIBS=OFF \
        -DCMAKE_POSITION_INDEPENDENT_CODE=ON \
        -DLOG4CPLUS_BUILD_TESTING=OFF \
        -DWITH_UNIT_TESTS=OFF \
    && cmake --build build --parallel "$(nproc)" --target install \
    && rm -rf build src

RUN git clone --branch=12.2.0 --depth=1 https://github.com/fmtlib/fmt.git src \
    && cmake -G Ninja -S src -B build -DCMAKE_BUILD_TYPE=Release \
        -DCMAKE_POLICY_VERSION_MINIMUM=3.5 \
        -DBUILD_SHARED_LIBS=OFF \
        -DCMAKE_POSITION_INDEPENDENT_CODE=ON \
        -DFMT_DOC=OFF \
        -DFMT_TEST=OFF \
    && cmake --build build --parallel "$(nproc)" --target install \
    && rm -rf build src

RUN git clone --branch=v1.17.0 --depth=1 https://github.com/gabime/spdlog.git src \
    && cmake -G Ninja -S src -B build -DCMAKE_BUILD_TYPE=Release \
        -DCMAKE_POLICY_VERSION_MINIMUM=3.5 \
        -DBUILD_SHARED_LIBS=OFF \
        -DCMAKE_POSITION_INDEPENDENT_CODE=ON \
        -DSPDLOG_BUILD_BENCH=OFF \
        -DSPDLOG_BUILD_EXAMPLE=OFF \
        -DSPDLOG_BUILD_TESTS=OFF \
        -DSPDLOG_FMT_EXTERNAL=ON \
    && cmake --build build --parallel "$(nproc)" --target install \
    && rm -rf build src

RUN git clone --branch=v0.9.8 --depth=1 https://github.com/Neargye/magic_enum.git src \
    && cmake -G Ninja -S src -B build -DCMAKE_BUILD_TYPE=Release \
        -DCMAKE_POLICY_VERSION_MINIMUM=3.5 \
        -DMAGIC_ENUM_OPT_BUILD_EXAMPLES=OFF \
        -DMAGIC_ENUM_OPT_BUILD_TESTS=OFF \
        -DMAGIC_ENUM_OPT_INSTALL=ON \
    && cmake --build build --parallel "$(nproc)" --target install \
    && rm -rf build src

RUN git clone --branch=v8.2.10 --depth=1 https://github.com/fastfloat/fast_float.git src \
    && cmake -G Ninja -S src -B build -DCMAKE_BUILD_TYPE=Release \
        -DCMAKE_POLICY_VERSION_MINIMUM=3.5 \
        -DFASTFLOAT_BENCHMARKS=OFF \
        -DFASTFLOAT_INSTALL=ON \
        -DFASTFLOAT_TEST=OFF \
    && cmake --build build --parallel "$(nproc)" --target install \
    && rm -rf build src

RUN git clone --branch=v0.7.0 --depth=1 https://github.com/Tessil/sparse-map.git src \
    && cmake -G Ninja -S src -B build -DCMAKE_BUILD_TYPE=Release \
        -DCMAKE_POLICY_VERSION_MINIMUM=3.5 \
    && cmake --build build --parallel "$(nproc)" --target install \
    && rm -rf build src

RUN git clone --branch=v2.3.1 --depth=1 https://github.com/gflags/gflags.git src \
    && cmake -G Ninja -S src -B build -DCMAKE_BUILD_TYPE=Release \
        -DCMAKE_POLICY_VERSION_MINIMUM=3.5 \
        -DBUILD_SHARED_LIBS=OFF \
        -DBUILD_STATIC_LIBS=ON \
        -DBUILD_TESTING=OFF \
        -DCMAKE_POSITION_INDEPENDENT_CODE=ON \
        -DINSTALL_HEADERS=ON \
        -DINSTALL_SHARED_LIBS=OFF \
        -DINSTALL_STATIC_LIBS=ON \
        -DREGISTER_INSTALL_PREFIX=OFF \
    && cmake --build build --parallel "$(nproc)" --target install \
    && rm -rf build src

RUN git clone --branch=v0.7.1 --depth=1 https://github.com/google/glog.git src \
    && cmake -G Ninja -S src -B build -DCMAKE_BUILD_TYPE=Release \
        -DCMAKE_POLICY_VERSION_MINIMUM=3.5 \
        -DBUILD_SHARED_LIBS=OFF \
        -DBUILD_TESTING=OFF \
        -DCMAKE_POSITION_INDEPENDENT_CODE=ON \
        -DWITH_GFLAGS=ON \
        -DWITH_GTEST=OFF \
        -DWITH_PKGCONFIG=ON \
        -DWITH_UNWIND=none \
    && cmake --build build --parallel "$(nproc)" --target install \
    && rm -rf build src

RUN git clone --branch=liburing-2.15 --depth=1 https://github.com/axboe/liburing.git src \
    && cd src \
    && CFLAGS=-fPIC ./configure --prefix=/usr/local \
    && make --jobs="$(nproc)" ENABLE_SHARED=0 library \
    && make ENABLE_SHARED=0 install \
    && cd .. \
    && rm -rf src

RUN curl --fail --location --output libaio.tar.gz \
        https://releases.pagure.org/libaio/libaio-0.3.113.tar.gz \
    && mkdir src \
    && tar --extract --gzip --file=libaio.tar.gz --directory=src --strip-components=1 \
    && rm libaio.tar.gz \
    && make --directory=src --jobs="$(nproc)" ENABLE_SHARED=0 \
    && make --directory=src ENABLE_SHARED=0 prefix=/usr/local install \
    && rm -rf src

RUN git clone --branch=v2.3.2 --depth=1 https://github.com/davea42/libdwarf-code.git src \
    && cmake -G Ninja -S src -B build -DCMAKE_BUILD_TYPE=Release \
        -DCMAKE_POLICY_VERSION_MINIMUM=3.5 \
        -DBUILD_DWARFDUMP=OFF \
        -DBUILD_DWARFEXAMPLE=OFF \
        -DBUILD_DWARFGEN=OFF \
        -DBUILD_NON_SHARED=ON \
        -DBUILD_SHARED=OFF \
        -DDO_TESTING=OFF \
        -DENABLE_DECOMPRESSION=ON \
        -DPIC_ALWAYS=ON \
    && cmake --build build --parallel "$(nproc)" --target install \
    && rm -rf build src

RUN git clone --branch=1.0.20-RELEASE --depth=1 https://github.com/jedisct1/libsodium.git src \
    && cd src \
    && ./autogen.sh \
    && ./configure --prefix=/usr/local --disable-shared --enable-static --with-pic \
    && make --jobs="$(nproc)" \
    && make install \
    && cd .. \
    && rm -rf src

RUN git clone --branch=v0.8.3 --depth=1 https://github.com/Cyan4973/xxHash.git src \
    && cmake -G Ninja -S src/cmake_unofficial -B build -DCMAKE_BUILD_TYPE=Release \
        -DCMAKE_POLICY_VERSION_MINIMUM=3.5 \
        -DBUILD_SHARED_LIBS=OFF \
        -DCMAKE_POSITION_INDEPENDENT_CODE=ON \
        -DXXHASH_BUILD_XXHSUM=OFF \
    && cmake --build build --parallel "$(nproc)" --target install \
    && rm -rf build src

RUN git clone --branch=v1.17.0 --depth=1 https://github.com/google/googletest.git src \
    && cmake -G Ninja -S src -B build -DCMAKE_BUILD_TYPE=Release \
        -DCMAKE_POLICY_VERSION_MINIMUM=3.5 \
        -DBUILD_GMOCK=ON \
        -DBUILD_SHARED_LIBS=OFF \
        -DCMAKE_POSITION_INDEPENDENT_CODE=ON \
        -DINSTALL_GTEST=ON \
        -Dgtest_build_samples=OFF \
        -Dgtest_build_tests=OFF \
    && cmake --build build --parallel "$(nproc)" --target install \
    && rm -rf build src

RUN git clone --branch=v2.0.19 --depth=1 https://github.com/numactl/numactl.git src \
    && cd src \
    && ./autogen.sh \
    && CFLAGS=-fPIC ./configure --prefix=/usr/local --disable-shared --enable-static \
    && make --jobs="$(nproc)" \
    && make install \
    && cd .. \
    && rm -rf src

# Meta/Facebook ecosystem libraries (Folly, Fizz, Wangle, mvfst, fbthrift,
# CacheLib) are not built on this musl target: they aren't on Meta's
# supported-OS list, and every compile error traced back so far is Folly
# reaching for a glibc-only macro/symbol with no musl branch in its
# portability layer (e.g. off64_t/lseek64/pread64 in
# folly/portability/Unistd.h, __ELF_NATIVE_CLASS in
# folly/debugging/symbolizer/Elf.cpp). Patching around each one as it
# surfaces is more likely to introduce subtle bugs than to reach a solid
# build, so this stack is intentionally left unbuilt on Alpine.
# RUN git clone --branch=v2026.08.03.00 --depth=1 https://github.com/facebook/folly.git src \
#     && CXXFLAGS="-DGLOG_USE_GLOG_EXPORT" \
#         cmake -G Ninja -S src -B build -DCMAKE_BUILD_TYPE=Release \
#         -DBOOST_LINK_STATIC=ON \
#         -DBUILD_BENCHMARKS=OFF \
#         -DBUILD_SHARED_LIBS=OFF \
#         -DBUILD_TESTS=OFF \
#         -DCMAKE_POSITION_INDEPENDENT_CODE=ON \
#         -DPYTHON_EXTENSIONS=OFF \
#     && cmake --build build --parallel "$(nproc)" --target install \
#     && rm -rf build src

# RUN git clone --branch=v2026.08.03.00 --depth=1 https://github.com/facebookincubator/fizz.git src \
#     && CXXFLAGS="-DGLOG_USE_GLOG_EXPORT" \
#         cmake -G Ninja -S src/fizz -B build -DCMAKE_BUILD_TYPE=Release \
#         -DBUILD_EXAMPLES=OFF \
#         -DBUILD_SHARED_LIBS=OFF \
#         -DBUILD_TESTS=OFF \
#         -DCMAKE_POSITION_INDEPENDENT_CODE=ON \
#         -Dsodium_USE_STATIC_LIBS=ON \
#     && cmake --build build --parallel "$(nproc)" --target install \
#     && rm -rf build src

# RUN git clone --branch=v2026.08.03.00 --depth=1 https://github.com/facebook/wangle.git src \
#     && CXXFLAGS="-DGLOG_USE_GLOG_EXPORT" \
#         cmake -G Ninja -S src/wangle -B build -DCMAKE_BUILD_TYPE=Release \
#         -DBUILD_EXAMPLES=OFF \
#         -DBUILD_SHARED_LIBS=OFF \
#         -DBUILD_TESTS=OFF \
#         -DCMAKE_POSITION_INDEPENDENT_CODE=ON \
#     && cmake --build build --parallel "$(nproc)" --target install \
#     && rm -rf build src

# RUN git clone --branch=v2026.08.03.00 --depth=1 https://github.com/facebook/mvfst.git src \
#     && CXXFLAGS="-DGLOG_USE_GLOG_EXPORT" \
#         cmake -G Ninja -S src -B build -DCMAKE_BUILD_TYPE=Release \
#         -DBUILD_SAMPLES=OFF \
#         -DBUILD_SHARED_LIBS=OFF \
#         -DBUILD_TESTS=OFF \
#         -DBUILD_TOOLS=OFF \
#         -DCMAKE_POSITION_INDEPENDENT_CODE=ON \
#     && cmake --build build --parallel "$(nproc)" --target install \
#     && rm -rf build src

# RUN git clone --branch=v2026.08.03.00 --depth=1 https://github.com/facebook/fbthrift.git src \
#     && CXXFLAGS="-DGLOG_USE_GLOG_EXPORT" \
#         cmake -G Ninja -S src -B build -DCMAKE_BUILD_TYPE=Release \
#         -DBUILD_SHARED_LIBS=OFF \
#         -DCMAKE_POSITION_INDEPENDENT_CODE=ON \
#         -DTHRIFT_BENCHMARKS=OFF \
#         -Denable_tests=OFF \
#         -Dthrift_python=OFF \
#         -Dthriftpy=OFF \
#         -Dthriftpy3=OFF \
#     && cmake --build build --parallel "$(nproc)" --target install \
#     && rm -rf build src

# RUN git clone --branch=v2026.08.03.00 --depth=1 https://github.com/facebook/CacheLib.git src \
#     && CXXFLAGS="-DGLOG_USE_GLOG_EXPORT" \
#         cmake -G Ninja -S src/cachelib -B build -DCMAKE_BUILD_TYPE=Release \
#         -DBOOST_LINK_STATIC=ON \
#         -DBUILD_SHARED_LIBS=OFF \
#         -DBUILD_TESTS=OFF \
#         -DCMAKE_POSITION_INDEPENDENT_CODE=ON \
#     && cmake --build build --parallel "$(nproc)" --target install \
#     && rm -rf build src

RUN curl --fail --location --output util-linux.tar.xz \
        https://mirrors.edge.kernel.org/pub/linux/utils/util-linux/v2.42/util-linux-2.42.2.tar.xz \
    && mkdir src \
    && tar --extract --xz --file=util-linux.tar.xz --directory=src --strip-components=1 \
    && rm util-linux.tar.xz \
    && cd src \
    && CFLAGS=-fPIC ./configure --prefix=/usr/local \
        --disable-all-programs \
        --disable-bash-completion \
        --disable-makeinstall-chown \
        --disable-nls \
        --disable-shared \
        --enable-libuuid \
        --enable-static \
    && make --jobs="$(nproc)" \
    && make install \
    && cd .. \
    && rm -rf src

RUN git clone --branch=v4.3.5 --depth=1 https://github.com/zeromq/libzmq.git src \
    && cmake -G Ninja -S src -B build -DCMAKE_BUILD_TYPE=Release \
        -DCMAKE_POLICY_VERSION_MINIMUM=3.5 \
        -DBUILD_SHARED=OFF \
        -DBUILD_STATIC=ON \
        -DBUILD_TESTS=OFF \
        -DCMAKE_POSITION_INDEPENDENT_CODE=ON \
        -DENABLE_CPACK=OFF \
        -DENABLE_CURVE=ON \
        -DENABLE_DRAFTS=OFF \
        -DWITH_DOC=OFF \
        -DWITH_DOCS=OFF \
        -DWITH_LIBSODIUM=ON \
        -DWITH_LIBSODIUM_STATIC=ON \
    && cmake --build build --parallel "$(nproc)" --target install \
    && rm -rf build src

RUN git clone --branch=v4.2.1 --depth=1 https://github.com/zeromq/czmq.git src \
    && cmake -G Ninja -S src -B build -DCMAKE_BUILD_TYPE=Release \
        -DCMAKE_POLICY_VERSION_MINIMUM=3.5 \
        -DCMAKE_POSITION_INDEPENDENT_CODE=ON \
        -DCZMQ_BUILD_SHARED=OFF \
        -DCZMQ_BUILD_STATIC=ON \
        -DCZMQ_WITH_LZ4=OFF \
        -DCZMQ_WITH_LIBCURL=OFF \
        -DCZMQ_WITH_LIBMICROHTTPD=OFF \
        -DCZMQ_WITH_NSS=OFF \
        -DCZMQ_WITH_SYSTEMD=OFF \
        -DCZMQ_WITH_UUID=ON \
        -DENABLE_DRAFTS=OFF \
    && cmake --build build --parallel "$(nproc)" --target install \
    && rm -rf build src

RUN git clone --branch=1.9.8 --depth=1 https://github.com/open-source-parsers/jsoncpp.git src \
    && cmake -G Ninja -S src -B build -DCMAKE_BUILD_TYPE=Release \
        -DCMAKE_POLICY_VERSION_MINIMUM=3.5 \
        -DBUILD_OBJECT_LIBS=OFF \
        -DBUILD_SHARED_LIBS=OFF \
        -DBUILD_STATIC_LIBS=ON \
        -DCMAKE_POSITION_INDEPENDENT_CODE=ON \
        -DJSONCPP_WITH_EXAMPLE=OFF \
        -DJSONCPP_WITH_POST_BUILD_UNITTEST=OFF \
        -DJSONCPP_WITH_TESTS=OFF \
    && cmake --build build --parallel "$(nproc)" --target install \
    && rm -rf build src

RUN git clone --branch=v2.15.0 --depth=1 https://github.com/confluentinc/librdkafka.git src \
    && cmake -G Ninja -S src -B build -DCMAKE_BUILD_TYPE=Release \
        -DCMAKE_POLICY_VERSION_MINIMUM=3.5 \
        -DCMAKE_POSITION_INDEPENDENT_CODE=ON \
        -DENABLE_LZ4_EXT=OFF \
        -DRDKAFKA_BUILD_EXAMPLES=OFF \
        -DRDKAFKA_BUILD_STATIC=ON \
        -DRDKAFKA_BUILD_TESTS=OFF \
        -DWITH_CURL=OFF \
        -DWITH_PLUGINS=OFF \
        -DWITH_SASL=OFF \
        -DWITH_SSL=ON \
        -DWITH_ZLIB=ON \
        -DWITH_ZSTD=ON \
    && cmake --build build --parallel "$(nproc)" --target install \
    && rm -rf build src

RUN git clone --branch=json-c-0.19-20260627 --depth=1 https://github.com/json-c/json-c.git src \
    && cmake -G Ninja -S src -B build -DCMAKE_BUILD_TYPE=Release \
        -DCMAKE_POLICY_VERSION_MINIMUM=3.5 \
        -DBUILD_APPS=OFF \
        -DBUILD_SHARED_LIBS=OFF \
        -DBUILD_STATIC_LIBS=ON \
        -DBUILD_TESTING=OFF \
        -DCMAKE_POSITION_INDEPENDENT_CODE=ON \
        -DDISABLE_EXTRA_LIBS=ON \
    && cmake --build build --parallel "$(nproc)" --target install \
    && rm -rf build src

COPY rapidjson-generic-string-ref-assignment.patch /tmp/
RUN git clone --branch=v1.1.0 --depth=1 https://github.com/Tencent/rapidjson.git src \
    && git -C src apply /tmp/rapidjson-generic-string-ref-assignment.patch \
    && cmake -G Ninja -S src -B build -DCMAKE_BUILD_TYPE=Release \
        -DCMAKE_POLICY_VERSION_MINIMUM=3.5 \
        -DRAPIDJSON_BUILD_DOC=OFF \
        -DRAPIDJSON_BUILD_EXAMPLES=OFF \
        -DRAPIDJSON_BUILD_TESTS=OFF \
    && cmake --build build --parallel "$(nproc)" --target install \
    && rm -rf build src /tmp/rapidjson-generic-string-ref-assignment.patch

RUN git clone --branch=curl-8_21_0 --depth=1 https://github.com/curl/curl.git src \
    && cmake -G Ninja -S src -B build -DCMAKE_BUILD_TYPE=Release \
        -DCMAKE_POLICY_VERSION_MINIMUM=3.5 \
        -DBUILD_CURL_EXE=OFF \
        -DBUILD_EXAMPLES=OFF \
        -DBUILD_LIBCURL_DOCS=OFF \
        -DBUILD_MISC_DOCS=OFF \
        -DBUILD_SHARED_LIBS=OFF \
        -DBUILD_STATIC_LIBS=ON \
        -DBUILD_TESTING=OFF \
        -DCMAKE_POSITION_INDEPENDENT_CODE=ON \
        -DCURL_BROTLI=OFF \
        -DCURL_USE_LIBPSL=OFF \
        -DCURL_USE_LIBSSH=OFF \
        -DCURL_USE_LIBSSH2=OFF \
        -DCURL_USE_OPENSSL=ON \
        -DENABLE_CURL_MANUAL=OFF \
        -DHTTP_ONLY=ON \
        -DUSE_LIBIDN2=OFF \
        -DUSE_NGHTTP2=OFF \
        -DUSE_NGTCP2=OFF \
        -DUSE_QUICHE=OFF \
    && cmake --build build --parallel "$(nproc)" --target install \
    && rm -rf build src

RUN git clone --branch=v1.4.1 --depth=1 https://github.com/redis/hiredis.git src \
    && cmake -G Ninja -S src -B build -DCMAKE_BUILD_TYPE=Release \
        -DCMAKE_POLICY_VERSION_MINIMUM=3.5 \
        -DBUILD_SHARED_LIBS=OFF \
        -DCMAKE_POSITION_INDEPENDENT_CODE=ON \
        -DENABLE_ASYNC_TESTS=OFF \
        -DENABLE_EXAMPLES=OFF \
        -DENABLE_NUGET=OFF \
        -DENABLE_SSL=OFF \
        -DENABLE_SSL_TESTS=OFF \
    && cmake --build build --parallel "$(nproc)" --target install \
    && rm -rf build src

RUN curl --fail --location --output gmp.tar.xz \
        https://mirrors.ustc.edu.cn/gnu/gmp/gmp-6.3.0.tar.xz \
    && mkdir src \
    && tar --extract --xz --file=gmp.tar.xz --directory=src --strip-components=1 \
    && rm gmp.tar.xz \
    && cd src \
    && CFLAGS="-fPIC -std=gnu17" ./configure --prefix=/usr/local --disable-shared --enable-static \
    && make --jobs="$(nproc)" \
    && make install \
    && cd .. \
    && rm -rf src

RUN curl --fail --location --output nettle.tar.gz \
        https://mirrors.ustc.edu.cn/gnu/nettle/nettle-3.10.2.tar.gz \
    && mkdir src \
    && tar --extract --gzip --file=nettle.tar.gz --directory=src --strip-components=1 \
    && rm nettle.tar.gz \
    && cd src \
    && CFLAGS=-fPIC ./configure --prefix=/usr/local --libdir=/usr/local/lib \
        --disable-documentation \
        --disable-shared \
        --enable-static \
    && make --jobs="$(nproc)" \
    && make install \
    && cd .. \
    && rm -rf src

RUN curl --fail --location --output gnutls.tar.xz \
        https://mirrors.dotsrc.org/gcrypt/gnutls/v3.8/gnutls-3.8.13.tar.xz \
    && mkdir src \
    && tar --extract --xz --file=gnutls.tar.xz --directory=src --strip-components=1 \
    && rm gnutls.tar.xz \
    && cd src \
    && CFLAGS=-fPIC ./configure --prefix=/usr/local \
        --with-included-libtasn1 \
        --with-included-unistring \
        --disable-cxx \
        --disable-doc \
        --disable-manpages \
        --disable-nls \
        --disable-shared \
        --disable-tests \
        --disable-tools \
        --enable-static \
        --without-brotli \
        --without-idn \
        --without-p11-kit \
        --without-tpm \
        --without-tpm2 \
        --without-zlib \
        --without-zstd \
    && make --jobs="$(nproc)" \
    && make install \
    && cd .. \
    && rm -rf src

RUN git clone --branch=1.13.3 --depth=1 https://github.com/maxmind/libmaxminddb.git src \
    && cmake -G Ninja -S src -B build -DCMAKE_BUILD_TYPE=Release \
        -DCMAKE_POLICY_VERSION_MINIMUM=3.5 \
        -DBUILD_SHARED_LIBS=OFF \
        -DBUILD_TESTING=OFF \
        -DCMAKE_POSITION_INDEPENDENT_CODE=ON \
        -DMAXMINDDB_BUILD_BINARIES=OFF \
    && cmake --build build --parallel "$(nproc)" --target install \
    && rm -rf build src

RUN git clone --branch=0.2.5 --depth=1 https://github.com/yaml/libyaml.git src \
    && cd src \
    && ./bootstrap \
    && CFLAGS=-fPIC ./configure --prefix=/usr/local --disable-shared --enable-static \
    && make --jobs="$(nproc)" \
    && make install \
    && cd .. \
    && rm -rf src

RUN git clone --branch=v2.15.3 --depth=1 https://gitlab.gnome.org/GNOME/libxml2.git src \
    && cmake -G Ninja -S src -B build -DCMAKE_BUILD_TYPE=Release \
        -DCMAKE_POLICY_VERSION_MINIMUM=3.5 \
        -DBUILD_SHARED_LIBS=OFF \
        -DCMAKE_POSITION_INDEPENDENT_CODE=ON \
        -DLIBXML2_WITH_DOCS=OFF \
        -DLIBXML2_WITH_ICU=OFF \
        -DLIBXML2_WITH_MODULES=OFF \
        -DLIBXML2_WITH_PROGRAMS=OFF \
        -DLIBXML2_WITH_PYTHON=OFF \
        -DLIBXML2_WITH_TESTS=OFF \
        -DLIBXML2_WITH_ZLIB=ON \
    && cmake --build build --parallel "$(nproc)" --target install \
    && rm -rf build src

RUN git clone --branch=1.3.15 --depth=1 https://github.com/sewenew/redis-plus-plus.git src \
    && cmake -G Ninja -S src -B build -DCMAKE_BUILD_TYPE=Release \
        -DCMAKE_POLICY_VERSION_MINIMUM=3.5 \
        -DREDIS_PLUS_PLUS_BUILD_SHARED=OFF \
        -DREDIS_PLUS_PLUS_BUILD_STATIC=ON \
        -DREDIS_PLUS_PLUS_BUILD_STATIC_WITH_PIC=ON \
        -DREDIS_PLUS_PLUS_BUILD_TEST=OFF \
    && cmake --build build --parallel "$(nproc)" --target install \
    && rm -rf build src

RUN git clone --branch=5.3.1 --depth=1 https://github.com/jemalloc/jemalloc.git src \
    && cd src \
    && ./autogen.sh \
    && CFLAGS=-fPIC CXXFLAGS=-fPIC ./configure --prefix=/usr/local \
        --disable-doc \
        --disable-shared \
        --enable-static \
    && make --jobs="$(nproc)" \
    && make install \
    && cd .. \
    && rm -rf src

RUN git clone --branch=release-2.7.1 --depth=1 https://github.com/megastep/makeself.git src \
    && cp src/makeself.sh src/makeself-header.sh /usr/local/bin/ \
    && ln -s makeself.sh /usr/local/bin/makeself \
    && rm -rf src

CMD ["/bin/sh"]
