Skip to content

Commit 53888cf

Browse files
committed
Build System supports windows arm64
1 parent 2c0d3ab commit 53888cf

File tree

5 files changed

+119
-51
lines changed

5 files changed

+119
-51
lines changed

ext/standard/config.w32

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ ADD_FLAG("LIBS_STANDARD", "iphlpapi.lib");
2525

2626
EXTENSION("standard", "array.c base64.c basic_functions.c browscap.c \
2727
crc32.c crypt.c crypt_freesec.c crypt_blowfish.c crypt_sha256.c \
28-
crypt_sha512.c php_crypt_r.c crc32_x86.c \
28+
crypt_sha512.c php_crypt_r.c " + (TARGET_ARCH != 'arm64'? " crc32_x86.c" : "") + " \
2929
datetime.c dir.c dl.c dns.c dns_win32.c exec.c \
3030
file.c filestat.c formatted_print.c fsock.c head.c html.c image.c \
3131
info.c iptc.c lcg.c link.c mail.c math.c md5.c metaphone.c microtime.c \

win32/build/Makefile.frag.w32

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
$(BUILD_DIR)\Zend\jump_$(FIBER_ASM_ARCH)_ms_pe_masm.obj: Zend\asm\jump_$(FIBER_ASM_ARCH)_ms_pe_masm.asm
2-
$(FIBER_ASSEMBLER) /DBOOST_CONTEXT_EXPORT=EXPORT /nologo /Fo $(BUILD_DIR)\Zend\jump_$(FIBER_ASM_ARCH)_ms_pe_masm.obj /c Zend\asm\jump_$(FIBER_ASM_ARCH)_ms_pe_masm.asm
1+
$(BUILD_DIR)\Zend\jump_$(FIBER_ASM_ABI).obj: Zend\asm\jump_$(FIBER_ASM_ABI).asm
2+
$(FIBER_ASSEMBLER) $(FIBER_ASM_FLAGS) $(BUILD_DIR)\Zend\jump_$(FIBER_ASM_ABI).obj Zend\asm\jump_$(FIBER_ASM_ABI).asm
33

4-
$(BUILD_DIR)\Zend\make_$(FIBER_ASM_ARCH)_ms_pe_masm.obj: Zend\asm\make_$(FIBER_ASM_ARCH)_ms_pe_masm.asm
5-
$(FIBER_ASSEMBLER) /DBOOST_CONTEXT_EXPORT=EXPORT /nologo /Fo $(BUILD_DIR)\Zend\make_$(FIBER_ASM_ARCH)_ms_pe_masm.obj /c Zend\asm\make_$(FIBER_ASM_ARCH)_ms_pe_masm.asm
4+
$(BUILD_DIR)\Zend\make_$(FIBER_ASM_ABI).obj: Zend\asm\make_$(FIBER_ASM_ABI).asm
5+
$(FIBER_ASSEMBLER) $(FIBER_ASM_FLAGS) $(BUILD_DIR)\Zend\make_$(FIBER_ASM_ABI).obj Zend\asm\make_$(FIBER_ASM_ABI).asm
66

7-
$(BUILD_DIR)\$(PHPDLL): $(BUILD_DIR)\Zend\jump_$(FIBER_ASM_ARCH)_ms_pe_masm.obj $(BUILD_DIR)\Zend\make_$(FIBER_ASM_ARCH)_ms_pe_masm.obj
7+
$(BUILD_DIR)\$(PHPDLL): $(BUILD_DIR)\Zend\jump_$(FIBER_ASM_ABI).obj $(BUILD_DIR)\Zend\make_$(FIBER_ASM_ABI).obj

win32/build/config.w32

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ ARG_WITH('cygwin', 'Path to cygwin utilities on your system', '\\cygwin');
1414

1515
toolset_setup_compiler();
1616

17-
// do we use x64 or 80x86 version of compiler?
18-
X64 = toolset_is_64();
17+
HOST_ARCH = toolset_host_arch();
18+
TARGET_ARCH = toolset_target_arch();
19+
// for compatible only
20+
X64 = TARGET_ARCH != 'x86';
1921
toolset_setup_arch();
2022

2123
toolset_setup_linker();
@@ -212,7 +214,7 @@ if (PHP_ANALYZER == "vs") {
212214
pvscfg.WriteLine("exclude-path = " + PROGRAM_FILES + "\\windows kits\\");
213215
}
214216
pvscfg.WriteLine("vcinstalldir = " + VCINSTALLDIR);
215-
pvscfg.WriteLine("platform = " + (X64 ? 'x64' : 'Win32'));
217+
pvscfg.WriteLine("platform = " + (TARGET_ARCH == 'x86' ? 'Win32' : 'x64'));
216218
pvscfg.WriteLine("preprocessor = visualcpp");
217219
pvscfg.WriteLine("language = C");
218220
pvscfg.WriteLine("skip-cl-exe = no");
@@ -241,14 +243,35 @@ ADD_SOURCES("Zend", "zend_language_parser.c zend_language_scanner.c \
241243
zend_enum.c zend_fibers.c");
242244
ADD_SOURCES("Zend\\Optimizer", "zend_optimizer.c pass1.c pass3.c optimize_func_calls.c block_pass.c optimize_temp_vars_5.c nop_removal.c compact_literals.c zend_cfg.c zend_dfg.c dfa_pass.c zend_ssa.c zend_inference.c zend_func_info.c zend_call_graph.c zend_dump.c escape_analysis.c compact_vars.c dce.c sccp.c scdf.c");
243245

244-
var FIBER_ASSEMBLER = X64 ? PATH_PROG('ML64') : PATH_PROG('ML');
246+
var FIBER_ASSEMBLER = PATH_PROG({
247+
'x64': 'ML64',
248+
'x86': 'ML',
249+
'arm64': 'armasm64'
250+
}[TARGET_ARCH]);
245251
DEFINE('FIBER_ASSEMBLER', FIBER_ASSEMBLER);
246252

247-
var FIBER_ASM_ARCH = X64 ? 'x86_64' : 'i386';
248-
DEFINE('FIBER_ASM_ARCH', FIBER_ASM_ARCH);
253+
var FIBER_ASM_ARCH = {
254+
'x64': 'x86_64',
255+
'x86': 'i386',
256+
'arm64': 'arm64'
257+
}[TARGET_ARCH];
258+
DEFINE('FIBER_ASM_ARCH', FIBER_ASM_ARCH); // for compatible
259+
260+
var FIBER_ASM_ABI = {
261+
'x64': 'x86_64_ms_pe_masm',
262+
'x86': 'i386_ms_pe_masm',
263+
'arm64': 'arm64_ms_pe_armasm'
264+
}[TARGET_ARCH];
265+
DEFINE('FIBER_ASM_ABI', FIBER_ASM_ABI);
266+
267+
if (TARGET_ARCH == 'arm64') {
268+
DEFINE('FIBER_ASM_FLAGS', '-nologo -machine ARM64 -o');
269+
} else {
270+
DEFINE('FIBER_ASM_FLAGS', '/DBOOST_CONTEXT_EXPORT=EXPORT /nologo /c /Fo');
271+
}
249272

250-
ADD_FLAG('LDFLAGS', '$(BUILD_DIR)\\Zend\\jump_' + FIBER_ASM_ARCH + '_ms_pe_masm.obj');
251-
ADD_FLAG('LDFLAGS', '$(BUILD_DIR)\\Zend\\make_' + FIBER_ASM_ARCH + '_ms_pe_masm.obj');
273+
ADD_FLAG('LDFLAGS', '$(BUILD_DIR)\\Zend\\jump_' + FIBER_ASM_ABI + '.obj');
274+
ADD_FLAG('LDFLAGS', '$(BUILD_DIR)\\Zend\\make_' + FIBER_ASM_ABI + '.obj');
252275

253276
ADD_MAKEFILE_FRAGMENT('win32/build/Makefile.frag.w32');
254277

win32/build/config.w32.phpize.in

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ var PHP_CYGWIN="notset";
1414

1515
toolset_setup_compiler();
1616

17-
// do we use x64 or 80x86 version of compiler?
18-
X64 = toolset_is_64();
17+
HOST_ARCH = toolset_host_arch();
18+
TARGET_ARCH = toolset_target_arch();
19+
// for compatible only
20+
X64 = TARGET_ARCH != 'x86';
1921
toolset_setup_arch();
2022

2123
toolset_setup_linker();

win32/build/confutils.js

Lines changed: 78 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,13 @@ function probe_binary(EXE, what)
168168
}
169169
var version = execute(command + '" 2>&1"');
170170

171-
if (what == "64") {
172-
if (version.match(/x64/)) {
173-
return 1;
171+
if (what == "arch") {
172+
if (version.match(/x86/)) {
173+
return "x86";
174+
} else if (version.match(/x64/)) {
175+
return "x64";
176+
} else if (version.match(/ARM64/)) {
177+
return "arm64";
174178
}
175179
} else {
176180
if (version.match(/(\d+\.\d+(\.\d+)?(\.\d+)?)/)) {
@@ -1670,7 +1674,7 @@ function ADD_SOURCES(dir, file_list, target, obj_dir)
16701674
}
16711675

16721676
if (PHP_ANALYZER == "clang") {
1673-
var analyzer_base_args = X64 ? "-m64" : "-m32";
1677+
var analyzer_base_args = TARGET_ARCH == 'x86' ? "-m32" : "-m64";
16741678
var analyzer_base_flags = "";
16751679

16761680
analyzer_base_args += " --analyze";
@@ -1693,10 +1697,14 @@ function ADD_SOURCES(dir, file_list, target, obj_dir)
16931697
analyzer_base_flags += " -D _MSC_VER=" + probe_binary(PATH_PROG('cl', null));
16941698
}
16951699

1696-
if (X64) {
1700+
if (TARGET_ARCH == 'x64') {
16971701
analyzer_base_flags += " -D _M_X64 -D _WIN64";
1698-
} else {
1702+
} else if (TARGET_ARCH == 'ARM64') {
1703+
analyzer_base_flags += " -D _M_ARM64 -D _WIN64";
1704+
} else if (TARGET_ARCH == 'x86') {
16991705
analyzer_base_flags += " -D _M_IX86 ";
1706+
} else {
1707+
ERROR("analyzer is not supported at arch " + TARGET_ARCH);
17001708
}
17011709
analyzer_base_flags += " -D _WIN32 -D WIN32 -D _WINDOWS";
17021710

@@ -1708,8 +1716,8 @@ function ADD_SOURCES(dir, file_list, target, obj_dir)
17081716
analyzer_base_flags += " -I " + "\"" + vc_incs[i] + "\"";
17091717
}
17101718

1711-
var cppcheck_platform = X64 ? "win64" : "win32A";
1712-
var cppcheck_lib = "win32\\build\\cppcheck_" + (X64 ? "x64" : "x86") + ".cfg";
1719+
var cppcheck_platform = TARGET_ARCH == 'x86' ? "win32A" : "win64";
1720+
var cppcheck_lib = "win32\\build\\cppcheck_" + (TARGET_ARCH == 'x86' ? "x86" : "x64") + ".cfg"; // use x64 for arm64 yet
17131721
analyzer_base_args += "--enable=warning,performance,portability,information,missingInclude " +
17141722
"--platform=" + cppcheck_platform + " " +
17151723
"--library=windows.cfg --library=microsoft_sal.cfg " +
@@ -1960,7 +1968,8 @@ function write_summary()
19601968
ar[k++] = ['Build type', PHP_DEBUG == "yes" ? "Debug" : "Release"];
19611969
ar[k++] = ['Thread Safety', PHP_ZTS == "yes" ? "Yes" : "No"];
19621970
ar[k++] = ['Compiler', COMPILER_NAME_LONG];
1963-
ar[k++] = ['Architecture', X64 ? 'x64' : 'x86'];
1971+
ar[k++] = ['Target Architecture', TARGET_ARCH];
1972+
ar[k++] = ['Host Architecture', HOST_ARCH];
19641973
if (PHP_PGO == "yes") {
19651974
ar[k++] = ['Optimization', "PGO"];
19661975
} else if (PHP_PGI == "yes") {
@@ -3131,10 +3140,32 @@ function toolset_get_compiler_name(short)
31313140
}
31323141

31333142

3134-
function toolset_is_64()
3143+
function toolset_host_arch()
3144+
{
3145+
var command = 'cmd /c "where cl.exe"';
3146+
var clpath = execute(command).split(/\n/)[0].replace(/\s$/, '');
3147+
3148+
var command = 'cmd /c "dumpbin "' + clpath + '" /nologo /headers"';
3149+
var full = execute(command);
3150+
3151+
/*
3152+
output is something like
3153+
FILE HEADER VALUES
3154+
8664 machine (x64)
3155+
*/
3156+
var matches = full.match(/FILE HEADER VALUES\s+[A-F0-9]{4}\smachine \((x64|x86|ARM64)\)/);
3157+
3158+
if(!matches){
3159+
ERROR("Unsupported toolset host");
3160+
}
3161+
3162+
return matches[1];
3163+
}
3164+
3165+
function toolset_target_arch()
31353166
{
31363167
if (VS_TOOLSET) {
3137-
return probe_binary(PHP_CL, 64);
3168+
return probe_binary(PHP_CL, 'arch');
31383169
} else if (CLANG_TOOLSET) {
31393170
/*var command = 'cmd /c ""' + PHP_CL + '" -v"';
31403171
var full = execute(command + '" 2>&1"');
@@ -3144,26 +3175,22 @@ function toolset_is_64()
31443175
/* Even executed within an environment setup with vcvars32.bat,
31453176
clang-cl doesn't recognize the arch toolset. But as it needs
31463177
the VS environment, checking the arch of cl.exe is correct. */
3147-
return probe_binary(PATH_PROG('cl', null), 64);
3178+
return probe_binary(PATH_PROG('cl', null), 'arch');
31483179
} else if (ICC_TOOLSET) {
3149-
var command = 'cmd /c ""' + PHP_CL + '" -v"';
3180+
var command = 'cmd /c "where cl"';
31503181
var full = execute(command + '" 2>&1"');
31513182

31523183
return null != full.match(/Intel\(R\) 64/);
31533184
}
31543185

3155-
ERROR("Unsupported toolset");
3186+
ERROR("Unsupported toolset target");
31563187
}
31573188

31583189
function toolset_setup_arch()
31593190
{
3160-
if (X64) {
3161-
STDOUT.WriteLine(" Detected 64-bit compiler");
3162-
} else {
3163-
STDOUT.WriteLine(" Detected 32-bit compiler");
3164-
}
3165-
AC_DEFINE('PHP_BUILD_ARCH', X64 ? 'x64' : 'x86', "Detected compiler architecture");
3166-
DEFINE("PHP_ARCHITECTURE", X64 ? 'x64' : 'x86');
3191+
STDOUT.WriteLine(" Detected " + TARGET_ARCH + " compiler" + (TARGET_ARCH == HOST_ARCH ? "" : " (cross compile from " + HOST_ARCH + ")"));
3192+
AC_DEFINE('PHP_BUILD_ARCH', TARGET_ARCH, "Detected compiler architecture");
3193+
DEFINE("PHP_ARCHITECTURE", TARGET_ARCH);
31673194
}
31683195

31693196
function toolset_setup_codegen_arch()
@@ -3177,7 +3204,7 @@ function toolset_setup_codegen_arch()
31773204

31783205
if ("IA32" != arc) {
31793206
ERROR("Only IA32 arch is supported by --with-codegen-arch, got '" + arc + "'");
3180-
} else if (X64) {
3207+
} else if (TARGET_ARCH != 'x86') {
31813208
ERROR("IA32 arch is only supported with 32-bit build");
31823209
}
31833210
ADD_FLAG("CFLAGS", "/arch:" + arc);
@@ -3237,10 +3264,10 @@ function toolset_setup_common_cflags()
32373264
// fun stuff: MS deprecated ANSI stdio and similar functions
32383265
// disable annoying warnings. In addition, time_t defaults
32393266
// to 64-bit. Ask for 32-bit.
3240-
if (X64) {
3241-
ADD_FLAG('CFLAGS', ' /wd4996 ');
3242-
} else {
3267+
if (TARGET_ARCH == 'x86') {
32433268
ADD_FLAG('CFLAGS', ' /wd4996 /D_USE_32BIT_TIME_T=1 ');
3269+
} else {
3270+
ADD_FLAG('CFLAGS', ' /wd4996 ');
32443271
}
32453272

32463273
if (PHP_DEBUG == "yes") {
@@ -3292,10 +3319,10 @@ function toolset_setup_common_cflags()
32923319

32933320
ADD_FLAG("CFLAGS", "/Zc:wchar_t");
32943321
} else if (CLANG_TOOLSET) {
3295-
if (X64) {
3296-
ADD_FLAG('CFLAGS', '-m64');
3297-
} else {
3322+
if (TARGET_ARCH == 'x86') {
32983323
ADD_FLAG('CFLAGS', '-m32');
3324+
} else {
3325+
ADD_FLAG('CFLAGS', '-m64');
32993326
}
33003327
ADD_FLAG("CFLAGS", " /fallback ");
33013328
ADD_FLAG("CFLAGS", "-Xclang -fmodules");
@@ -3325,6 +3352,14 @@ function toolset_setup_intrinsic_cflags()
33253352
ERROR("Can't enable intrinsics, --with-codegen-arch passed with an incompatible option. ")
33263353
}
33273354

3355+
if (TARGET_ARCH == 'arm64') {
3356+
/* arm64 supports neon */
3357+
configure_subst.Add("PHP_SIMD_SCALE", 'NEON');
3358+
/* all offically supported arm64 cpu supports crc32 (TODO: to be confirmed) */
3359+
AC_DEFINE('HAVE_ARCH64_CRC32', 1);
3360+
return;
3361+
}
3362+
33283363
if ("no" == PHP_NATIVE_INTRINSICS || "yes" == PHP_NATIVE_INTRINSICS) {
33293364
PHP_NATIVE_INTRINSICS = default_enabled;
33303365
}
@@ -3352,7 +3387,7 @@ function toolset_setup_intrinsic_cflags()
33523387
}
33533388
}
33543389
}
3355-
if (!X64) {
3390+
if (TARGET_ARCH == 'x86') {
33563391
/* SSE2 is currently the default on 32-bit. It could change later,
33573392
for now no need to pass it. But, if SSE only was chosen,
33583393
/arch:SSE is required. */
@@ -3423,7 +3458,7 @@ function toolset_setup_build_mode()
34233458
{
34243459
if (PHP_DEBUG == "yes") {
34253460
ADD_FLAG("CFLAGS", "/LDd /MDd /Od /D _DEBUG /D ZEND_DEBUG=1 " +
3426-
(X64?"/Zi":"/ZI"));
3461+
(TARGET_ARCH == 'x86'?"/ZI":"/Zi"));
34273462
ADD_FLAG("LDFLAGS", "/debug");
34283463
// Avoid problems when linking to release libraries that use the release
34293464
// version of the libc
@@ -3458,11 +3493,16 @@ function object_out_dir_option_handle()
34583493
} else {
34593494
PHP_OBJECT_OUT_DIR = FSO.GetAbsolutePathName(".") + '\\';
34603495

3461-
if (X64) {
3496+
if (TARGET_ARCH == 'x64') {
34623497
PHP_OBJECT_OUT_DIR += 'x64\\';
34633498
if (!FSO.FolderExists(PHP_OBJECT_OUT_DIR)) {
34643499
FSO.CreateFolder(PHP_OBJECT_OUT_DIR);
34653500
}
3501+
} else if (TARGET_ARCH == 'arm64') {
3502+
PHP_OBJECT_OUT_DIR += 'arm64\\';
3503+
if (!FSO.FolderExists(PHP_OBJECT_OUT_DIR)) {
3504+
FSO.CreateFolder(PHP_OBJECT_OUT_DIR);
3505+
}
34663506
}
34673507
}
34683508
}
@@ -3519,7 +3559,7 @@ function php_build_option_handle()
35193559
if (FSO.FolderExists("..\\php_build")) {
35203560
PHP_PHP_BUILD = "..\\php_build";
35213561
} else {
3522-
if (X64) {
3562+
if (TARGET_ARCH != 'x86') {
35233563
if (FSO.FolderExists("..\\win64build")) {
35243564
PHP_PHP_BUILD = "..\\win64build";
35253565
} else if (FSO.FolderExists("..\\php-win64-dev\\php_build")) {
@@ -3681,7 +3721,7 @@ function get_clang_lib_dir()
36813721
ERROR("Failed to determine clang lib path");
36823722
}
36833723

3684-
if (X64) {
3724+
if (TARGET_ARCH != 'x86') {
36853725
ret = PROGRAM_FILES + "\\LLVM\\lib\\clang\\" + ver + "\\lib";
36863726
if (!FSO.FolderExists(ret)) {
36873727
ret = null;
@@ -3718,10 +3758,13 @@ function add_asan_opts(cflags_name, libs_name, ldflags_name)
37183758
ADD_FLAG(cflags_name, "-fsanitize=address,undefined");
37193759
}
37203760
if (!!libs_name) {
3721-
if (X64) {
3761+
if (TARGET_ARCH == 'x64') {
37223762
ADD_FLAG(libs_name, "clang_rt.asan_dynamic-x86_64.lib clang_rt.asan_dynamic_runtime_thunk-x86_64.lib");
3723-
} else {
3763+
} else if (TARGET_ARCH == 'x86') {
37243764
ADD_FLAG(libs_name, "clang_rt.asan_dynamic-i386.lib clang_rt.asan_dynamic_runtime_thunk-i386.lib");
3765+
} else {
3766+
// TODO: support arm64?
3767+
ERROR("Failed to determine clang lib path");
37253768
}
37263769
}
37273770

0 commit comments

Comments
 (0)