Skip to content

Commit 3988baf

Browse files
ondrejmirtesclaude
andcommitted
Subsplit turbo-ext into phpstan/turbo-ext and package it for PIE
subsplit-turbo-ext.yml replays every commit touching turbo-ext/ onto https://github.com/phpstan/turbo-ext — incremental and idempotent via a Split-From trailer, with a generated VERSION.txt carrying the extension version at each replayed commit. composer.json makes the split repo the phpstan/turbo PIE package (prebuilt release assets first, source build as the fallback), and config.m4 provides the phpize path that fallback needs, guarded by the new turbo-phpize job. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HfL64DBGo52Nz91fBLtf9D
1 parent 1a8260e commit 3988baf

11 files changed

Lines changed: 401 additions & 12 deletions

File tree

‎.github/workflows/phar.yml‎

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,93 @@ jobs:
199199
echo "::error::After changing either side, verify the implementations still match and add a follow-up commit setting the constant to that commit's short SHA (the binary bakes its version from git at build time)."
200200
exit 1
201201
fi
202+
# VERSION.txt is generated into the phpstan/turbo-ext subsplit by
203+
# subsplit-turbo-ext.yml; a copy committed here would go stale and
204+
# silently win over git in phpize builds.
205+
if [ -e turbo-ext/VERSION.txt ]; then
206+
echo "::error::turbo-ext/VERSION.txt must not exist in the monorepo — it is generated per replayed commit by the subsplit-turbo-ext.yml workflow."
207+
exit 1
208+
fi
209+
210+
turbo-phpize:
211+
# Builds through phpize && ./configure && make — the pipeline PIE drives
212+
# when it falls back to a source build of the phpstan/turbo package
213+
# (config.m4). The distributed binaries keep coming from the Makefile
214+
# legs in turbo-compile: the libtool link here cannot statically fold
215+
# libstdc++/libgcc into the .so, which the shipped Linux binaries need
216+
# to stay independent of the host's GLIBCXX symbol versions. One PHP
217+
# version suffices — per-version compile coverage comes from
218+
# turbo-compile; this job guards the build system itself.
219+
name: "Turbo Extension phpize Build"
220+
runs-on: ${{ matrix.operating-system }}
221+
timeout-minutes: 30
222+
223+
strategy:
224+
fail-fast: false
225+
matrix:
226+
operating-system: ["ubuntu-latest", "macos-latest"]
227+
228+
steps:
229+
- name: Harden the runner (Audit all outbound calls)
230+
uses: step-security/harden-runner@9af89fc71515a100421586dfdb3dc9c984fbf411 # v2.19.4
231+
with:
232+
egress-policy: audit
233+
234+
- name: "Checkout"
235+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
236+
with:
237+
persist-credentials: false
238+
fetch-depth: 0 # the VERSION.txt written below bakes from git log over turbo-ext/src
239+
240+
- name: "Install PHP"
241+
uses: "shivammathur/setup-php@f3e473d116dcccaddc5834248c87452386958240" # v2.37.2
242+
with:
243+
coverage: "none"
244+
php-version: "8.5"
245+
246+
- name: "Build via phpize outside the checkout"
247+
# The copy is deliberately outside the git checkout and gets a
248+
# VERSION.txt generated the same way subsplit-turbo-ext.yml commits
249+
# it into phpstan/turbo-ext — the exact shape a PIE source build
250+
# sees: no monorepo history, the version supplied by the file.
251+
run: |
252+
if [ "$RUNNER_OS" = "macOS" ]; then
253+
command -v autoconf > /dev/null || brew install autoconf
254+
fi
255+
cp -R turbo-ext "$RUNNER_TEMP/turbo-ext"
256+
mapfile -t MAPPED_PHP < <(jq -r '.[] | select(.vendored != true) | .php' turbo-ext/shadowed-classes.json)
257+
git log -1 --format=%H -- turbo-ext/src "${MAPPED_PHP[@]}" | cut -c1-7 > "$RUNNER_TEMP/turbo-ext/VERSION.txt"
258+
echo "VERSION.txt: $(cat "$RUNNER_TEMP/turbo-ext/VERSION.txt")"
259+
cd "$RUNNER_TEMP/turbo-ext"
260+
phpize
261+
./configure
262+
make -j"$(getconf _NPROCESSORS_ONLN)"
263+
264+
- name: "Verify the built extension reports the expected version"
265+
run: |
266+
REPORTED="$(php -d extension="$RUNNER_TEMP/turbo-ext/modules/phpstan_turbo.so" -r 'echo phpversion("phpstan_turbo");')"
267+
EXPECTED="$(sed -n "s/.*EXPECTED_EXTENSION_VERSION = '\([^']*\)'.*/\1/p" src/Turbo/TurboExtensionEnabler.php)"
268+
echo "built extension reports: $REPORTED, enabler expects: $EXPECTED"
269+
[ "$REPORTED" = "$EXPECTED" ]
270+
271+
- uses: "ramsey/composer-install@65e4f84970763564f46a70b8a54b90d033b3bdda" # v4.0.0
272+
273+
- name: "Smoke test (differential: native vs PHP implementations)"
274+
run: php -d extension="$RUNNER_TEMP/turbo-ext/modules/phpstan_turbo.so" turbo-ext/tests/smoke.php
275+
276+
- name: "Arena smoke test (cross-process shared-memory records)"
277+
run: php -d extension="$RUNNER_TEMP/turbo-ext/modules/phpstan_turbo.so" turbo-ext/tests/arena-smoke.php
278+
279+
- name: "Signature parity (reflect native classes against the PHP twins)"
280+
run: php -d extension="$RUNNER_TEMP/turbo-ext/modules/phpstan_turbo.so" turbo-ext/tests/signature-parity.php
281+
282+
- name: "Parser corpus (differential: native vs PHP ASTs must be byte-identical)"
283+
run: php -d extension="$RUNNER_TEMP/turbo-ext/modules/phpstan_turbo.so" -d memory_limit=4G turbo-ext/tests/parser-corpus.php
284+
285+
- name: "make install into a scratch root (PIE finishes with make install)"
286+
run: |
287+
make -C "$RUNNER_TEMP/turbo-ext" install INSTALL_ROOT="$RUNNER_TEMP/install-root"
288+
find "$RUNNER_TEMP/install-root" -name 'phpstan_turbo.so' | grep .
202289
203290
turbo-compile:
204291
name: "Compile Turbo Extension"
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
# Monorepo-style subsplit: replays every commit that touches turbo-ext/ onto
2+
# https://github.com/phpstan/turbo-ext, where the extension is distributed
3+
# standalone (the phpstan/turbo PIE package on Packagist).
4+
#
5+
# Each replayed commit keeps the original message, author, committer and
6+
# dates, and its tree is the commit's turbo-ext/ subtree — plus a
7+
# "Split-From: <monorepo sha>" trailer and a generated VERSION.txt carrying
8+
# the extension version at that commit (the monorepo short SHA the enabler
9+
# pins; builds in the split cannot compute it — replayed commits have
10+
# different SHAs, and PIE tarballs have no git at all). The trailer is what
11+
# makes the replay incremental and idempotent: a run reads the most recent
12+
# trailer from the split repository and replays only the commits made since,
13+
# on top of the split branch's current head. A failed or skipped run is
14+
# simply caught up by the next one (or by a manual workflow_dispatch).
15+
# git subtree split is not used because it walks the entire monorepo history
16+
# on every run, which takes tens of minutes at this repository's size.
17+
#
18+
# When a new maintained branch (2.3.x, ...) starts, update the branch trigger
19+
# below (like phar.yml) and create the same-named branch in phpstan/turbo-ext
20+
# from the previous branch's head — that head's trailer keeps the replay
21+
# incremental across the branch point.
22+
23+
name: "Subsplit turbo-ext"
24+
25+
on:
26+
workflow_dispatch:
27+
push:
28+
branches:
29+
- "2.2.x"
30+
paths:
31+
- "turbo-ext/**"
32+
- ".github/workflows/subsplit-turbo-ext.yml"
33+
34+
# The replay chain builds on the split branch's current head; two runs
35+
# building on the same head would race each other, so queue them instead.
36+
concurrency:
37+
group: subsplit-turbo-ext
38+
cancel-in-progress: false
39+
40+
permissions: {}
41+
42+
jobs:
43+
subsplit:
44+
name: "Replay turbo-ext commits"
45+
runs-on: "ubuntu-latest"
46+
timeout-minutes: 10
47+
48+
steps:
49+
- name: Harden the runner (Audit all outbound calls)
50+
uses: step-security/harden-runner@9af89fc71515a100421586dfdb3dc9c984fbf411 # v2.19.4
51+
with:
52+
egress-policy: audit
53+
54+
- name: "Checkout"
55+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
56+
with:
57+
persist-credentials: false
58+
fetch-depth: 0 # the replay walks the full history of the branch
59+
60+
- name: "Replay commits touching turbo-ext/ and push them to phpstan/turbo-ext"
61+
env:
62+
PUSH_TOKEN: ${{ secrets.PHPSTAN_BOT_TOKEN }}
63+
BRANCH: ${{ github.ref_name }}
64+
run: |
65+
PREFIX="turbo-ext"
66+
67+
# The split branch must already exist (see the header comment); the
68+
# fetch fails loudly when it does not.
69+
git fetch --no-tags https://github.com/phpstan/turbo-ext.git "refs/heads/$BRANCH"
70+
target_head="$(git rev-parse FETCH_HEAD)"
71+
72+
# The most recent Split-From trailer marks where the previous
73+
# replay stopped. No trailer anywhere (the split repository only
74+
# has its initial commit) means the full history gets replayed.
75+
last_synced="$(git log FETCH_HEAD --format='%(trailers:key=Split-From,valueonly)' | grep -m1 . || true)"
76+
if [ -n "$last_synced" ] && ! git merge-base --is-ancestor "$last_synced" HEAD; then
77+
echo "::error::$BRANCH does not contain $last_synced, the most recent Split-From trailer in the split repository. Was the branch history rewritten?"
78+
exit 1
79+
fi
80+
81+
# Every commit touching turbo-ext/ so far sits on the first-parent
82+
# chain (verified July 2026), and first-parent order is append-only,
83+
# so the replay never reorders. A maintained-branch forward merge
84+
# that touches turbo-ext/ replays as the merge commit itself.
85+
mapfile -t commits < <(git rev-list --reverse --first-parent ${last_synced:+"$last_synced.."}HEAD -- "$PREFIX")
86+
if [ "${#commits[@]}" -eq 0 ]; then
87+
echo "The split repository is up to date at $target_head."
88+
exit 0
89+
fi
90+
91+
parent="$target_head"
92+
for commit in "${commits[@]}"; do
93+
# The version at this commit, mirroring the Makefile's git
94+
# computation: the last commit touching turbo-ext/src or a
95+
# non-vendored PHP class from the manifest as it existed at this
96+
# commit ("dev" before that layout existed).
97+
watched=("$PREFIX/src")
98+
while IFS= read -r mapped; do
99+
watched+=("$mapped")
100+
done < <(git show "$commit:$PREFIX/shadowed-classes.json" 2>/dev/null | jq -r '.[] | select(.vendored != true) | .php' 2>/dev/null || true)
101+
version="$(git log -1 --format=%H "$commit" -- "${watched[@]}" | cut -c1-7)"
102+
blob="$(printf '%s\n' "${version:-dev}" | git hash-object -w --stdin)"
103+
# a commit removing the directory altogether replays as an empty tree
104+
if subtree="$(git rev-parse -q --verify "$commit:$PREFIX")"; then
105+
tree="$({ git ls-tree "$subtree" | awk -F'\t' '$2 != "VERSION.txt"'; printf '100644 blob %s\tVERSION.txt\n' "$blob"; } | git mktree)"
106+
else
107+
tree="$(git hash-object -t tree /dev/null)"
108+
fi
109+
parent="$(
110+
git log -1 --format=%B "$commit" \
111+
| git interpret-trailers --trailer "Split-From: $commit" \
112+
| GIT_AUTHOR_NAME="$(git log -1 --format=%an "$commit")" \
113+
GIT_AUTHOR_EMAIL="$(git log -1 --format=%ae "$commit")" \
114+
GIT_AUTHOR_DATE="$(git log -1 --format=%aD "$commit")" \
115+
GIT_COMMITTER_NAME="$(git log -1 --format=%cn "$commit")" \
116+
GIT_COMMITTER_EMAIL="$(git log -1 --format=%ce "$commit")" \
117+
GIT_COMMITTER_DATE="$(git log -1 --format=%cD "$commit")" \
118+
git commit-tree "$tree" -p "$parent"
119+
)"
120+
echo "$commit -> $parent"
121+
done
122+
123+
echo "Replayed ${#commits[@]} commit(s), pushing to $BRANCH"
124+
git push "https://x-access-token:${PUSH_TOKEN}@github.com/phpstan/turbo-ext.git" "$parent:refs/heads/$BRANCH"

