This proof of concept is one approach to static musl libc based builds. It leverages musl-cross-make to compile a musl libc targeting toolchain, made up of GCC 10.3.0 + binutils 2.37 + musl libc 1.2.3, and then uses that toolchain to build our depends libraries, and ultimately bitcoind
.
More than likely we’d take a different approach in Guix for (potentially) release builds, however, something like this could exist in depends, and provide an alternative to building against glibc outside Guix. Or, this may well end up being something we just throw away in favour of a better approach; still lots to be thought about here.
Only tested compiling on, for x86_64-pc-linux-gnu
so far.
You can use it as follows:
0make -C depends/ -j9 NO_QT=1 NO_WALLET=1 NO_UPNP=1 NO_ZMQ=1 NO_NATPMP=1 USE_MUSL_LIBC=1 HOST=x86_64-linux-musl
1./autogen.sh
2CONFIG_SITE=/path/to/your/bitcoin/depends/x86_64-pc-linux-musl/share/config.site ./configure --enable-reduce-exports --enable-lto LDFLAGS="-Wl,-O2" LIBTOOL_APP_LDFLAGS="-all-static"
3make src/bitcoind
The end result (once stripped) is a ~10mb static bitcoind
:
0ldd src/bitcoind
1 statically linked
If you see:
0terminate called after throwing an instance of 'std::runtime_error'
1 what(): locale::facet::_S_create_c_locale name not valid
2Aborted (core dumped)
when running, pass LC_ALL=C
. i.e LC_ALL=C src/bitcoind
.
I’ve taken the binary onto a few different system / inside VMs, and am running a full sync.
Note that all dependencies do compile, except for Qt (build issue with FreeType I have not investigated), I’ve just excluded all optional dependencies from the depends build above.
When building, you may see warnings about libraries, such as libstdc++
, as having been moved, during linking, and/or other warnings, from dependencies, such as sqlite, due to -flto
usage.
Related to #18110.