matrix-org / matrix-org/rust-synapse-compress-state

Please provide static builds or static build instructions

Open
#82 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
173
Forks
37
PR merge metrics
No merged PRs in 30d

Description

As far as I can tell, it is not possible to build this program statically. This seems to mostly be the fault of rust, with the musl target no longer magically letting you compile rust statically, but a tool that is intended to run on a server really should be distributable as a static binary somehow.

It would be great if there were either static build instructions that folks could copy-paste, or the project itself provided static builds of its binaries. There are static builds for the 0.1.0 release but the main branch has the `synapse_auto_compressor` program which didn't exist ~2 years ago when the last release was made.

After reading lots of blog posts and rustc bug reports, I managed to reach the following command run inside an Alpine Linux container (good luck getting this to work on a glibc-based distribution installation because it will treat the musl target as a cross-compilation target which will then not work with building openssl):

```
% RUSTFLAGS="-C target-feature=+crt-static -C link-self-contained=yes -L native=/usr/lib -l static=ssl -l static=crypto -l static=c" cargo build --release --target x86_64-alpine-linux-musl
```

(The `--target` is necessary for the reasons mentioned in https://github.com/rust-lang/rust/issues/78210 -- basically it's because proc-macros don't get the `RUSTFLAGS` applied unless you explicitly set the `--target` -- **even if** the target is the same as the host.)

In addition, I had to patch out the jemalloc requirement because I couldn't figure out how to get it to build (I'm a little confused why the compressor binary needs to use jemalloc -- surely for a tool which runs once in a while you don't need a super optimised memory allocator?).

However **the resulting binary is *still* dynamically linked**, it's just that every library except the link loader are statically linked into the binary. This is a problem because the loader is `/lib/ld-musl` which won't work for my glibc-based server. In addition, the binary itself segfaults *even if you try to run it on alpine* -- it seems that one or all of the RUSTFLAGS are causing issues (it seems that even if you only use `-C target-feature=+crt-static` you get segfaulting binaries).

If you can offer some kind of script or anything that would help me solve this problem I would seriously appreciate it.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Alpine cargo build command and the reported jemalloc, OpenSSL, loader, and segmentation-fault problems. Investigate how the project builds its binaries, including synapse_auto_compressor, and determine whether reproducible static builds or copy-paste build instructions are feasible. Done means the current binaries can be built and run as documented on the intended target environments.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
build-system
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.