Skip to content

Instantly share code, notes, and snippets.

@rcd27
Created March 5, 2026 20:58
Show Gist options
  • Select an option

  • Save rcd27/5497fcca7a87b441c9e7f658df7db6ce to your computer and use it in GitHub Desktop.

Select an option

Save rcd27/5497fcca7a87b441c9e7f658df7db6ce to your computer and use it in GitHub Desktop.
`LUA INIT ERROR` workaround для `zapret2` на `aarch64`
FROM ubuntu:24.04 AS builder
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential git pkg-config \
gcc-aarch64-linux-gnu g++-aarch64-linux-gnu \
autoconf automake libtool \
ca-certificates
# musl cross toolchain для статической линковки
RUN apt-get install -y --no-install-recommends wget xz-utils && \
wget -q https://musl.cc/aarch64-linux-musl-cross.tgz -O /tmp/musl-cross.tgz && \
tar xf /tmp/musl-cross.tgz -C /opt && \
rm /tmp/musl-cross.tgz
ENV PATH="/opt/aarch64-linux-musl-cross/bin:${PATH}"
ENV CC=aarch64-linux-musl-gcc
ENV CROSS=aarch64-linux-musl-
ENV HOST_CC="gcc -m64"
# Lua 5.4 (не LuaJIT — LuaJIT падает с LUA INIT ERROR на aarch64 OpenWrt)
RUN wget -q https://www.lua.org/ftp/lua-5.4.7.tar.gz -O /tmp/lua.tar.gz && \
tar xf /tmp/lua.tar.gz -C /tmp && \
cd /tmp/lua-5.4.7 && \
make CC=${CC} AR="${CROSS}ar rcu" RANLIB="${CROSS}ranlib" \
MYCFLAGS="-fPIC" PLAT=linux-readline INSTALL_TOP=/opt/lua-arm64 \
linux-readline 2>/dev/null || \
make CC=${CC} AR="${CROSS}ar rcu" RANLIB="${CROSS}ranlib" \
MYCFLAGS="-fPIC" MYLIBS="" PLAT=posix INSTALL_TOP=/opt/lua-arm64 \
posix && \
make INSTALL_TOP=/opt/lua-arm64 install
# Собираем зависимости nfqws2 из исходников (статически)
WORKDIR /tmp/deps
# libmnl
RUN git clone --depth=1 https://git.netfilter.org/libmnl && \
cd libmnl && autoreconf -fi && \
./configure --host=aarch64-linux-musl --prefix=/opt/deps --enable-static --disable-shared && \
make -j$(nproc) && make install
# libnfnetlink
RUN git clone --depth=1 https://git.netfilter.org/libnfnetlink && \
cd libnfnetlink && autoreconf -fi && \
./configure --host=aarch64-linux-musl --prefix=/opt/deps --enable-static --disable-shared && \
make -j$(nproc) && make install
# libnetfilter_queue
RUN git clone --depth=1 https://git.netfilter.org/libnetfilter_queue && \
cd libnetfilter_queue && autoreconf -fi && \
PKG_CONFIG_PATH=/opt/deps/lib/pkgconfig \
./configure --host=aarch64-linux-musl --prefix=/opt/deps --enable-static --disable-shared && \
make -j$(nproc) && make install
# zlib
RUN git clone --depth=1 https://github.com/madler/zlib.git && \
cd zlib && \
CHOST=aarch64-linux-musl ./configure --prefix=/opt/deps --static && \
make -j$(nproc) && make install
# sys/queue.h (BSD, отсутствует в musl)
RUN mkdir -p /opt/deps/include/sys && \
cp /usr/include/x86_64-linux-gnu/sys/queue.h /opt/deps/include/sys/queue.h
# libcap (для sys/capability.h и -lcap)
RUN git clone --depth=1 https://git.kernel.org/pub/scm/libs/libcap/libcap.git && \
cd libcap/libcap && \
make CC=${CC} BUILD_CC=gcc SHARED=no \
DESTDIR=/opt/deps PREFIX=/ INCDIR=/include LIBDIR=/lib \
install && \
mkdir -p /opt/deps/include/linux && \
cp include/uapi/linux/capability.h /opt/deps/include/linux/ 2>/dev/null || true
# zapret2 с обычным Lua (LUA_JIT=0)
RUN git clone --depth=1 https://github.com/bol-van/zapret2.git /tmp/zapret2
WORKDIR /tmp/zapret2/nfq2
RUN ${CC} -s -std=gnu99 -Os -flto=auto -ffunction-sections -fdata-sections \
-I/opt/lua-arm64/include \
-I/opt/deps/include \
-static \
-o nfqws2 *.c crypto/*.c \
-L/opt/lua-arm64/lib -llua \
-L/opt/deps/lib -lnetfilter_queue -lnfnetlink -lmnl -lcap -lz -lm \
-flto=auto -Wl,--gc-sections
FROM scratch
COPY --from=builder /tmp/zapret2/nfq2/nfqws2 /nfqws2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment