Last active
July 24, 2018 22:40
-
-
Save DaveM2011/a18a741ea3d91e89a96bbc58e8d048d3 to your computer and use it in GitHub Desktop.
Revisions
-
DaveM2011 revised this gist
Jul 24, 2018 . 1 changed file with 117 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,117 @@ [Net.ServicePointManager]::SecurityProtocol = "tls12, tls11, tls" function Invoke-BatchFile { param([string]$Path, [string]$Parameters) $tempFile = [IO.Path]::GetTempFileName() ## Store the output of cmd.exe. We also ask cmd.exe to output ## the environment table after the batch file completes cmd.exe /c " `"$Path`" $Parameters && set " > $tempFile ## Go through the environment variables in the temp file. ## For each of them, set the variable in our local environment. Get-Content $tempFile | Foreach-Object { if ($_ -match "^(.*?)=(.*)$") { Set-Content "env:\$($matches[1])" $matches[2] } else { $_ } } Remove-Item $tempFile } $Dir = "$pwd" $BuildDir = "..\build" $PhpUrl = "https://windows.php.net/downloads/releases/php-7.2.8-nts-Win32-VC15-x64.zip" $PhpDest = $BuildDir + "\php-7.2.8-nts-Win32-VC15-x64.zip" $PhpDevPackUrl = "https://windows.php.net/downloads/releases/php-devel-pack-7.2.8-nts-Win32-VC15-x64.zip" $PhpDevPackDest = $BuildDir + "\php-devel-pack-7.2.8-nts-Win32-VC15-x64.zip" $ZephirParserUrl = "https://github.com/phalcon/php-zephir-parser/releases/download/v1.1.2/zephir_parser_x64_vc15_php7.2-nts_1.1.2-290.zip" $ZephirParserDest = $BuildDir + "\zephir_parser_x64_vc15_php7.2-nts_1.1.2-290.zip" $Color1 = 'DarkGreen' $Color2 = 'White' #$Color3 = 'Red' #$Color4 = 'Black' If (-Not(Test-Path -PathType Container -Path $BuildDir)) { Write-Host "Creating build directory" -BackgroundColor $Color1 -ForegroundColor $Color2 New-Item -ItemType Directory -Force -Path $BuildDir } else { Write-Host "Build directory exists" -BackgroundColor $Color1 -ForegroundColor $Color2 } If (-Not(Test-Path -PathType Container -Path $BuildDir\php)) { #New-Item -ItemType Directory -Force -Path $BuildDir\php } #get php If (-Not(Test-Path -PathType Container -Path $BuildDir\php)) { Write-Host "Getting PHP" -BackgroundColor $Color1 -ForegroundColor $Color2 Invoke-WebRequest -Uri $PhpUrl -OutFile $PhpDest Microsoft.PowerShell.Archive\Expand-Archive -Path $PhpDest -DestinationPath $BuildDir\php -Force Remove-Item $PhpDest } #get php-sdk If (-Not(Test-Path -PathType Container -Path $BuildDir\php-sdk)) { Write-Host "Cloning PHP-SDK" -BackgroundColor $Color1 -ForegroundColor $Color2 git clone -q https://github.com/Microsoft/php-sdk-binary-tools.git $BuildDir\php-sdk } #get php devpack If (-Not(Test-Path -PathType Container -Path $BuildDir\phpdevel)) { Write-Host "Getting PHP-DEVPACK" -BackgroundColor $Color1 -ForegroundColor $Color2 Invoke-WebRequest -Uri $PhpDevPackUrl -OutFile $PhpDevPackDest Microsoft.PowerShell.Archive\Expand-Archive -Force -Path $PhpDevPackDest -DestinationPath $BuildDir Rename-Item -Path $BuildDir\php-7.2.8-devel-VC15-x64 phpdevel Remove-Item $PhpDevPackDest } #get the zephir parser and extract to ext dir If (-Not(Test-Path -Path $BuildDir\php\ext\php_zephir_parser.dll)) { Write-Host "Getting zephir parser" -BackgroundColor $Color1 -ForegroundColor $Color2 Invoke-WebRequest -Uri $ZephirParserUrl -OutFile $ZephirParserDest Microsoft.PowerShell.Archive\Expand-Archive -Force -Path $ZephirParserDest -DestinationPath $BuildDir\php\ext Remove-Item $ZephirParserDest } #get zephir If (-Not(Test-Path -PathType Container -Path $BuildDir\zephir)) { Write-Host "Cloning zephir" -BackgroundColor $Color1 -ForegroundColor $Color2 git clone -q https://github.com/phalcon/zephir.git $BuildDir\zephir } #set env Write-Host "Setting up enviroment" -BackgroundColor $Color1 -ForegroundColor $Color2 $PathExtra = ";" + $Dir + "\..\build\php;" + $Dir + "\..\build\php-sdk;" + $Dir + "\..\build\phpdevel;" + $Dir + "\..\build\zephir\bin" $env:Path += $PathExtra $env:php_sdk = $Dir + "\" + $BuildDir + "\php-sdk" $env:php_devpack = $Dir + "\" + $BuildDir + "\phpdevel" #x86 build i think #Invoke-BatchFile "${env:ProgramFiles(x86)}\Microsoft Visual Studio\2017\BuildTools\Common7\Tools\VsDevCmd.bat" > $null #x64 build Invoke-BatchFile "${env:ProgramFiles(x86)}\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars64.bat" > $null Invoke-BatchFile $BuildDir\php-sdk\bin\phpsdk_setvars.bat > $null Write-Host "Enviroment setup done" -BackgroundColor $Color1 -ForegroundColor $Color2 If (-Not(Test-Path -Path $BuildDir\php\php.ini)) { Write-Host "Setting up php.ini" -BackgroundColor $Color1 -ForegroundColor $Color2 Rename-Item -Path $BuildDir\php\php.ini-development php.ini Add-Content $BuildDir\php\php.ini ' extension_dir = "ext" [Zephir Parser] extension=zephir_parser' #use this to enable default extensions needed for your module u can also add custom ones in the Add-Content above #(Get-Content $BuildDir\php\php.ini) | Foreach-Object {$_ -replace ';extension=curl','extension=curl'} | Foreach-Object {$_ -replace ';extension=intl','extension=intl'} | Foreach-Object {$_ -replace ';extension=mbstring','extension=mbstring'} | Foreach-Object {$_ -replace ';extension=mysqli','extension=mysqli'} | Foreach-Object {$_ -replace ';extension=openssl','extension=openssl'} | Foreach-Object {$_ -replace ';extension=pdo_mysql','extension=pdo_mysql'} | Out-File -Encoding UTF8 $BuildDir\php\php.ini } zephir init yournamespace Write-Output 'All done' Pause -
DaveM2011 created this gist
Jul 24, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,130 @@ [Net.ServicePointManager]::SecurityProtocol = "tls12, tls11, tls" function Invoke-BatchFile { param([string]$Path, [string]$Parameters) $tempFile = [IO.Path]::GetTempFileName() ## Store the output of cmd.exe. We also ask cmd.exe to output ## the environment table after the batch file completes cmd.exe /c " `"$Path`" $Parameters && set " > $tempFile ## Go through the environment variables in the temp file. ## For each of them, set the variable in our local environment. Get-Content $tempFile | Foreach-Object { if ($_ -match "^(.*?)=(.*)$") { Set-Content "env:\$($matches[1])" $matches[2] } else { $_ } } Remove-Item $tempFile } $Dir = "$pwd" $BuildDir = "..\build" $PhpUrl = "https://windows.php.net/downloads/releases/php-7.2.8-nts-Win32-VC15-x64.zip" $PhpDest = $BuildDir + "\php-7.2.8-nts-Win32-VC15-x64.zip" $PhpDevPackUrl = "https://windows.php.net/downloads/releases/php-devel-pack-7.2.8-nts-Win32-VC15-x64.zip" $PhpDevPackDest = $BuildDir + "\php-devel-pack-7.2.8-nts-Win32-VC15-x64.zip" $ZephirParserUrl = "https://github.com/phalcon/php-zephir-parser/releases/download/v1.1.2/zephir_parser_x64_vc15_php7.2-nts_1.1.2-290.zip" $ZephirParserDest = $BuildDir + "\zephir_parser_x64_vc15_php7.2-nts_1.1.2-290.zip" $Color1 = 'DarkGreen' $Color2 = 'White' #$Color3 = 'Red' #$Color4 = 'Black' If (-Not(Test-Path -PathType Container -Path $BuildDir)) { Write-Host "Creating build directory" -BackgroundColor $Color1 -ForegroundColor $Color2 New-Item -ItemType Directory -Force -Path $BuildDir } else { Write-Host "Build directory exists" -BackgroundColor $Color1 -ForegroundColor $Color2 } If (-Not(Test-Path -PathType Container -Path $BuildDir\php)) { #New-Item -ItemType Directory -Force -Path $BuildDir\php } #get php If (-Not(Test-Path -PathType Container -Path $BuildDir\php)) { Write-Host "Getting PHP" -BackgroundColor $Color1 -ForegroundColor $Color2 Invoke-WebRequest -Uri $PhpUrl -OutFile $PhpDest Microsoft.PowerShell.Archive\Expand-Archive -Path $PhpDest -DestinationPath $BuildDir\php -Force Remove-Item $PhpDest } #get php-sdk If (-Not(Test-Path -PathType Container -Path $BuildDir\php-sdk)) { Write-Host "Cloning PHP-SDK" -BackgroundColor $Color1 -ForegroundColor $Color2 git clone -q https://github.com/Microsoft/php-sdk-binary-tools.git $BuildDir\php-sdk } #get php devpack If (-Not(Test-Path -PathType Container -Path $BuildDir\phpdevel)) { Write-Host "Getting PHP-DEVPACK" -BackgroundColor $Color1 -ForegroundColor $Color2 Invoke-WebRequest -Uri $PhpDevPackUrl -OutFile $PhpDevPackDest Microsoft.PowerShell.Archive\Expand-Archive -Force -Path $PhpDevPackDest -DestinationPath $BuildDir Rename-Item -Path $BuildDir\php-7.2.8-devel-VC15-x64 phpdevel Remove-Item $PhpDevPackDest } #get the zephir parser and extract to ext dir If (-Not(Test-Path -Path $BuildDir\php\ext\php_zephir_parser.dll)) { Write-Host "Getting zephir parser" -BackgroundColor $Color1 -ForegroundColor $Color2 Invoke-WebRequest -Uri $ZephirParserUrl -OutFile $ZephirParserDest Microsoft.PowerShell.Archive\Expand-Archive -Force -Path $ZephirParserDest -DestinationPath $BuildDir\php\ext Remove-Item $ZephirParserDest } #get zephir If (-Not(Test-Path -PathType Container -Path $BuildDir\zephir)) { Write-Host "Cloning zephir" -BackgroundColor $Color1 -ForegroundColor $Color2 git clone -q https://github.com/phalcon/zephir.git $BuildDir\zephir } #set env Write-Host "Setting up enviroment" -BackgroundColor $Color1 -ForegroundColor $Color2 $PathExtra = ";" + $Dir + "\..\build\php;" + $Dir + "\..\build\php-sdk;" + $Dir + "\..\build\phpdevel;" + $Dir + "\..\build\zephir\bin" $env:Path += $PathExtra $env:php_sdk = $Dir + "\" + $BuildDir + "\php-sdk" $env:php_devpack = $Dir + "\" + $BuildDir + "\phpdevel" #x86 build i think #Invoke-BatchFile "${env:ProgramFiles(x86)}\Microsoft Visual Studio\2017\BuildTools\Common7\Tools\VsDevCmd.bat" > $null #x64 build Invoke-BatchFile "${env:ProgramFiles(x86)}\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars64.bat" > $null Invoke-BatchFile $BuildDir\php-sdk\bin\phpsdk_setvars.bat > $null Write-Host "Enviroment setup done" -BackgroundColor $Color1 -ForegroundColor $Color2 If (-Not(Test-Path -Path $BuildDir\php\php.ini)) { Write-Host "Setting up php.ini" -BackgroundColor $Color1 -ForegroundColor $Color2 Rename-Item -Path $BuildDir\php\php.ini-development php.ini Add-Content $BuildDir\php\php.ini ' extension_dir = "ext" [Zephir Parser] extension=zephir_parser' #use this to enable default extensions needed for your module u can also add custom ones in the Add-Content above #(Get-Content $BuildDir\php\php.ini) | Foreach-Object {$_ -replace ';extension=curl','extension=curl'} | Foreach-Object {$_ -replace ';extension=intl','extension=intl'} | Foreach-Object {$_ -replace ';extension=mbstring','extension=mbstring'} | Foreach-Object {$_ -replace ';extension=mysqli','extension=mysqli'} | Foreach-Object {$_ -replace ';extension=openssl','extension=openssl'} | Foreach-Object {$_ -replace ';extension=pdo_mysql','extension=pdo_mysql'} | Out-File -Encoding UTF8 $BuildDir\php\php.ini } Write-Host "Building extension" -BackgroundColor Red -ForegroundColor Black $confirmation = Read-Host "Fullclean? [y/N]" If($confirmation -eq "y") { zephir fullclean > $null } zephir build > $null Set-Location -Path ext $Arg = "--enable-" + (Get-Item -Path "..\").Name Invoke-BatchFile configure.bat $Arg > $null nmake > $null Write-Output 'All done' Pause