Skip to content

Latest commit

 

History

History
154 lines (115 loc) · 5.43 KB

windows.md

File metadata and controls

154 lines (115 loc) · 5.43 KB

Windows build system for PHP

Index

Windows build system in PHP is a separate collection of JScript files and command-line scripts. Some files are manually created unlike with Autoconf. For example, header files. Similarly to *.m4 files for *nix build system, on Windows there are *.w32 files for each extension and SAPI module.

1. Directory structure

Directory structure from the Windows build system perspective looks like this:

📂 <php-src>
└─📂 ext
  └─📂 bcmath
    └─📄 config.w32          # Extension's Windows build system item file
  └─📂 iconv
    ├─📄 config.w32          # Extension's Windows build system item file
    └─📄 php_iconv.def       # Module-definition file for linker when building DLL
  └─📂 opcache
    └─📂 jit
      └─📄 Makefile.frag.w32 # Makefile fragment for OPcache Jit
    └─📄 config.w32          # Windows build system script item
└─📂 main
  ├─📄 config.w32.h          # Generated by configure.bat
  └─📄 php_version.h         # Generated by release managers using `configure`
└─📂 sapi
  └─📂 cli
    └─📄 config.w32          # Windows build system item file for CLI SAPI
└─📂 win32                   # Windows build files
  └─📂 build                 # Windows build system configuration and scripts
    ├─📄 config.w32          # Main configuration file to create configure.js
    ├─📄 config.w32.h.in     # Windows configuration header template
    ├─📄 confutils.js        # The configure script utilities
    ├─📄 Makefile            # Windows build system Makefile template
    └─📄 wsyslog.mc          # Message template file for win32/wsyslog.h
  ├─📄 cp_enc_map.c          # Generated by `win32/cp_enc_map_gen.exe`
  └─📄 wsyslog.h             # Generated by message compiler (mc.exe)
└─📂 TSRM
  └─📄 config.w32            # Windows build system script item
└─📂 Zend
  └─📄 zend_config.w32.h     # Windows configuration header for Zend Engine
└─📄 buildconf.bat           # Windows build system configuration builder

2. Windows prerequisites

  • Windows operating system.
  • Visual Studio installed (e.g., Visual Studio 2019 or later).
  • NMAKE command-line tool for creating Makefiles on Windows; comes installed with Visual Studio.
  • Git installed (download from https://git-scm.com/downloads).

3. Building PHP on Windows

To build PHP on Windows using provided JScript build system files, a separate repository php-sdk-binary-tools provides required scripts, files, and helpers to simplify the build process:

# Clone SDK binary tools Git repository
git clone https://github.com/php/php-sdk-binary-tools C:\php-sdk
cd C:\php-sdk

# Setup the build environment
.\phpsdk-vs17-x64.bat

# Create build tree
phpsdk_buildtree phpmaster

# Clone php-src Git repository
git clone https://github.com/php/php-src
cd php-src

# Download and configure dependencies
phpsdk_deps --update --branch master

# Create Windows configure.bat script
.\buildconf.bat

# Configure PHP build and create Makefile
.\configure.bat

# Build PHP
nmake

# Built files reside in the <architecture>\Release_TS directory. For example
x64\Release_TS\php.exe -v

# Or run the PHP executable with nmake
nmake /nologo run ARGS=-v

# To run tests:
nmake test

4. The configure.bat command-line options

Configuration can be passed on the command line at the configuration phase:

.\configure.bat VAR=VALUE --enable-FEATURE --with-PACKAGE

There are two main types of command-line options for the configure.bat script (--enable-FEATURE and --with-PACKAGE):

  • --enable-FEATURE[=ARG] and its belonging opposite --disable-FEATURE

    --disable-FEATURE is the same as --enable-FEATURE=no

    These normally don't require 3rd party library or package installed on the system. For some extensions, PHP bundles 3rd party dependencies in the extension itself. For example, bcmath, gd, etc.

  • --with-PACKAGE[=ARG] and its belonging opposite --without-PACKAGE

    --without-PACKAGE is the same as --with-PACKAGE=no

    These require 3rd party package installed on the system. PHP has even some libraries bundled in PHP source code. For example, the PCRE library and similar.

Other custom options that don't follow this pattern are used for adjusting specific features during the build process.

See .\configure.bat --help for all available configuration options and variables. Configure options for all PHP versions are listed also in the Windows directory.

Some common arguments can be passed to command-line options:

  • To build extension as shared: --enable-EXT=shared or --with-EXT=shared.

5. Dependencies

PHP Windows build uses forks for some dependencies. Sources are available at github.com/winlibs.

6. See more