Skip to content

Commit

Permalink
windows supports
Browse files Browse the repository at this point in the history
  • Loading branch information
matyhtf committed Dec 26, 2023
1 parent 825c5b6 commit edbc040
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 4 deletions.
6 changes: 3 additions & 3 deletions config.w32
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ if (PHP_PHPY != "no") {
if (PYTHONHOME) {
ADD_SOURCES("ext/phpy/src/bridge", "core.cc", "phpy")
ADD_SOURCES("ext/phpy/src/php", "object.cc type.cc error.cc iter.cc dict.cc core.cc fn.cc str.cc sequence.cc list.cc set.cc tuple.cc module.cc", "phpy")
ADD_SOURCES("ext/phpy/src/python", "class.cc module.cc object.cc reference.cc resource.cc callable.cc", "phpy")
ADD_SOURCES("ext/phpy/src/python", "class.cc module.cc object.cc reference.cc resource.cc callable.cc string.cc array.cc", "phpy")

EXTENSION("phpy", "phpy.cc", null, '-std=c++14 /DZEND_ENABLE_STATIC_TSRMLS_CACHE=1 -Iext/phpy/include -Iext/phpy /I ' + PYTHONHOME + '/include')
EXTENSION("phpy", "phpy.cc", null, '/DZEND_ENABLE_STATIC_TSRMLS_CACHE=1 -Iext/phpy/include -Iext/phpy /I ' + PYTHONHOME + '/include')

ADD_FLAG("CFLAGS", "/D PHP_PHPY_EXPORTS ")
ADD_FLAG("LDFLAGS_PHPY", '/libpath:' + PYTHONHOME + '/libs')
ADD_FLAG("CXXFLAGS", "-std=c++14 -Wall -Wno-unused-function -Wno-deprecated -Wno-deprecated-declarations -z now")
ADD_FLAG("CXXFLAGS", "-Wall -Wno-unused-function -Wno-deprecated -Wno-deprecated-declarations -z now")
} else {
WARNING("python not found; the python libraries and headers not found");
}
Expand Down
110 changes: 110 additions & 0 deletions docs/cn/php/build-on-windows.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
# Windows 编译

> 仅支持 `PHP-8.1` 或更高版本
## 开发环境

参考:[https://wiki.php.net/internals/windows/stepbystepbuild_sdk_2](https://wiki.php.net/internals/windows/stepbystepbuild_sdk_2)

- 安装 `Visual C++ 16.0`
- 安装 `php-sdk-binary-tools`,地址:[https://github.com/php/php-sdk-binary-tools](https://github.com/php/php-sdk-binary-tools)
- 下载 `php` 源代码
- 安装依赖库,地址:[https://windows.php.net/downloads/php-sdk/deps/](https://windows.php.net/downloads/php-sdk/deps/)


> 所有文件均安装在 `d:\workspace` 目录下

## 构建目录

```shell
cd D:\workspace\php-sdk\php-sdk-binary-tools-2.2.0
phpsdk-vs16-x64.bat
```

成功后,在此终端进入 `php-src` 目录

```shell
cd D:\workspace\php-sdk\php-sdk-binary-tools-2.2.0\phpdev\vs16\x64\php-8.1.5
```

扩展项目放置于 `php-src``ext` 目录下,例如:`D:\workspace\php-sdk\php-sdk-binary-tools-2.2.0\phpdev\vs16\x64\php-8.1.5\ext\phpy`,也可以使用 `mklink` 命令创建软连接。


## 编译配置

```shell
$ buildconf --force
Rebuilding configure.js
Now run 'configure --help'
configure --disable-all --enable-cli --disable-zts --enable-phpy=shared
```

`--enable-phpy=shared` 表示启用 `phpy` 扩展,并且编译为 `.dll` 动态链接库

执行成功后,输出:

```shell
...

Generating main/config.w32.h
Generating phpize
Done.


Enabled extensions:
-----------------------
| Extension | Mode |
-----------------------
| date | static |
| hash | static |
| json | static |
| pcre | static |
| phpy | shared |
| reflection | static |
| spl | static |
| standard | static |
-----------------------


Enabled SAPI:
-------------
| Sapi Name |
-------------
| cli |
-------------


---------------------------------------
| | |
---------------------------------------
| Build type | Release |
| Thread Safety | No |
| Compiler | Visual C++ 2019 |
| Architecture | x64 |
| Optimization | PGO disabled |
| Native intrinsics | SSE2 |
| Static analyzer | disabled |
---------------------------------------


Type 'nmake' to build PHP

D:\workspace\php-sdk\php-sdk-binary-tools-2.2.0\phpdev\vs16\x64\php-8.1.5
$
```


## 编译扩展
```shell
nmake clean
nmake
```

## 二进制打包

```shell
nmake snap
```

执行成功后,将在 `D:\workspace\php-sdk\php-sdk-binary-tools-2.2.0\phpdev\vs16\x64\php-8.1.5\x64\Release` 生成 `php-8.1.5-nts-Win32-vs16-x64.zip`
2 changes: 1 addition & 1 deletion docs/cn/php/build.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 编译
# Linux/macOS/Unix 编译

> 目前仅支持 `Python 3.10` 或更高版本
Expand Down

0 comments on commit edbc040

Please sign in to comment.