Skip to content

Commit 4288ee5

Browse files
committed
Initial implement for arm64 build
1 parent c56dfe3 commit 4288ee5

File tree

6 files changed

+66
-42
lines changed

6 files changed

+66
-42
lines changed

bin/phpsdk_buildtree.bat

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ if "%PHP_SDK_ARCH%" NEQ "" (
2727
MD %_%\%%i\x64\deps\bin
2828
MD %_%\%%i\x64\deps\lib
2929
MD %_%\%%i\x64\deps\include
30+
MD %_%\%%i\arm64\deps\bin
31+
MD %_%\%%i\arm64\deps\lib
32+
MD %_%\%%i\arm64\deps\include
3033
)
3134
)
3235

bin/phpsdk_deps.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ function usage(int $code = -1)
180180
echo "Usage: ", PHP_EOL, PHP_EOL;
181181
echo "Configuration:", PHP_EOL;
182182
echo " -b --branch Branch name, eg. 7.0, 7.1, etc. If omited, several guess methods apply.", PHP_EOL;
183-
echo " -a --arch Architecture, x86 or x64. If omited, cl.exe is used to guess.", PHP_EOL;
183+
echo " -a --arch Architecture, x86 or x64 or arm64. If omited, cl.exe is used to guess.", PHP_EOL;
184184
echo " -t --crt CRT, marked by the corresponding VC++ version, eg. vc11, vc14, etc.", PHP_EOL;
185185
echo " -s --stability One of stable or staging.", PHP_EOL, PHP_EOL;
186186
echo "Commands:", PHP_EOL;

bin/phpsdk_dumpenv.bat

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,8 @@ echo.
1212
call %PHP_SDK_BIN_PATH%\phpsdk_version.bat
1313
echo.
1414

15-
if "%PHP_SDK_OS_ARCH%"=="x64" (
16-
echo OS architecture: 64-bit
17-
) else (
18-
echo OS architecture: 32-bit
19-
)
20-
21-
if "%PHP_SDK_ARCH%"=="x64" (
22-
echo Build architecture: 64-bit
23-
) else (
24-
echo Build architecture: 32-bit
25-
)
26-
15+
echo OS architecture: %PHP_SDK_OS_ARCH%
16+
echo Build architecture: %PHP_SDK_ARCH%
2717
echo Visual C++: %PHP_SDK_VC_TOOLSET_VER%
2818
echo PHP-SDK path: %PHP_SDK_ROOT_PATH%
2919

bin/phpsdk_setshell.bat

Lines changed: 49 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -46,30 +46,42 @@ set TMP_CHK=
4646

4747
if /i not "%2"=="x64" (
4848
if /i not "%2"=="x86" (
49-
echo Unsupported arch "%2"
50-
goto out_error
49+
if /i not "%2"=="arm64" (
50+
echo Unsupported arch "%2"
51+
goto out_error
52+
)
5153
)
5254
)
5355

5456
set PHP_SDK_ARCH=%2
5557

5658
rem check OS arch
57-
set TMPKEY=HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion
58-
reg query "%TMPKEY%" /v "ProgramFilesDir (x86)" >nul 2>nul
59+
rem Architecture=9 meaning x86_64
60+
wmic cpu get Architecture /value | findstr "Architecture=9\>" >nul 2>nul
5961
if not errorlevel 1 (
6062
set PHP_SDK_OS_ARCH=x64
61-
) else (
62-
if /i "%PHP_SDK_ARCH%"=="x64" (
63-
echo 32-bit OS detected, native 64-bit toolchain is unavailable.
64-
goto out_error
65-
)
63+
)
64+
rem Architecture=12 meaning arm64
65+
wmic cpu get Architecture /value | findstr "Architecture=12\>" >nul 2>nul
66+
if not errorlevel 1 (
67+
set PHP_SDK_OS_ARCH=arm64
68+
)
69+
rem Architecture=0 meaning x86
70+
wmic cpu get Architecture /value | findstr "Architecture=0\>" >nul 2>nul
71+
if not errorlevel 1 (
6672
set PHP_SDK_OS_ARCH=x86
6773
)
68-
set TMPKEY=
74+
75+
rem cross compile is ok, so we donot need this
76+
rem if not /i "%PHP_SDK_ARCH%"=="PHP_SDK_OS_ARCH" (
77+
rem echo 32-bit OS detected, native 64-bit toolchain is unavailable.
78+
rem goto out_error
79+
rem )
6980

