@@ -168,9 +168,13 @@ function probe_binary(EXE, what)
168
168
}
169
169
var version = execute ( command + '" 2>&1"' ) ;
170
170
171
- if ( what == "64" ) {
172
- if ( version . match ( / x 6 4 / ) ) {
173
- return 1 ;
171
+ if ( what == "arch" ) {
172
+ if ( version . match ( / x 8 6 / ) ) {
173
+ return "x86" ;
174
+ } else if ( version . match ( / x 6 4 / ) ) {
175
+ return "x64" ;
176
+ } else if ( version . match ( / A R M 6 4 / ) ) {
177
+ return "arm64" ;
174
178
}
175
179
} else {
176
180
if ( version . match ( / ( \d + \. \d + ( \. \d + ) ? ( \. \d + ) ? ) / ) ) {
@@ -1670,7 +1674,7 @@ function ADD_SOURCES(dir, file_list, target, obj_dir)
1670
1674
}
1671
1675
1672
1676
if ( PHP_ANALYZER == "clang" ) {
1673
- var analyzer_base_args = X64 ? "-m64 " : "-m32 " ;
1677
+ var analyzer_base_args = TARGET_ARCH == 'x86' ? "-m32 " : "-m64 " ;
1674
1678
var analyzer_base_flags = "" ;
1675
1679
1676
1680
analyzer_base_args += " --analyze" ;
@@ -1693,10 +1697,14 @@ function ADD_SOURCES(dir, file_list, target, obj_dir)
1693
1697
analyzer_base_flags += " -D _MSC_VER=" + probe_binary ( PATH_PROG ( 'cl' , null ) ) ;
1694
1698
}
1695
1699
1696
- if ( X64 ) {
1700
+ if ( TARGET_ARCH == 'x64' ) {
1697
1701
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' ) {
1699
1705
analyzer_base_flags += " -D _M_IX86 " ;
1706
+ } else {
1707
+ ERROR ( "analyzer is not supported at arch " + TARGET_ARCH ) ;
1700
1708
}
1701
1709
analyzer_base_flags += " -D _WIN32 -D WIN32 -D _WINDOWS" ;
1702
1710
@@ -1708,8 +1716,8 @@ function ADD_SOURCES(dir, file_list, target, obj_dir)
1708
1716
analyzer_base_flags += " -I " + "\"" + vc_incs [ i ] + "\"" ;
1709
1717
}
1710
1718
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
1713
1721
analyzer_base_args += "--enable=warning,performance,portability,information,missingInclude " +
1714
1722
"--platform=" + cppcheck_platform + " " +
1715
1723
"--library=windows.cfg --library=microsoft_sal.cfg " +
@@ -1960,7 +1968,8 @@ function write_summary()
1960
1968
ar [ k ++ ] = [ 'Build type' , PHP_DEBUG == "yes" ? "Debug" : "Release" ] ;
1961
1969
ar [ k ++ ] = [ 'Thread Safety' , PHP_ZTS == "yes" ? "Yes" : "No" ] ;
1962
1970
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 ] ;
1964
1973
if ( PHP_PGO == "yes" ) {
1965
1974
ar [ k ++ ] = [ 'Optimization' , "PGO" ] ;
1966
1975
} else if ( PHP_PGI == "yes" ) {
@@ -3131,10 +3140,32 @@ function toolset_get_compiler_name(short)
3131
3140
}
3132
3141
3133
3142
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 ( / F I L E H E A D E R V A L U E S \s + [ A - F 0 - 9 ] { 4 } \s m a c h i n e \( ( x 6 4 | x 8 6 | A R M 6 4 ) \) / ) ;
3157
+
3158
+ if ( ! matches ) {
3159
+ ERROR ( "Unsupported toolset host" ) ;
3160
+ }
3161
+
3162
+ return matches [ 1 ] ;
3163
+ }
3164
+
3165
+ function toolset_target_arch ( )
3135
3166
{
3136
3167
if ( VS_TOOLSET ) {
3137
- return probe_binary ( PHP_CL , 64 ) ;
3168
+ return probe_binary ( PHP_CL , 'arch' ) ;
3138
3169
} else if ( CLANG_TOOLSET ) {
3139
3170
/*var command = 'cmd /c ""' + PHP_CL + '" -v"';
3140
3171
var full = execute(command + '" 2>&1"');
@@ -3144,26 +3175,22 @@ function toolset_is_64()
3144
3175
/* Even executed within an environment setup with vcvars32.bat,
3145
3176
clang-cl doesn't recognize the arch toolset. But as it needs
3146
3177
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' ) ;
3148
3179
} else if ( ICC_TOOLSET ) {
3149
- var command = 'cmd /c ""' + PHP_CL + '" -v "';
3180
+ var command = 'cmd /c "where cl "' ;
3150
3181
var full = execute ( command + '" 2>&1"' ) ;
3151
3182
3152
3183
return null != full . match ( / I n t e l \( R \) 6 4 / ) ;
3153
3184
}
3154
3185
3155
- ERROR ( "Unsupported toolset" ) ;
3186
+ ERROR ( "Unsupported toolset target " ) ;
3156
3187
}
3157
3188
3158
3189
function toolset_setup_arch ( )
3159
3190
{
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 ) ;
3167
3194
}
3168
3195
3169
3196
function toolset_setup_codegen_arch ( )
@@ -3177,7 +3204,7 @@ function toolset_setup_codegen_arch()
3177
3204
3178
3205
if ( "IA32" != arc ) {
3179
3206
ERROR ( "Only IA32 arch is supported by --with-codegen-arch, got '" + arc + "'" ) ;
3180
- } else if ( X64 ) {
3207
+ } else if ( TARGET_ARCH != 'x86' ) {
3181
3208
ERROR ( "IA32 arch is only supported with 32-bit build" ) ;
3182
3209
}
3183
3210
ADD_FLAG ( "CFLAGS" , "/arch:" + arc ) ;
@@ -3237,10 +3264,10 @@ function toolset_setup_common_cflags()
3237
3264
// fun stuff: MS deprecated ANSI stdio and similar functions
3238
3265
// disable annoying warnings. In addition, time_t defaults
3239
3266
// to 64-bit. Ask for 32-bit.
3240
- if ( X64 ) {
3241
- ADD_FLAG ( 'CFLAGS' , ' /wd4996 ' ) ;
3242
- } else {
3267
+ if ( TARGET_ARCH == 'x86' ) {
3243
3268
ADD_FLAG ( 'CFLAGS' , ' /wd4996 /D_USE_32BIT_TIME_T=1 ' ) ;
3269
+ } else {
3270
+ ADD_FLAG ( 'CFLAGS' , ' /wd4996 ' ) ;
3244
3271
}
3245
3272
3246
3273
if ( PHP_DEBUG == "yes" ) {
@@ -3292,10 +3319,10 @@ function toolset_setup_common_cflags()
3292
3319
3293
3320
ADD_FLAG ( "CFLAGS" , "/Zc:wchar_t" ) ;
3294
3321
} else if ( CLANG_TOOLSET ) {
3295
- if ( X64 ) {
3296
- ADD_FLAG ( 'CFLAGS' , '-m64' ) ;
3297
- } else {
3322
+ if ( TARGET_ARCH == 'x86' ) {
3298
3323
ADD_FLAG ( 'CFLAGS' , '-m32' ) ;
3324
+ } else {
3325
+ ADD_FLAG ( 'CFLAGS' , '-m64' ) ;
3299
3326
}
3300
3327
ADD_FLAG ( "CFLAGS" , " /fallback " ) ;
3301
3328
ADD_FLAG ( "CFLAGS" , "-Xclang -fmodules" ) ;
@@ -3325,6 +3352,14 @@ function toolset_setup_intrinsic_cflags()
3325
3352
ERROR ( "Can't enable intrinsics, --with-codegen-arch passed with an incompatible option. " )
3326
3353
}
3327
3354
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
+
3328
3363
if ( "no" == PHP_NATIVE_INTRINSICS || "yes" == PHP_NATIVE_INTRINSICS ) {
3329
3364
PHP_NATIVE_INTRINSICS = default_enabled ;
3330
3365
}
@@ -3352,7 +3387,7 @@ function toolset_setup_intrinsic_cflags()
3352
3387
}
3353
3388
}
3354
3389
}
3355
- if ( ! X64 ) {
3390
+ if ( TARGET_ARCH == 'x86' ) {
3356
3391
/* SSE2 is currently the default on 32-bit. It could change later,
3357
3392
for now no need to pass it. But, if SSE only was chosen,
3358
3393
/arch:SSE is required. */
@@ -3423,7 +3458,7 @@ function toolset_setup_build_mode()
3423
3458
{
3424
3459
if ( PHP_DEBUG == "yes" ) {
3425
3460
ADD_FLAG ( "CFLAGS" , "/LDd /MDd /Od /D _DEBUG /D ZEND_DEBUG=1 " +
3426
- ( X64 ?"/Zi " :"/ZI " ) ) ;
3461
+ ( TARGET_ARCH == 'x86' ?"/ZI " :"/Zi " ) ) ;
3427
3462
ADD_FLAG ( "LDFLAGS" , "/debug" ) ;
3428
3463
// Avoid problems when linking to release libraries that use the release
3429
3464
// version of the libc
@@ -3458,11 +3493,16 @@ function object_out_dir_option_handle()
3458
3493
} else {
3459
3494
PHP_OBJECT_OUT_DIR = FSO . GetAbsolutePathName ( "." ) + '\\' ;
3460
3495
3461
- if ( X64 ) {
3496
+ if ( TARGET_ARCH == 'x64' ) {
3462
3497
PHP_OBJECT_OUT_DIR += 'x64\\' ;
3463
3498
if ( ! FSO . FolderExists ( PHP_OBJECT_OUT_DIR ) ) {
3464
3499
FSO . CreateFolder ( PHP_OBJECT_OUT_DIR ) ;
3465
3500
}
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
+ }
3466
3506
}
3467
3507
}
3468
3508
}
@@ -3519,7 +3559,7 @@ function php_build_option_handle()
3519
3559
if ( FSO . FolderExists ( "..\\php_build" ) ) {
3520
3560
PHP_PHP_BUILD = "..\\php_build" ;
3521
3561
} else {
3522
- if ( X64 ) {
3562
+ if ( TARGET_ARCH != 'x86' ) {
3523
3563
if ( FSO . FolderExists ( "..\\win64build" ) ) {
3524
3564
PHP_PHP_BUILD = "..\\win64build" ;
3525
3565
} else if ( FSO . FolderExists ( "..\\php-win64-dev\\php_build" ) ) {
@@ -3681,7 +3721,7 @@ function get_clang_lib_dir()
3681
3721
ERROR ( "Failed to determine clang lib path" ) ;
3682
3722
}
3683
3723
3684
- if ( X64 ) {
3724
+ if ( TARGET_ARCH != 'x86' ) {
3685
3725
ret = PROGRAM_FILES + "\\LLVM\\lib\\clang\\" + ver + "\\lib" ;
3686
3726
if ( ! FSO . FolderExists ( ret ) ) {
3687
3727
ret = null ;
@@ -3718,10 +3758,13 @@ function add_asan_opts(cflags_name, libs_name, ldflags_name)
3718
3758
ADD_FLAG ( cflags_name , "-fsanitize=address,undefined" ) ;
3719
3759
}
3720
3760
if ( ! ! libs_name ) {
3721
- if ( X64 ) {
3761
+ if ( TARGET_ARCH == 'x64' ) {
3722
3762
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' ) {
3724
3764
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" ) ;
3725
3768
}
3726
3769
}
3727
3770
0 commit comments