internals:windows:stepbystepbuild_sdk_2

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
internals:windows:stepbystepbuild_sdk_2 [2017/03/30 00:26] abinternals:windows:stepbystepbuild_sdk_2 [2022/01/10 09:43] (current) – use php fork of php-sdk-binary-tools cmb
Line 1: Line 1:
 ====== Build your own PHP on Windows ====== ====== Build your own PHP on Windows ======
  
-This tutorial concerns the new PHP SDK and PHP 7.2 and later, while the described PHP SDK is compatible with at least PHP 7.0. To build PHP prior to 7.0, or if you experience issues building PHP lower than 7.2 with the new PHP SDK, please refer to [[internals:windows:stepbystepbuild|older documentation]].+**This tutorial concerns the new PHP SDK and PHP 7.2 and later, while the described PHP SDK is compatible with at least PHP 7.0. To build PHP prior to 7.0, or if you experience issues building PHP lower than 7.2 with the new PHP SDK, please refer to [[internals:windows:stepbystepbuild|older documentation]].**
  
 ===== Before you Begin ===== ===== Before you Begin =====
Line 14: Line 14:
 ==== Requirements ==== ==== Requirements ====
  
-PHP officially supports building with Microsoft's Visual C++ compilers, ICC and clang. MinGW and Cygwin are NOT supported. Though, he production quality binaries are guaranteed only by using Visual C++. The freely available Community VC++ editions are fully supported and can be used. For more information and how to get the compiler see the [[internals:windows:compiler|supported versions]]. The following VC++ versions are supported:+PHP officially supports building with Microsoft's Visual C++ compilers. MinGW and Cygwin are NOT supported. ICC and clang can be used for experimental purposes. Though, **be aware**, the production quality binaries are guaranteed only by using Visual C++. The freely available Community VC++ editions are fully supported and can be used. For more information and how to get the compiler see the [[internals:windows:compiler|supported versions]]. The following VC++ versions are supported:
  
   * Visual C++ 14.0 (Visual Studio 2015) for **PHP 7.0** or **PHP 7.1**.   * Visual C++ 14.0 (Visual Studio 2015) for **PHP 7.0** or **PHP 7.1**.
-  * Visual C++ 15.0 (Visual Studio 2017) for **PHP 7.2** +  * Visual C++ 15.0 (Visual Studio 2017) for **PHP 7.2**, **PHP 7.3** or **PHP 7.4**. 
-  * +  * Visual C++ 16.0 (Visual Studio 2019) for **master**. 
 + 
 +Always keep your installed Visual C++ up to date. Otherwise build errors may occur due to dependencies built with newer versions. 
 + 
 +Support for a certain Visual Studio version means only support for its default platform toolset; building PHP with a non-default platform toolset (such as 14.16 with Visual Studio 2019) may work, but is not recommended. 
 + 
 +In filenames (and the ''PHP_SDK_VS'' environment variable; see below) the Visual Studio version is usually abbreviated. Before Visual Studio 2019, the abbreviation used the scheme "vc#" (for instance, "vc14"). This number ("#") has tradionally been the major number of the respective platform toolset. The preview releases of Visual Studio 2017 shipped with platform toolset 15.00, so "vc15" was used. The first GA release of Visual Studio 2017, however, shipped with platform toolset 14.10 (to signal the backward compatibility), but the internal Visual Studio version number stayed 15.00. To avoid confusion "vc15" has been kept. For the Visual Studio 2019 builds (master), the "vc#" has finally been changed to "vs#" (note the "s"), where the number now designates the major internal Visual Studio version number. 
 ==== Setup ==== ==== Setup ====
    
-  * Fetch the latest stable SDK tag from https://github.com/OSTC/php-sdk-binary-tools+  * Fetch the latest stable SDK tag or HEAD from https://github.com/php/php-sdk-binary-tools
     * The new PHP SDK is required, when building PHP 7.2+     * The new PHP SDK is required, when building PHP 7.2+
     * Read the PHP SDK specific notes on the Github repository page     * Read the PHP SDK specific notes on the Github repository page
   * If compiling **PHP 7.0+**:   * If compiling **PHP 7.0+**:
     * Install Visual Studio 2015     * Install Visual Studio 2015
 +  * If compiling **PHP 7.2+**:
 +    * Install Visual Studio 2017
 +  * If compiling **master**:
 +    * Install Visual Studio 2019
  
   * Optional tools    * Optional tools 
