Skip to content

Commit 3a4163b

Browse files
dixyescmb69
authored andcommitted
Initial support for arm64 cross compilation
Closes GH-1.
1 parent cc7c11a commit 3a4163b

File tree

6 files changed

+98
-50
lines changed

6 files changed

+98
-50
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: 81 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -44,32 +44,62 @@ if 14 gtr %TMP_CHK% (
4444
set PHP_SDK_VS_NUM=%TMP_CHK%
4545
set TMP_CHK=
4646

47-
if /i not "%2"=="x64" (
48-
if /i not "%2"=="x86" (
49-
echo Unsupported arch "%2"
50-
goto out_error
51-
)
47+
rem check target arch
48+
if "%2"=="x86" set PHP_SDK_ARCH=%2
49+
if "%2"=="x64" set PHP_SDK_ARCH=%2
50+
if "%2"=="x86_64" set PHP_SDK_ARCH=x64
51+
if "%2"=="amd64" set PHP_SDK_ARCH=x64
52+
if "%2"=="arm64" set PHP_SDK_ARCH=%2
53+
if "%PHP_SDK_ARCH%"=="" (
54+
echo Unsupported target arch %2 >&2
55+
goto out_error
5256
)
5357

54-
set PHP_SDK_ARCH=%2
55-
5658
rem check OS arch
57-
set TMPKEY=HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion
58-
reg query "%TMPKEY%" /v "ProgramFilesDir (x86)" >nul 2>nul
59-
if not errorlevel 1 (
60-
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-
)
66-
set PHP_SDK_OS_ARCH=x86
59+
rem todo: allow user choose host sdk arch (i.e. x64 target can be compiled at x64(native) or x86(cross))
60+
for /f "usebackq tokens=1*" %%i in (`wmic cpu get Architecture /value /format:table ^| findstr /r "[1234567890][1234567890]*"`) do (
61+
set PHP_SDK_OS_ARCH_NUM=%%i
62+
)
63+
64+
goto os_arch_cases
65+
:os_arch_error
66+
echo Unsupported OS arch %PHP_SDK_OS_ARCH% >&2
67+
goto out_error
68+
69+
:os_arch_cases
70+
if "%PHP_SDK_OS_ARCH_NUM%"=="0" set PHP_SDK_OS_ARCH=x86
71+
if "%PHP_SDK_OS_ARCH_NUM%"=="1" (set PHP_SDK_OS_ARCH=mips && goto os_arch_error)
72+
if "%PHP_SDK_OS_ARCH_NUM%"=="2" (set PHP_SDK_OS_ARCH=alpha && goto os_arch_error)
73+
if "%PHP_SDK_OS_ARCH_NUM%"=="3" (set PHP_SDK_OS_ARCH=ppc && goto os_arch_error)
74+
if "%PHP_SDK_OS_ARCH_NUM%"=="4" (set PHP_SDK_OS_ARCH=shx && goto os_arch_error)
75+
if "%PHP_SDK_OS_ARCH_NUM%"=="5" (set PHP_SDK_OS_ARCH=arm32 && goto os_arch_error)
76+
if "%PHP_SDK_OS_ARCH_NUM%"=="6" (set PHP_SDK_OS_ARCH=ia64 && goto os_arch_error)
77+
if "%PHP_SDK_OS_ARCH_NUM%"=="7" (set PHP_SDK_OS_ARCH=alpha64 && goto os_arch_error)
78+
if "%PHP_SDK_OS_ARCH_NUM%"=="8" (set PHP_SDK_OS_ARCH=msil && goto os_arch_error)
79+
if "%PHP_SDK_OS_ARCH_NUM%"=="9" set PHP_SDK_OS_ARCH=x64
80+
rem wow64
81+
if "%PHP_SDK_OS_ARCH_NUM%"=="10" set PHP_SDK_OS_ARCH=x86
82+
if "%PHP_SDK_OS_ARCH_NUM%"=="11" (set PHP_SDK_OS_ARCH=neutral && goto os_arch_error)
83+
if "%PHP_SDK_OS_ARCH_NUM%"=="12" set PHP_SDK_OS_ARCH=arm64
84+
if "%PHP_SDK_OS_ARCH_NUM%"=="13" (set PHP_SDK_OS_ARCH=arm32 && goto os_arch_error)
85+
rem woa64
86+
if "%PHP_SDK_OS_ARCH_NUM%"=="14" set PHP_SDK_OS_ARCH=x86
87+
if "%PHP_SDK_OS_ARCH%"=="" (
88+
goto os_arch_error
6789
)
68-
set TMPKEY=
90+
91+
set PHP_SDK_OS_ARCH_NUM=
92+
93+
rem cross compile is ok, so we donot need this
94+
rem if not /i "%PHP_SDK_ARCH%"=="PHP_SDK_OS_ARCH" (
95+
rem echo 32-bit OS detected, native 64-bit toolchain is unavailable.
96+
rem goto out_error
97+
rem )
6998

7099
rem get vc base dir
71100
if 15 gtr %PHP_SDK_VS_NUM% (
72-
if /i "%PHP_SDK_OS_ARCH%"=="x64" (
101+
rem for arch other than x86, use WOW6432
102+
if /i not "%PHP_SDK_OS_ARCH%"=="x86" (
73103
set TMPKEY=HKLM\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\%PHP_SDK_VS:~2%.0\Setup\VC
74104
) else (
75105
set TMPKEY=HKLM\SOFTWARE\Microsoft\VisualStudio\%PHP_SDK_VS:~2%.0\Setup\VC
@@ -85,16 +115,20 @@ if 15 gtr %PHP_SDK_VS_NUM% (
85115
set /a PHP_SDK_VS_RANGE=PHP_SDK_VS_NUM + 1
86116
set PHP_SDK_VS_RANGE="[%PHP_SDK_VS_NUM%,!PHP_SDK_VS_RANGE%!)"
87117

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 (
118+
set APPEND=x86.x64
119+
if /i "%PHP_SDK_OS_ARCH%"=="arm64" (
120+
set APPEND=ARM64
121+
)
122+
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 (
89123
set PHP_SDK_VC_DIR=%%b\VC
90124
)
91125
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 (
126+
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 (
93127
set PHP_SDK_VC_DIR=%%b\VC
94128
)
95129
if not exist "!PHP_SDK_VC_DIR!" (
96130
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 (
131+
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 (
98132
set PHP_SDK_VC_DIR=%%b\VC
99133
)
100134
if not exist "!PHP_SDK_VC_DIR!" (
@@ -105,13 +139,15 @@ if 15 gtr %PHP_SDK_VS_NUM% (
105139
)
106140
set VSCMD_ARG_no_logo=nologo
107141
)
142+
set APPEND=
108143
set TMPKEY=
109144
set PHP_SDK_VS_RANGE=
110145

111146
if 15 gtr %PHP_SDK_VS_NUM% (
112147
rem get sdk dir
113148
rem if 10.0 is available, it's ok
114-
if /i "%PHP_SDK_OS_ARCH%"=="x64" (
149+
rem for arch other than x86, use WOW6432
150+
if /i not "%PHP_SDK_OS_ARCH%"=="x86" (
115151
set TMPKEY=HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Microsoft SDKs\Windows\v10.0
116152
) else (
117153
set TMPKEY=HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v10.0
@@ -125,7 +161,8 @@ if 15 gtr %PHP_SDK_VS_NUM% (
125161
)
126162

127163
rem Otherwise 8.1 should be available anyway
128-
if /i "%PHP_SDK_OS_ARCH%"=="x64" (
164+
rem for arch other than x86, use WOW6432
165+
if /i not "%PHP_SDK_OS_ARCH%"=="x86" (
129166
set TMPKEY=HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Microsoft SDKs\Windows\v8.1
130167
) else (
131168
set TMPKEY=HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v8.1
@@ -143,18 +180,28 @@ if 15 gtr %PHP_SDK_VS_NUM% (
143180
)
144181

145182
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-
)
183+
set TARGET_ARCH_NAME=amd64
151184
) 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-
)
185+
set TARGET_ARCH_NAME=%PHP_SDK_ARCH%
186+
)
187+
188+
if /i "%PHP_SDK_OS_ARCH%"=="x64" (
189+
set HOST_ARCH_NAME=amd64
190+
) else (
191+
set HOST_ARCH_NAME=%PHP_SDK_ARCH%
192+
)
193+
194+
if "%HOST_ARCH_NAME%"=="%TARGET_ARCH_NAME%" (
195+
set VCVARSALL_ARCH_NAME=%HOST_ARCH_NAME%
196+
) else (
197+
set VCVARSALL_ARCH_NAME=%HOST_ARCH_NAME%_%TARGET_ARCH_NAME%
198+
)
199+
if 15 gtr %PHP_SDK_VS_NUM% (
200+
set PHP_SDK_VS_SHELL_CMD="!PHP_SDK_VC_DIR!\vcvarsall.bat" !VCVARSALL_ARCH_NAME!
201+
) else (
202+
set PHP_SDK_VS_SHELL_CMD="!PHP_SDK_VC_DIR!\Auxiliary\Build\vcvarsall.bat" !VCVARSALL_ARCH_NAME!
157203
)
204+
set VCVARSALL_ARCH_NAME=
158205

159206
rem echo Visual Studio VC path %PHP_SDK_VC_DIR%
160207
rem echo Windows SDK path %PHP_SDK_WIN_SDK_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)