7081
rem get vc base dir
7182
if 15 gtr %PHP_SDK_VS_NUM% (
72-
if /i "%PHP_SDK_OS_ARCH%"=="x64" (
83+
rem for arch other than x86, use WOW6432
84+
if /i not "%PHP_SDK_OS_ARCH%"=="x86" (
7385
set TMPKEY=HKLM\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\%PHP_SDK_VS:~2%.0\Setup\VC
7486
) else (
7587
set TMPKEY=HKLM\SOFTWARE\Microsoft\VisualStudio\%PHP_SDK_VS:~2%.0\Setup\VC
@@ -85,16 +97,20 @@ if 15 gtr %PHP_SDK_VS_NUM% (
8597
set /a PHP_SDK_VS_RANGE=PHP_SDK_VS_NUM + 1
8698
set PHP_SDK_VS_RANGE="[%PHP_SDK_VS_NUM%,!PHP_SDK_VS_RANGE%!)"
8799

88-
for /f "tokens=1* delims=: " %%a in ('%~dp0\vswhere -nologo -version !PHP_SDK_VS_RANGE! -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath -format text') do (
100+
set APPEND=x86.x64
101+
if /i "%PHP_SDK_OS_ARCH%"=="arm64" (
102+
set APPEND=ARM64
103+
)
104+
for /f "tokens=1* delims=: " %%a in ('%~dp0\vswhere -nologo -version !PHP_SDK_VS_RANGE! -requires Microsoft.VisualStudio.Component.VC.Tools.!APPEND! -property installationPath -format text') do (
89105
set PHP_SDK_VC_DIR=%%b\VC
90106
)
91107
if not exist "!PHP_SDK_VC_DIR!" (
92-
for /f "tokens=1* delims=: " %%a in ('%~dp0\vswhere -nologo -version !PHP_SDK_VS_RANGE! -products Microsoft.VisualStudio.Product.BuildTools -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath -format text') do (
108+
for /f "tokens=1* delims=: " %%a in ('%~dp0\vswhere -nologo -version !PHP_SDK_VS_RANGE! -products Microsoft.VisualStudio.Product.BuildTools -requires Microsoft.VisualStudio.Component.VC.Tools.!APPEND! -property installationPath -format text') do (
93109
set PHP_SDK_VC_DIR=%%b\VC
94110
)
95111
if not exist "!PHP_SDK_VC_DIR!" (
96112
rem check for a preview release
97-
for /f "tokens=1* delims=: " %%a in ('%~dp0\vswhere -nologo -version !PHP_SDK_VS_RANGE! -prerelease -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath -format text') do (
113+
for /f "tokens=1* delims=: " %%a in ('%~dp0\vswhere -nologo -version !PHP_SDK_VS_RANGE! -prerelease -requires Microsoft.VisualStudio.Component.VC.Tools.!APPEND! -property installationPath -format text') do (
98114
set PHP_SDK_VC_DIR=%%b\VC
99115
)
100116
if not exist "!PHP_SDK_VC_DIR!" (
@@ -105,13 +121,15 @@ if 15 gtr %PHP_SDK_VS_NUM% (
105121
)
106122
set VSCMD_ARG_no_logo=nologo
107123
)
124+
set APPEND=
108125
set TMPKEY=
109126
set PHP_SDK_VS_RANGE=
110127

111128
if 15 gtr %PHP_SDK_VS_NUM% (
112129
rem get sdk dir
113130
rem if 10.0 is available, it's ok
114-
if /i "%PHP_SDK_OS_ARCH%"=="x64" (
131+
rem for arch other than x86, use WOW6432
132+
if /i not "%PHP_SDK_OS_ARCH%"=="x86" (
115133
set TMPKEY=HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Microsoft SDKs\Windows\v10.0
116134
) else (
117135
set TMPKEY=HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v10.0
@@ -125,7 +143,8 @@ if 15 gtr %PHP_SDK_VS_NUM% (
125143
)
126144

127145
rem Otherwise 8.1 should be available anyway
128-
if /i "%PHP_SDK_OS_ARCH%"=="x64" (
146+
rem for arch other than x86, use WOW6432
147+
if /i not "%PHP_SDK_OS_ARCH%"=="x86" (
129148
set TMPKEY=HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Microsoft SDKs\Windows\v8.1
130149
) else (
131150
set TMPKEY=HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v8.1
@@ -143,17 +162,21 @@ if 15 gtr %PHP_SDK_VS_NUM% (
143162
)
144163

145164
if /i "%PHP_SDK_ARCH%"=="x64" (
146-
if 15 gtr %PHP_SDK_VS_NUM% (
147-
set PHP_SDK_VS_SHELL_CMD="!PHP_SDK_VC_DIR!\vcvarsall.bat" amd64
148-
) else (
149-
set PHP_SDK_VS_SHELL_CMD="!PHP_SDK_VC_DIR!\Auxiliary\Build\vcvarsall.bat" amd64
150-
)
165+
set TARGET_ARCH_NAME=amd64
151166
) else (
152-
if 15 gtr %PHP_SDK_VS_NUM% (
153-
set PHP_SDK_VS_SHELL_CMD="!PHP_SDK_VC_DIR!\vcvarsall.bat" x86
154-
) else (
155-
set PHP_SDK_VS_SHELL_CMD="!PHP_SDK_VC_DIR!\Auxiliary\Build\vcvarsall.bat" x86
156-
)
167+
set TARGET_ARCH_NAME=%PHP_SDK_ARCH%
168+
)
169+
170+
if /i "%PHP_SDK_OS_ARCH%"=="x64" (
171+
set HOST_ARCH_NAME=amd64
172+
) else (
173+
set HOST_ARCH_NAME=%PHP_SDK_ARCH%
174+
)
175+
176+
if 15 gtr %PHP_SDK_VS_NUM% (
177+
set PHP_SDK_VS_SHELL_CMD="!PHP_SDK_VC_DIR!\vcvarsall.bat" !HOST_ARCH_NAME!_!TARGET_ARCH_NAME!
178+
) else (
179+
set PHP_SDK_VS_SHELL_CMD="!PHP_SDK_VC_DIR!\Auxiliary\Build\vcvarsall.bat" !HOST_ARCH_NAME!_!TARGET_ARCH_NAME!
157180
)
158181

159182
rem echo Visual Studio VC path %PHP_SDK_VC_DIR%

lib/php/libsdk/SDK/Config.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ public static function setCurrentArchName(string $arch) : void
4747
{/*{{{*/
4848
$arch = strtolower($arch);
4949

50-
if ("x64" != $arch && "x86" != $arch) {
51-
throw new Exception("Unknown arch keyword, either x86 or x64 is accepted");
50+
if ("x64" != $arch && "x86" != $arch && "arm64" != $arch) {
51+
throw new Exception("Unknown arch keyword, x86 or x64 or arm64 is accepted");
5252
}
5353

5454
self::$currentArchName = $arch;
@@ -72,6 +72,8 @@ public static function getCurrentArchName() : string
7272
self::setCurrentArchName("x64");
7373
} elseif (preg_match(",x86,", $out[0])) {
7474
self::setCurrentArchName("x86");
75+
} elseif (preg_match(",arm64,", $out[0])) {
76+
self::setCurrentArchName("arm64");
7577
} else {
7678
throw new Exception("Couldn't determine Arch.");
7779
}
@@ -146,7 +148,7 @@ public static function getKnownBranches() : array
146148
$tmp = $fetcher->getByUri(self::$depsBaseUri . "/series/");
147149
if (false !== $tmp) {
148150
$data = array();
149-
if (preg_match_all(",/packages-(.+)-(v[cs]\d+)-(x86|x64)-(stable|staging)\.txt,U", $tmp, $m, PREG_SET_ORDER)) {
151+
if (preg_match_all(",/packages-(.+)-(v[cs]\d+)-(x86|x64|arm64)-(stable|staging)\.txt,U", $tmp, $m, PREG_SET_ORDER)) {
150152
foreach ($m as $b) {
151153
if (!isset($data[$b[1]])) {
152154
$data[$b[1]] = array();

pgo/tpl/php/phpsdk_pgo.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@
1414
{
1515
"cache": {
1616
"ini": {
17+
"arm64": {
18+
"opcache.memory_consumption": 256,
19+
"opcache.interned_strings_buffer": 16,
20+
"opcache.max_accelerated_files": 8000,
21+
"opcache.jit_buffer_size": "32M"
22+
},
1723
"x64": {
1824
"opcache.memory_consumption": 256,
1925
"opcache.interned_strings_buffer": 16,

0 commit comments

Comments
 (0)