Skip to content

Fix doctor on fresh Linux, auto-install llvm-tools for cross builds - #1256

Merged
crazywhalecc merged 3 commits into
v3from
v3c/llvm-tools-followup
Oct 16, 2026
Merged

crazywhalecc merged 3 commits into
v3from
v3c/llvm-tools-followup

Conversation

@crazywhalecc

Copy link
Copy Markdown
Owner

What does this PR do?

Follow-up to #1254, which was merged without these changes.

  • Fixes spc doctor --auto-fix on fresh Linux machines (regression from V3c/llvm tools prev #1254). Since the zig toolchain declares zig in every run, PackageInstaller::run() replaced the doctor's global binary-only with the list of binary-only packages (zig). The pkg-config fix then built pkg-config from source with zig-cc, which doctor never puts on PATH, and failed with exit code 77. This breaks the first run of static-php/hosted's llvm-tools.yml (https://github.com/static-php/hosted/actions/runs/38704035893) and every other workflow that starts with doctor. The list is now merged into an existing global flag (DownloaderOptions::addToList()).
  • Removes --with-llvm-tools, as requested in the V3c/llvm tools prev #1254 review. ZigToolchain now declares llvm-tools itself for cross builds, where the host binutils cannot handle the binaries (SystemTarget::isCrossCompiling() reads the architecture from the target triple, so e.g. arm32 targets count too). Toolchain packages prefer the published binary, with the source build as fallback. Native builds keep using the host binutils, and the warnings now point to bin/spc install-pkg llvm-tools.
  • Pre-built llvm-tools come from dl.static-php.dev/v3/deps/llvm-tools/, published by static-php/hosted's llvm-tools.yml. The archive is selected by the host architecture (the tools run on the build machine) and verified against the published .sha256.
  • Fixes the llvm-tools source build: its private zlib now gets -DHAVE_UNISTD_H, because clang >= 16 rejects zlib's undeclared lseek/read/close.
  • No more stray a.o: ZigToolchain::getCompilerVersion() uses zig cc -dumpversion, because zig cc --version left an empty a.o in the user's working directory on every run.
  • Docs (en/zh) updated; new unit tests for isCrossCompiling() and addToList().

Also validated before #1254 was merged, in a Linux arm64 container (Debian, PHP 8.4):

  • doctor --auto-fix from scratch, then build:libs llvm-tools, producing static binaries (a 2.09 MB archive).
  • A native build doesn't install llvm-tools. An x86_64 cross build on the aarch64 host pulls the pre-built archive by itself and strips with it; the host GNU binutils reject the same binary.

Checklist before merging

  • If you modified *.php or *.yml, run them locally to ensure your changes are valid:
    • composer cs-fix (no changes)
    • composer analyse (no errors)
    • composer test (OK, 465 tests)
    • bin/spc dev:lint-config (no changes)

…builds

Follow-up to #1254:
- Merge the installer's binary-only package list into a caller's global
  binary-only instead of replacing it. Since the zig toolchain declares zig
  in every run, doctor's pkg-config fix built pkg-config from source without
  zig-cc on PATH and failed on fresh Linux machines.
- Replace --with-llvm-tools: ZigToolchain declares llvm-tools for cross
  builds, and toolchain packages prefer pre-built binaries.
- Download pre-built llvm-tools from dl.static-php.dev by host arch and
  verify the .sha256 sidecar.
- Build llvm-tools' private zlib with HAVE_UNISTD_H (clang >= 16).
- Use `zig cc -dumpversion`; `--version` left an empty a.o behind.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Comment thread src/Package/Artifact/llvm_tools.php Outdated
Comment thread src/StaticPHP/Package/PackageBuilder.php
@crazywhalecc
crazywhalecc merged commit b0007ed into v3 Oct 16, 2026
9 checks passed
@crazywhalecc
crazywhalecc deleted the v3c/llvm-tools-followup branch October 16, 2026 00:19
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.

2 participants