diff --git a/.ci/AppVeyor.psm1 b/.ci/AppVeyor.psm1 deleted file mode 100644 index d4887f7b..00000000 --- a/.ci/AppVeyor.psm1 +++ /dev/null @@ -1,75 +0,0 @@ -# This file is part of the Zephir Parser. -# -# (c) Zephir Team -# -# For the full copyright and license information, please view -# the LICENSE file that was distributed with this source code. - -Function InitializeBuildVars { - If ($Env:PLATFORM -eq 'x64') { - $Env:ARCH = 'x86_amd64' - } Else { - $Env:ARCH = 'x86' - } -} - -Function InitializeReleaseVars { - If ($Env:BUILD_TYPE -Match "nts-Win32") { - $Env:RELEASE_ZIPBALL = "zephir_parser_${Env:PLATFORM}_vc${Env:VC_VERSION}_php${Env:PHP_VERSION}-nts_${Env:APPVEYOR_BUILD_VERSION}" - - If ($Env:PLATFORM -eq 'x86') { - $Env:RELEASE_FOLDER = "Release" - } Else { - $Env:RELEASE_FOLDER = "x64\Release" - } - } Else { - $Env:RELEASE_ZIPBALL = "zephir_parser_${Env:PLATFORM}_vc${Env:VC_VERSION}_php${Env:PHP_VERSION}_${Env:APPVEYOR_BUILD_VERSION}" - - If ($Env:PLATFORM -eq 'x86') { - $Env:RELEASE_FOLDER = "Release_TS" - } Else { - $Env:RELEASE_FOLDER = "x64\Release_TS" - } - } - - $Env:RELEASE_PATH = "${Env:APPVEYOR_BUILD_FOLDER}\${Env:RELEASE_FOLDER}" -} - -Function AppendSessionPath { - [string[]] $PathsCollection = @( - "${Env:VSCOMNTOOLS}\..\..\VC", - "C:\Program Files (x86)\Microsoft Visual Studio ${Env:VC_VERSION}.0\VC", - "C:\Program Files (x86)\Microsoft Visual Studio ${Env:VC_VERSION}.0\VC\bin", - "${Env:VSCOMNTOOLS}", - "C:\php" - "C:\php\bin" - "C:\php-sdk\bin", - "C:\php-devpack" - ) - - $CurrentPath = (Get-Item -Path ".\" -Verbose).FullName - - ForEach ($PathItem In $PathsCollection) { - Set-Location Env: - $AllPaths = (Get-ChildItem Path).value.split(";") | Sort-Object -Unique - $AddToPath = $true - - ForEach ($AddedPath In $AllPaths) { - If (-not "${AddedPath}") { - continue - } - - $AddedPath = $AddedPath -replace '\\$', '' - - If ($PathItem -eq $AddedPath) { - $AddToPath = $false - } - } - - If ($AddToPath) { - $Env:Path += ";$PathItem" - } - } - - Set-Location "${CurrentPath}" -} diff --git a/.ci/build-win32.bat b/.ci/build-win32.bat deleted file mode 100644 index 34bc2110..00000000 --- a/.ci/build-win32.bat +++ /dev/null @@ -1,19 +0,0 @@ -@ECHO off - -REM This file is part of the Zephir Parser. -REM -REM (c) Zephir Team -REM -REM For the full copyright and license information, please view -REM the LICENSE file that was distributed with this source code. - -REM Rewrite this using PowerShell -CD parser - -cl lemon.c -DEL zephir.c zephir.h parser.c scanner.c -re2c -o scanner.c scanner.re -lemon -s zephir.lemon -ECHO #include ^ > parser.c -TYPE zephir.c >> parser.c -TYPE base.c >> parser.c diff --git a/.ci/lemon-parser.ps1 b/.ci/lemon-parser.ps1 new file mode 100644 index 00000000..567654c7 --- /dev/null +++ b/.ci/lemon-parser.ps1 @@ -0,0 +1,45 @@ +# This file is part of the Zephir Parser. +# +# (c) Zephir Team +# +# For the full copyright and license information, please view +# the LICENSE file that was distributed with this source code. + +Write-Output "-- Compiling Lemon parser..." +$LemonSrc = Join-Path -Path './parser' -ChildPath 'lemon.c' +$LemonBin = Join-Path -Path './parser' -ChildPath 'lemon.exe' + +if ($IsWindows) { + & cl /Fe${LemonExe} ${LemonSrc} +} +else { + $LemonBin = Join-Path -Path './parser' -ChildPath 'lemon' + & gcc ${LemonSrc} -o ${LemonBin} +} +& ${LemonBin} -x + +Write-Output "-- Cleanup initial file state..." + +$AutoFiles = "./parser/zephir.c", + "./parser/zephir.h", + "./parser/parser.c", + "./parser/scanner.c" + +foreach ($GeneratedFile in $AutoFiles) { + if (Test-Path -Path $GeneratedFile) { + Remove-Item $GeneratedFile + } +} + +Write-Output "-- Run re2c..." +& re2c -o (Join-Path -Path './parser' -ChildPath 'scanner.c') (Join-Path -Path './parser' -ChildPath 'scanner.re') + +Write-Output "-- Generating zephir.c file with lemon parser..." +& ${LemonBin} -s (Join-Path -Path './parser' -ChildPath 'zephir.lemon') + +Write-Output "-- Generating parser.c file..." +$ParserC = Join-Path -Path './parser' -ChildPath 'parser.c' +$ZephirC = Join-Path -Path './parser' -ChildPath 'zephir.c' +$BaseC = Join-Path -Path './parser' -ChildPath 'base.c' +Set-Content -Path ${ParserC} -Value '#include ' +Get-Content ${ZephirC}, ${BaseC} | Add-Content ${ParserC} diff --git a/.ci/win-ci-tools.psm1 b/.ci/win-ci-tools.psm1 new file mode 100644 index 00000000..19869b11 --- /dev/null +++ b/.ci/win-ci-tools.psm1 @@ -0,0 +1,417 @@ +# This file is part of the Zephir Parser. +# +# (c) Zephir Team +# +# For the full copyright and license information, please view +# the LICENSE file that was distributed with this source code. + +function SetupCommonEnvironment { + <# + .SYNOPSIS + Creates common directories if not exists + #> + + $CommonPath = "C:\Downloads", "C:\Downloads\Choco" + + foreach ($path in $CommonPath) { + if (-not (Test-Path $path)) { + New-Item -ItemType Directory -Force -Path $path | Out-Null + } + } + + # Hide "You are in 'detached HEAD' state" message + git config --global advice.detachedHead false +} + +function InitializeReleaseVars { + <# + .SYNOPSIS + Configures Environment variables for Release build. + #> + + # Build artifacts should be names like this: + # zephir-parser-php-7.0-nts-win32-vc14-x86.zip + # zephir-parser-php-7.0-ts-win32-vc14-x64.zip + + $VC_Prefix = "vc" + if (${env:VC_VERSION} -ge 16) { + $VC_Prefix = "vc" + } + + # Configure for Windows define `BUILD_DIR` using the next logic: + # + # Release ZTS x86 => Release_TS\php_zephir_parser.dll + # Release NTS x86 => Release\php_zephir_parser.dll + # Release ZTS x64 => x64\Release_TS\php_zephir_parser.dll + # Release NTS x64 => x64\Release\php_zephir_parser.dll + + $env:RELEASE_FOLDER = "Release" + if (${env:BUILD_TYPE} -eq 'ts') { + $env:RELEASE_FOLDER = -join($env:RELEASE_FOLDER, "_TS") + } + + if (${env:PHP_ARCH} -eq 'x64') { + $env:RELEASE_FOLDER = -join("x64\", $env:RELEASE_FOLDER) + } + + $env:RELEASE_DLL_PATH = "${env:GITHUB_WORKSPACE}\${env:RELEASE_FOLDER}\${env:EXTENSION_FILE}" + $env:RELEASE_ZIPBALL = "zephir-parser-php-${env:PHP_MINOR}-${env:BUILD_TYPE}-win32-${VC_Prefix}${env:VC_VERSION}-${env:PHP_ARCH}" + + Write-Output "RELEASE_FOLDER=${env:RELEASE_FOLDER}" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append + Write-Output "RELEASE_ZIPBALL=${env:RELEASE_ZIPBALL}" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append + Write-Output "RELEASE_DLL_PATH=${env:RELEASE_DLL_PATH}" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append +} + +function InstallPhpSdk { + <# + .SYNOPSIS + Install PHP SDK binary tools from sources. + #> + + Write-Output "Install PHP SDK binary tools: ${env:PHP_SDK_VERSION}" + + $PhpSdk = "php-sdk-${env:PHP_SDK_VERSION}.zip" + $RemoteUrl = "https://github.com/microsoft/php-sdk-binary-tools/archive/${PhpSdk}" + $DestinationPath = "C:\Downloads\${PhpSdk}" + + if (-not (Test-Path $env:PHP_SDK_PATH)) { + if (-not [System.IO.File]::Exists($DestinationPath)) { + Write-Output "Downloading PHP SDK binary tools: $RemoteUrl ..." + DownloadFile $RemoteUrl $DestinationPath + } + + $DestinationUnzipPath = "${env:Temp}\php-sdk-binary-tools-php-sdk-${env:PHP_SDK_VERSION}" + + if (-not (Test-Path "$DestinationUnzipPath")) { + Expand-Item7zip $DestinationPath $env:Temp + } + + Move-Item -Path $DestinationUnzipPath -Destination $env:PHP_SDK_PATH + } +} + +function InstallPhpDevPack { + <# + .SYNOPSIS + Intstall PHP Developer pack from sources. + #> + + Write-Output "Install PHP Dev pack: ${env:PHP_VERSION}" + + $TS = Get-ThreadSafety + + if ($env:VC_VERSION -gt 15) { + $VSPrefix = "VS" + $VSPrefixSmall = "vs" + } else { + $VSPrefix = "VC" + $VSPrefixSmall = "vc" + } + + $BaseUrl = "http://windows.php.net/downloads/releases" + $DevPack = "php-devel-pack-${env:PHP_VERSION}${TS}-Win32-${VSPrefixSmall}${env:VC_VERSION}-${env:PHP_ARCH}.zip" + + $RemoteUrl = "${BaseUrl}/${DevPack}" + $RemoteArchiveUrl = "${BaseUrl}/archives/${DevPack}" + $DestinationPath = "C:\Downloads\php-devel-pack-${env:PHP_VERSION}${TS}-${VSPrefix}${env:VC_VERSION}-${env:PHP_ARCH}.zip" + + if (-not (Test-Path $env:PHP_DEVPACK)) { + if (-not [System.IO.File]::Exists($DestinationPath)) { + DownloadFileUsingAlternative -RemoteUrl $RemoteUrl ` + -RemoteArchiveUrl $RemoteArchiveUrl ` + -DestinationPath $DestinationPath ` + -Message "Downloading PHP Dev pack" + } + + $DestinationUnzipPath = "${env:Temp}\php-${env:PHP_VERSION}-devel-${VSPrefix}${env:VC_VERSION}-${env:PHP_ARCH}" + + if (-not (Test-Path "$DestinationUnzipPath")) { + Expand-Item7zip $DestinationPath $env:Temp + } + + Move-Item -Path $DestinationUnzipPath -Destination $env:PHP_DEVPACK + } +} + +function DownloadFileUsingAlternative { + <# + .SYNOPSIS + Downloads files from URL using alternative ULR if primary URL not found + #> + + [CmdletBinding()] + param( + [parameter(Mandatory = $true, ValueFromPipeline = $true)] [ValidateNotNullOrEmpty()] [System.String] $RemoteUrl, + [parameter(Mandatory = $true, ValueFromPipeline = $true)] [ValidateNotNullOrEmpty()] [System.String] $RemoteArchiveUrl, + [parameter(Mandatory = $true, ValueFromPipeline = $true)] [ValidateNotNullOrEmpty()] [System.String] $DestinationPath, + [parameter(Mandatory = $true, ValueFromPipeline = $true)] [ValidateNotNullOrEmpty()] [System.String] $Message + ) + + process { + try { + Write-Output "${Message}: ${RemoteUrl} ..." + DownloadFile $RemoteUrl $DestinationPath + } catch [System.Net.WebException] { + Write-Output "${Message} from archive: ${RemoteArchiveUrl} ..." + DownloadFile $RemoteArchiveUrl $DestinationPath + } + } +} + +function DownloadFile { + <# + .SYNOPSIS + Downloads file from providing URL to specified destionation. + + .NOTES + Throws System.Net.WebException if $RequestUrl not found. + #> + + [CmdletBinding()] + param( + [parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [System.String] $RemoteUrl, + [parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [System.String] $DestinationPath + ) + + process { + $RetryMax = 5 + $RetryCount = 0 + $Completed = $false + + $WebClient = New-Object System.Net.WebClient + $WebClient.Headers.Add('User-Agent', 'GitHub Actions PowerShell Script') + + while (-not $Completed -or $RetryCount -eq $RetryMax) { + try { + $WebClient.DownloadFile($RemoteUrl, $DestinationPath) + $Completed = $true + } catch [System.Net.WebException] { + $ErrorMessage = $_.Exception.Message + + if ($_.Exception.Response.StatusCode -eq 404) { + Write-Warning -Message "Error downloading ${RemoteUrl}: $ErrorMessage" + throw [System.Net.WebException] "Error downloading ${RemoteUrl}" + } + + if ($RetryCount -ge $RetryMax) { + Write-Output "Error downloading ${RemoteUrl}: $ErrorMessage" + $Completed = $true + } else { + $RetryCount++ + } + } + } + } +} + +function Expand-Item7zip { + <# + .SYNOPSIS + Extracts ZIP archives to specified directory + #> + + param( + [Parameter(Mandatory = $true)] [System.String] $Archive, + [Parameter(Mandatory = $true)] [System.String] $Destination + ) + + if (-not (Test-Path -Path $Archive -PathType Leaf)) { + throw "Specified archive File is invalid: [$Archive]" + } + + if (-not (Test-Path -Path $Destination -PathType Container)) { + New-Item $Destination -ItemType Directory | Out-Null + } + + $Result = (& 7z x "$Archive" "-o$Destination" -aoa -bd -y -r) + + if ($LastExitCode -ne 0) { + Write-Output "An error occurred while unzipping [$Archive] to [$Destination]. Error code was: ${LastExitCode}" + Exit $LastExitCode + } +} + +function Get-ThreadSafety { + <# + .SYNOPSIS + Detects if Build is Thread Safety or not and returns `ts` suffix. + #> + + if ($env:BUILD_TYPE -Match "nts") { + return "-nts" + } + + return [string]::Empty +} + +function AppendSessionPath { + [string[]] $PathsCollection = @( + "${Env:VSCOMNTOOLS}\..\..\VC", + "C:\Program Files (x86)\Microsoft Visual Studio ${Env:VC_VERSION}.0\VC", + "C:\Program Files (x86)\Microsoft Visual Studio ${Env:VC_VERSION}.0\VC\bin", + "${Env:VSCOMNTOOLS}", + "C:\php" + "C:\php\bin" + "C:\php-sdk\bin", + "C:\php-devpack" + ) + + $CurrentPath = (Get-Item -Path ".\" -Verbose).FullName + + ForEach ($PathItem In $PathsCollection) { + Set-Location Env: + $AllPaths = (Get-ChildItem Path).value.split(";") | Sort-Object -Unique + $AddToPath = $true + + ForEach ($AddedPath In $AllPaths) { + If (-not "${AddedPath}") { + continue + } + + $AddedPath = $AddedPath -replace '\\$', '' + + If ($PathItem -eq $AddedPath) { + $AddToPath = $false + } + } + + If ($AddToPath) { + $Env:Path += ";$PathItem" + } + } + + Set-Location "${CurrentPath}" +} + +function EnableExtension { + <# + .SYNOPSIS + Enables PHP Extension. + #> + + if (-not (Test-Path env:RELEASE_DLL_PATH)) { + InitializeReleaseVars + } + + if (-not (Test-Path "${env:RELEASE_DLL_PATH}")) { + throw "Unable to locate extension path: ${env:RELEASE_DLL_PATH}" + } + + Copy-Item -Path "${env:RELEASE_DLL_PATH}" -Destination "${env:PHPROOT}\ext\" + + Enable-PhpExtension -Extension 'Zephir Parser' -Path "${env:PHPROOT}" +} + +function PrepareReleasePackage { + param ( + [Parameter(Mandatory=$true)] [System.String] $PhpVersion, + [Parameter(Mandatory=$true)] [System.String] $BuildType, + [Parameter(Mandatory=$true)] [System.String] $Platform, + [Parameter(Mandatory=$false)] [System.String] $ZipballName = '', + [Parameter(Mandatory=$false)] [System.String[]] $ReleaseFiles = @(), + [Parameter(Mandatory=$false)] [System.String] $ReleaseFile = 'RELEASE.txt', + [Parameter(Mandatory=$false)] [System.Boolean] $ConvertMd2Html = $false, + [Parameter(Mandatory=$false)] [System.String] $BasePath = '.' + ) + + $BasePath = Resolve-Path $BasePath + $ReleaseDirectory = "${Env:GITHUB_ACTOR}-${Env:RUNNER_OS}-${Env:GITHUB_JOB}-${Env:GITHUB_RUN_NUMBER}" + + Write-Output "ReleaseDirectory: ${ReleaseDirectory}" + + PrepareReleaseNote ` + -PhpVersion $PhpVersion ` + -BuildType $BuildType ` + -Platform $Platform ` + -ReleaseFile $ReleaseFile ` + -ReleaseDirectory $ReleaseDirectory ` + -BasePath $BasePath + + $ReleaseDestination = "${BasePath}\${ReleaseDirectory}" + + $CurrentPath = Resolve-Path '.' + + if ($ConvertMd2Html) { + FormatReleaseFiles -ReleaseDirectory $ReleaseDirectory + } + + if ($ReleaseFiles.count -gt 0) { + foreach ($File in $ReleaseFiles) { + Copy-Item "${File}" "${ReleaseDestination}" + Write-Debug "Copy ${File} to ${ReleaseDestination}" + } + } + + if (!$ZipballName) { + if (!$Env:RELEASE_ZIPBALL) { + throw "Required parameter `"ZipballName`" is missing" + } else { + $ZipballName = $Env:RELEASE_ZIPBALL; + } + } + + Set-Location "${ReleaseDestination}" + $Output = (& 7z a "${ZipballName}.zip" *) + $ExitCode = $LASTEXITCODE + + $DirectoryContents = Get-ChildItem -Path "${ReleaseDestination}" + Write-Debug ($DirectoryContents | Out-String) + + if ($ExitCode -ne 0) { + Set-Location "${CurrentPath}" + throw "An error occurred while creating release zipball: `"${ZipballName}`". ${Output}" + } + + Move-Item "${ZipballName}.zip" -Destination "${BasePath}" + Write-Output "Release file created: ${BasePath}\${ZipballName}.zip" + Set-Location "${CurrentPath}" +} + +function PrepareReleaseNote { + param ( + [Parameter(Mandatory=$true)] [System.String] $PhpVersion, + [Parameter(Mandatory=$true)] [System.String] $BuildType, + [Parameter(Mandatory=$true)] [System.String] $Platform, + [Parameter(Mandatory=$false)] [System.String] $ReleaseFile, + [Parameter(Mandatory=$false)] [System.String] $ReleaseDirectory, + [Parameter(Mandatory=$false)] [System.String] $BasePath + ) + + $Destination = "${BasePath}\${ReleaseDirectory}" + + if (-not (Test-Path $Destination)) { + New-Item -ItemType Directory -Force -Path "${Destination}" | Out-Null + } + + $ReleaseFile = "${Destination}\${ReleaseFile}" + $ReleaseDate = Get-Date -Format o + + $Version = Get-Content (Join-Path -Path ${BasePath} -ChildPath 'VERSION') -First 1 + + Write-Output "Release date: ${ReleaseDate}" | Out-File -Encoding "ASCII" -Append "${ReleaseFile}" + Write-Output "Release version: ${Version}" | Out-File -Encoding "ASCII" -Append "${ReleaseFile}" + Write-Output "Git commit: ${Env:GITHUB_SHA}" | Out-File -Encoding "ASCII" -Append "${ReleaseFile}" + Write-Output "Build type: ${BuildType}" | Out-File -Encoding "ASCII" -Append "${ReleaseFile}" + Write-Output "Platform: ${Platform}" | Out-File -Encoding "ASCII" -Append "${ReleaseFile}" + Write-Output "Target PHP version: ${PhpVersion}" | Out-File -Encoding "ASCII" -Append "${ReleaseFile}" +} + +function FormatReleaseFiles { + param ( + [Parameter(Mandatory=$true)] [System.String] $ReleaseDirectory, + [Parameter(Mandatory=$false)] [System.String] $BasePath = '.' + ) + + $CurrentPath = (Get-Item -Path ".\" -Verbose).FullName + + $BasePath = Resolve-Path $BasePath + Set-Location "${BasePath}" + + Get-ChildItem (Get-Item -Path ".\" -Verbose).FullName *.md | + ForEach-Object{ + $BaseName = $_.BaseName + pandoc -f markdown -t html5 "${BaseName}.md" > "${BasePath}\${ReleaseDirectory}\${BaseName}.html" + } + + Set-Location "${CurrentPath}" +} diff --git a/.editorconfig b/.editorconfig index b5023d03..e5cfdb0b 100644 --- a/.editorconfig +++ b/.editorconfig @@ -11,7 +11,7 @@ indent_size = 4 charset = utf-8 trim_trailing_whitespace = true -[*.{yml,m4,sh,md,php,phpt,xml,json,w32}] +[*.{yml,m4,sh,md,php,phpt,xml,json,w32,ps1,psm1}] indent_style = space [*.{yml,m4,sh}] diff --git a/.github/workflows/main.yml b/.github/workflows/linux-macos.yml similarity index 98% rename from .github/workflows/main.yml rename to .github/workflows/linux-macos.yml index a416d5e7..5f223ec0 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/linux-macos.yml @@ -1,4 +1,4 @@ -name: build +name: Linux and MacOS on: push: @@ -25,6 +25,7 @@ jobs: php: - '7.0' - '7.1' + - '7.2' - '7.3' - '7.4' - '8.0' diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml new file mode 100644 index 00000000..97a6e8ed --- /dev/null +++ b/.github/workflows/windows.yml @@ -0,0 +1,213 @@ +name: Windows + +on: + push: + branches-ignore: + - 'wip-*' + paths-ignore: + - '*.md' + +# pull_request: +# branches: +# - master +# - development + +# schedule: +# - cron: '0 11 * * *' + +env: + PHP_SDK_VERSION: 2.2.0 + PHP_DEVPACK: C:\tools\php-devpack + PHP_SDK_PATH: C:\tools\php-sdk + EXTENSION_FILE: php_zephir_parser.dll + +jobs: + ci: + strategy: + fail-fast: false + + matrix: + php: ['7.0', '7.1', '7.2', '7.3', '7.4', '8.0'] + arch: ['x86', 'x64'] + build_type: ['ts', 'nts'] + + include: + - php: '7.0' + vc_num: 14 + vc_prefix: 'vc' + os: windows-2016 + + - php: '7.1' + vc_num: 14 + vc_prefix: 'vc' + os: windows-2016 + + - php: '7.2' + vc_num: 15 + vc_prefix: 'vc' + os: windows-2016 + + - php: '7.3' + vc_num: 15 + vc_prefix: 'vc' + os: windows-2016 + + - php: '7.4' + vc_num: 15 + vc_prefix: 'vc' + os: windows-2016 + + - php: '8.0' + vc_num: 16 + vc_prefix: 'vs' + os: windows-2019 + + name: "PHP-${{ matrix.php }}-${{ matrix.build_type }}-win32-${{ matrix.vc_prefix }}${{ matrix.vc_num }}-${{ matrix.arch }}" + runs-on: ${{ matrix.os}} + + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 1 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + coverage: none + env: + PHPTS: ${{ matrix.build_type }} + + - name: Set Environment Variables + run: | + Write-Output "PHP_VERSION=$(php -r 'echo phpversion();')" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append + Write-Output "PHP_MINOR=${{ matrix.php }}" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append + Write-Output "TEST_PHP_EXECUTABLE=${env:PHPROOT}\php.exe" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append + Write-Output "BUILD_TYPE=${{ matrix.build_type }}" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append + Write-Output "VC_VERSION=${{ matrix.vc_num }}" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append + Write-Output "PHP_ARCH=${{ matrix.arch }}" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append + Write-Output "BUILD_VERSION=${env:GITHUB_RUN_NUMBER}" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append + + - name: Setup Common Environmet + run: | + Import-Module .\.ci\win-ci-tools.psm1 + SetupCommonEnvironment + InitializeReleaseVars + + - name: Cache Downloads + uses: actions/cache@v2 + with: + path: C:\Downloads + key: ${{ runner.os }}-zephir_parser-php-${{ matrix.php }}-${{ matrix.build_type }}-win32-${{ matrix.vc_prefix }}${{ matrix.vc_num }}-${{ matrix.arch }} + + - name: Install System Dependencies + run: | + choco install -y --no-progress --cache-location=C:\Downloads\Choco pandoc + + - name: Install PHP SDK Binary Tools + run: | + Import-Module .\.ci\win-ci-tools.psm1 + InstallPhpSdk + + - name: Install PHP Dev pack + run: | + Import-Module .\.ci\win-ci-tools.psm1 + InstallPhpDevPack + + - name: Install MSVC Compiler Tool + uses: ilammy/msvc-dev-cmd@v1 + with: + arch: ${{ matrix.arch }} + + - name: Set PHP SDK Environment variables + shell: cmd + run: | + call C:\tools\php-sdk\phpsdk-${{ matrix.vc_prefix }}${{ matrix.vc_num }}-${{ matrix.arch }}.bat + call C:\tools\php-sdk\bin\phpsdk_setvars.bat + + - name: Parse Zephir Parser (Lemon) + shell: cmd + run: | + call C:\tools\php-sdk\bin\phpsdk_setvars.bat + powershell.exe -File .\.ci\lemon-parser.ps1 + + - name: Phpize + shell: cmd + run: | + call C:\tools\php-devpack\phpize.bat + + - name: Configure + shell: cmd + run: | + call C:\tools\php-sdk\phpsdk-${{ matrix.vc_prefix }}${{ matrix.vc_num }}-${{ matrix.arch }}.bat + call C:\tools\php-sdk\bin\phpsdk_setvars.bat + configure --with-codegen-arch=yes --with-prefix=C:\php --with-php-build=C:\php-devpack --disable-all --enable-zephir-parser=shared + + - name: Compile + shell: cmd + run: | + call C:\tools\php-sdk\phpsdk-${{ matrix.vc_prefix }}${{ matrix.vc_num }}-${{ matrix.arch }}.bat + call C:\tools\php-sdk\bin\phpsdk_setvars.bat + nmake + + - name: Get Zephir Parser extension info + run: | + Get-Php "${env:PHPROOT}" + Get-PhpExtension "${env:RELEASE_DLL_PATH}" + & ${env:TEST_PHP_EXECUTABLE} --ini + + - name: Enable Zephir Parser + run: | + Add-Content -Path "${env:PHPROOT}\php.ini" -Value 'extension=php_zephir_parser.dll' + Copy-Item -Path "${env:RELEASE_DLL_PATH}" -Destination "${env:PHPROOT}\ext\" + + # Run tests only for x64 PHP builds (Windows currently not support setup php with multi arch) + - name: Run Tests + if: matrix.arch == 'x64' + run: | + & ${env:TEST_PHP_EXECUTABLE} --ri 'Zephir Parser' + & ${env:TEST_PHP_EXECUTABLE} run-tests.php + + - name: Prepare Release Package + run: | + Import-Module .\.ci\win-ci-tools.psm1 + PrepareReleasePackage ` + -PhpVersion $Env:PHP_VERSION ` + -BuildType $Env:BUILD_TYPE ` + -Platform $Env:PLATFORM ` + -ZipballName $Env:RELEASE_ZIPBALL ` + -ConvertMd2Html $true ` + -ReleaseFiles "${Env:RELEASE_DLL_PATH}",` + "${Env:GITHUB_WORKSPACE}\LICENSE",` + "${Env:GITHUB_WORKSPACE}\CREDITS",` + "${Env:GITHUB_WORKSPACE}\VERSION",` + "${Env:GITHUB_WORKSPACE}\NO_WARRANTY" + + - name: Upload Zephir Parser + uses: actions/upload-artifact@v2 + with: + name: zephir-parser-php-${{ matrix.php }}-${{ matrix.build_type }}-win32-${{ matrix.vc_prefix }}${{ matrix.vc_num }}-${{ matrix.arch }} + path: | + ${{ github.workspace }}\zephir-parser-*.zip + + - name: Check for Errors + if: always() + run: | + Get-ChildItem (Get-Item -Path ".\" -Verbose).FullName *.log | + ForEach-Object{ + $BaseName = $_.BaseName + Write-Output "-- Log details: ${BaseName}.log --" + Get-Content -Path "${env:GITHUB_WORKSPACE}\${BaseName}.log" + } + + - name: Upload Infor for Debug on Fail + if: failure() + uses: actions/upload-artifact@v2 + with: + retention-days: 2 + name: errors-zephir-parser-php-${{ matrix.php }}-${{ matrix.build_type }}-win32-${{ matrix.vc_prefix }}${{ matrix.vc_num }}-${{ matrix.arch }} + path: | + ${{ github.workspace }}\tests + ${{ github.workspace }}\parser + ${{ github.workspace }}\Release* + ${{ github.workspace }}\**\Release* diff --git a/docker/windows/Dockerfile b/docker/windows/Dockerfile new file mode 100644 index 00000000..cbec6e2d --- /dev/null +++ b/docker/windows/Dockerfile @@ -0,0 +1,77 @@ +FROM mcr.microsoft.com/windows/servercore:ltsc2019 + +COPY . C:/php-zephir-parser + +# Download required functions for git installation +RUN powershell.exe -Command \ + ((new-object net.webclient).DownloadFile('https://raw.githubusercontent.com/actions/virtual-environments/5690645f0e91c30d888353d7b58432dc0466eca9/images/win/scripts/ImageHelpers/ChocoHelpers.ps1', 'C:\ChocoHelpers.ps1')); \ + ((new-object net.webclient).DownloadFile('https://raw.githubusercontent.com/actions/virtual-environments/f93413492e47983bafbc29ab84cb697aeeb41f7b/images/win/scripts/ImageHelpers/InstallHelpers.ps1', 'C:\InstallHelpers.ps1')); \ + ((new-object net.webclient).DownloadFile('https://raw.githubusercontent.com/actions/virtual-environments/b7f276c003aea42575b52247bdb2183e355fca2f/images/win/scripts/ImageHelpers/PathHelpers.ps1', 'C:\PathHelpers.ps1')); + +# Install Choco and Git +RUN powershell.exe -Command \ + Import-Module C:\ChocoHelpers.ps1; \ + Import-Module C:\InstallHelpers.ps1; \ + Import-Module C:\PathHelpers.ps1; \ + Invoke-Expression ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/actions/virtual-environments/main/images/win/scripts/Installers/Install-Choco.ps1')); \ + Invoke-Expression ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/actions/virtual-environments/main/images/win/scripts/Installers/Install-Git.ps1')); + +# Clone 'virtual-environments' +RUN powershell.exe git clone https://github.com/actions/virtual-environments.git + +# Install all necessary dependecies +RUN powershell.exe -Command \ + Import-Module C:\virtual-environments\images\win\scripts\ImageHelpers\PathHelpers.ps1; \ + Import-Module C:\virtual-environments\images\win\scripts\ImageHelpers\InstallHelpers.ps1; \ + Import-Module C:\virtual-environments\images\win\scripts\ImageHelpers\ChocoHelpers.ps1; \ + Import-Module C:\virtual-environments\images\win\scripts\ImageHelpers\VisualStudioHelpers.ps1; \ + Invoke-Expression C:\virtual-environments\images\win\scripts\Installers\Install-VCRedist.ps1; \ + Invoke-Expression C:\virtual-environments\images\win\scripts\Installers\Install-VS.ps1; \ + Invoke-Expression C:\virtual-environments\images\win\scripts\Installers\Install-PHP.ps1; + +RUN curl -SL --output vs_buildtools.exe https://aka.ms/vs/16/release/vs_buildtools.exe && \ + (start /w vs_buildtools.exe --quiet --wait --norestart --nocache modify \ + --installPath "C:\BuildTools" \ + --add Microsoft.VisualStudio.Workload.AzureBuildTools \ + --remove Microsoft.VisualStudio.Component.Windows10SDK.10240 \ + --remove Microsoft.VisualStudio.Component.Windows10SDK.10586 \ + --remove Microsoft.VisualStudio.Component.Windows10SDK.14393 \ + --remove Microsoft.VisualStudio.Component.Windows81SDK) && \ + del /q vs_buildtools.exe + +RUN dir "C:\BuildTools" + +#RUN call "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools\\Common7\\Tools\\VsDevCmd.bat" + +ENV PHP_VERSION=8.0.9 +ENV PHP_MINOR=8.0 +ENV TEST_PHP_EXECUTABLE=C:/php/php.exe +ENV BUILD_TYPE=ts +ENV VC_VERSION=16 +ENV PHP_ARCH=x64 +ENV BUILD_VERSION=1 + +ENV PHP_SDK_VERSION=2.2.0 +ENV PHP_DEVPACK=C:/tools/php-devpack +ENV PHP_SDK_PATH=C:/tools/php-sdk +ENV EXTENSION_FILE=php_zephir_parser.dll + +# choco install visualstudio2019-workload-vctools; \ +# choco install llvm; \ +RUN powershell.exe -Command \ + choco install 7zip; \ + Import-Module C:\php-zephir-parser\.ci\win-ci-tools.psm1; \ + SetupCommonEnvironment; \ + InstallPhpSdk; \ + InstallPhpDevPack; \ + AppendSessionPath; + +RUN call C:\tools\php-sdk\bin\phpsdk_setvars.bat && \ + cd C:\php-zephir-parser\parser && \ + cl.exe lemon.c && \ + DEL zephir.c zephir.h parser.c scanner.c && \ + re2c.exe -o scanner.c scanner.re && \ + lemon.exe -s zephir.lemon && \ + ECHO #include ^ > parser.c && \ + TYPE zephir.c >> parser.c && \ + TYPE base.c >> parser.c diff --git a/tests/base/cblocks.phpt b/tests/base/cblocks.phpt index 26dc07b8..158977f4 100644 --- a/tests/base/cblocks.phpt +++ b/tests/base/cblocks.phpt @@ -2,6 +2,7 @@ Tests recognizing wrapping C-code in CBLOCKs --SKIPIF-- + --FILE-- + --FILE-- + --FILE--