llvm-tools: build host llvm-objcopy/strip/profdata under ZigToolchain - #1172
llvm-tools: build host llvm-objcopy/strip/profdata under ZigToolchain#1172henderkes wants to merge 7 commits into
Conversation
|
@henderkes Looks using |
|
Yes, I'll need to rework this. |
6df778f to
fb779e7
Compare
fb779e7 to
680919b
Compare
crazywhalecc
left a comment
There was a problem hiding this comment.
Most of it seems fine, but I don't think installing these two packages by default offers any benefit. Most people don't need PGO and shared builds. They could be triggered under specific conditions, similar to --with-upx-pack (either in doctor or the toolchain).
Do you want to scan cflags for lto/pgo instead and error out? libcompiler_rt needs to be built for cpu_model anyway, though. Many libraries/extensions use builtin_cpu_supports and building it only takes a few seconds anyways. |
|
Forgot to mention, but gnu objcopy also can't work for cross compilation (e.g. from aarch64 to arm32). I think if we host the tools it's preferable to always have. |
Co-authored-by: Jerry Ma <jesse2061@outlook.com>
There was a problem hiding this comment.
🟡 Changes recommended
A detected flag-handling bug in zig-cc.sh can prevent linking the profile runtime when profile flags come from SPC_COMPILER_EXTRA, and binutil override precedence in PackageBuilder needs adjustment for expected behavior.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Adds a new llvm-tools tool artifact and a llvm-compiler-rt target to make ZigToolchain builds reliable when binutils/strip choke on Zig-produced archives/bitcode, and wires these tools into the build/doctor flow.
Changes:
- Introduces
llvm-tools(llvm-objcopy/llvm-strip/llvm-profdata) andllvm-compiler-rtpackages/artifacts aligned to the active Zig-shipped clang/LLVM version. - Updates ZigToolchain to export
SPC_COMPILER_RT_DIRand to auto-ensure required LLVM deps when the toolchain is initialized for real builds. - Updates PackageBuilder to prefer LLVM binutils under Zig, and extends the zig wrapper to link missing compiler-rt components when needed.
File summaries
| File | Description |
|---|---|
| src/StaticPHP/Toolchain/ZigToolchain.php | Exports compiler-rt dir and ensures Zig-specific build deps are present. |
| src/StaticPHP/Runtime/SystemTarget.php | Adds a canonical target triple helper used by Zig/LLVM packages. |
| src/StaticPHP/Package/PackageBuilder.php | Routes strip/objcopy selection through a Zig-aware binutil resolver. |
| src/StaticPHP/Doctor/Item/LlvmToolsCheck.php | Adds doctor checks/fixes for llvm-tools and llvm-compiler-rt when ZigToolchain is active. |
| src/Package/Tool/llvm_tools.php | Implements building host llvm tools (plus private zlib) from source. |
| src/Package/Target/llvm_compiler_rt.php | Builds missing compiler-rt bits Zig needs into zig/lib/{triple}. |
| src/Package/Artifact/zig.php | Adds helper to detect Zig-shipped clang/LLVM version; refactors wrapper generation. |
| src/Package/Artifact/llvm_tools.php | Custom artifact for llvm-tools (source + hosted binary) keyed to Zig LLVM version. |
| src/Package/Artifact/llvm_compiler_rt.php | Custom source artifact for compiler-rt keyed to Zig LLVM version. |
| src/globals/scripts/zig-cc.sh | Injects compiler-rt libs/objects into Zig link steps when required by flags. |
| config/pkg/tool/llvm-tools.yml | Declares the llvm-tools tool package (provides + install layout + license metadata). |
| config/pkg/target/llvm-compiler-rt.yml | Declares the llvm-compiler-rt target package and its Zig tool dependency. |
Review details
- Files reviewed: 12/12 changed files
- Comments generated: 2
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Add an
llvm-toolstarget artifact that downloads llvm-project source matching the version of clang shipped by the active zig install, builds llvm-objcopy, llvm-strip and llvm-profdata into PKG_ROOT_PATH/llvm-tools/bin, and exposes them through the same path/binary/isInstalled static surface as the other artifacts.A new LlvmToolsCheck doctor item runs when the active toolchain is ZigToolchain and reports whether the three tools are built, with a fix that installs the package and runs the build.
PackageBuilder now picks the right tool when the active toolchain is ZigToolchain:
System strip/objcopy refuse zig-produced archives and bitcode sections, so without this the strip stage breaks LTO builds. Other toolchains keep using the system binaries.
ApplicationContext::tryGet() wraps the container's get() in a try/catch and returns null on failure, so PackageBuilder can ask "which toolchain is active right now" without PHP-DI throwing on autowirable-but-unconstructable classes.
Depends on v3c/artifact-static-helpers (uses zig::isInstalled() and zig::binary()).
What does this PR do?
Checklist before merging
*.phpor*.yml, run them locally to ensure your changes are valid:composer cs-fixcomposer analysecomposer testbin/spc dev:lint-config