diff --git a/.github/workflows/windows-build.yml b/.github/workflows/windows-build.yml index 5e351a18..1c6746d8 100644 --- a/.github/workflows/windows-build.yml +++ b/.github/workflows/windows-build.yml @@ -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 diff --git a/phpunit/src/EntryScriptCodegenTest.php b/phpunit/src/EntryScriptCodegenTest.php index 242f205f..9d69c439 100644 --- a/phpunit/src/EntryScriptCodegenTest.php +++ b/phpunit/src/EntryScriptCodegenTest.php @@ -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 diff --git a/phpunit/src/NanoCapabilityPolicyTest.php b/phpunit/src/NanoCapabilityPolicyTest.php index 7ac4ca4f..5392a0cf 100644 --- a/phpunit/src/NanoCapabilityPolicyTest.php +++ b/phpunit/src/NanoCapabilityPolicyTest.php @@ -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( diff --git a/src/Translator.php b/src/Translator.php index b07379bc..021a5229 100644 --- a/src/Translator.php +++ b/src/Translator.php @@ -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;