userdocs / qbittorrent-nox-static

A bash script which builds a fully static qbittorent-nox binary with current dependencies to use on any Linux OS

Home Page:https://userdocs.github.io/qbittorrent-nox-static

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ability to dynamically link libc

KyleSanderson opened this issue · comments

Hope you're well. There's a cool (upcoming) feature in mergerfs that uses a LD_PRELOAD to hook open() and creat() calls to bypass the overhead of FUSE for read/write operations. I'm hoping to use this with these builds, but I'm not seeing a direct way to not statically link glibc as part of the script. (Happy to connect offline to chat if you'd like.)

https://github.com/trapexit/mergerfs/blob/87475098a1ee3b888629c9e5e8fd6ad4cceab6bc/README.md#preloadso

You can test this

https://raw.githubusercontent.com/userdocs/qbittorrent-nox-static-test/main/qbittorrent-nox-static.sh

./qbittorrent-nox-static.sh all -si

Then when it's done

ldd qbt-build/completed/qbittorrent-nox

tbh, I tested it enough to be ok with pushing it via v2.0.6

Using the new -si flag will link to the host libc dynamically, or static-ish, skipping glibc on a Debian host. Just use the previous commands.

/usr/bin/c++ -march=native -std=c++17 -static -w -Wno-psabi -I/app/qbittorrent-nox-static/qbt-build/include -O3 -DNDEBUG -march=native   -L/app/q
bittorrent-nox-static/qbt-build/lib -pthread test/CMakeFiles/gtest_zlib.dir/test_compress.cc.o test/CMakeFiles/gtest_zlib.dir/test_compress_bound.cc.o
 test/CMakeFiles/gtest_zlib.dir/test_cve-2003-0107.cc.o test/CMakeFiles/gtest_zlib.dir/test_deflate_bound.cc.o test/CMakeFiles/gtest_zlib.dir/test_def
late_copy.cc.o test/CMakeFiles/gtest_zlib.dir/test_deflate_dict.cc.o test/CMakeFiles/gtest_zlib.dir/test_deflate_hash_head_0.cc.o test/CMakeFiles/gtes
t_zlib.dir/test_deflate_header.cc.o test/CMakeFiles/gtest_zlib.dir/test_deflate_params.cc.o test/CMakeFiles/gtest_zlib.dir/test_deflate_pending.cc.o t
est/CMakeFiles/gtest_zlib.dir/test_deflate_prime.cc.o test/CMakeFiles/gtest_zlib.dir/test_deflate_quick_bi_valid.cc.o test/CMakeFiles/gtest_zlib.dir/t
est_deflate_quick_block_open.cc.o test/CMakeFiles/gtest_zlib.dir/test_deflate_tune.cc.o test/CMakeFiles/gtest_zlib.dir/test_dict.cc.o test/CMakeFiles/
gtest_zlib.dir/test_inflate_adler32.cc.o test/CMakeFiles/gtest_zlib.dir/test_large_buffers.cc.o test/CMakeFiles/gtest_zlib.dir/test_raw.cc.o test/CMak
eFiles/gtest_zlib.dir/test_small_buffers.cc.o test/CMakeFiles/gtest_zlib.dir/test_small_window.cc.o test/CMakeFiles/gtest_zlib.dir/test_gzio.cc.o test
/CMakeFiles/gtest_zlib.dir/test_adler32.cc.o test/CMakeFiles/gtest_zlib.dir/test_aligned_alloc.cc.o test/CMakeFiles/gtest_zlib.dir/test_compare256.cc.
o test/CMakeFiles/gtest_zlib.dir/test_crc32.cc.o test/CMakeFiles/gtest_zlib.dir/test_inflate_sync.cc.o test/CMakeFiles/gtest_zlib.dir/test_main.cc.o t
est/CMakeFiles/gtest_zlib.dir/test_version.cc.o test/CMakeFiles/gtest_zlib.dir/test_deflate_concurrency.cc.o -o gtest_zlib  libz.a  lib/libgtest.a  -W
l,--whole-archive  -lpthread  -Wl,--no-whole-archive  -lgcc_s  -lgcc_s && :
/usr/bin/ld: cannot find -lgcc_s: No such file or directory
/usr/bin/ld: cannot find -lgcc_s: No such file or directory

bash qbittorrent-nox-static.sh -si -o all

debian:bookworm

I doubt that is the script but your env, assuming you are not using docker.

This will work and is the best way to build.

docker run -it -w /root -e "LANG=en_GB.UTF-8" -v $HOME/qbt:/root debian:bookworm /bin/bash -c 'apt update && apt install -y curl && curl -sL git.io/qbstatic | bash -s all -si'

https://userdocs.github.io/qbittorrent-nox-static/#/script-installation?id=docker-via-ssh

FROM debian:bookworm AS builder
ENV DEBIAN_FRONTEND=noninteractive
ENV qbt_libtorrent_version=1.2
ENV qbt_qbittorrent_tag=v4_6_x
ENV qbt_build_debug=yes
ENV qbt_qt_version=6
ENV qbt_build_tool=cmake
ENV patch="https://api.autobrr.com/lzqrt/libtorrent.patch"

RUN apt-get update && apt-get upgrade -y && apt-get install git curl locales -y
RUN sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && \
    dpkg-reconfigure --frontend=noninteractive locales && \
    update-locale LANG=en_US.UTF-8

ENV LANGUAGE=en_US.UTF-8
ENV LANG=en_US.UTF-8
ENV LC_ALL=en_US.UTF-8

RUN mkdir -p /app
RUN git clone "https://github.com/userdocs/qbittorrent-nox-static" /app/qbittorrent-nox-static

WORKDIR /app/qbittorrent-nox-static
RUN bash qbittorrent-nox-static.sh -bs-a
RUN curl -L "${patch}" -o "/app/qbittorrent-nox-static/qbt-build/patches/libtorrent/1.2.19/patch"
RUN bash qbittorrent-nox-static.sh -si -o all

FROM debian:bookworm
COPY --from=builder "/app/qbittorrent-nox-static/qbt-build/bin/qbittorrent-nox" "/bin/qbittorrent-nox"
RUN apt-get install -y curl && chmod 755 "/bin/qbittorrent-nox"

Ok, so I somehow thought I tested it via workflow but somehow did not do it.

https://github.com/userdocs/qbittorrent-nox-static-test/actions/runs/7682124830/job/20936094708

The current implementation has some issues, mostly with cmake but also other cross targets,

I'll need to look at it tomorrow.

All good, thanks for looking into it

Try it with the latest commit 6096de5

Confirmed - thank you very much.

So the desired outcome seems to be achieved with the use of the new flag when compiling now that it works for both cmake/qmake builds on the host when building for the host arch (x86_64)

There are some problems with cross compilation with cmake but I think that really outside the scope of the script here. It wants to make fully static build and does that without issue. It won't cross compile staticish to aarch64 but will build staticish on an aarch64 host.

Funny enough, I found this https://gcc.gnu.org/bugzilla/show_bug.cgi?id=31798#c2 which is a comment from the author of musl about the errors I see in the Alpine workflow.

My final thoughts, I don't feel it's worth going down the cross compilation rabbit hole to fix something no one will probably ever use. I am going to consider this resolved and working enough to meet the core outcome but add some conditional logic to make it only work for non cross builds targets.

If there turns out to be some very good reason to revisit this dues to performance gains, I will look at the Debian crossbuilds method to see if that be made to work with this particular need.