Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions script/bootstrap-gen0-install-prelinked-driver.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
3 changes: 3 additions & 0 deletions script/bootstrap-resolve-compile-invoke.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down
6 changes: 5 additions & 1 deletion script/bootstrap-selfhost-lib-spine-smoke-link.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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=""
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions test/unit/BootstrapLibSpineVmSmokeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 4 additions & 0 deletions test/unit/BootstrapSelfhostLinkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand All @@ -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(
Expand Down