Line 34: Line 45:
 ==== Command prompt ==== ==== Command prompt ====
  
-The PHP SDK 2.0.0+ provides starter scripts, that automaticaly setup the compiler environment. The starter scripts also provide functionality to inject custom setup pieces. To create a customized setup script, put your code into the file ''phpsdk-local.bat'' into the PHP SDK root dir. The following variables are automatically available within the PHP SDK shell+The PHP SDK 2.0.0+ provides starter scripts, that automatically setup the compiler environment. The starter scripts also provide functionality to inject custom setup pieces. To create a customized setup script, put your code into the file ''phpsdk-local.bat'' into the PHP SDK root dir. The following variables are automatically available within the PHP SDK shell
  
   * PHP_SDK_ARCH - the target build architecture used for environment setup   * PHP_SDK_ARCH - the target build architecture used for environment setup
   * PHP_SDK_OS_ARCH - the operating system architecture   * PHP_SDK_OS_ARCH - the operating system architecture
   * PHP_SDK_PHP_CMD - integrated PHP binary wrapper script   * PHP_SDK_PHP_CMD - integrated PHP binary wrapper script
-  * PHP_SDK_ROOT_PATH - the path to the PHP SDK rood directory +  * PHP_SDK_ROOT_PATH - the path to the PHP SDK root directory 
-  * PHP_SDK_VC - Visual C++ version used for the environment+  * PHP_SDK_VS - Visual C++ version used for the environment (before PHP SDK 2.2.0beta4, this variable was named PHP_SDK_VC)
   * several other less relevant vars are available, that can be viewed by the ''set'' command   * several other less relevant vars are available, that can be viewed by the ''set'' command
  
 The full list of the tools included with the PHP SDK can be found on the repository readme page. The full list of the tools included with the PHP SDK can be found on the repository readme page.
  
-Each version of Visual Studio (or Windows SDK) provides a command prompt environment for compiling (available from the Start Menu group). It is usable, for example, if you want to ommit the starter scripts usage or want to test a pre release Visual Studio version.+Each version of Visual Studio (or Windows SDK) provides a command prompt environment for compiling (available from the Start Menu group). It is usable, for example, if you want to omit the starter scripts usage or want to test a pre release Visual Studio version.
  
     * If compiling **PHP 7.0+** open either the **"VS2015 x64 Native Tools Command Prompt"** or the **"VS2015 x86 Native Tools Command Prompt"**.     * If compiling **PHP 7.0+** open either the **"VS2015 x64 Native Tools Command Prompt"** or the **"VS2015 x86 Native Tools Command Prompt"**.