‎turbo-ext/.gitignore‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,39 @@
44
/phpstan_turbo.so
55
/side-by-side.html
66
/version.stamp
7+
8+
# Generated and committed into the phpstan/turbo-ext subsplit by
9+
# subsplit-turbo-ext.yml — must not exist in the monorepo (builds here take
10+
# the version from git; a stale copy would poison phpize builds).
11+
/VERSION.txt
12+
13+
# phpize/configure artifacts (the PIE build path; note that ./configure also
14+
# overwrites the committed Makefile — git restore brings it back)
15+
/.libs/
16+
/acinclude.m4
17+
/aclocal.m4
18+
/autom4te.cache/
19+
/build/
20+
/config.guess
21+
/config.h
22+
/config.h.in
23+
/config.log
24+
/config.nice
25+
/config.status
26+
/config.sub
27+
/configure
28+
/configure.ac
29+
/install-sh
30+
/libtool
31+
/ltmain.sh
32+
/Makefile.fragments
33+
/Makefile.global
34+
/Makefile.objects
35+
/missing
36+
/mkinstalldirs
37+
/modules/
38+
/run-tests.php
39+
/src/*.lo
40+
/src/parser/*.lo
41+
/src/.libs/
42+
/src/parser/.libs/

‎turbo-ext/CLAUDE.md‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,10 @@ being ≥0.5% faster is. When the estimate is marginal, don't port.
7373
10. **Version bump**: commit the change, then a follow-up commit setting
7474
`TurboExtensionEnabler::EXPECTED_EXTENSION_VERSION` to
7575
`git log -1 --format=%H -- turbo-ext/src <shadowed PHP files> | cut -c1-7`.
76-
The binary's own version is baked from git at build time, so only the
77-
PHP constant is hand-edited. The bump cannot be part of the same commit —
76+
The binary's own version is baked from git at build time (builds outside
77+
the monorepo read the VERSION.txt that subsplit-turbo-ext.yml generates
78+
into phpstan/turbo-ext — never create that file here), so only the PHP
79+
constant is hand-edited. The bump cannot be part of the same commit —
7880
the SHA would change under it.
7981

8082
## Build and verify commands

‎turbo-ext/LICENSE‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
MIT License
2+
3+
Copyright (c) 2016 Ondřej Mirtes
4+
Copyright (c) 2025 PHPStan s.r.o.
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.

‎turbo-ext/Makefile‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,23 @@ CXXFLAGS := $(WARN_FLAGS) -O2 -std=c++17 -fPIC \
2121
# The extension version is the short SHA of the last commit touching
2222
# turbo-ext/src/ or a shadowed PHP twin (the same watched set the CI version
2323
# job enforces against TurboExtensionEnabler::EXPECTED_EXTENSION_VERSION),
24-
# computed from git at build time and baked in via -D. Outside a git checkout
25-
# it degrades to "dev", which the enabler rejects — the extension then simply
26-
# stays inactive. version.stamp makes a SHA change rebuild main.o.
24+
# computed from git at build time and baked in via -D. Outside the monorepo
25+
# (the phpstan/turbo-ext subsplit, a release tarball) git yields nothing —
26+
# and the subsplit's replayed commits have different SHAs anyway — so
27+
# VERSION.txt carries the monorepo SHA instead: subsplit-turbo-ext.yml
28+
# generates and commits it per replayed commit, and it must never exist in
29+
# the monorepo (the .txt suffix is load-bearing — C++ stdlibs #include
30+
# <version>, and with the extension root on the include path a file named
31+
# VERSION satisfies that include on case-insensitive filesystems). With
32+
# neither source it degrades to "dev", which the enabler rejects — the
33+
# extension then simply stays inactive. version.stamp makes a SHA change
34+
# rebuild main.o.
2735
MAPPED_PHP := $(shell php -n -r 'echo implode(" ", array_map(static fn ($$e) => $$e["php"], array_filter(json_decode(file_get_contents("shadowed-classes.json"), true), static fn ($$e) => !($$e["vendored"] ?? false))));' 2>/dev/null)
2836
PHPSTANTURBO_VERSION := $(shell git -C .. log -1 --format=%H -- turbo-ext/src $(MAPPED_PHP) 2>/dev/null | cut -c1-7)
2937
ifeq ($(PHPSTANTURBO_VERSION),)
38+
PHPSTANTURBO_VERSION := $(strip $(shell cat VERSION.txt 2>/dev/null))
39+
endif
40+
ifeq ($(PHPSTANTURBO_VERSION),)
3041
PHPSTANTURBO_VERSION := dev
3142
endif
3243
CXXFLAGS += -DPHPSTANTURBO_VERSION='"$(PHPSTANTURBO_VERSION)"'

‎turbo-ext/README.md‎

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,13 @@ is declared by hand. After changing either side of a shadowed pair, verify the
3838
implementations still match and add a follow-up commit updating the constant
3939
to the short SHA of the changing commit; the phar.yml `turbo-version` job
4040
enforces the SHA and the compile job verifies the built binary reports what
41-
the enabler expects. Builds outside a git checkout bake the version "dev",
42-
which the enabler rejects — the extension then simply stays inactive.
41+
the enabler expects. Builds outside the monorepo — the phpstan/turbo-ext
42+
subsplit and PIE source builds from it — cannot ask git (the subsplit's
43+
replayed commits have different SHAs, tarballs have no checkout at all), so
44+
the subsplit workflow generates and commits a `VERSION.txt` there and the
45+
builds fall back to it; the file must never exist in the monorepo. With
46+
neither git nor `VERSION.txt` the version bakes as "dev", which the enabler
47+
rejects — the extension then simply stays inactive.
4348

4449
## Keeping the two implementations in sync
4550

@@ -202,6 +207,21 @@ supported — the build inherits thread-safety from the `php-config` it is
202207
pointed at (ZTS hosts like PMMP's bundled PHP get a matching build; PHPStan
203208
itself only ever runs the native code single-threaded).
204209

210+
The standard `phpize && ./configure && make` pipeline works too
211+
(`config.m4`) — it is what [PIE] drives when it builds the phpstan/turbo
212+
package from source, e.g. for combinations without a prebuilt binary. That
213+
path bakes the version from `VERSION.txt` (present only in the
214+
phpstan/turbo-ext subsplit, where its workflow commits it — in the monorepo
215+
build with `make` instead), and its `./configure` overwrites this
216+
directory's Makefile with the generated one (`git restore Makefile` brings
217+
it back; PIE builds in its own extracted copy). The hand-written Makefile
218+
stays the primary build: it statically links libstdc++/libgcc on Linux —
219+
the distributed binaries must not depend on the build host's GLIBCXX symbol
220+
versions — and carries the strict warning setup, neither of which survives
221+
the libtool link.
222+
223+
[PIE]: https://github.com/php/pie
224+
205225
On Windows the extension builds through the standard PHP extension pipeline
206226
(`config.w32`): with a PHP devel pack, [php-sdk-binary-tools] and a VS2022
207227
x64 developer prompt, run `phpize && configure --enable-phpstan-turbo &&
@@ -212,7 +232,7 @@ the PHP core, and the official php.net binaries are built with VS2022
212232
(whose VS2026 image links with 14.5x). Set the `PHPSTANTURBO_VERSION`
213233
environment variable before `configure` to bake the version (the Makefile
214234
computes it from git automatically; `config.w32` reads it from the
215-
environment).
235+
environment, falling back to `VERSION.txt`).
216236

217237
[php-sdk-binary-tools]: https://github.com/php/php-sdk-binary-tools
218238

‎turbo-ext/composer.json‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"name": "phpstan/turbo",
3+
"description": "Native acceleration extension for PHPStan",
4+
"license": [
5+
"MIT"
6+
],
7+
"type": "php-ext",
8+
"homepage": "https://phpstan.org",
9+
"require": {
10+
"php": "~8.3.0 || ~8.4.0 || ~8.5.0"
11+
},
12+
"php-ext": {
13+
"extension-name": "phpstan_turbo",
14+
"download-url-method": [
15+
"pre-packaged-binary",
16+
"composer-default"
17+
],
18+
"os-families": [
19+
"linux",
20+
"darwin",
21+
"windows"
22+
]
23+
},
24+
"support": {
25+
"issues": "https://github.com/phpstan/phpstan/issues",
26+
"source": "https://github.com/phpstan/turbo-ext"
27+
}
28+
}

0 commit comments

Comments
 (0)