fix(nano): correct entry point header inclusion in nano mode

- Add proper header inclusion check in EntryScriptCodegenTest
- Update NanoCapabilityPolicyTest to use correct extension file path
- Fix translator condition logic for nano policy mode entry header
- Add Windows Nano smoke test workflow with proper executable handling
- Include windows_nano_smoke.exe in packaged compiler artifacts
master
韩天峰 2 weeks ago
parent 31ad2664e7
commit e088776d24
  1. 45
      .github/workflows/windows-build.yml
  2. 5
      phpunit/src/EntryScriptCodegenTest.php
  3. 6
      phpunit/src/NanoCapabilityPolicyTest.php
  4. 7
      src/Translator.php

@ -389,6 +389,50 @@ jobs:
throw "Unexpected Windows smoke output: $stdout"
}
- name: Run Windows Nano smoke test
shell: pwsh
run: |
$ErrorActionPreference = 'Stop'
$env:PHPRC = Join-Path $env:PHP_HOME 'php.ini'
$env:PATH = "$env:PHPX_HOME\build;$env:PATH"
$nanoExe = Join-Path '${{ github.workspace }}' 'tests\windows\smoke\windows_nano_smoke.exe'
& .\tpc.exe tests\windows\smoke\project.yml --nano --output $nanoExe --job 1 --no-progress
if ($LASTEXITCODE -ne 0) {
throw "Windows Nano smoke project compilation failed with exit code $LASTEXITCODE"
}
Remove-Item Env:PHPRC
if (-not (Test-Path $nanoExe)) {
throw "Windows Nano smoke executable was not generated: $nanoExe"
}
$processInfo = [Diagnostics.ProcessStartInfo]::new()
$processInfo.FileName = $nanoExe
$processInfo.ArgumentList.Add('zts')
$processInfo.UseShellExecute = $false
$processInfo.RedirectStandardOutput = $true
$processInfo.RedirectStandardError = $true
$process = [Diagnostics.Process]::new()
$process.StartInfo = $processInfo
if (-not $process.Start()) {
throw 'Unable to start the Windows Nano smoke executable'
}
$stdout = $process.StandardOutput.ReadToEnd()
$stderr = $process.StandardError.ReadToEnd()
$process.WaitForExit()
Write-Host "Windows Nano smoke stdout: $stdout"
Write-Host "Windows Nano smoke stderr: $stderr"
Write-Host "Windows Nano smoke exit code: $($process.ExitCode)"
if ($process.ExitCode -ne 0) {
throw "Windows Nano smoke executable failed with exit code $($process.ExitCode)"
}
if ($stdout.Trim() -ne 'windows-smoke-ok:zts') {
throw "Unexpected Windows Nano smoke output: $stdout"
}
- name: Package tested Windows compiler
if: startsWith(github.ref, 'refs/tags/')
shell: pwsh
@ -497,6 +541,7 @@ jobs:
path: |
tpc.exe
tests/windows/smoke/windows_smoke.exe
tests/windows/smoke/windows_nano_smoke.exe
tests/windows/smoke/build/**/*.cc
tests/windows/smoke/build/**/*.h
tests/windows/smoke/build/**/*.rsp

@ -72,11 +72,16 @@ PHP);
);
$compiler->convert($files);
$extension = file_get_contents($this->projectDir . '/build/extension-nano_args.cc');
$entrypoint = file_get_contents($this->projectDir . '/build/nano-entry-nano_args.cc');
$entryHeader = basename($compiler->getDeclarationHeaderFile($source));
self::assertIsString($extension);
self::assertStringNotContainsString("#include <{$entryHeader}>", $extension);
self::assertStringContainsString(
'php_main(php::global("argc").toInt(), php::global("argv").toArray())',
$entrypoint,
);
self::assertStringContainsString("#include <{$entryHeader}>", $entrypoint);
}
private function removeDirectory(string $directory): void

@ -147,10 +147,12 @@ final class NanoCapabilityPolicyTest extends BaseTest
$translator = $compiler;
$compiler->addFiles([$source]);
$compiler->prepareFile($source);
$compiler->convertFile($source);
$extension = file_get_contents($compiler->genExtension());
$compiler->convert([$source]);
$extension = file_get_contents($directory . '/build/extension-nano_policy_entry.cc');
$entryHeader = basename($compiler->getDeclarationHeaderFile($source));
self::assertIsString($extension);
self::assertStringContainsString("#include <{$entryHeader}>", $extension);
self::assertStringContainsString('php_main();', $extension);
self::assertStringNotContainsString('php::eval(', $extension);
self::assertStringContainsString(

@ -3541,7 +3541,12 @@ CODE;
// php_main() prototype — must be visible to this translation unit.
// True Nano mode keeps php_main() encapsulated inside the separate
// nano-entry translation unit, so only the policy path needs this.
if ($this->isNanoPolicyMode() && $this->hasFunction(self::ENTRY_FUNCTION)) {
if ($this->isNanoPolicyMode()
&& !$this->isNanoMode()
&& $this->isBuildModeBin()
&& $this->hasSapi('embed')
&& $this->hasFunction(self::ENTRY_FUNCTION)
) {
$entryHeader = $this->declarationHeaderFiles[
$this->getFunction(self::ENTRY_FUNCTION)->sourceFile
] ?? null;

Loading…
Cancel
Save