Line 57: Line 68:
     * clone the [[http://git.php.net/|PHP Git repository]] ([[https://github.com/php/php-src|GitHub mirror]])     * clone the [[http://git.php.net/|PHP Git repository]] ([[https://github.com/php/php-src|GitHub mirror]])
   - Get the binary tools:   - Get the binary tools:
-    * available from [[https://github.com/OSTC/php-sdk-binary-tools]]+    * available from [[https://github.com/php/php-sdk-binary-tools]]
     * either fetch a tag as zip, or clone the git repository and checkout the tag     * either fetch a tag as zip, or clone the git repository and checkout the tag
   - Get the libraries on which PHP depends:   - Get the libraries on which PHP depends:
-    * use the PHP SDK tools to fetch the suitable dependencies automatically by calling ''phpsdk_deps -u'', or alternatively do the following steps +    * use the PHP SDK tools to fetch the suitable dependencies automatically by calling ''phpsdk_deps -u'' 
-    * download the packaged deps from [[http://windows.php.net/downloads/php-sdk/]] +    * alternatively, download the packaged deps from [[http://windows.php.net/downloads/php-sdk/deps/]] choosing the matching VC++ version and architecture directory. **Note** the .7z packages are not provided anymore for PHP 7.2 and up.
-    * dependency archives are named ''deps-<php version>-<vc version>-<architecture>.7z'' +
-    chose the archive which matches your desired PHP version and architecture, for example ''deps-7.1-vc14-x64.7z''+
     * **Note:** This should include the libraries needed to build most the core extensions. However, some other extensions may need additional libraries, header files and helper apps.  See [[internals/windows/libs]], fetch the version you need and extract the archive into the deps directory (see below). Another set of libraries used for the PECL extension builds is available under [[http://windows.php.net/downloads/pecl/deps/|PECL deps directory]]. If required, they need to be fetched manually.     * **Note:** This should include the libraries needed to build most the core extensions. However, some other extensions may need additional libraries, header files and helper apps.  See [[internals/windows/libs]], fetch the version you need and extract the archive into the deps directory (see below). Another set of libraries used for the PECL extension builds is available under [[http://windows.php.net/downloads/pecl/deps/|PECL deps directory]]. If required, they need to be fetched manually.
  
Line 77: Line 86:
   - Run the ''phpsdk_buildtree'' batch script which will create the desired directory structure: <code bash>phpsdk_buildtree phpdev</code>   - Run the ''phpsdk_buildtree'' batch script which will create the desired directory structure: <code bash>phpsdk_buildtree phpdev</code>
   - The ''phpsdk_buildtree'' script will create the path according to the currently VC++ version used and switch into the newly created directory   - The ''phpsdk_buildtree'' script will create the path according to the currently VC++ version used and switch into the newly created directory
-  - Extract the PHP source code to ''C:\php-sdk\phpdev\**vc##**\**x##**'', where: +  - Extract the PHP source code to ''C:\php-sdk\phpdev\**vX##**\**x##**'', where: 
-    * ''**vc##**'' is the compiler version you are using (eq ''vc14'')+    * ''**vX##**'' is the compiler version you are using (eq ''vc14'' or ''vs16'')
     * ''**x##**'' is your architecture (''x86'' or ''x64'')     * ''**x##**'' is your architecture (''x86'' or ''x64'')
     * For example: ''C:\php-sdk\phpdev\vc14\x64\php-7.1.0-src''     * For example: ''C:\php-sdk\phpdev\vc14\x64\php-7.1.0-src''
   - In the same directory where you extracted the PHP source there is a ''**deps**'' directory. Do one of the following   - In the same directory where you extracted the PHP source there is a ''**deps**'' directory. Do one of the following
     * switch into the php source directory and run ''phpsdk_deps -u''     * switch into the php source directory and run ''phpsdk_deps -u''
-    * If you downloaded the dependencies manually in the perevious step (the ''deps-*.7z'' archive), extract them into deps+    * If you downloaded the dependencies manually in the previous step, extract them into deps
  
 ===== Compile ===== ===== Compile =====
Line 90: Line 99:
  
   - Invoke the starter script to automatically setup the environment for the desired build config, fe <code bash>c:\php-sdk\phpsdk-vc14-x64.bat</code>   - Invoke the starter script to automatically setup the environment for the desired build config, fe <code bash>c:\php-sdk\phpsdk-vc14-x64.bat</code>
-  - Change directory to the location of your PHP source code, e.g. <code bash>cd 'C:\php-sdk\phpdev\vc14\x64\php-7.1.0-src</code>+  - Change directory to the location of your PHP source code, e.g. <code bash>cd C:\php-sdk\phpdev\vc14\x64\php-7.1.0-src</code>
   - Run: <code bash>buildconf</code>   - Run: <code bash>buildconf</code>
   - To get an overview of the compiling flags: <code bash>configure --help</code>   - To get an overview of the compiling flags: <code bash>configure --help</code>
Line 96: Line 105:
   - To build PHP, run: <code bash>nmake</code>   - To build PHP, run: <code bash>nmake</code>
   - If you want the resulting PHP builds and extensions to be zipped, after 'nmake' also run: <code bash>nmake snap</code>   - If you want the resulting PHP builds and extensions to be zipped, after 'nmake' also run: <code bash>nmake snap</code>
-  - The compiled PHP is now under "C:\php-sdk\phpdev\vcXX\x##\php-source-directory\Release_TS" If you ran 'nmake snap' the zip file will also be here. +  - The compiled PHP is now under "C:\php-sdk\phpdev\vX##\x##\php-source-directory\Release_TS" If you ran 'nmake snap' the zip file will also be here. 
-    * If you compiled with "--disable-zts" the compiled PHP will be under "C:\php-sdk\phpdev\vcXX\x##\php-source-directory\Release"+    * If you compiled with "--disable-zts" the compiled PHP will be under "C:\php-sdk\phpdev\vX##\x##\php-source-directory\Release"
  
 ==== Recompile after you have done some changes ==== ==== Recompile after you have done some changes ====
Line 128: Line 137:
  
 At this point, your compiled extension will be located in the release directory. At this point, your compiled extension will be located in the release directory.
 +
 +==== Building PECL extensions with phpize ====
 +
 +Alternatively to the "in-tree" build described above, you can do a "phpize" build, what is mostly useful if you don't need to build PHP from source, but rather use a pre-built PHP binary package.
 +
 +  - Download and unpack the development package which corresponds to your pre-built PHP version and variant from https://windows.php.net/
 +  - Download and unpack the source of the PECL extension
 +  - Invoke the starter script to automatically setup the environment for the desired build config, e.g. ''c:\php-sdk\phpsdk-vs16-x64.bat''
 +  - Add the development package folder and the PHP folder to the ''PATH''
 +  - Enter the source folder of the PECL extension
 +  - Run ''phpize''
 +  - Run ''configure --help'' to see the list of configuration options
 +    * the most important option is the one which enables the extension to be built (e.g. ''--enable-apcu'')
 +    * another important options is ''--with-prefix'' which expects the PHP folder to be passed
 +    * if the extension depends on C libraries, you need to download these and put them either in the ''--with-php-build'' folder, or use the ''--with-extra-includes'' and ''--with-extra-libs'' options; suitable pre-built libraries can be found on https://windows.php.net/downloads/php-sdk/deps/ and https://windows.php.net/downloads/pecl/deps/
 +    * there may be further interesting configuration options, e.g. those which allows to configure details of the extension to be built
 +  - Run ''configure'' with the desired options
 +  - Run ''nmake''
 +  - After successful compilation, the build artifacts are located in the release folder
 +  - If the extension has a PHPT test suite, run ''nmake test''
 +
 +If you want to build your extension via Github Actions, consider to use https://github.com/cmb69/setup-php-sdk.
 +
 +==== Release directories ====
 +
 +When you have successfully compiled PHP, the release directory can be one of multiple, depending on the build configuration:
 +
 +    - `Release`: Release NTS build
 +    - `Release_TS`: Release ZTS build
 +    - `Debug`: Debug NTS build
 +    - `Debug_TS`: Debug ZTS build
 +
 +If you are compiling using a 64-bit compiler, then these directories will be located in a directory called `x64`.
  
 ===== Pitfalls ===== ===== Pitfalls =====
  
   - For possible PHP SDK issues, please consult the PHP SDK readme   - For possible PHP SDK issues, please consult the PHP SDK readme
 +  - As of PHP 7.3 the switch --enable-native-intrinsics is available. The resulting binary will then require a processor with the corresponding feature set available. For example, if you set --enable-native-intrinsics=avx2, be sure the target machine has processor with AVX2 support.
 +  - In some circumstances, you may hit the [[https://docs.microsoft.com/en-us/cpp/error-messages/compiler-errors-1/fatal-error-c1047?view=msvc-160|linker error C1047]]; you may be able to work around that with ''set LDFLAGS=/d2:-AllowCompatibleILVersions'' and re-configuring the build.
  
  
internals/windows/stepbystepbuild_sdk_2.1490833608.txt.gz · Last modified: 2017/09/22 13:28 (external edit)