Statically-link pre-compiled binaries
Problem
Hi mdBook Team, Thanks so much for making this tool! I'm using it to publish https://www.applin.dev/docs/ .
Running the pre-built binary on Render.com in a Rust build is failing:
curl --silent --show-error --location https://github.com/rust-lang/mdBook/releases/download/v0.4.35/mdbook-v0.4.35-x86_64-unknown-linux-gnu.tar.gz --output mdbook.tar.gz --time-cond mdbook.tar.gz
echo '4ef777bfcb3fd01687deed990372a6eb5e125f79b592014b0ac09b61595f0b34 mdbook.tar.gz' >mdbook.tar.gz.sha256
shasum -a 256 mdbook.tar.gz.sha256
tar xzvf mdbook.tar.gz mdbook
mdbook build docs/
mdbook: /lib/x86_64-linux-gnu/libm.so.6: version `GLIBC_2.29' not found (required by mdbook)
This is a problem with Render's Linux image having incompatible versions of libm and libc. I fixed the build by making it download and build mdbook, which is slow.
Proposed Solution
I wish mdbook was statically linked. Then it would always work, even on systems with broken or missing libraries.
What do you think about statically linking the pre-compiled mdbook binaries?
Cheers, Michael
Notes
No response
Static linking with glibc is notoriously hard and error-prone:
https://stackoverflow.com/questions/31770604/how-to-generate-statically-linked-executables https://users.rust-lang.org/t/statically-link-executable-with-glibc/32648 https://stackoverflow.com/questions/3430400/linux-static-linking-is-dead
I tried building it statically myself and failed, miserably. I'm afraid this one is a WONTFIX, as sad as that sounds.
However, there are a few things that could be done to make glibc struggles a bit less painful:
- Musl supports static linking out of the box without much issue, so we could publish binaries built against musl
- We can ship Docker containers to isolate mdbook's dependencies from the host system (though installing Docker Engine on a system that has glibc issues would be a very miserable exercise for the reader)
- We can ship a systemd portable service, but it might also be pretty useless if glibc itself is borked
- You can use Nix! It's a binary package manager that is linked statically, and it can be used to install the whole dependency tree of mdbook isolated from the host environment
- We can ship a Nix bundle. It uses some very clever tricks to create no-runtime, no-installation, distro-agnostic self-sufficient packages. It has some drawbacks, but it's very universal
For your particular use case, I think solution number 1 is best. It would be indeed nice to have musl static binaries.
@rustbot label +A-Installation +S-Wishlist
There is a musl build now so it should be ok?