Build and test

Building for Windows

Match the PHP SDK, import libraries and runtime for version, architecture, NTS/ZTS and debug settings.

Building with MSVC on Windows

To prepare the SDK automatically with xwin, see Cross-compilation.

With a matching PHP development package, run this in PowerShell:

zig build `
  -Dtarget=native-native-msvc `
  -Dphp-include-dir=C:\php-sdk\include `
  -Dphp-lib-dir=C:\php-sdk\lib

Add -Dwindows-zts=true for ZTS and -Dwindows-debug=true for debug packages. The header root contains main, Zend, TSRM and ext. The library directory contains the matching php8*.lib.

Load the resulting modules/php_my_php_extension.dll in a matching Windows PHP process:

php -n -dextension=./modules/php_my_php_extension.dll -r 'hello();'

PHP for Windows uses the MSVC ABI. MinGW builds use a different ABI.

Cross-compiling for Windows from Linux

For the Linux build command and SDK setup, see Cross-compilation.

Testing and configuration

Replace zig build with zig build run-tests in the PowerShell example, keeping its other arguments. See PHPT tests for the test format and running individual cases.

Use the actual DLL path when loading through INI. See Loading the extension with php.ini for configuration and troubleshooting.