@@ -497,6 +497,7 @@ jobs:
497497 PHP_MINOR : ${{ matrix.target.php-version }}
498498 PHP_ZTS : " 0"
499499 TURBO_ARTIFACT : " phpstan_turbo_core-${{ matrix.target.name }}"
500+ PGO_PROFILE_ARTIFACT : " turbo-pgo-profile-${{ matrix.target.name }}"
500501 ORIGIN_RUN_ID : ${{ fromJSON(needs.turbo-origins.outputs.origins || '{}')[format('phpstan_turbo_core-{0}', matrix.target.name)] }}
501502
502503 strategy :
@@ -544,6 +545,17 @@ jobs:
544545 run-id : ${{ env.ORIGIN_RUN_ID }}
545546 github-token : ${{ github.token }}
546547
548+ # the profile that core was compiled with, uploaded before it (see
549+ # "Upload the core's profile")
550+ - name : " Download the profile of the core compiled from identical build inputs"
551+ if : env.ORIGIN_RUN_ID != ''
552+ uses : actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
553+ with :
554+ name : ${{ env.PGO_PROFILE_ARTIFACT }}
555+ path : " turbo-ext"
556+ run-id : ${{ env.ORIGIN_RUN_ID }}
557+ github-token : ${{ github.token }}
558+
547559 - name : " Record the run that compiled the core"
548560 if : env.ORIGIN_RUN_ID != ''
549561 run : echo "$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$ORIGIN_RUN_ID" | tee turbo-reused.txt
@@ -614,8 +626,11 @@ jobs:
614626 # locally, so a profile-guided core can be reproduced outside CI.
615627 # The strict set itself lives in turbo-ext/Makefile
616628 # (STRICT_WARN_FLAGS), which documents why each exemption is there.
629+ # `make pgo-pack` keeps the core's share of the profile for the pie
630+ # legs of turbo-compile, which build with it instead of training again.
617631 run : |
618632 make SPLIT=1 pgo WARN_FLAGS="$(make -s print-warn-flags)" -j"$(getconf _NPROCESSORS_ONLN 2>/dev/null || nproc)"
633+ make SPLIT=1 pgo-pack
619634
620635 # Before signing (stripping invalidates a signature) and before the
621636 # upload. The symbol tables are a quarter of the binary; see `strip`
@@ -651,6 +666,16 @@ jobs:
651666 echo "core + extension report: $REPORTED, enabler expects: $EXPECTED"
652667 [ "$REPORTED" = "$EXPECTED" ]
653668
669+ # Before the core, so that a run carrying the core (all that
670+ # find-turbo-origins.sh checks) carries its profile too. A reused one
671+ # is uploaded again, like the core.
672+ - name : " Upload the core's profile"
673+ uses : actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
674+ with :
675+ name : ${{ env.PGO_PROFILE_ARTIFACT }}
676+ path : " turbo-ext/pgo-profile.tar"
677+ if-no-files-found : " error"
678+
654679 # A reused core is uploaded again under the same name, so the
655680 # turbo-compile legs find it in this run.
656681 - name : " Upload core artifact"
@@ -688,6 +713,7 @@ jobs:
688713 PHP_MINOR : " 8.5"
689714 PHP_ZTS : " 0"
690715 TURBO_ARTIFACT : " phpstan_turbo_core-linux-musl-arm64"
716+ PGO_PROFILE_ARTIFACT : " turbo-pgo-profile-linux-musl-arm64"
691717 ORIGIN_RUN_ID : ${{ fromJSON(needs.turbo-origins.outputs.origins || '{}')['phpstan_turbo_core-linux-musl-arm64'] }}
692718
693719 steps :
@@ -696,7 +722,7 @@ jobs:
696722 with :
697723 egress-policy : audit
698724
699- # See the same two steps in turbo-compile-core.
725+ # See the same three steps in turbo-compile-core.
700726 - name : " Download the core compiled from identical build inputs"
701727 if : env.ORIGIN_RUN_ID != ''
702728 uses : actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
@@ -706,6 +732,15 @@ jobs:
706732 run-id : ${{ env.ORIGIN_RUN_ID }}
707733 github-token : ${{ github.token }}
708734
735+ - name : " Download the profile of the core compiled from identical build inputs"
736+ if : env.ORIGIN_RUN_ID != ''
737+ uses : actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
738+ with :
739+ name : ${{ env.PGO_PROFILE_ARTIFACT }}
740+ path : " turbo-ext"
741+ run-id : ${{ env.ORIGIN_RUN_ID }}
742+ github-token : ${{ github.token }}
743+
709744 - name : " Record the run that compiled the core"
710745 if : env.ORIGIN_RUN_ID != ''
711746 run : echo "$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$ORIGIN_RUN_ID" | tee turbo-reused.txt
@@ -751,6 +786,7 @@ jobs:
751786 run : |
752787 docker exec -i -w /work/turbo-ext alpine-build sh -e <<'EOF'
753788 make SPLIT=1 pgo WARN_FLAGS="$(make -s print-warn-flags)" -j"$(getconf _NPROCESSORS_ONLN 2>/dev/null || nproc)"
789+ make SPLIT=1 pgo-pack
754790 make SPLIT=1 strip
755791 ls -l phpstan_turbo_core.so phpstan_turbo.so
756792 EOF
@@ -765,6 +801,13 @@ jobs:
765801 [ "$REPORTED" = "$EXPECTED" ]
766802 EOF
767803
804+ - name : " Upload the core's profile"
805+ uses : actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
806+ with :
807+ name : ${{ env.PGO_PROFILE_ARTIFACT }}
808+ path : " turbo-ext/pgo-profile.tar"
809+ if-no-files-found : " error"
810+
768811 - name : " Upload core artifact"
769812 uses : actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
770813 with :
@@ -791,7 +834,8 @@ jobs:
791834 # there, and the commit job checks that every leg of a platform carries
792835 # the same core.
793836 # The `pie` variant legs build the same version self-contained instead,
794- # profile-guided like the core — PIE installs a pre-packaged binary by
837+ # profile-guided with the profile the platform's core was built with
838+ # (`make pgo-from-profile`) — PIE installs a pre-packaged binary by
795839 # copying the one extension file, so the PIE release assets cannot be
796840 # the thin extension (see .github/scripts/turbo-pie-assets.sh). Nothing
797841 # else ships them, so they only run for release tags (turbo-pie-release
@@ -910,8 +954,21 @@ jobs:
910954 run : |
911955 make SPLIT=1 extension WARN_FLAGS="$(make -s print-warn-flags)" -j"$(getconf _NPROCESSORS_ONLN 2>/dev/null || nproc)"
912956
957+ # The profile the platform's core was compiled with (turbo-compile-core,
958+ # `make pgo-pack`): the core is all but the four version-specific
959+ # sources and compiles to the same code against every version's
960+ # headers, so the self-contained build of this version uses its profile
961+ # instead of training one of its own — which took most of the leg.
962+ - name : " Download the profile of the platform's core"
963+ if : matrix.variant == 'pie'
964+ uses : actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
965+ with :
966+ name : " turbo-pgo-profile-${{ matrix.target.name }}"
967+ path : " turbo-ext"
968+
913969 # see the same steps in turbo-compile-core: the training run of
914- # `make pgo` runs bin/phpstan on the checkout
970+ # `make pgo` runs bin/phpstan on the checkout (pgo-from-profile falls
971+ # back to it when another compiler recorded the profile)
915972 - uses : " ramsey/composer-install@65e4f84970763564f46a70b8a54b90d033b3bdda" # v4.0.0
916973 if : matrix.variant == 'pie' && matrix.target.family == 'macos'
917974 with :
@@ -924,12 +981,12 @@ jobs:
924981 php composer.phar install --no-interaction --no-progress
925982 rm composer.phar
926983
927- # A plain `make pgo` builds one self-contained phpstan_turbo.so.
984+ # A plain `make pgo-use ` builds one self-contained phpstan_turbo.so.
928985 - name : " Compile the self-contained extension with strict warnings (profile-guided)"
929986 if : matrix.variant == 'pie'
930987 working-directory : " turbo-ext"
931988 run : |
932- make pgo WARN_FLAGS="$(make -s print-warn-flags)" -j"$(getconf _NPROCESSORS_ONLN 2>/dev/null || nproc)"
989+ make pgo-from-profile WARN_FLAGS="$(make -s print-warn-flags)" -j"$(getconf _NPROCESSORS_ONLN 2>/dev/null || nproc)"
933990
934991 # Before signing and the upload; a plain `make strip` leaves the core
935992 # (already stripped and signed by its own job) untouched.
@@ -1027,6 +1084,14 @@ jobs:
10271084 name : " phpstan_turbo_core-linux-musl-arm64"
10281085 path : " turbo-ext"
10291086
1087+ # see turbo-compile
1088+ - name : " Download the profile of the platform's core"
1089+ if : matrix.variant == 'pie'
1090+ uses : actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
1091+ with :
1092+ name : " turbo-pgo-profile-linux-musl-arm64"
1093+ path : " turbo-ext"
1094+
10301095 - name : " Start the Alpine build container"
10311096 env :
10321097 ALPINE_IMAGE : ${{ matrix.php-version == '8.6' && matrix.ts == 'nts' && 'alpine:edge' || 'alpine:3.24' }}
@@ -1052,8 +1117,8 @@ jobs:
10521117 ls -l phpstan_turbo.so phpstan_turbo_core.so
10531118 EOF
10541119
1055- # see turbo-compile: the training run of `make pgo` runs bin/phpstan
1056- # on the checkout
1120+ # see turbo-compile: the training run of `make pgo`, which
1121+ # pgo-from-profile falls back to, runs bin/phpstan on the checkout
10571122 - name : " Compile the self-contained extension with strict warnings (profile-guided)"
10581123 if : matrix.variant == 'pie'
10591124 run : |
@@ -1062,7 +1127,7 @@ jobs:
10621127 php composer.phar install --no-interaction --no-progress
10631128 rm composer.phar
10641129 cd turbo-ext
1065- make pgo WARN_FLAGS="$(make -s print-warn-flags)" -j"$(getconf _NPROCESSORS_ONLN 2>/dev/null || nproc)"
1130+ make pgo-from-profile WARN_FLAGS="$(make -s print-warn-flags)" -j"$(getconf _NPROCESSORS_ONLN 2>/dev/null || nproc)"
10661131 make strip
10671132 ls -l phpstan_turbo.so
10681133 EOF
0 commit comments