Skip to content

build: fully static musl phpr (static-pie) via scripts/build-musl-deps.sh - #8

Open
annmuor wants to merge 1 commit into
francescotinti:mainfrom
annmuor:static-build-musl-linux
Open

annmuor wants to merge 1 commit into
francescotinti:mainfrom
annmuor:static-build-musl-linux

Conversation

@annmuor

@annmuor annmuor commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

Part of #5 discussion.

php-types build.rs hard-coded dylib= for gd, tidy, xslt, exslt and xml2, so a --target x86_64-unknown-linux-musl build still loaded the glibc-built system shared objects (and the glibc loader) despite +crt-static. Distributions ship those libraries only as glibc shared objects, which cannot go into a static musl binary.

On musl targets build.rs now links PIC static archives from $PHPR_MUSL_PREFIX (default ~/.local/phpr-musl, outside the repo) and stops with a pointer to the script when they are missing. The libxml2 XPath-name probe asks the prefix's xml2-config on musl. glibc builds are unchanged.

scripts/build-musl-deps.sh builds, with musl-gcc: zlib, libpng, libjpeg-turbo, libwebp, libaom, libavif, libgd (library only; no FreeType/fontconfig, phpr does not use them), libxml2 (no ICU), libxslt/libexslt and tidy-html5. It works around NASM 3's reworded help text in libaom's probe and tidy 5.8's old cmake_minimum_required. Incremental: only missing libraries are rebuilt; --clean starts over.

Requirements (Linux x86_64 host):

  • musl toolchain with musl-gcc (Arch: musl; Debian/Ubuntu: musl-tools)
  • rustup target add x86_64-unknown-linux-musl (pinned toolchain)
  • cmake, make, nasm, curl, tar with xz support

Process:

  1. scripts/build-musl-deps.sh
  2. cargo build --release --target x86_64-unknown-linux-musl -p php-cli -> target/x86_64-unknown-linux-musl/release/phpr, static-pie, ldd: "statically linked"

…s.sh

php-types build.rs hard-coded dylib= for gd, tidy, xslt, exslt and xml2, so a
--target x86_64-unknown-linux-musl build still loaded the glibc-built system
shared objects (and the glibc loader) despite +crt-static. Distributions ship
those libraries only as glibc shared objects, which cannot go into a static
musl binary.

On musl targets build.rs now links PIC static archives from $PHPR_MUSL_PREFIX
(default ~/.local/phpr-musl, outside the repo) and stops with a pointer to the
script when they are missing. The libxml2 XPath-name probe asks the prefix's
xml2-config on musl. glibc builds are unchanged.

scripts/build-musl-deps.sh builds, with musl-gcc: zlib, libpng, libjpeg-turbo,
libwebp, libaom, libavif, libgd (library only; no FreeType/fontconfig, phpr
does not use them), libxml2 (no ICU), libxslt/libexslt and tidy-html5. It
works around NASM 3's reworded help text in libaom's probe and tidy 5.8's old
cmake_minimum_required. Incremental: only missing libraries are rebuilt;
--clean starts over.

Requirements (Linux x86_64 host):
- musl toolchain with musl-gcc (Arch: musl; Debian/Ubuntu: musl-tools)
- rustup target add x86_64-unknown-linux-musl (pinned toolchain)
- cmake, make, nasm, curl, tar with xz support

Process:
1. scripts/build-musl-deps.sh
2. cargo build --release --target x86_64-unknown-linux-musl -p php-cli
   -> target/x86_64-unknown-linux-musl/release/phpr, static-pie, ldd:
   "statically linked"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant