Add a script that builds a static Linux executable

scripts/build-static.sh builds the daemon for x86_64 Linux against
musl, as one executable without dependencies to copy to a router. It
finds a musl C compiler for jemalloc (musl-cross on macOS, musl-gcc on
Linux), and uses its ar and ranlib too: with the host's, a build from
macOS gets an empty libjemalloc.a and fails to link. It prints the
revision and the SHA-256 of the result.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Rayhaan JaufeerallyandClaude Opus 5.5 committed 2026-10-04 01:03:16 +02:00
1 parent 361c48f656
commit e1d819d629
2 files changed
+78

No files matched your search

@@ -57,6 +57,35 @@ To build and install the daemon:
The command displays the installed version, for example `bgp 0.1.0`.
## Building a Static Executable
The script `scripts/build-static.sh` builds the daemon as a single static
executable for x86_64 Linux, linked against musl. The executable runs on any
x86_64 Linux distribution without other dependencies.
The script requires the Rust target and a musl C compiler for jemalloc:
```bash
rustup target add x86_64-unknown-linux-musl
```
On macOS, install the cross compiler with
`brew install FiloSottile/musl-cross/musl-cross`. On x86_64 Linux, install
`musl-tools` (Debian, Ubuntu) or `musl` (Arch Linux).
```bash
scripts/build-static.sh
```
The script displays the path of the executable, the source revision, and
the SHA-256 checksum of the executable:
```
target/x86_64-unknown-linux-musl/release/bgp: ELF 64-bit LSB pie executable, x86-64, static-pie linked
revision 9ce81a8
2faa32d3... target/x86_64-unknown-linux-musl/release/bgp
```
## Building a Container Image
The `Dockerfile` in the repository builds the daemon in a Rust build stage