diff --git a/script/bootstrap-gen0-install-prelinked-driver.sh b/script/bootstrap-gen0-install-prelinked-driver.sh index c8ad91ff26f..286f9d76869 100755 --- a/script/bootstrap-gen0-install-prelinked-driver.sh +++ b/script/bootstrap-gen0-install-prelinked-driver.sh @@ -43,6 +43,78 @@ bootstrap_gen0_seed_prelinked_m3_sidecars() { fi cp -f "${minimal_seed}" "${minimal_blob}" chmod +x "${blob}" "${minimal_blob}" + local compiler_lib_seed="${root}/prelinked/bootstrap-gen0/compiler_lib_aot_blob" + if [[ -f "${compiler_lib_seed}" && -s "${compiler_lib_seed}" ]]; then + cp -f "${compiler_lib_seed}" "${root}/build/.m3_compiler_lib_aot_blob" + chmod +x "${root}/build/.m3_compiler_lib_aot_blob" + if [[ -f "${root}/prelinked/bootstrap-gen0/.m3_compiler_lib_sidecar.sha" ]]; then + cp -f "${root}/prelinked/bootstrap-gen0/.m3_compiler_lib_sidecar.sha" \ + "${root}/build/.m3_compiler_lib_sidecar.sha" + fi + fi + return 0 +} + +# SHA-1 of M2 compiler_lib_spine_smoke entry (sidecar + inventory argv driver must match). +bootstrap_compiler_lib_spine_entry_sha() { + local root="${ROOT:-}" + local entry="${root}/test/selfhost/compiler_lib_spine_smoke/main.php" + if [[ -z "${root}" || ! -f "${entry}" ]]; then + return 1 + fi + sha1sum "${entry}" | awk '{print $1}' +} + +# Ensure build/.m3_compiler_lib_aot_blob matches current spine entry (#3012, #2967). +bootstrap_ensure_m3_compiler_lib_sidecar() { + local root="${ROOT:-}" + local entry="${root}/test/selfhost/compiler_lib_spine_smoke/main.php" + local blob="${root}/build/.m3_compiler_lib_aot_blob" + local stamp="${root}/build/.m3_compiler_lib_sidecar.sha" + if [[ -z "${root}" || ! -f "${entry}" ]]; then + echo "bootstrap-ensure-m3-compiler-lib-sidecar: missing spine entry ${entry}" >&2 + return 1 + fi + local want_sha + want_sha="$(bootstrap_compiler_lib_spine_entry_sha)" || return 1 + if [[ -f "${blob}" && -s "${blob}" && -f "${stamp}" && "$(cat "${stamp}" 2>/dev/null)" == "${want_sha}" ]]; then + return 0 + fi + bootstrap_gen0_seed_prelinked_m3_sidecars 2>/dev/null || true + if [[ -f "${blob}" && -s "${blob}" && -f "${stamp}" && "$(cat "${stamp}" 2>/dev/null)" == "${want_sha}" ]]; then + return 0 + fi + if [[ "${BOOTSTRAP_SKIP_COMPILER_LIB_SIDECAR_REGEN:-0}" == "1" ]]; then + echo "bootstrap-ensure-m3-compiler-lib-sidecar: stale/missing ${blob} (BOOTSTRAP_SKIP_COMPILER_LIB_SIDECAR_REGEN=1)" >&2 + return 1 + fi + if ! command -v php >/dev/null 2>&1; then + echo "bootstrap-ensure-m3-compiler-lib-sidecar: php required to host-compile ${entry}" >&2 + return 1 + fi + echo "bootstrap-ensure-m3-compiler-lib-sidecar: host-compile spine entry -> ${blob} (#3012)" >&2 + mkdir -p "${root}/build" + rm -f "${blob}" + local regen_log regen_code=0 + set +e + regen_log="$( + env PHP_COMPILER_M3_EMIT_SIDECAR_RECURSION_GUARD=1 \ + PHP_COMPILER_SELFHOST_AOT=1 \ + PHP_COMPILER_CLI_SPINE_BUNDLE=1 \ + PHP_COMPILER_MEMORY_LIMIT="${PHP_COMPILER_MEMORY_LIMIT:-4096M}" \ + php -d "memory_limit=${PHP_COMPILER_MEMORY_LIMIT:-4096M}" \ + "${root}/bin/compile.php" -o "${blob}" "${entry}" 2>&1 + )" + regen_code=$? + set -e + if [[ "${regen_code}" -ne 0 || ! -f "${blob}" || ! -s "${blob}" ]]; then + printf '%s\n' "${regen_log}" >&2 + echo "bootstrap-ensure-m3-compiler-lib-sidecar: host-compile failed (exit ${regen_code}); inventory argv driver may return parseAndCompile null (#2967)" >&2 + echo "bootstrap-ensure-m3-compiler-lib-sidecar: hint: refresh prelinked/bootstrap-gen0 after spine entry changes, or fix Zend spine AOT (VM/JIT)" >&2 + return 1 + fi + chmod +x "${blob}" + printf '%s' "${want_sha}" >"${stamp}" return 0 } diff --git a/script/bootstrap-resolve-compile-invoke.sh b/script/bootstrap-resolve-compile-invoke.sh index ce6c7c91fb5..00e67b294eb 100755 --- a/script/bootstrap-resolve-compile-invoke.sh +++ b/script/bootstrap-resolve-compile-invoke.sh @@ -127,6 +127,7 @@ bootstrap_ensure_inventory_argv_driver() { source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/bootstrap-gen0-install-prelinked-driver.sh" fi bootstrap_gen0_seed_prelinked_m3_sidecars 2>/dev/null || true + bootstrap_ensure_m3_compiler_lib_sidecar 2>/dev/null || true if ! env PHP_COMPILER_M3_SOURCE="${root}/bin/compile.php" PHP_COMPILER_M3_OUT="${out}" \ "${root}/script/bootstrap-selfhost-helloworld-compile-bin.sh"; then local prelink="${root}/prelinked/bootstrap-gen0/bin-compile-aot" @@ -137,12 +138,14 @@ bootstrap_ensure_inventory_argv_driver() { cp -f "${prelink}" "${root}/build/.m3_bin_compile_aot_blob" chmod +x "${out}" "${root}/build/.m3_bin_compile_aot_blob" if bootstrap_inventory_argv_driver_smoke "${out}"; then + bootstrap_ensure_m3_compiler_lib_sidecar 2>/dev/null || true return 0 fi fi echo "bootstrap-ensure-inventory-argv-driver: helloworld-compile-bin failed" >&2 return 1 fi + bootstrap_ensure_m3_compiler_lib_sidecar 2>/dev/null || true if ! bootstrap_is_inventory_bin_compile_argv_driver "${out}"; then echo "bootstrap-ensure-inventory-argv-driver: ${out} is not a verified inventory argv driver" >&2 return 1 diff --git a/script/bootstrap-selfhost-lib-spine-smoke-link.sh b/script/bootstrap-selfhost-lib-spine-smoke-link.sh index 1f59df81326..ae26c9b2256 100755 --- a/script/bootstrap-selfhost-lib-spine-smoke-link.sh +++ b/script/bootstrap-selfhost-lib-spine-smoke-link.sh @@ -100,6 +100,9 @@ fi INVENTORY_ARGV_DRIVER="${ROOT}/build/bin-compile-aot-inventory" +# M3 compiler_lib spine sidecar must match test/selfhost/compiler_lib_spine_smoke/main.php (#3012). +bootstrap_ensure_m3_compiler_lib_sidecar 2>/dev/null || true + # Prefer the proven inventory argv driver path (same strategy as bootstrap-selfhost-full-revision-probe, #2968). if [[ "${BOOTSTRAP_LIB_SPINE_SMOKE_USE_COMPILE_INVOKE:-0}" != "1" ]]; then SPINE_COMPILE_DRIVER="" @@ -173,7 +176,8 @@ if [[ "${BOOTSTRAP_LIB_SPINE_SMOKE_USE_COMPILE_INVOKE:-0}" != "1" ]]; then if [[ "${BOOTSTRAP_LIB_SPINE_SMOKE_GEN0_FALLBACK:-1}" == "1" ]] && command -v php >/dev/null 2>&1; then echo "bootstrap-selfhost-lib-spine-smoke-link: gen-0 Zend fallback (native argv driver blocked; #2967)" >&2 rm -f "${OUT}" - php "${ROOT}/bin/compile.php" -o "${OUT}" "${ENTRY}" 2>&1 || true + env PHP_COMPILER_SELFHOST_AOT=1 PHP_COMPILER_CLI_SPINE_BUNDLE=1 \ + php "${ROOT}/bin/compile.php" -o "${OUT}" "${ENTRY}" 2>&1 || true fi if [[ ! -x "${OUT}" ]]; then echo "bootstrap-selfhost-lib-spine-smoke-link: compile failed (progress gate; see stderr above)" >&2 diff --git a/test/unit/BootstrapLibSpineVmSmokeTest.php b/test/unit/BootstrapLibSpineVmSmokeTest.php index a082e1e69b9..e1b068b6975 100644 --- a/test/unit/BootstrapLibSpineVmSmokeTest.php +++ b/test/unit/BootstrapLibSpineVmSmokeTest.php @@ -44,6 +44,8 @@ public function testLibSpineLinkScriptSeedsSidecarsAndGen0Fallback(): void $script = (string) file_get_contents(self::$root.'/script/bootstrap-selfhost-lib-spine-smoke-link.sh'); $this->assertStringContainsString('bootstrap-gen0-install-prelinked-driver.sh', $script); $this->assertStringContainsString('ci_ensure_vendor_patches', $script); + $this->assertStringContainsString('bootstrap_ensure_m3_compiler_lib_sidecar', $script); + $this->assertStringContainsString('PHP_COMPILER_CLI_SPINE_BUNDLE=1', $script); $this->assertStringContainsString('BOOTSTRAP_LIB_SPINE_SMOKE_GEN0_FALLBACK', $script); $this->assertStringContainsString('gen-0 Zend fallback', $script); } diff --git a/test/unit/BootstrapSelfhostLinkTest.php b/test/unit/BootstrapSelfhostLinkTest.php index 754baed2884..de3c41442b0 100644 --- a/test/unit/BootstrapSelfhostLinkTest.php +++ b/test/unit/BootstrapSelfhostLinkTest.php @@ -34,6 +34,9 @@ public function testLinkScriptInstallsPrelinkedGen0Driver(): void $this->assertStringContainsString('bootstrap_gen0_copy_prelinked_inventory_driver', $install); $this->assertStringContainsString('#2930', $install); $this->assertStringContainsString('compiler_minimal_aot_blob', $install); + $this->assertStringContainsString('bootstrap_ensure_m3_compiler_lib_sidecar', $install); + $this->assertStringContainsString('.m3_compiler_lib_aot_blob', $install); + $this->assertStringContainsString('bootstrap_compiler_lib_spine_entry_sha', $install); $this->assertFileExists(self::$root.'/prelinked/bootstrap-gen0/bin-compile-aot'); $this->assertFileExists(self::$root.'/prelinked/bootstrap-gen0/compiler_minimal_aot_blob'); } @@ -50,6 +53,7 @@ public function testLinkScriptUsesCompiledDriverResolver(): void $this->assertStringContainsString('build/bin-compile-aot-inventory', $body); $this->assertStringContainsString('exited 0 but missing', $body); $this->assertStringContainsString('bootstrap_gen0_seed_prelinked_m3_sidecars', $body); + $this->assertStringContainsString('bootstrap_ensure_m3_compiler_lib_sidecar', $body); $this->assertStringContainsString('build/selfhost-compile-driver', $body); $this->assertStringContainsString('build/bin-compile-aot', $body); $this->assertStringContainsString(