mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-07-02 22:35:43 +08:00
Compare commits
152 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
279a1dab4b | ||
|
|
9fb5173e3e | ||
|
|
0b37080cdd | ||
|
|
8747266df6 | ||
|
|
12cc422d5b | ||
|
|
bfc56cff72 | ||
|
|
d5405ce436 | ||
|
|
e158cc5886 | ||
|
|
aee040d6a4 | ||
|
|
e637cce6f2 | ||
|
|
98b906db40 | ||
|
|
7625f585d2 | ||
|
|
ed8837fe9f | ||
|
|
a5754125a8 | ||
|
|
6b848da4dd | ||
|
|
2768dc0c40 | ||
|
|
90b2e5568c | ||
|
|
b4f9235cb6 | ||
|
|
86ce7e9d25 | ||
|
|
2e47e8af6b | ||
|
|
d40f2cafec | ||
|
|
e84a246dd2 | ||
|
|
98f32ae0f0 | ||
|
|
5499109278 | ||
|
|
9a5b02692d | ||
|
|
970a74896a | ||
|
|
29179ecb84 | ||
|
|
5e0cccfe3d | ||
|
|
ed52ec9ee1 | ||
|
|
f25d2d5db4 | ||
|
|
e00908d8cb | ||
|
|
c24dc8f518 | ||
|
|
d381e48605 | ||
|
|
8dcec73929 | ||
|
|
9b9644fe63 | ||
|
|
8a70da6291 | ||
|
|
c84eb723ec | ||
|
|
5934e5e881 | ||
|
|
99150e2cef | ||
|
|
8191444fe9 | ||
|
|
5cfba6e83b | ||
|
|
4e9b8980d0 | ||
|
|
c800a53f77 | ||
|
|
6cc7e6cff6 | ||
|
|
d56c060863 | ||
|
|
b6409bded4 | ||
|
|
ca1189b6ca | ||
|
|
75b9d66698 | ||
|
|
6dfd35348f | ||
|
|
0007043f4a | ||
|
|
da1cbeb79c | ||
|
|
a83a457905 | ||
|
|
a4dc177621 | ||
|
|
a7265bf624 | ||
|
|
64dfb57366 | ||
|
|
658e8e74bd | ||
|
|
46b0ecf3fa | ||
|
|
830f379bf6 | ||
|
|
c9b544f8c4 | ||
|
|
11af370fe1 | ||
|
|
1e11559c4b | ||
|
|
8b188bd1b9 | ||
|
|
e0e3bc6d97 | ||
|
|
dbb566ac7c | ||
|
|
37b9704fbb | ||
|
|
c225aeffed | ||
|
|
2e3544f296 | ||
|
|
ce60a9c804 | ||
|
|
b6c0b998b3 | ||
|
|
6277539a79 | ||
|
|
9520d68cda | ||
|
|
812c71f31f | ||
|
|
b3cc360eeb | ||
|
|
39fe6fa081 | ||
|
|
243ee63283 | ||
|
|
24c946d687 | ||
|
|
84d1c789bd | ||
|
|
a983667b90 | ||
|
|
8d9cace469 | ||
|
|
e9d3e48f90 | ||
|
|
ed53394389 | ||
|
|
8893d08ba9 | ||
|
|
5a13daee39 | ||
|
|
c1e9cd2ea3 | ||
|
|
30213da70a | ||
|
|
5d363bdb0b | ||
|
|
630c0d3a5d | ||
|
|
56caef78e3 | ||
|
|
29be3a2e39 | ||
|
|
fbe149bcac | ||
|
|
92cafb36f6 | ||
|
|
8636f2e7c9 | ||
|
|
8f43a09533 | ||
|
|
654c5cba0c | ||
|
|
f9685b82a1 | ||
|
|
f2371d3702 | ||
|
|
fe39aecd72 | ||
|
|
68d176ad26 | ||
|
|
d7627dd81a | ||
|
|
a4e173f16d | ||
|
|
1437be3a9d | ||
|
|
059c32e59c | ||
|
|
e3a4cd6e1d | ||
|
|
dd9a5d8316 | ||
|
|
3b83c1fa7b | ||
|
|
ff128df76b | ||
|
|
cd04a9ea4f | ||
|
|
3b793005fe | ||
|
|
87e073a0b9 | ||
|
|
db8aa15677 | ||
|
|
6ed9749732 | ||
|
|
4e99211bc3 | ||
|
|
824748c2a7 | ||
|
|
fe6a98b30d | ||
|
|
49149cebf1 | ||
|
|
7b6a1b4212 | ||
|
|
965e7a25e2 | ||
|
|
0c3885c33d | ||
|
|
be32190829 | ||
|
|
f1d5916090 | ||
|
|
b2ea479fac | ||
|
|
16cc5df66d | ||
|
|
a63e3f4575 | ||
|
|
6b061e6332 | ||
|
|
4a17491aaa | ||
|
|
06f29712e2 | ||
|
|
4b1d59c5a9 | ||
|
|
1a81fe6a0d | ||
|
|
c63136d484 | ||
|
|
4b500f2dd8 | ||
|
|
9da20497cc | ||
|
|
5efc15b404 | ||
|
|
fa0740f216 | ||
|
|
52430cbdde | ||
|
|
01c4538ce0 | ||
|
|
3183ecceaf | ||
|
|
dd2e7cc129 | ||
|
|
adfa620ef4 | ||
|
|
1a32ddc70a | ||
|
|
4bfca6fe93 | ||
|
|
dbec043894 | ||
|
|
727d78a689 | ||
|
|
9b1e784604 | ||
|
|
50d44d8310 | ||
|
|
3b300698f3 | ||
|
|
899eb94b8b | ||
|
|
451a0c0e34 | ||
|
|
085c1a159c | ||
|
|
ca3f8a350d | ||
|
|
5025850f71 | ||
|
|
fe2f658e08 | ||
|
|
00a49c662b |
47
.github/workflows/release-build.yml
vendored
Normal file
47
.github/workflows/release-build.yml
vendored
Normal file
@@ -0,0 +1,47 @@
|
||||
name: Upload SPC Binary (Release)
|
||||
|
||||
on:
|
||||
release:
|
||||
types:
|
||||
- published
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
build-release-artifacts:
|
||||
name: "Upload SPC Binary (Release)"
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
operating-system:
|
||||
- "linux-x86_64"
|
||||
- "macos-x86_64"
|
||||
- "linux-aarch64"
|
||||
- "macos-aarch64"
|
||||
steps:
|
||||
- name: "Checkout"
|
||||
uses: "actions/checkout@v4"
|
||||
|
||||
- name: Reuse static-php-cli-hosted artifacts
|
||||
uses: dawidd6/action-download-artifact@v2
|
||||
with:
|
||||
repo: crazywhalecc/static-php-cli-hosted
|
||||
branch: master
|
||||
workflow: build-spc-release.yml
|
||||
name: "spc-${{ matrix.operating-system }}"
|
||||
|
||||
- name: "Archive Executable"
|
||||
run: |
|
||||
tar -czf spc-${{ matrix.operating-system }}.tar.gz spc
|
||||
echo "filename=spc-${{ matrix.operating-system }}.tar.gz" >> $GITHUB_ENV
|
||||
|
||||
- name: upload binaries to release
|
||||
uses: softprops/action-gh-release@v1
|
||||
if: ${{startsWith(github.ref, 'refs/tags/') }}
|
||||
with:
|
||||
files: ${{ env.filename }}
|
||||
|
||||
- name: "Upload Artifact"
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
path: spc
|
||||
name: spc-${{ matrix.operating-system }}
|
||||
3
.gitignore
vendored
3
.gitignore
vendored
@@ -4,8 +4,7 @@ docker/libraries/
|
||||
docker/extensions/
|
||||
docker/source/
|
||||
|
||||
# Composer file
|
||||
composer.lock
|
||||
# Vendor files
|
||||
/vendor/
|
||||
|
||||
# default source extract directory
|
||||
|
||||
244
README-en.md
244
README-en.md
@@ -1,245 +1,3 @@
|
||||
# static-php-cli
|
||||
|
||||
Build single static PHP binary, with PHP project together, with popular extensions included.
|
||||
|
||||
The project name is static-php-cli, but it actually supports cli, fpm, micro and embed (on the way) SAPI 😎
|
||||
|
||||
Compile a purely static php-cli binary file with various extensions to make PHP applications more portable! (cli SAPI)
|
||||
|
||||
<img width="600" alt="2023-05-02 15 53 13" src="https://user-images.githubusercontent.com/20330940/235610282-23e58d68-bd35-4092-8465-171cff2d5ba8.png">
|
||||
|
||||
You can also use the micro binary file to combine php binary and php source code into one for distribution!
|
||||
This feature is provided by [dixyes/phpmicro](https://github.com/dixyes/phpmicro). (micro SAPI)
|
||||
|
||||
<img width="600" alt="2023-05-02 15 52 33" src="https://user-images.githubusercontent.com/20330940/235610318-2ef4e3f1-278b-4ca4-99f4-b38120efc395.png">
|
||||
|
||||
[]()
|
||||
[]()
|
||||
[](https://github.com/crazywhalecc/static-php-cli/actions/workflows/build.yml)
|
||||
[](https://github.com/crazywhalecc/static-php-cli/actions/workflows/build.yml)
|
||||
|
||||
[]()
|
||||
[]()
|
||||
|
||||
## Compilation Requirements
|
||||
|
||||
Yes, this project is written in PHP, pretty funny.
|
||||
But static-php-cli runtime only requires an environment above PHP 8.1 and `mbstring`, `pcntl` extension.
|
||||
|
||||
Here is the architecture support status, where `CI` represents support for GitHub Action builds,
|
||||
`Local` represents support for local builds, and blank represents not currently supported.
|
||||
|
||||
| | x86_64 | aarch64 |
|
||||
|---------|-----------|-----------|
|
||||
| macOS | CI, Local | Local |
|
||||
| Linux | CI, Local | CI, Local |
|
||||
| Windows | | |
|
||||
|
||||
> macOS-arm64 is not supported for GitHub Actions, if you are going to build on arm, you can build it manually on your own machine.
|
||||
|
||||
Currently supported PHP versions for compilation are: `7.3`, `7.4`, `8.0`, `8.1`, `8.2`, `8.3`.
|
||||
|
||||
## Docs
|
||||
|
||||
docs here: <https://static-php-cli.zhamao.me>.
|
||||
|
||||
## Simple Usage
|
||||
|
||||
Please first select the extension you want to compile based on the extension list below.
|
||||
|
||||
### Direct Download
|
||||
|
||||
If you don't compile yourself, you can download pre-compiled artifact from Actions, or from self-hosted server: [Here](https://dl.zhamao.xin/static-php-cli/)
|
||||
|
||||
> self-hosted server contains extensions: `bcmath,bz2,calendar,ctype,curl,dom,exif,fileinfo,filter,ftp,gd,gmp,iconv,xml,mbstring,mbregex,mysqlnd,openssl,pcntl,pdo,pdo_mysql,pdo_sqlite,phar,posix,redis,session,simplexml,soap,sockets,sqlite3,tokenizer,xmlwriter,xmlreader,zlib,zip`
|
||||
|
||||
### Supported Extensions
|
||||
|
||||
[Supported Extension List](https://static-php-cli.zhamao.me/en/guide/extensions.html)
|
||||
|
||||
> If there is no extension you need here, you can submit an issue.
|
||||
|
||||
### GitHub Actions Build
|
||||
|
||||
Use GitHub Action to easily build a statically compiled PHP and phpmicro,
|
||||
and at the same time define the extensions to be compiled by yourself.
|
||||
|
||||
1. Fork me.
|
||||
2. Go to the Actions of the project and select `CI`.
|
||||
3. Select `Run workflow`, fill in the PHP version you want to compile, the target type, and the list of extensions. (extensions comma separated, e.g. `bcmath,curl,mbstring`)
|
||||
4. After waiting for about a period of time, enter the corresponding task and get `Artifacts`.
|
||||
|
||||
If you enable `debug`, all logs will be output at build time, including compiled logs, for troubleshooting.
|
||||
|
||||
- When using ubuntu-latest, it will build linux-x86_64 binary.
|
||||
- When using macos-latest, it will build macOS-x86_64 binary.
|
||||
|
||||
### Manual Build
|
||||
|
||||
Clone repo first:
|
||||
|
||||
```bash
|
||||
git clone https://github.com/crazywhalecc/static-php-cli.git
|
||||
```
|
||||
|
||||
If you have not installed php on your system, you can use package management to install PHP (such as brew, apt, yum, apk etc.).
|
||||
|
||||
And you can also download single-file php binary and composer using command `bin/setup-runtime`.
|
||||
The PHP runtime for static-php-cli itself will be downloaded at `bin/php`, and composer is at `bin/composer`.
|
||||
|
||||
```bash
|
||||
cd static-php-cli
|
||||
chmod +x bin/setup-runtime
|
||||
# It will download php-cli from self-hosted server and composer from getcomposer.org
|
||||
./bin/setup-runtime
|
||||
|
||||
# Use this php runtime to run static-php-cli compiler
|
||||
./bin/php bin/spc
|
||||
|
||||
# Use composer
|
||||
./bin/php bin/composer
|
||||
```
|
||||
|
||||
Basic usage for building php and micro with some extensions:
|
||||
|
||||
```bash
|
||||
cd static-php-cli
|
||||
composer update
|
||||
chmod +x bin/spc
|
||||
# Check system tool dependencies, fix them automatically
|
||||
./bin/spc doctor
|
||||
# fetch all libraries
|
||||
./bin/spc fetch --all
|
||||
# with bcmath,openssl,tokenizer,sqlite3,pdo_sqlite,ftp,curl extension, build both CLI and phpmicro SAPI
|
||||
./bin/spc build bcmath,openssl,tokenizer,sqlite3,pdo_sqlite,ftp,curl --build-cli --build-micro
|
||||
```
|
||||
|
||||
You can also use the parameter `--with-php=x.y` to specify the downloaded PHP version, currently supports 7.4 ~ 8.2:
|
||||
|
||||
```bash
|
||||
# Using PHP >= 8.0 is recommended, because PHP7 cannot use phpmicro
|
||||
./bin/spc fetch --with-php=8.2 --all
|
||||
```
|
||||
|
||||
Now we support `cli`, `micro`, `fpm`, you can use one or more of the following parameters to specify the compiled SAPI:
|
||||
|
||||
- `--build-cli`: build static cli executable
|
||||
- `--build-micro`: build static phpmicro self-extracted executable
|
||||
- `--build-fpm`: build static fpm binary
|
||||
- `--build-all`: build all
|
||||
|
||||
If anything goes wrong, use `--debug` option to display full terminal output:
|
||||
|
||||
```bash
|
||||
./bin/spc build openssl,pcntl,mbstring --debug --build-all
|
||||
./bin/spc fetch --all --debug
|
||||
```
|
||||
|
||||
In addition, we build NTS by default. If you are going to build ZTS version, just add `--enable-zts` option.
|
||||
|
||||
```bash
|
||||
./bin/spc build openssl,pcntl --build-all --enable-zts
|
||||
```
|
||||
|
||||
Adding option `--no-strip` can produce binaries with debug symbols, in order to debug (using gdb). Disabling strip will increase the size of static binary.
|
||||
|
||||
### php-cli Usage
|
||||
|
||||
> php-cli is a single static binary, you can use it like normal php installed on your system.
|
||||
|
||||
When using the parameter `--build-cli` or `--build-all`,
|
||||
the final compilation result will output a binary file named `./php`,
|
||||
which can be distributed and used directly.
|
||||
This file will be located in the directory `buildroot/bin/`, copy it out for use.
|
||||
|
||||
```bash
|
||||
cd buildroot/bin/
|
||||
./php -v # check version
|
||||
./php -m # check extensions
|
||||
./php your_code.php # run your php code
|
||||
./php your_project.phar # run your phar (project archive)
|
||||
```
|
||||
|
||||
### micro.sfx Usage
|
||||
|
||||
> phpmicro is a SelF-extracted eXecutable SAPI module,
|
||||
> provided by [dixyes/phpmicro](https://github.com/dixyes/phpmicro).
|
||||
> It can put php runtime and your source code together.
|
||||
|
||||
When using the parameter `--build-all` or `--build-micro`,
|
||||
the final compilation result will output a file named `./micro.sfx`,
|
||||
which needs to be used with your PHP source code like `code.php`.
|
||||
This file will be located in the path `buildroot/bin/micro.sfx`, simply copy it out for use.
|
||||
|
||||
Prepare your project source code, which can be a single PHP file or a Phar file, for use.
|
||||
|
||||
```bash
|
||||
echo "<?php echo 'Hello world' . PHP_EOL;" > code.php
|
||||
cat micro.sfx code.php > single-app && chmod +x single-app
|
||||
./single-app
|
||||
|
||||
# If packing a PHAR file, replace code.php with the Phar file path.
|
||||
```
|
||||
|
||||
> In some cases, PHAR files may not run in a micro environment.
|
||||
|
||||
### php-fpm Usage
|
||||
|
||||
When using the parameter `--build-all` or `--build-fpm`,
|
||||
the final compilation result will output a file named `./php-fpm`,
|
||||
This file will be located in the path `buildroot/bin/`, simply copy it out for use.
|
||||
|
||||
In normal Linux distributions and macOS systems, the package manager will automatically generate a default fpm configuration file after installing php-fpm.
|
||||
Because php-fpm must specify a configuration file before running, the php-fpm compiled by this project will not have any configuration files, so you need to write `php-fpm.conf` and `pool.conf` configuration files yourself.
|
||||
|
||||
Specifying `php-fpm.conf` can use the command parameter `-y`, for example: `./php-fpm -y php-fpm.conf`.
|
||||
|
||||
## Contribution
|
||||
|
||||
Currently, there are only a few supported extensions.
|
||||
If the extension you need is missing, you can create an issue.
|
||||
If you are familiar with this project, you are also welcome to initiate a pull request.
|
||||
|
||||
The basic principles for contributing are as follows:
|
||||
|
||||
- This project uses php-cs-fixer and phpstan as code formatting tools. Before contributing, please run `composer analyze` and `composer cs-fix` on the updated code.
|
||||
- If other open source libraries are involved, the corresponding licenses should be provided.
|
||||
Also, configuration files should be sorted using the command `sort-config` after modification.
|
||||
For more information about sorting commands, see the documentation.
|
||||
- Naming conventions should be followed, such as using the extension name registered in PHP for the extension name itself,
|
||||
and external library names should follow the project's own naming conventions. For internal logic functions, class names, variables, etc.,
|
||||
camelCase and underscore formats should be followed, and mixing within the same module is prohibited.
|
||||
- When compiling external libraries and creating patches, compatibility with different operating systems should be considered.
|
||||
|
||||
If you want to contribute document content, please go to [crazywhalecc/static-php-cli-docs](https://github.com/crazywhalecc/static-php-cli-docs).
|
||||
|
||||
Part of the English document is written by me, and part is translated by Google,
|
||||
and there may be inaccurate descriptions, strange or offensive expressions.
|
||||
If you are a native English speaker, some corrections to the documentation are welcome.
|
||||
|
||||
|
||||
## Sponsor this project
|
||||
|
||||
You can sponsor my project on [this page](https://github.com/crazywhalecc/crazywhalecc/blob/master/FUNDING.md).
|
||||
|
||||
## Open-Source License
|
||||
|
||||
This project itself is based on MIT License,
|
||||
some newly added extensions and dependencies may originate from the following projects (including but not limited to),
|
||||
and the headers of these code files will also be given additional instructions LICENSE and AUTHOR:
|
||||
|
||||
- [dixyes/lwmbs](https://github.com/dixyes/lwmbs) (Mulun Permissive License)
|
||||
- [swoole/swoole-cli](https://github.com/swoole/swoole-cli) (Apache 2.0 LICENSE+SWOOLE-CLI LICENSE)
|
||||
|
||||
Due to the special nature of this project,
|
||||
many other open source projects such as curl and protobuf will be used during the project compilation process,
|
||||
and they all have their own open source licenses.
|
||||
|
||||
Please use the `bin/spc dump-license` command to export the open source licenses used in the project after compilation,
|
||||
and comply with the corresponding project's LICENSE.
|
||||
|
||||
## Advanced
|
||||
|
||||
The refactoring branch of this project is written modularly.
|
||||
If you are interested in this project and want to join the development,
|
||||
you can refer to the [Contribution Guide](https://static-php-cli.zhamao.me) of the documentation to contribute code or documentation.
|
||||
English README has been moved to [README.md](README.md).
|
||||
|
||||
253
README-zh.md
Executable file
253
README-zh.md
Executable file
@@ -0,0 +1,253 @@
|
||||
# static-php-cli
|
||||
|
||||
Build single static PHP binary, with PHP project together, with popular extensions included.
|
||||
|
||||
🌐 **[中文](README-zh.md)** | **[English](README.md)**
|
||||
|
||||
编译纯静态的 PHP Binary 二进制文件,带有各种扩展,让 PHP-cli 应用变得更便携!(cli SAPI)
|
||||
|
||||
<img width="600" alt="截屏2023-05-02 15 53 13" src="https://user-images.githubusercontent.com/20330940/235610282-23e58d68-bd35-4092-8465-171cff2d5ba8.png">
|
||||
|
||||
同时可以使用 micro 二进制文件,将 PHP 源码和 PHP 二进制构建为一个文件分发!(micro SAPI)
|
||||
|
||||
<img width="600" alt="截屏2023-05-02 15 52 33" src="https://user-images.githubusercontent.com/20330940/235610318-2ef4e3f1-278b-4ca4-99f4-b38120efc395.png">
|
||||
|
||||
> 该 SAPI 源自 [dixyes/phpmicro](https://github.com/dixyes/phpmicro) 的 [Fork 仓库](https://github.com/crazywhalecc/phpmicro)。
|
||||
|
||||
[]()
|
||||
[]()
|
||||
[](https://github.com/crazywhalecc/static-php-cli/actions/workflows/build.yml)
|
||||
[](https://github.com/crazywhalecc/static-php-cli/actions/workflows/build.yml)
|
||||
[]()
|
||||
[]()
|
||||
|
||||
> 项目名称是 static-php-cli,但其实支持 cli、fpm、micro 和 embed SAPI 😎
|
||||
|
||||
## 文档
|
||||
|
||||
目前 README 编写了基本用法。有关 static-php-cli 所有的功能,请点击这里查看文档:<https://static-php.dev>。
|
||||
|
||||
## 自托管直接下载
|
||||
|
||||
如果你不想自行编译 PHP,可以从本项目现有的示例 Action 下载 Artifact,也可以从自托管的服务器下载:[进入](https://dl.static-php.dev/static-php-cli/common/)
|
||||
|
||||
> 自托管的服务器默认包含的扩展有:`bcmath,bz2,calendar,ctype,curl,dom,exif,fileinfo,filter,ftp,gd,gmp,iconv,xml,mbstring,mbregex,mysqlnd,openssl,pcntl,pdo,pdo_mysql,pdo_sqlite,phar,posix,redis,session,simplexml,soap,sockets,sqlite3,tokenizer,xmlwriter,xmlreader,zlib,zip`
|
||||
|
||||
## 使用 static-php-cli 构建 PHP
|
||||
|
||||
### 编译环境需求
|
||||
|
||||
是的,本项目采用 PHP 编写,编译前需要一个 PHP 环境,比较滑稽。
|
||||
但本项目默认可通过自身构建的 micro 和 static-php 二进制运行,其他只需要包含 mbstring、pcntl 扩展和 PHP 版本大于等于 8.1 即可。
|
||||
|
||||
下面是架构支持情况,:octocat: 代表支持 GitHub Action 构建,:computer: 代表支持本地构建,空 代表暂不支持。
|
||||
|
||||
| | x86_64 | aarch64 |
|
||||
|---------|----------------------|----------------------|
|
||||
| macOS | :octocat: :computer: | :computer: |
|
||||
| Linux | :octocat: :computer: | :octocat: :computer: |
|
||||
| Windows | | |
|
||||
| FreeBSD | :computer: | :computer: |
|
||||
|
||||
> macOS-arm64 因 GitHub 暂未提供 arm runner,如果要构建 arm 二进制,可以使用手动构建。
|
||||
|
||||
目前支持编译的 PHP 版本为:`7.3`,`7.4`,`8.0`,`8.1`,`8.2`,`8.3`。
|
||||
|
||||
### 支持的扩展情况
|
||||
|
||||
请先根据下方扩展列表选择你要编译的扩展。
|
||||
|
||||
- [扩展支持列表](https://static-php.dev/zh/guide/extensions.html)
|
||||
- [编译命令生成器](https://static-php.dev/zh/guide/cli-generator.html)
|
||||
|
||||
> 如果这里没有你需要的扩展,可以提交 Issue。
|
||||
|
||||
### 使用 Actions 构建
|
||||
|
||||
使用 GitHub Action 可以方便地构建一个静态编译的 PHP,同时可以自行定义要编译的扩展。
|
||||
|
||||
1. Fork 本项目。
|
||||
2. 进入项目的 Actions,选择 CI。
|
||||
3. 选择 `Run workflow`,填入你要编译的 PHP 版本、目标类型、扩展列表。(扩展列表使用英文逗号分割,例如 `bcmath,curl,mbstring`)
|
||||
4. 等待大约一段时间后,进入对应的任务中,获取 `Artifacts`。
|
||||
|
||||
如果你选择了 `debug`,则会在构建时输出所有日志,包括编译的日志,以供排查错误。
|
||||
|
||||
### 手动构建(使用 SPC 二进制)
|
||||
|
||||
本项目提供了一个 static-php-cli 的二进制文件,你可以直接下载对应平台的二进制文件,然后使用它来构建静态的 PHP。目前 `spc` 二进制支持的平台有 Linux 和 macOS。
|
||||
|
||||
下面是从 GitHub Action 下载的方法:
|
||||
|
||||
1. 进入 [GitHub Action](https://github.com/crazywhalecc/static-php-cli/actions/workflows/release-build.yml)。
|
||||
2. 选择一个最新的构建任务,进入后选择 `Artifacts`,下载对应平台的二进制文件。
|
||||
3. 解压 `.zip` 文件。解压后,为其添加执行权限:`chmod +x ./spc`。
|
||||
|
||||
你也可以从自托管的服务器下载二进制文件:[进入](https://dl.static-php.dev/static-php-cli/spc-bin/nightly/)。
|
||||
|
||||
### 手动构建(使用源码)
|
||||
|
||||
先克隆本项目:
|
||||
|
||||
```bash
|
||||
git clone https://github.com/crazywhalecc/static-php-cli.git
|
||||
```
|
||||
|
||||
如果你本机没有安装 PHP,你需要先使用包管理(例如 brew、apt、yum、apk 等)安装 php。
|
||||
|
||||
你也可以通过 `bin/setup-runtime` 命令下载静态编译好的 php-cli 和 Composer。下载的 php 和 Composer 将保存为 `bin/php` 和 `bin/composer`。
|
||||
|
||||
```bash
|
||||
cd static-php-cli
|
||||
chmod +x bin/setup-runtime
|
||||
./bin/setup-runtime
|
||||
|
||||
# 使用独立的 php 运行 static-php-cli
|
||||
./bin/php bin/spc
|
||||
|
||||
# 使用 composer
|
||||
./bin/php bin/composer
|
||||
|
||||
# 初始化本项目
|
||||
cd static-php-cli
|
||||
composer update
|
||||
chmod +x bin/spc
|
||||
```
|
||||
|
||||
### 使用 static-php-cli 命令行程序
|
||||
|
||||
下面是使用 static-php-cli 编译静态 php 和 micro 的基础用法:
|
||||
|
||||
> 如果你使用的是打包好的 `spc` 二进制,你需要将下列命令的 `bin/spc` 替换为 `./spc`。
|
||||
|
||||
```bash
|
||||
# 检查环境依赖,并根据提示的命令安装缺失的编译工具
|
||||
./bin/spc doctor
|
||||
# 拉取所有依赖库
|
||||
./bin/spc fetch --all
|
||||
# 只拉取编译指定扩展需要的所有依赖
|
||||
./bin/spc download --for-extensions=openssl,pcntl,mbstring,pdo_sqlite
|
||||
# 构建包含 bcmath,openssl,tokenizer,sqlite3,pdo_sqlite,ftp,curl 扩展的 php-cli 和 micro.sfx
|
||||
./bin/spc build "bcmath,openssl,tokenizer,sqlite3,pdo_sqlite,ftp,curl" --build-cli --build-micro
|
||||
```
|
||||
|
||||
你也可以使用参数 `--with-php=x.y` 来指定下载的 PHP 版本,目前支持 7.3 ~ 8.2:
|
||||
|
||||
```bash
|
||||
# 优先考虑使用 >= 8.0 的 PHP 版本,因为 phpmicro 不支持在 PHP7 中构建
|
||||
./bin/spc download --with-php=8.2 --all
|
||||
```
|
||||
|
||||
其中,目前支持构建 cli,micro,fpm 三种静态二进制,使用以下参数的一个或多个来指定编译的 SAPI:
|
||||
|
||||
- `--build-cli`:构建 cli 二进制
|
||||
- `--build-micro`:构建 phpmicro 自执行二进制
|
||||
- `--build-fpm`:构建 fpm
|
||||
- `--build-embed`:构建 embed(libphp)
|
||||
- `--build-all`:构建所有
|
||||
|
||||
如果出现了任何错误,可以使用 `--debug` 参数来展示完整的输出日志,以供排查错误:
|
||||
|
||||
```bash
|
||||
./bin/spc build openssl,pcntl,mbstring --debug --build-all
|
||||
./bin/spc fetch --all --debug
|
||||
```
|
||||
|
||||
此外,默认编译的 PHP 为 NTS 版本。如需编译线程安全版本(ZTS),只需添加参数 `--enable-zts` 即可。
|
||||
|
||||
```bash
|
||||
./bin/spc build openssl,pcntl --build-all --enable-zts
|
||||
```
|
||||
|
||||
同时,你也可以使用参数 `--no-strip` 来关闭裁剪,关闭裁剪后可以使用 gdb 等工具调试,但这样会让静态二进制体积变大。
|
||||
|
||||
## 不同 SAPI 的使用
|
||||
|
||||
### 使用 cli
|
||||
|
||||
> php-cli 是一个静态的二进制文件,类似 Go、Rust 语言编译后的单个可移植的二进制文件。
|
||||
|
||||
采用参数 `--build-cli` 或`--build-all` 参数时,最后编译结果会输出一个 `./php` 的二进制文件,此文件可分发、可直接使用。
|
||||
该文件编译后会存放在 `buildroot/bin/` 目录中,名称为 `php`,拷贝出来即可。
|
||||
|
||||
```bash
|
||||
cd buildroot/bin/
|
||||
./php -v # 检查版本
|
||||
./php -m # 检查编译的扩展
|
||||
./php your_code.php # 运行代码
|
||||
./php your_project.phar # 运行打包为 phar 单文件的项目
|
||||
```
|
||||
|
||||
### 使用 micro
|
||||
|
||||
> phpmicro 是一个提供自执行二进制 PHP 的项目,本项目依赖 phpmicro 进行编译自执行二进制。详见 [dixyes/phpmicro](https://github.com/dixyes/phpmicro)。
|
||||
|
||||
采用项目参数 `--build-micro` 或 `--build-all` 时,最后编译结果会输出一个 `./micro.sfx` 的文件,此文件需要配合你的 PHP 源码使用。
|
||||
该文件编译后会存放在 `buildroot/bin/` 目录中,拷贝出来即可。
|
||||
|
||||
使用时应准备好你的项目源码文件,可以是单个 PHP 文件,也可以是 Phar 文件。
|
||||
|
||||
```bash
|
||||
echo "<?php echo 'Hello world' . PHP_EOL;" > code.php
|
||||
cat micro.sfx code.php > single-app && chmod +x single-app
|
||||
./single-app
|
||||
```
|
||||
|
||||
如果打包 PHAR 文件,仅需把 code.php 更换为 phar 文件路径即可。
|
||||
你可以使用 [box-project/box](https://github.com/box-project/box) 将你的 CLI 项目打包为 Phar,
|
||||
然后将它与 phpmicro 结合,生成独立可执行的二进制文件。
|
||||
|
||||
```bash
|
||||
# 使用 static-php-cli 生成的 micro.sfx 结合,也可以直接使用 cat 命令结合它们
|
||||
bin/spc micro:combine my-app.phar
|
||||
cat buildroot/bin/micro.sfx my-app.phar > my-app && chmod +x my-app
|
||||
|
||||
# 使用 micro:combine 结合可以将 INI 选项注入到二进制中
|
||||
bin/spc micro:combine my-app.phar -I "memory_limit=4G" -I "disable_functions=system" --output my-app-2
|
||||
```
|
||||
|
||||
> 有些情况下的 phar 文件或 PHP 项目可能无法在 micro 环境下运行。
|
||||
|
||||
### 使用 fpm
|
||||
|
||||
采用项目参数 `--build-fpm` 或 `--build-all` 时,最后编译结果会输出一个 `./php-fpm` 的文件。
|
||||
该文件存放在 `buildroot/bin/` 目录,拷贝出来即可使用。
|
||||
|
||||
在正常的 Linux 发行版和 macOS 系统中,安装 php-fpm 后包管理会自动生成默认的 fpm 配置文件。
|
||||
因为 php-fpm 必须指定配置文件才可启动,本项目编译的 php-fpm 不会带任何配置文件,所以需自行编写 `php-fpm.conf` 和 `pool.conf` 配置文件。
|
||||
|
||||
指定 `php-fpm.conf` 可以使用命令参数 `-y`,例如:`./php-fpm -y php-fpm.conf`。
|
||||
|
||||
### 使用 embed
|
||||
|
||||
采用项目参数 `--build-embed` 或 `--build-all` 时,最后编译结果会输出一个 `libphp.a`、`php-config` 以及一系列头文件,存放在 `buildroot/`,你可以在你的其他代码中引入它们。
|
||||
|
||||
如果你知道 [embed SAPI](https://github.com/php/php-src/tree/master/sapi/embed),你应该知道如何使用它。对于有可能编译用到引入其他库的问题,你可以使用 `buildroot/bin/php-config` 来获取编译时的配置。
|
||||
|
||||
另外,有关如何使用此功能的高级示例,请查看[如何使用它构建 FrankenPHP 的静态版本](https://github.com/dunglas/frankenphp/blob/main/docs/static.md)。
|
||||
|
||||
## 贡献
|
||||
|
||||
如果缺少你需要的扩展,可发起 Issue。如果你对本项目较熟悉,也欢迎为本项目发起 Pull Request。
|
||||
|
||||
另外,添加新扩展的贡献方式,可以参考下方 `进阶`。
|
||||
|
||||
如果你想贡献文档内容,请到项目仓库 [crazywhalecc/static-php-cli-docs](https://github.com/crazywhalecc/static-php-cli-docs) 贡献。
|
||||
|
||||
## 赞助本项目
|
||||
|
||||
你可以在 [我的个人赞助页](https://github.com/crazywhalecc/crazywhalecc/blob/master/FUNDING.md) 支持我和我的项目。
|
||||
|
||||
## 开源协议
|
||||
|
||||
本项目依据旧版本惯例采用 MIT License 开源,部分扩展的集成编译命令参考或修改自以下项目:
|
||||
|
||||
- [dixyes/lwmbs](https://github.com/dixyes/lwmbs)(木兰宽松许可证)
|
||||
- [swoole/swoole-cli](https://github.com/swoole/swoole-cli)(Apache 2.0 LICENSE、SWOOLE-CLI LICENSE)
|
||||
|
||||
因本项目的特殊性,使用项目编译过程中会使用很多其他开源项目,例如 curl、protobuf 等,它们都有各自的开源协议。
|
||||
请在编译完成后,使用命令 `bin/spc dump-license` 导出项目使用项目的开源协议,并遵守对应项目的 LICENSE。
|
||||
|
||||
## 进阶
|
||||
|
||||
本项目重构分支为模块化编写。如果你对本项目感兴趣,想加入开发,可以参照文档的 [贡献指南](https://static-php.dev) 贡献代码或文档。
|
||||
282
README.md
282
README.md
@@ -2,214 +2,290 @@
|
||||
|
||||
Build single static PHP binary, with PHP project together, with popular extensions included.
|
||||
|
||||
**If you are using English, see [English README](README-en.md).**
|
||||
🌐 **[中文](README-zh.md)** | **[English](README.md)**
|
||||
|
||||
编译纯静态的 PHP Binary 二进制文件,带有各种扩展,让 PHP-cli 应用变得更便携!(cli SAPI)
|
||||
The project name is static-php-cli, but it actually supports cli, fpm, micro and embed SAPI 😎
|
||||
|
||||
<img width="600" alt="截屏2023-05-02 15 53 13" src="https://user-images.githubusercontent.com/20330940/235610282-23e58d68-bd35-4092-8465-171cff2d5ba8.png">
|
||||
Compile a purely static php-cli binary file with various extensions to make PHP applications more portable! (cli SAPI)
|
||||
|
||||
同时可以使用 micro 二进制文件,将 PHP 源码和 PHP 二进制构建为一个文件分发!(由 [dixyes/phpmicro](https://github.com/dixyes/phpmicro) 提供支持)(micro SAPI)
|
||||
<img width="600" alt="2023-05-02 15 53 13" src="https://user-images.githubusercontent.com/20330940/235610282-23e58d68-bd35-4092-8465-171cff2d5ba8.png">
|
||||
|
||||
<img width="600" alt="截屏2023-05-02 15 52 33" src="https://user-images.githubusercontent.com/20330940/235610318-2ef4e3f1-278b-4ca4-99f4-b38120efc395.png">
|
||||
You can also use the micro binary file to combine php binary and php source code into one for distribution! (micro SAPI)
|
||||
|
||||
[]()
|
||||
<img width="600" alt="2023-05-02 15 52 33" src="https://user-images.githubusercontent.com/20330940/235610318-2ef4e3f1-278b-4ca4-99f4-b38120efc395.png">
|
||||
|
||||
> This SAPI feature is from the [Fork](https://github.com/crazywhalecc/phpmicro) of [dixyes/phpmicro](https://github.com/dixyes/phpmicro).
|
||||
|
||||
[]()
|
||||
[]()
|
||||
[](https://github.com/crazywhalecc/static-php-cli/actions/workflows/build.yml)
|
||||
[](https://github.com/crazywhalecc/static-php-cli/actions/workflows/build.yml)
|
||||
|
||||
[]()
|
||||
[]()
|
||||
|
||||
> 项目名称是 static-php-cli,但其实支持 cli、fpm、micro 和 embed(正在路上)SAPI 😎
|
||||
## Docs
|
||||
|
||||
## 编译环境需求
|
||||
The current README contains basic usage. For all the features of static-php-cli,
|
||||
see <https://static-php.dev>.
|
||||
|
||||
是的,本项目采用 PHP 编写,编译前需要一个 PHP 环境,比较滑稽。
|
||||
但本项目默认可通过自身构建的 micro 和 static-php 二进制运行,其他只需要包含 mbstring、pcntl 扩展和 PHP 版本大于等于 8.1 即可。
|
||||
## Direct Download
|
||||
|
||||
下面是架构支持情况,`CI` 代表支持 GitHub Action 构建,`Local` 代表支持本地构建,空 代表暂不支持。
|
||||
If you don't want to compile yourself, you can download example pre-compiled artifact from Actions, or from self-hosted server: [Here](https://dl.static-php.dev/static-php-cli/common/)
|
||||
|
||||
| | x86_64 | aarch64 |
|
||||
|---------|-----------|-----------|
|
||||
| macOS | CI, Local | Local |
|
||||
| Linux | CI, Local | CI, Local |
|
||||
| Windows | | |
|
||||
> self-hosted server contains extensions: `bcmath,bz2,calendar,ctype,curl,dom,exif,fileinfo,filter,ftp,gd,gmp,iconv,xml,mbstring,mbregex,mysqlnd,openssl,pcntl,pdo,pdo_mysql,pdo_sqlite,phar,posix,redis,session,simplexml,soap,sockets,sqlite3,tokenizer,xmlwriter,xmlreader,zlib,zip`
|
||||
|
||||
> macOS-arm64 因 GitHub 暂未提供 arm runner,如果要构建 arm 二进制,可以使用手动构建。
|
||||
## Use static-php-cli to build PHP
|
||||
|
||||
目前支持编译的 PHP 版本为:`7.3`,`7.4`,`8.0`,`8.1`,`8.2`,`8.3`。
|
||||
### Compilation Requirements
|
||||
|
||||
## 文档
|
||||
Yes, this project is written in PHP, pretty funny.
|
||||
But static-php-cli runtime only requires an environment above PHP 8.1 and `mbstring`, `pcntl` extension.
|
||||
|
||||
点击这里查看文档:<https://static-php-cli.zhamao.me>。
|
||||
Here is the architecture support status, where :octocat: represents support for GitHub Action builds,
|
||||
:computer: represents support for local manual builds, and blank represents not currently supported.
|
||||
|
||||
## 使用
|
||||
| | x86_64 | aarch64 |
|
||||
|---------|----------------------|----------------------|
|
||||
| macOS | :octocat: :computer: | :computer: |
|
||||
| Linux | :octocat: :computer: | :octocat: :computer: |
|
||||
| Windows | | |
|
||||
| FreeBSD | :computer: | :computer: |
|
||||
|
||||
请先根据下方扩展列表选择你要编译的扩展。
|
||||
> macOS-arm64 is not supported for GitHub Actions, if you are going to build on arm, you can build it manually on your own machine.
|
||||
|
||||
### 自托管直接下载
|
||||
Currently supported PHP versions for compilation are: `7.3`, `7.4`, `8.0`, `8.1`, `8.2`, `8.3`.
|
||||
|
||||
如果你不想自行编译,可以从本项目现有的 Action 下载 Artifact,也可以从自托管的服务器下载:[进入](https://dl.zhamao.xin/static-php-cli/)
|
||||
### Supported Extensions
|
||||
|
||||
> 自托管的服务器默认包含的扩展有:`bcmath,bz2,calendar,ctype,curl,dom,exif,fileinfo,filter,ftp,gd,gmp,iconv,xml,mbstring,mbregex,mysqlnd,openssl,pcntl,pdo,pdo_mysql,pdo_sqlite,phar,posix,redis,session,simplexml,soap,sockets,sqlite3,tokenizer,xmlwriter,xmlreader,zlib,zip`
|
||||
Please first select the extension you want to compile based on the extension list below.
|
||||
|
||||
### 支持的扩展情况
|
||||
- [Supported Extension List](https://static-php.dev/en/guide/extensions.html)
|
||||
- [Command Generator](https://static-php.dev/en/guide/cli-generator.html)
|
||||
|
||||
[扩展支持列表](https://static-php-cli.zhamao.me/zh/guide/extensions.html)
|
||||
> If an extension you need is missing, you can submit an issue.
|
||||
|
||||
> 如果这里没有你需要的扩展,可以提交 Issue。
|
||||
### GitHub Actions Build
|
||||
|
||||
### 使用 Actions 构建
|
||||
Use GitHub Action to easily build a statically compiled PHP,
|
||||
and at the same time define the extensions to be compiled by yourself.
|
||||
|
||||
使用 GitHub Action 可以方便地构建一个静态编译的 PHP 和 phpmicro,同时可以自行定义要编译的扩展。
|
||||
1. Fork me.
|
||||
2. Go to the Actions of the project and select `CI`.
|
||||
3. Select `Run workflow`, fill in the PHP version you want to compile, the target type, and the list of extensions. (extensions comma separated, e.g. `bcmath,curl,mbstring`)
|
||||
4. After waiting for about a period of time, enter the corresponding task and get `Artifacts`.
|
||||
|
||||
1. Fork 本项目。
|
||||
2. 进入项目的 Actions,选择 CI。
|
||||
3. 选择 `Run workflow`,填入你要编译的 PHP 版本、目标类型、扩展列表。(扩展列表使用英文逗号分割,例如 `bcmath,curl,mbstring`)
|
||||
4. 等待大约一段时间后,进入对应的任务中,获取 `Artifacts`。
|
||||
If you enable `debug`, all logs will be output at build time, including compiled logs, for troubleshooting.
|
||||
|
||||
如果你选择了 `debug`,则会在构建时输出所有日志,包括编译的日志,以供排查错误。
|
||||
- When using ubuntu-latest, it will build linux-x86_64 binary.
|
||||
- When using macos-latest, it will build macOS-x86_64 binary.
|
||||
|
||||
### 手动构建
|
||||
### Manual build (using SPC binary)
|
||||
|
||||
先克隆本项目:
|
||||
This project provides a binary file of static-php-cli.
|
||||
You can directly download the binary file of the corresponding platform and then use it to build static PHP.
|
||||
Currently, the platforms supported by `spc` binary are Linux and macOS.
|
||||
|
||||
Here's how to download from GitHub Actions:
|
||||
|
||||
1. Enter [GitHub Actions](https://github.com/crazywhalecc/static-php-cli/actions/workflows/release-build.yml).
|
||||
2. Select the latest build task, select `Artifacts`, and download the binary file of the corresponding platform.
|
||||
3. Unzip the `.zip` file. After decompressing, add execution permissions to it: `chmod +x ./spc`.
|
||||
|
||||
You can also download binaries from a self-hosted server: [enter](https://dl.static-php.dev/static-php-cli/spc-bin/nightly/).
|
||||
|
||||
> SPC single-file binary is built by phpmicro and box.
|
||||
|
||||
### Manual build (using source code)
|
||||
|
||||
Clone repo first:
|
||||
|
||||
```bash
|
||||
git clone https://github.com/crazywhalecc/static-php-cli.git
|
||||
```
|
||||
|
||||
如果你本机没有安装 PHP,你需要先使用包管理(例如 brew、apt、yum、apk 等)安装 php。
|
||||
If you have not installed php on your system, you can use package management to install PHP (such as brew, apt, yum, apk etc.).
|
||||
|
||||
你也可以通过 `bin/setup-runtime` 命令下载静态编译好的 php-cli 和 Composer。下载的 php 和 Composer 将保存为 `bin/php` 和 `bin/composer`。
|
||||
And you can also download single-file php binary and composer using command `bin/setup-runtime`.
|
||||
The PHP runtime for static-php-cli itself will be downloaded at `bin/php`, and composer is at `bin/composer`.
|
||||
|
||||
```bash
|
||||
cd static-php-cli
|
||||
chmod +x bin/setup-runtime
|
||||
# It will download php-cli from self-hosted server and composer from getcomposer.org
|
||||
./bin/setup-runtime
|
||||
|
||||
# 使用独立的 php 运行 static-php-cli
|
||||
# Use this php runtime to run static-php-cli compiler
|
||||
./bin/php bin/spc
|
||||
|
||||
# 使用 composer
|
||||
# Use composer
|
||||
./bin/php bin/composer
|
||||
```
|
||||
|
||||
下面是使用 static-php-cli 编译静态 php 和 micro 的基础用法:
|
||||
|
||||
```bash
|
||||
# 克隆本项目
|
||||
# Initialize this project
|
||||
cd static-php-cli
|
||||
composer update
|
||||
chmod +x bin/spc
|
||||
# 检查环境依赖,并根据提示的命令安装缺失的编译工具
|
||||
./bin/spc doctor
|
||||
# 拉取所有依赖库
|
||||
./bin/spc fetch --all
|
||||
# 构建包含 bcmath,openssl,tokenizer,sqlite3,pdo_sqlite,ftp,curl 扩展的 php-cli 和 micro.sfx
|
||||
./bin/spc build "bcmath,openssl,tokenizer,sqlite3,pdo_sqlite,ftp,curl" --build-cli --build-micro
|
||||
```
|
||||
|
||||
你也可以使用参数 `--with-php=x.y` 来指定下载的 PHP 版本,目前支持 7.3 ~ 8.3:
|
||||
### Use static-php-cli
|
||||
|
||||
Basic usage for building php and micro with some extensions:
|
||||
|
||||
> If you are using the packaged `spc` binary, you need to replace `bin/spc` with `./spc` in the following commands.
|
||||
|
||||
```bash
|
||||
# 优先考虑使用 >= 8.0 的 PHP 版本,因为 phpmicro 不支持在 PHP7 中构建
|
||||
# Check system tool dependencies, fix them automatically
|
||||
./bin/spc doctor
|
||||
# fetch all libraries
|
||||
./bin/spc download --all
|
||||
# only fetch necessary sources by needed extensions
|
||||
./bin/spc download --for-extensions=openssl,pcntl,mbstring,pdo_sqlite
|
||||
# with bcmath,openssl,tokenizer,sqlite3,pdo_sqlite,ftp,curl extension, build both CLI and phpmicro SAPI
|
||||
./bin/spc build bcmath,openssl,tokenizer,sqlite3,pdo_sqlite,ftp,curl --build-cli --build-micro
|
||||
```
|
||||
|
||||
You can also use the parameter `--with-php=x.y` to specify the downloaded PHP version, currently supports 7.4 ~ 8.2:
|
||||
|
||||
```bash
|
||||
# Using PHP >= 8.0 is recommended, because PHP7 cannot use phpmicro
|
||||
./bin/spc fetch --with-php=8.2 --all
|
||||
```
|
||||
|
||||
其中,目前支持构建 cli,micro,fpm 三种静态二进制,使用以下参数的一个或多个来指定编译的 SAPI:
|
||||
Now we support `cli`, `micro`, `fpm`, you can use one or more of the following parameters to specify the compiled SAPI:
|
||||
|
||||
- `--build-cli`:构建 cli 二进制
|
||||
- `--build-micro`:构建 phpmicro 自执行二进制
|
||||
- `--build-fpm`:构建 fpm
|
||||
- `--build-all`:构建所有
|
||||
- `--build-cli`: build static cli executable
|
||||
- `--build-micro`: build static phpmicro self-extracted executable
|
||||
- `--build-fpm`: build static fpm binary
|
||||
- `--build-embed`: build embed (libphp)
|
||||
- `--build-all`: build all
|
||||
|
||||
如果出现了任何错误,可以使用 `--debug` 参数来展示完整的输出日志,以供排查错误:
|
||||
If anything goes wrong, use `--debug` option to display full terminal output:
|
||||
|
||||
```bash
|
||||
./bin/spc build openssl,pcntl,mbstring --debug --build-all
|
||||
./bin/spc fetch --all --debug
|
||||
```
|
||||
|
||||
此外,默认编译的 PHP 为 NTS 版本。如需编译线程安全版本(ZTS),只需添加参数 `--enable-zts` 即可。
|
||||
In addition, we build NTS by default. If you are going to build ZTS version, just add `--enable-zts` option.
|
||||
|
||||
```bash
|
||||
./bin/spc build openssl,pcntl --build-all --enable-zts
|
||||
```
|
||||
|
||||
同时,你也可以使用参数 `--no-strip` 来关闭裁剪,关闭裁剪后可以使用 gdb 等工具调试,但这样会让静态二进制体积变大。
|
||||
Adding option `--no-strip` can produce binaries with debug symbols, in order to debug (using gdb). Disabling strip will increase the size of static binary.
|
||||
|
||||
### 使用 php-cli
|
||||
## Different SAPI Usage
|
||||
|
||||
> php-cli 是一个静态的二进制文件,类似 Go、Rust 语言编译后的单个可移植的二进制文件。
|
||||
### Use cli
|
||||
|
||||
采用参数 `--build-cli` 或`--build-all` 参数时,最后编译结果会输出一个 `./php` 的二进制文件,此文件可分发、可直接使用。
|
||||
该文件编译后会存放在 `buildroot/bin/` 目录中,名称为 `php`,拷贝出来即可。
|
||||
> php-cli is a single static binary, you can use it like normal php installed on your system.
|
||||
|
||||
When using the parameter `--build-cli` or `--build-all`,
|
||||
the final compilation result will output a binary file named `./php`,
|
||||
which can be distributed and used directly.
|
||||
This file will be located in the directory `buildroot/bin/`, copy it out for use.
|
||||
|
||||
```bash
|
||||
cd buildroot/bin/
|
||||
./php -v # 检查版本
|
||||
./php -m # 检查编译的扩展
|
||||
./php your_code.php # 运行代码
|
||||
./php your_project.phar # 运行打包为 phar 单文件的项目
|
||||
./php -v # check version
|
||||
./php -m # check extensions
|
||||
./php your_code.php # run your php code
|
||||
./php your_project.phar # run your phar (project archive)
|
||||
```
|
||||
|
||||
### 使用 micro.sfx
|
||||
### Use micro
|
||||
|
||||
> phpmicro 是一个提供自执行二进制 PHP 的项目,本项目依赖 phpmicro 进行编译自执行二进制。详见 [dixyes/phpmicro](https://github.com/dixyes/phpmicro)。
|
||||
> phpmicro is a SelF-extracted eXecutable SAPI module,
|
||||
> provided by [phpmicro](https://github.com/dixyes/phpmicro) project.
|
||||
> But this project is using a [fork](https://github.com/crazywhalecc/phpmicro) of phpmicro, because we need to add some features to it.
|
||||
> It can put php runtime and your source code together.
|
||||
|
||||
采用项目参数 `--build-micro` 或 `--build-all` 时,最后编译结果会输出一个 `./micro.sfx` 的文件,此文件需要配合你的 PHP 源码使用。
|
||||
该文件编译后会存放在 `buildroot/bin/` 目录中,拷贝出来即可。
|
||||
When using the parameter `--build-all` or `--build-micro`,
|
||||
the final compilation result will output a file named `./micro.sfx`,
|
||||
which needs to be used with your PHP source code like `code.php`.
|
||||
This file will be located in the path `buildroot/bin/micro.sfx`, simply copy it out for use.
|
||||
|
||||
使用时应准备好你的项目源码文件,可以是单个 PHP 文件,也可以是 Phar 文件。
|
||||
Prepare your project source code, which can be a single PHP file or a Phar file, for use.
|
||||
|
||||
```bash
|
||||
echo "<?php echo 'Hello world' . PHP_EOL;" > code.php
|
||||
cat micro.sfx code.php > single-app && chmod +x single-app
|
||||
./single-app
|
||||
|
||||
# 如果打包 PHAR 文件,仅需把 code.php 更换为 phar 文件路径即可
|
||||
```
|
||||
|
||||
> 有些情况下的 phar 文件可能无法在 micro 环境下运行。
|
||||
If you package a PHAR file, just replace `code.php` with the phar file path.
|
||||
You can use [box-project/box](https://github.com/box-project/box) to package your CLI project as Phar,
|
||||
It is then combined with phpmicro to produce a standalone executable binary.
|
||||
|
||||
### 使用 php-fpm
|
||||
```bash
|
||||
# Use the micro.sfx generated by static-php-cli to combine,
|
||||
bin/spc micro:combine my-app.phar
|
||||
# or you can directly use the cat command to combine them.
|
||||
cat buildroot/bin/micro.sfx my-app.phar > my-app && chmod +x my-app
|
||||
|
||||
采用项目参数 `--build-fpm` 或 `--build-all` 时,最后编译结果会输出一个 `./php-fpm` 的文件。
|
||||
该文件存放在 `buildroot/bin/` 目录,拷贝出来即可使用。
|
||||
# Use micro:combine combination to inject INI options into the binary.
|
||||
bin/spc micro:combine my-app.phar -I "memory_limit=4G" -I "disable_functions=system" --output my-app-2
|
||||
```
|
||||
|
||||
在正常的 Linux 发行版和 macOS 系统中,安装 php-fpm 后包管理会自动生成默认的 fpm 配置文件。
|
||||
因为 php-fpm 必须指定配置文件才可启动,本项目编译的 php-fpm 不会带任何配置文件,所以需自行编写 `php-fpm.conf` 和 `pool.conf` 配置文件。
|
||||
> In some cases, PHAR files may not run in a micro environment.
|
||||
|
||||
指定 `php-fpm.conf` 可以使用命令参数 `-y`,例如:`./php-fpm -y php-fpm.conf`。
|
||||
### Use fpm
|
||||
|
||||
## 贡献
|
||||
When using the parameter `--build-all` or `--build-fpm`,
|
||||
the final compilation result will output a file named `./php-fpm`,
|
||||
This file will be located in the path `buildroot/bin/`, simply copy it out for use.
|
||||
|
||||
目前支持的扩展较少,如果缺少你需要的扩展,可发起 Issue。如果你对本项目较熟悉,也欢迎为本项目发起 Pull Request。
|
||||
In normal Linux distributions and macOS systems, the package manager will automatically generate a default fpm configuration file after installing php-fpm.
|
||||
Because php-fpm must specify a configuration file before running, the php-fpm compiled by this project will not have any configuration files, so you need to write `php-fpm.conf` and `pool.conf` configuration files yourself.
|
||||
|
||||
贡献基本原则如下:
|
||||
Specifying `php-fpm.conf` can use the command parameter `-y`, for example: `./php-fpm -y php-fpm.conf`.
|
||||
|
||||
- 项目采用了 php-cs-fixer、phpstan 作为代码规范工具,贡献前请对更新的代码执行 `composer analyze` 和 `composer cs-fix`。
|
||||
- 涉及到其他开源库的部分应提供对应库的协议,同时对配置文件在修改后采用命令 `sort-config` 排序。有关排序的命令,见文档。
|
||||
- 应遵循命名规范,例如扩展名称应采取 PHP 内注册的扩展名本身,外部库名应遵循项目本身的名称,内部逻辑的函数、类名、变量等应遵循驼峰、下划线等格式,禁止同一模块混用。
|
||||
- 涉及编译外部库的命令和 Patch 时应注意兼容不同操作系统。
|
||||
### Use embed
|
||||
|
||||
另外,添加新扩展的贡献方式,可以参考下方 `进阶`。
|
||||
When using the project parameters `--build-embed` or `--build-all`,
|
||||
the final compilation result will output a `libphp.a`, `php-config` and a series of header files,
|
||||
stored in `buildroot/`. You can introduce them in your other projects.
|
||||
|
||||
如果你想贡献文档内容,请到项目仓库 [crazywhalecc/static-php-cli-docs](https://github.com/crazywhalecc/static-php-cli-docs) 贡献。
|
||||
If you know [embed SAPI](https://github.com/php/php-src/tree/master/sapi/embed), you should know how to use it.
|
||||
You may require the introduction of other libraries during compilation,
|
||||
you can use `buildroot/bin/php-config` to obtain the compile-time configuration.
|
||||
|
||||
## 赞助本项目
|
||||
For an advanced example of how to use this feature, take a look at [how to use it to build a static version of FrankenPHP](https://github.com/dunglas/frankenphp/blob/main/docs/static.md).
|
||||
|
||||
你可以在 [我的个人赞助页](https://github.com/crazywhalecc/crazywhalecc/blob/master/FUNDING.md) 支持我和我的项目。
|
||||
## Contribution
|
||||
|
||||
## 开源协议
|
||||
If the extension you need is missing, you can create an issue.
|
||||
If you are familiar with this project, you are also welcome to initiate a pull request.
|
||||
|
||||
本项目依据旧版本惯例采用 MIT License 开源,自身的部分代码引用或修改自以下项目:
|
||||
If you want to contribute document content, please go to [crazywhalecc/static-php-cli-docs](https://github.com/crazywhalecc/static-php-cli-docs).
|
||||
|
||||
- [dixyes/lwmbs](https://github.com/dixyes/lwmbs)(木兰宽松许可证)
|
||||
- [swoole/swoole-cli](https://github.com/swoole/swoole-cli)(Apache 2.0 LICENSE、SWOOLE-CLI LICENSE)
|
||||
Part of the English document is written by me, and part is translated by Google,
|
||||
and there may be inaccurate descriptions, strange or offensive expressions.
|
||||
If you are a native English speaker, some corrections to the documentation are welcome.
|
||||
|
||||
因本项目的特殊性,使用项目编译过程中会使用很多其他开源项目,例如 curl、protobuf 等,它们都有各自的开源协议。
|
||||
请在编译完成后,使用命令 `bin/spc dump-license` 导出项目使用项目的开源协议,并遵守对应项目的 LICENSE。
|
||||
|
||||
## 进阶
|
||||
## Sponsor this project
|
||||
|
||||
本项目重构分支为模块化编写。如果你对本项目感兴趣,想加入开发,可以参照文档的 [贡献指南](https://static-php-cli.zhamao.me) 贡献代码或文档。
|
||||
You can sponsor my project on [this page](https://github.com/crazywhalecc/crazywhalecc/blob/master/FUNDING.md).
|
||||
|
||||
## Open-Source License
|
||||
|
||||
This project itself is based on MIT License,
|
||||
some newly added extensions and dependencies may originate from the following projects (including but not limited to),
|
||||
and the headers of these code files will also be given additional instructions LICENSE and AUTHOR:
|
||||
|
||||
- [dixyes/lwmbs](https://github.com/dixyes/lwmbs) (Mulun Permissive License)
|
||||
- [swoole/swoole-cli](https://github.com/swoole/swoole-cli) (Apache 2.0 LICENSE+SWOOLE-CLI LICENSE)
|
||||
|
||||
Due to the special nature of this project,
|
||||
many other open source projects such as curl and protobuf will be used during the project compilation process,
|
||||
and they all have their own open source licenses.
|
||||
|
||||
Please use the `bin/spc dump-license` command to export the open source licenses used in the project after compilation,
|
||||
and comply with the corresponding project's LICENSE.
|
||||
|
||||
## Advanced
|
||||
|
||||
The refactoring branch of this project is written modularly.
|
||||
If you are interested in this project and want to join the development,
|
||||
you can refer to the [Contribution Guide](https://static-php.dev) of the documentation to contribute code or documentation.
|
||||
|
||||
@@ -25,7 +25,7 @@ __DIR__=$(cd "$(dirname "$0")" && pwd)
|
||||
__PROJECT__=$(cd "${__DIR__}"/../ && pwd)
|
||||
|
||||
# set download dir
|
||||
__PHP_RUNTIME_URL__="https://dl.zhamao.xin/static-php-cli/php-8.2.6-cli-${__OS_FIXED__}-${__ARCH__}.tar.gz"
|
||||
__PHP_RUNTIME_URL__="https://dl.static-php.dev/static-php-cli/common/php-8.2.10-cli-${__OS_FIXED__}-${__ARCH__}.tar.gz"
|
||||
__COMPOSER_URL__="https://getcomposer.org/download/latest-stable/composer.phar"
|
||||
|
||||
# use china mirror
|
||||
@@ -46,7 +46,7 @@ done
|
||||
|
||||
case "$mirror" in
|
||||
china)
|
||||
__PHP_RUNTIME_URL__="https://dl.zhamao.xin/static-php-cli/php-8.2.6-cli-${__OS_FIXED__}-${__ARCH__}.tar.gz"
|
||||
__PHP_RUNTIME_URL__="https://dl.static-php.dev/static-php-cli/common/php-8.2.10-cli-${__OS_FIXED__}-${__ARCH__}.tar.gz"
|
||||
__COMPOSER_URL__="https://mirrors.aliyun.com/composer/composer.phar"
|
||||
;;
|
||||
|
||||
|
||||
@@ -59,12 +59,12 @@ RUN apk update; \
|
||||
apk add --no-cache \
|
||||
autoconf \
|
||||
automake \
|
||||
gettext \
|
||||
bash \
|
||||
binutils \
|
||||
bison \
|
||||
build-base \
|
||||
cmake \
|
||||
composer \
|
||||
curl \
|
||||
file \
|
||||
flex \
|
||||
@@ -77,21 +77,26 @@ RUN apk update; \
|
||||
linux-headers \
|
||||
m4 \
|
||||
make \
|
||||
php81 \
|
||||
php81-common \
|
||||
php81-pcntl \
|
||||
php81-phar \
|
||||
php81-posix \
|
||||
php81-tokenizer \
|
||||
php81-xml \
|
||||
php82 \
|
||||
php82-common \
|
||||
php82-pcntl \
|
||||
php82-phar \
|
||||
php82-posix \
|
||||
php82-sodium \
|
||||
php82-tokenizer \
|
||||
php82-dom \
|
||||
php82-xml \
|
||||
php82-xmlwriter \
|
||||
composer \
|
||||
pkgconfig \
|
||||
wget \
|
||||
xz
|
||||
|
||||
WORKDIR /app
|
||||
ADD ./src /app/src
|
||||
ADD ./composer.json /app/composer.json
|
||||
COPY ./composer.* /app/
|
||||
ADD ./bin /app/bin
|
||||
RUN composer update --no-dev --classmap-authoritative
|
||||
RUN composer install --no-dev --classmap-authoritative
|
||||
EOF
|
||||
fi
|
||||
|
||||
|
||||
19
box.json
Normal file
19
box.json
Normal file
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"alias": "spc-php.phar",
|
||||
"banner": false,
|
||||
"blacklist": [
|
||||
".github"
|
||||
],
|
||||
"directories": [
|
||||
"config",
|
||||
"src",
|
||||
"vendor/psr",
|
||||
"vendor/laravel/prompts",
|
||||
"vendor/illuminate",
|
||||
"vendor/symfony",
|
||||
"vendor/zhamao"
|
||||
],
|
||||
"git-commit-short": "git_commit_short",
|
||||
"metadata": "ConsoleApplication::VERSION",
|
||||
"output": "spc.phar"
|
||||
}
|
||||
@@ -12,7 +12,7 @@
|
||||
"php": ">= 8.1",
|
||||
"ext-mbstring": "*",
|
||||
"ext-pcntl": "*",
|
||||
"laravel/prompts": "^0.1.3",
|
||||
"laravel/prompts": "^0.1.12",
|
||||
"symfony/console": "^5.4 || ^6 || ^7",
|
||||
"zhamao/logger": "^1.0"
|
||||
},
|
||||
@@ -20,6 +20,7 @@
|
||||
"captainhook/captainhook": "^5.10",
|
||||
"captainhook/plugin-composer": "^5.3",
|
||||
"friendsofphp/php-cs-fixer": "^3.25",
|
||||
"humbug/box": "^4.3",
|
||||
"nunomaduro/collision": "^7.8",
|
||||
"phpstan/phpstan": "^1.10",
|
||||
"phpunit/phpunit": "^10.3"
|
||||
@@ -44,7 +45,8 @@
|
||||
"scripts": {
|
||||
"analyse": "phpstan analyse --memory-limit 300M",
|
||||
"cs-fix": "php-cs-fixer fix",
|
||||
"test": "vendor/bin/phpunit tests/ --no-coverage"
|
||||
"test": "vendor/bin/phpunit tests/ --no-coverage",
|
||||
"build:phar": "vendor/bin/box compile"
|
||||
},
|
||||
"config": {
|
||||
"allow-plugins": {
|
||||
|
||||
6030
composer.lock
generated
Normal file
6030
composer.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -146,16 +146,22 @@
|
||||
},
|
||||
"intl": {
|
||||
"type": "builtin",
|
||||
"cpp-extension": true,
|
||||
"lib-depends": [
|
||||
"icu"
|
||||
]
|
||||
},
|
||||
"ldap": {
|
||||
"type": "builtin",
|
||||
"arg-type": "with",
|
||||
"arg-type": "with-prefix",
|
||||
"lib-depends": [
|
||||
"ldap"
|
||||
],
|
||||
"lib-suggests": [
|
||||
"gmp",
|
||||
"libsodium"
|
||||
],
|
||||
"ext-suggests": [
|
||||
"openssl"
|
||||
]
|
||||
},
|
||||
"mbregex": {
|
||||
@@ -226,9 +232,12 @@
|
||||
},
|
||||
"openssl": {
|
||||
"type": "builtin",
|
||||
"arg-type": "with",
|
||||
"arg-type": "custom",
|
||||
"lib-depends": [
|
||||
"openssl"
|
||||
],
|
||||
"ext-depends": [
|
||||
"zlib"
|
||||
]
|
||||
},
|
||||
"pcntl": {
|
||||
@@ -488,7 +497,7 @@
|
||||
},
|
||||
"zlib": {
|
||||
"type": "builtin",
|
||||
"arg-type": "with",
|
||||
"arg-type": "custom",
|
||||
"arg-type-windows": "enable",
|
||||
"lib-depends": [
|
||||
"zlib"
|
||||
|
||||
@@ -63,6 +63,7 @@
|
||||
],
|
||||
"frameworks": [
|
||||
"CoreFoundation",
|
||||
"CoreServices",
|
||||
"SystemConfiguration"
|
||||
]
|
||||
},
|
||||
@@ -110,6 +111,7 @@
|
||||
},
|
||||
"icu": {
|
||||
"source": "icu",
|
||||
"cpp-library": true,
|
||||
"static-libs-unix": [
|
||||
"libicui18n.a",
|
||||
"libicuio.a",
|
||||
@@ -121,24 +123,36 @@
|
||||
"source": "imagemagick",
|
||||
"static-libs-unix": [
|
||||
"libMagick++-7.Q16HDRI.a",
|
||||
"libMagickCore-7.Q16HDRI.a",
|
||||
"libMagickWand-7.Q16HDRI.a"
|
||||
"libMagickWand-7.Q16HDRI.a",
|
||||
"libMagickCore-7.Q16HDRI.a"
|
||||
],
|
||||
"lib-depends": [
|
||||
"zlib",
|
||||
"libpng",
|
||||
"libjpeg",
|
||||
"bzip2",
|
||||
"libwebp",
|
||||
"freetype"
|
||||
],
|
||||
"lib-suggests": [
|
||||
"zstd",
|
||||
"xz",
|
||||
"bzip2",
|
||||
"libzip",
|
||||
"libxml2"
|
||||
]
|
||||
},
|
||||
"ldap": {
|
||||
"source": "ldap",
|
||||
"static-libs-unix": [
|
||||
"liblber.a",
|
||||
"libldap.a"
|
||||
],
|
||||
"lib-suggests": [
|
||||
"openssl",
|
||||
"gmp",
|
||||
"libsodium"
|
||||
]
|
||||
},
|
||||
"libavif": {
|
||||
"source": "libavif",
|
||||
"static-libs-unix": [
|
||||
@@ -210,7 +224,7 @@
|
||||
"libpng": {
|
||||
"source": "libpng",
|
||||
"static-libs-unix": [
|
||||
"libpng.a"
|
||||
"libpng16.a"
|
||||
],
|
||||
"static-libs-windows": [
|
||||
"libpng16_static.lib"
|
||||
@@ -421,7 +435,10 @@
|
||||
"readline"
|
||||
],
|
||||
"lib-suggests": [
|
||||
"icu"
|
||||
"icu",
|
||||
"libxslt",
|
||||
"ldap",
|
||||
"zstd"
|
||||
]
|
||||
},
|
||||
"pthreads4w": {
|
||||
@@ -451,10 +468,9 @@
|
||||
"libsnappy.a"
|
||||
],
|
||||
"headers-unix": [
|
||||
"snappy.h",
|
||||
"snappy-c.h",
|
||||
"snappy-sinksource.h",
|
||||
"snappy.h",
|
||||
"snappy-stubs-internal.h",
|
||||
"snappy-stubs-public.h"
|
||||
],
|
||||
"lib-depends": [
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -1,3 +1,3 @@
|
||||
# Extension List
|
||||
|
||||
See: [Docs - Extensions](https://static-php-cli.zhamao.me/en/guide/extensions.html)
|
||||
See: [Docs - Extensions](https://static-php.dev/en/guide/extensions.html)
|
||||
|
||||
@@ -4,7 +4,16 @@ declare(strict_types=1);
|
||||
|
||||
namespace SPC;
|
||||
|
||||
use SPC\store\FileSystem;
|
||||
use SPC\command\BuildCliCommand;
|
||||
use SPC\command\BuildLibsCommand;
|
||||
use SPC\command\dev\AllExtCommand;
|
||||
use SPC\command\dev\PhpVerCommand;
|
||||
use SPC\command\dev\SortConfigCommand;
|
||||
use SPC\command\DoctorCommand;
|
||||
use SPC\command\DownloadCommand;
|
||||
use SPC\command\DumpLicenseCommand;
|
||||
use SPC\command\ExtractCommand;
|
||||
use SPC\command\MicroCombineCommand;
|
||||
use Symfony\Component\Console\Application;
|
||||
use Symfony\Component\Console\Command\HelpCommand;
|
||||
use Symfony\Component\Console\Command\ListCommand;
|
||||
@@ -12,38 +21,30 @@ use Symfony\Component\Console\Command\ListCommand;
|
||||
/**
|
||||
* static-php-cli console app entry
|
||||
*/
|
||||
class ConsoleApplication extends Application
|
||||
final class ConsoleApplication extends Application
|
||||
{
|
||||
public const VERSION = '2.0-rc6';
|
||||
public const VERSION = '2.0.0-rc8';
|
||||
|
||||
/**
|
||||
* @throws \ReflectionException
|
||||
* @throws exception\FileSystemException
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct('static-php-cli', self::VERSION);
|
||||
|
||||
global $argv;
|
||||
$this->addCommands(
|
||||
[
|
||||
new BuildCliCommand(),
|
||||
new BuildLibsCommand(),
|
||||
new DoctorCommand(),
|
||||
new DownloadCommand(),
|
||||
new DumpLicenseCommand(),
|
||||
new ExtractCommand(),
|
||||
new MicroCombineCommand(),
|
||||
|
||||
// Detailed debugging errors are not displayed in the production environment. Only the error display provided by Symfony console is used.
|
||||
$this->setCatchExceptions(file_exists(ROOT_DIR . '/.prod') || !in_array('--debug', $argv));
|
||||
|
||||
// Add subcommands by scanning the directory src/static-php-cli/command/
|
||||
$commands = FileSystem::getClassesPsr4(ROOT_DIR . '/src/SPC/command', 'SPC\\command');
|
||||
$phar = class_exists('\\Phar') && \Phar::running() || !class_exists('\\Phar');
|
||||
$commands = array_filter($commands, function ($y) use ($phar) {
|
||||
$archive_blacklist = [
|
||||
'SPC\command\dev\SortConfigCommand',
|
||||
'SPC\command\DeployCommand',
|
||||
];
|
||||
if ($phar && in_array($y, $archive_blacklist)) {
|
||||
return false;
|
||||
}
|
||||
$reflection = new \ReflectionClass($y);
|
||||
return !$reflection->isAbstract() && !$reflection->isInterface();
|
||||
});
|
||||
$this->addCommands(array_map(function ($x) { return new $x(); }, $commands));
|
||||
// Dev commands
|
||||
new AllExtCommand(),
|
||||
new PhpVerCommand(),
|
||||
new SortConfigCommand(),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
protected function getDefaultCommands(): array
|
||||
|
||||
@@ -85,7 +85,7 @@ abstract class BuilderBase
|
||||
|
||||
// build all libs
|
||||
foreach ($this->libs as $lib) {
|
||||
match ($lib->tryBuild()) {
|
||||
match ($lib->tryBuild($this->getOption('rebuild', false))) {
|
||||
BUILD_STATUS_OK => logger()->info('lib [' . $lib::NAME . '] build success'),
|
||||
BUILD_STATUS_ALREADY => logger()->notice('lib [' . $lib::NAME . '] already built'),
|
||||
BUILD_STATUS_FAILED => logger()->error('lib [' . $lib::NAME . '] build failed'),
|
||||
@@ -112,6 +112,16 @@ abstract class BuilderBase
|
||||
return $this->libs[$name] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all library objects.
|
||||
*
|
||||
* @return LibraryBase[]
|
||||
*/
|
||||
public function getLibs(): array
|
||||
{
|
||||
return $this->libs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add extension to build.
|
||||
*/
|
||||
@@ -139,23 +149,27 @@ abstract class BuilderBase
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if there is a cpp extension.
|
||||
* Check if there is a cpp extensions or libraries.
|
||||
*
|
||||
* @throws FileSystemException
|
||||
* @throws WrongUsageException
|
||||
*/
|
||||
public function hasCppExtension(): bool
|
||||
public function hasCpp(): bool
|
||||
{
|
||||
// judge cpp-extension
|
||||
$exts = array_keys($this->getExts());
|
||||
$cpp = false;
|
||||
foreach ($exts as $ext) {
|
||||
if (Config::getExt($ext, 'cpp-extension', false) === true) {
|
||||
$cpp = true;
|
||||
break;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return $cpp;
|
||||
$libs = array_keys($this->getLibs());
|
||||
foreach ($libs as $lib) {
|
||||
if (Config::getLib($lib, 'cpp-library', false) === true) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -227,12 +241,22 @@ abstract class BuilderBase
|
||||
|
||||
/**
|
||||
* Get PHP Version ID from php-src/main/php_version.h
|
||||
*
|
||||
* @throws RuntimeException
|
||||
* @throws WrongUsageException
|
||||
*/
|
||||
public function getPHPVersionID(): int
|
||||
{
|
||||
if (!file_exists(SOURCE_PATH . '/php-src/main/php_version.h')) {
|
||||
throw new WrongUsageException('PHP source files are not available, you need to download them first');
|
||||
}
|
||||
|
||||
$file = file_get_contents(SOURCE_PATH . '/php-src/main/php_version.h');
|
||||
preg_match('/PHP_VERSION_ID (\d+)/', $file, $match);
|
||||
return intval($match[1]);
|
||||
if (preg_match('/PHP_VERSION_ID (\d+)/', $file, $match) !== 0) {
|
||||
return intval($match[1]);
|
||||
}
|
||||
|
||||
throw new RuntimeException('PHP version file format is malformed, please remove it and download again');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -252,6 +276,9 @@ abstract class BuilderBase
|
||||
if (($type & BUILD_TARGET_FPM) === BUILD_TARGET_FPM) {
|
||||
$ls[] = 'fpm';
|
||||
}
|
||||
if (($type & BUILD_TARGET_EMBED) === BUILD_TARGET_EMBED) {
|
||||
$ls[] = 'embed';
|
||||
}
|
||||
return implode(', ', $ls);
|
||||
}
|
||||
|
||||
@@ -292,6 +319,18 @@ abstract class BuilderBase
|
||||
$this->options[$key] = $value;
|
||||
}
|
||||
|
||||
public function getEnvString(array $vars = ['cc', 'cxx', 'ar', 'ld']): string
|
||||
{
|
||||
$env = [];
|
||||
foreach ($vars as $var) {
|
||||
$var = strtoupper($var);
|
||||
if (getenv($var) !== false) {
|
||||
$env[] = "{$var}=" . getenv($var);
|
||||
}
|
||||
}
|
||||
return implode(' ', $env);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if all libs are downloaded.
|
||||
* If not, throw exception.
|
||||
|
||||
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace SPC\builder;
|
||||
|
||||
use SPC\builder\freebsd\BSDBuilder;
|
||||
use SPC\builder\linux\LinuxBuilder;
|
||||
use SPC\builder\macos\MacOSBuilder;
|
||||
use SPC\exception\FileSystemException;
|
||||
@@ -31,6 +32,7 @@ class BuilderProvider
|
||||
// ),
|
||||
'Darwin' => new MacOSBuilder($input->getOptions()),
|
||||
'Linux' => new LinuxBuilder($input->getOptions()),
|
||||
'BSD' => new BSDBuilder($input->getOptions()),
|
||||
default => throw new WrongUsageException('Current OS "' . PHP_OS_FAMILY . '" is not supported yet'),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -46,6 +46,7 @@ class Extension
|
||||
break;
|
||||
case 'Darwin':
|
||||
case 'Linux':
|
||||
case 'BSD':
|
||||
$arg .= $this->getUnixConfigureArg();
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace SPC\builder;
|
||||
|
||||
use SPC\builder\macos\library\MacOSLibraryBase;
|
||||
use SPC\exception\FileSystemException;
|
||||
use SPC\exception\RuntimeException;
|
||||
use SPC\exception\WrongUsageException;
|
||||
@@ -19,6 +18,8 @@ abstract class LibraryBase
|
||||
|
||||
protected array $dependencies = [];
|
||||
|
||||
protected bool $patched = false;
|
||||
|
||||
/**
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
@@ -130,10 +131,15 @@ abstract class LibraryBase
|
||||
*/
|
||||
public function tryBuild(bool $force_build = false): int
|
||||
{
|
||||
if (file_exists($this->source_dir . '/.spc.patched')) {
|
||||
$this->patched = true;
|
||||
}
|
||||
// force means just build
|
||||
if ($force_build) {
|
||||
logger()->info('Building required library [' . static::NAME . ']');
|
||||
$this->patchBeforeBuild();
|
||||
if (!$this->patched && $this->patchBeforeBuild()) {
|
||||
file_put_contents($this->source_dir . '/.spc.patched', 'PATCHED!!!');
|
||||
}
|
||||
$this->build();
|
||||
return BUILD_STATUS_OK;
|
||||
}
|
||||
@@ -153,7 +159,7 @@ abstract class LibraryBase
|
||||
}
|
||||
}
|
||||
// pkg-config is treated specially. If it is pkg-config, check if the pkg-config binary exists
|
||||
if ($this instanceof MacOSLibraryBase && static::NAME === 'pkg-config' && !file_exists(BUILD_ROOT_PATH . '/bin/pkg-config')) {
|
||||
if (static::NAME === 'pkg-config' && !file_exists(BUILD_ROOT_PATH . '/bin/pkg-config')) {
|
||||
$this->tryBuild(true);
|
||||
return BUILD_STATUS_OK;
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||
namespace SPC\builder\extension;
|
||||
|
||||
use SPC\builder\Extension;
|
||||
use SPC\builder\macos\MacOSBuilder;
|
||||
use SPC\util\CustomExt;
|
||||
|
||||
#[CustomExt('iconv')]
|
||||
@@ -13,6 +14,9 @@ class iconv extends Extension
|
||||
public function patchBeforeConfigure(): bool
|
||||
{
|
||||
// macOS need to link iconv dynamically, we add it to extra-libs
|
||||
if (!$this->builder instanceof MacOSBuilder) {
|
||||
return false;
|
||||
}
|
||||
$extra_libs = $this->builder->getOption('extra-libs', '');
|
||||
if (!str_contains($extra_libs, '-liconv')) {
|
||||
$extra_libs .= ' -liconv';
|
||||
|
||||
@@ -10,13 +10,11 @@ use SPC\util\CustomExt;
|
||||
#[CustomExt('imagick')]
|
||||
class imagick extends Extension
|
||||
{
|
||||
public function patchBeforeBuildconf(): bool
|
||||
public function patchBeforeMake(): bool
|
||||
{
|
||||
// linux need to link library manually, we add it to extra-libs
|
||||
// imagick may call omp_pause_all which requires -lgomp
|
||||
$extra_libs = $this->builder->getOption('extra-libs', '');
|
||||
if (!str_contains($extra_libs, 'libMagickCore')) {
|
||||
$extra_libs .= ' /usr/lib/libMagick++-7.Q16HDRI.a /usr/lib/libMagickCore-7.Q16HDRI.a /usr/lib/libMagickWand-7.Q16HDRI.a';
|
||||
}
|
||||
$extra_libs .= ' -lgomp ';
|
||||
$this->builder->setOption('extra-libs', $extra_libs);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ namespace SPC\builder\extension;
|
||||
|
||||
use SPC\builder\Extension;
|
||||
use SPC\util\CustomExt;
|
||||
use SPC\util\Util;
|
||||
|
||||
#[CustomExt('openssl')]
|
||||
class openssl extends Extension
|
||||
@@ -14,12 +13,18 @@ class openssl extends Extension
|
||||
public function patchBeforeMake(): bool
|
||||
{
|
||||
// patch openssl3 with php8.0 bug
|
||||
if (file_exists(SOURCE_PATH . '/openssl/VERSION.dat') && Util::getPHPVersionID() < 80100) {
|
||||
if (file_exists(SOURCE_PATH . '/openssl/VERSION.dat') && $this->builder->getPHPVersionID() < 80100) {
|
||||
$openssl_c = file_get_contents(SOURCE_PATH . '/php-src/ext/openssl/openssl.c');
|
||||
$openssl_c = preg_replace('/REGISTER_LONG_CONSTANT\s*\(\s*"OPENSSL_SSLV23_PADDING"\s*.+;/', '', $openssl_c);
|
||||
file_put_contents(SOURCE_PATH . '/php-src/ext/openssl/openssl.c', $openssl_c);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getUnixConfigureArg(): string
|
||||
{
|
||||
return '--with-openssl=' . BUILD_ROOT_PATH . ' --with-openssl-dir=' . BUILD_ROOT_PATH;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ namespace SPC\builder\extension;
|
||||
use SPC\builder\Extension;
|
||||
use SPC\exception\RuntimeException;
|
||||
use SPC\util\CustomExt;
|
||||
use SPC\util\Util;
|
||||
|
||||
#[CustomExt('swow')]
|
||||
class swow extends Extension
|
||||
@@ -25,7 +24,7 @@ class swow extends Extension
|
||||
*/
|
||||
public function patchBeforeBuildconf(): bool
|
||||
{
|
||||
if (Util::getPHPVersionID() >= 80000 && !is_link(SOURCE_PATH . '/php-src/ext/swow')) {
|
||||
if ($this->builder->getPHPVersionID() >= 80000 && !is_link(SOURCE_PATH . '/php-src/ext/swow')) {
|
||||
if (PHP_OS_FAMILY === 'Windows') {
|
||||
f_passthru('cd ' . SOURCE_PATH . '/php-src/ext && mklink /D swow swow-src\ext');
|
||||
} else {
|
||||
|
||||
17
src/SPC/builder/extension/zlib.php
Normal file
17
src/SPC/builder/extension/zlib.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace SPC\builder\extension;
|
||||
|
||||
use SPC\builder\Extension;
|
||||
use SPC\util\CustomExt;
|
||||
|
||||
#[CustomExt('zlib')]
|
||||
class zlib extends Extension
|
||||
{
|
||||
public function getUnixConfigureArg(): string
|
||||
{
|
||||
return '--with-zlib --with-zlib-dir="' . BUILD_ROOT_PATH . '"';
|
||||
}
|
||||
}
|
||||
253
src/SPC/builder/freebsd/BSDBuilder.php
Normal file
253
src/SPC/builder/freebsd/BSDBuilder.php
Normal file
@@ -0,0 +1,253 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace SPC\builder\freebsd;
|
||||
|
||||
use SPC\builder\BuilderBase;
|
||||
use SPC\builder\traits\UnixBuilderTrait;
|
||||
use SPC\exception\FileSystemException;
|
||||
use SPC\exception\RuntimeException;
|
||||
use SPC\exception\WrongUsageException;
|
||||
use SPC\store\FileSystem;
|
||||
use SPC\store\SourcePatcher;
|
||||
|
||||
class BSDBuilder extends BuilderBase
|
||||
{
|
||||
/** Unix compatible builder methods */
|
||||
use UnixBuilderTrait;
|
||||
|
||||
/** @var bool Micro patch phar flag */
|
||||
private bool $phar_patched = false;
|
||||
|
||||
/**
|
||||
* @throws RuntimeException
|
||||
* @throws WrongUsageException
|
||||
* @throws FileSystemException
|
||||
*/
|
||||
public function __construct(array $options = [])
|
||||
{
|
||||
$this->options = $options;
|
||||
|
||||
// ---------- set necessary options ----------
|
||||
// set C Compiler (default: clang)
|
||||
f_putenv('CC=' . $this->getOption('cc', 'clang'));
|
||||
// set C++ Composer (default: clang++)
|
||||
f_putenv('CXX=' . $this->getOption('cxx', 'clang++'));
|
||||
// set PATH
|
||||
f_putenv('PATH=' . BUILD_ROOT_PATH . '/bin:' . getenv('PATH'));
|
||||
// set PKG_CONFIG
|
||||
f_putenv('PKG_CONFIG=' . BUILD_ROOT_PATH . '/bin/pkg-config');
|
||||
// set PKG_CONFIG_PATH
|
||||
f_putenv('PKG_CONFIG_PATH=' . BUILD_LIB_PATH . '/pkgconfig/');
|
||||
|
||||
// set arch (default: current)
|
||||
$this->setOptionIfNotExist('arch', php_uname('m'));
|
||||
$this->setOptionIfNotExist('gnu-arch', arch2gnu($this->getOption('arch')));
|
||||
|
||||
// ---------- set necessary compile environments ----------
|
||||
// concurrency
|
||||
$this->concurrency = SystemUtil::getCpuCount();
|
||||
// cflags
|
||||
$this->arch_c_flags = SystemUtil::getArchCFlags($this->getOption('arch'));
|
||||
$this->arch_cxx_flags = SystemUtil::getArchCFlags($this->getOption('arch'));
|
||||
// cmake toolchain
|
||||
$this->cmake_toolchain_file = SystemUtil::makeCmakeToolchainFile('BSD', $this->getOption('arch'), $this->arch_c_flags);
|
||||
|
||||
// create pkgconfig and include dir (some libs cannot create them automatically)
|
||||
f_mkdir(BUILD_LIB_PATH . '/pkgconfig', recursive: true);
|
||||
f_mkdir(BUILD_INCLUDE_PATH, recursive: true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Just start to build statically linked php binary
|
||||
*
|
||||
* @param int $build_target build target
|
||||
* @throws FileSystemException
|
||||
* @throws RuntimeException
|
||||
* @throws WrongUsageException
|
||||
*/
|
||||
public function buildPHP(int $build_target = BUILD_TARGET_NONE): void
|
||||
{
|
||||
// ---------- Update extra-libs ----------
|
||||
$extra_libs = $this->getOption('extra-libs', '');
|
||||
// add libc++, some extensions or libraries need it (C++ cannot be linked statically)
|
||||
$extra_libs .= (empty($extra_libs) ? '' : ' ') . ($this->hasCpp() ? '-lc++ ' : '');
|
||||
if (!$this->getOption('bloat', false)) {
|
||||
$extra_libs .= (empty($extra_libs) ? '' : ' ') . implode(' ', $this->getAllStaticLibFiles());
|
||||
} else {
|
||||
logger()->info('bloat linking');
|
||||
$extra_libs .= (empty($extra_libs) ? '' : ' ') . implode(' ', array_map(fn ($x) => "-Wl,-force_load,{$x}", array_filter($this->getAllStaticLibFiles())));
|
||||
}
|
||||
$this->setOption('extra-libs', $extra_libs);
|
||||
|
||||
SourcePatcher::patchBeforeBuildconf($this);
|
||||
|
||||
shell()->cd(SOURCE_PATH . '/php-src')->exec('./buildconf --force');
|
||||
|
||||
SourcePatcher::patchBeforeConfigure($this);
|
||||
|
||||
$json_74 = $this->getPHPVersionID() < 80000 ? '--enable-json ' : '';
|
||||
$zts = $this->getOption('enable-zts', false) ? '--enable-zts --disable-zend-signals ' : '';
|
||||
|
||||
$enableCli = ($build_target & BUILD_TARGET_CLI) === BUILD_TARGET_CLI;
|
||||
$enableFpm = ($build_target & BUILD_TARGET_FPM) === BUILD_TARGET_FPM;
|
||||
$enableMicro = ($build_target & BUILD_TARGET_MICRO) === BUILD_TARGET_MICRO;
|
||||
$enableEmbed = ($build_target & BUILD_TARGET_EMBED) === BUILD_TARGET_EMBED;
|
||||
|
||||
shell()->cd(SOURCE_PATH . '/php-src')
|
||||
->exec(
|
||||
'./configure ' .
|
||||
'--prefix= ' .
|
||||
'--with-valgrind=no ' . // Not detect memory leak
|
||||
'--enable-shared=no ' .
|
||||
'--enable-static=yes ' .
|
||||
"CFLAGS='{$this->arch_c_flags} -Werror=unknown-warning-option' " .
|
||||
'--disable-all ' .
|
||||
'--disable-cgi ' .
|
||||
'--disable-phpdbg ' .
|
||||
($enableCli ? '--enable-cli ' : '--disable-cli ') .
|
||||
($enableFpm ? '--enable-fpm ' : '--disable-fpm ') .
|
||||
($enableEmbed ? '--enable-embed=static ' : '--disable-embed ') .
|
||||
($enableMicro ? '--enable-micro ' : '--disable-micro ') .
|
||||
$json_74 .
|
||||
$zts .
|
||||
$this->makeExtensionArgs()
|
||||
);
|
||||
|
||||
SourcePatcher::patchBeforeMake($this);
|
||||
|
||||
$this->cleanMake();
|
||||
|
||||
if ($enableCli) {
|
||||
logger()->info('building cli');
|
||||
$this->buildCli();
|
||||
}
|
||||
if ($enableFpm) {
|
||||
logger()->info('building fpm');
|
||||
$this->buildFpm();
|
||||
}
|
||||
if ($enableMicro) {
|
||||
logger()->info('building micro');
|
||||
$this->buildMicro();
|
||||
}
|
||||
if ($enableEmbed) {
|
||||
logger()->info('building embed');
|
||||
if ($enableMicro) {
|
||||
FileSystem::replaceFileStr(SOURCE_PATH . '/php-src/Makefile', 'OVERALL_TARGET =', 'OVERALL_TARGET = libphp.la');
|
||||
}
|
||||
$this->buildEmbed();
|
||||
}
|
||||
|
||||
if (php_uname('m') === $this->getOption('arch')) {
|
||||
$this->sanityCheck($build_target);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Build cli sapi
|
||||
*
|
||||
* @throws RuntimeException
|
||||
* @throws FileSystemException
|
||||
*/
|
||||
public function buildCli(): void
|
||||
{
|
||||
$vars = SystemUtil::makeEnvVarString([
|
||||
'EXTRA_CFLAGS' => '-g -Os', // with debug information, but optimize for size
|
||||
'EXTRA_LIBS' => "{$this->getOption('extra-libs')} /usr/lib/libm.a",
|
||||
]);
|
||||
|
||||
$shell = shell()->cd(SOURCE_PATH . '/php-src');
|
||||
$shell->exec('sed -ie "s|//lib|/lib|g" Makefile');
|
||||
$shell->exec("make -j{$this->concurrency} {$vars} cli");
|
||||
if (!$this->getOption('no-strip', false)) {
|
||||
$shell->exec('strip sapi/cli/php');
|
||||
}
|
||||
$this->deployBinary(BUILD_TARGET_CLI);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build phpmicro sapi
|
||||
*
|
||||
* @throws FileSystemException
|
||||
* @throws RuntimeException
|
||||
* @throws WrongUsageException
|
||||
*/
|
||||
public function buildMicro(): void
|
||||
{
|
||||
if ($this->getPHPVersionID() < 80000) {
|
||||
throw new WrongUsageException('phpmicro only support PHP >= 8.0!');
|
||||
}
|
||||
if ($this->getExt('phar')) {
|
||||
$this->phar_patched = true;
|
||||
SourcePatcher::patchMicro(['phar']);
|
||||
}
|
||||
|
||||
$enable_fake_cli = $this->getOption('with-micro-fake-cli', false) ? ' -DPHP_MICRO_FAKE_CLI' : '';
|
||||
$vars = [
|
||||
// with debug information, optimize for size, remove identifiers, patch fake cli for micro
|
||||
'EXTRA_CFLAGS' => '-g -Os' . $enable_fake_cli,
|
||||
// link resolv library (macOS needs it)
|
||||
'EXTRA_LIBS' => "{$this->getOption('extra-libs')} /usr/lib/libm.a",
|
||||
];
|
||||
$vars = SystemUtil::makeEnvVarString($vars);
|
||||
|
||||
shell()->cd(SOURCE_PATH . '/php-src')
|
||||
->exec("make -j{$this->concurrency} {$vars} micro");
|
||||
|
||||
if (!$this->getOption('no-strip', false)) {
|
||||
shell()->cd(SOURCE_PATH . '/php-src/sapi/micro')->exec('strip --strip-all micro.sfx');
|
||||
}
|
||||
$this->deployBinary(BUILD_TARGET_MICRO);
|
||||
|
||||
if ($this->phar_patched) {
|
||||
SourcePatcher::patchMicro(['phar'], true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Build fpm sapi
|
||||
*
|
||||
* @throws RuntimeException
|
||||
* @throws FileSystemException
|
||||
*/
|
||||
public function buildFpm(): void
|
||||
{
|
||||
$vars = SystemUtil::makeEnvVarString([
|
||||
'EXTRA_CFLAGS' => '-g -Os', // with debug information, but optimize for size
|
||||
'EXTRA_LIBS' => "{$this->getOption('extra-libs')} /usr/lib/libm.a", // link resolv library (macOS needs it)
|
||||
]);
|
||||
|
||||
$shell = shell()->cd(SOURCE_PATH . '/php-src');
|
||||
$shell->exec("make -j{$this->concurrency} {$vars} fpm");
|
||||
if (!$this->getOption('no-strip', false)) {
|
||||
$shell->exec('strip sapi/fpm/php-fpm');
|
||||
}
|
||||
$this->deployBinary(BUILD_TARGET_FPM);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build embed sapi
|
||||
*
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public function buildEmbed(): void
|
||||
{
|
||||
$vars = SystemUtil::makeEnvVarString([
|
||||
'EXTRA_CFLAGS' => '-g -Os', // with debug information, but optimize for size
|
||||
'EXTRA_LIBS' => "{$this->getOption('extra-libs')} /usr/lib/libm.a", // link resolv library (macOS needs it)
|
||||
]);
|
||||
|
||||
shell()
|
||||
->cd(SOURCE_PATH . '/php-src')
|
||||
->exec('make INSTALL_ROOT=' . BUILD_ROOT_PATH . " -j{$this->concurrency} {$vars} install")
|
||||
// Workaround for https://github.com/php/php-src/issues/12082
|
||||
->exec('rm -Rf ' . BUILD_ROOT_PATH . '/lib/php-o')
|
||||
->exec('mkdir ' . BUILD_ROOT_PATH . '/lib/php-o')
|
||||
->cd(BUILD_ROOT_PATH . '/lib/php-o')
|
||||
->exec('ar x ' . BUILD_ROOT_PATH . '/lib/libphp.a')
|
||||
->exec('rm ' . BUILD_ROOT_PATH . '/lib/libphp.a')
|
||||
->exec('ar rcs ' . BUILD_ROOT_PATH . '/lib/libphp.a *.o')
|
||||
->exec('rm -Rf ' . BUILD_ROOT_PATH . '/lib/php-o');
|
||||
}
|
||||
}
|
||||
46
src/SPC/builder/freebsd/SystemUtil.php
Normal file
46
src/SPC/builder/freebsd/SystemUtil.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace SPC\builder\freebsd;
|
||||
|
||||
use SPC\builder\traits\UnixSystemUtilTrait;
|
||||
use SPC\exception\RuntimeException;
|
||||
use SPC\exception\WrongUsageException;
|
||||
|
||||
class SystemUtil
|
||||
{
|
||||
/** Unix System Util Compatible */
|
||||
use UnixSystemUtilTrait;
|
||||
|
||||
/**
|
||||
* Get Logic CPU Count for macOS
|
||||
*
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public static function getCpuCount(): int
|
||||
{
|
||||
[$ret, $output] = shell()->execWithResult('sysctl -n hw.ncpu');
|
||||
if ($ret !== 0) {
|
||||
throw new RuntimeException('Failed to get cpu count');
|
||||
}
|
||||
|
||||
return (int) $output[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Target Arch CFlags
|
||||
*
|
||||
* @param string $arch Arch Name
|
||||
* @return string return Arch CFlags string
|
||||
* @throws WrongUsageException
|
||||
*/
|
||||
public static function getArchCFlags(string $arch): string
|
||||
{
|
||||
return match ($arch) {
|
||||
'amd64', 'x86_64' => '--target=x86_64-unknown-freebsd',
|
||||
'arm64','aarch64' => '--target=aarch-unknown-freebsd',
|
||||
default => throw new WrongUsageException('unsupported arch: ' . $arch),
|
||||
};
|
||||
}
|
||||
}
|
||||
27
src/SPC/builder/freebsd/library/BSDLibraryBase.php
Normal file
27
src/SPC/builder/freebsd/library/BSDLibraryBase.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace SPC\builder\freebsd\library;
|
||||
|
||||
use SPC\builder\BuilderBase;
|
||||
use SPC\builder\freebsd\BSDBuilder;
|
||||
use SPC\builder\LibraryBase;
|
||||
use SPC\builder\traits\UnixLibraryTrait;
|
||||
|
||||
abstract class BSDLibraryBase extends LibraryBase
|
||||
{
|
||||
use UnixLibraryTrait;
|
||||
|
||||
protected array $headers;
|
||||
|
||||
public function __construct(protected BSDBuilder $builder)
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function getBuilder(): BuilderBase
|
||||
{
|
||||
return $this->builder;
|
||||
}
|
||||
}
|
||||
12
src/SPC/builder/freebsd/library/bzip2.php
Normal file
12
src/SPC/builder/freebsd/library/bzip2.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace SPC\builder\freebsd\library;
|
||||
|
||||
class bzip2 extends BSDLibraryBase
|
||||
{
|
||||
use \SPC\builder\unix\library\bzip2;
|
||||
|
||||
public const NAME = 'bzip2';
|
||||
}
|
||||
21
src/SPC/builder/freebsd/library/curl.php
Normal file
21
src/SPC/builder/freebsd/library/curl.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace SPC\builder\freebsd\library;
|
||||
|
||||
class curl extends BSDLibraryBase
|
||||
{
|
||||
use \SPC\builder\unix\library\curl;
|
||||
|
||||
public const NAME = 'curl';
|
||||
|
||||
public function getStaticLibFiles(string $style = 'autoconf', bool $recursive = true): string
|
||||
{
|
||||
$libs = parent::getStaticLibFiles($style, $recursive);
|
||||
if ($this->builder->getLib('openssl')) {
|
||||
$this->builder->setOption('extra-libs', $this->builder->getOption('extra-libs') . ' /usr/lib/libpthread.a /usr/lib/libdl.a');
|
||||
}
|
||||
return $libs;
|
||||
}
|
||||
}
|
||||
12
src/SPC/builder/freebsd/library/onig.php
Normal file
12
src/SPC/builder/freebsd/library/onig.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace SPC\builder\freebsd\library;
|
||||
|
||||
class onig extends BSDLibraryBase
|
||||
{
|
||||
use \SPC\builder\unix\library\onig;
|
||||
|
||||
public const NAME = 'onig';
|
||||
}
|
||||
63
src/SPC/builder/freebsd/library/openssl.php
Normal file
63
src/SPC/builder/freebsd/library/openssl.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2022 Yun Dou <dixyes@gmail.com>
|
||||
*
|
||||
* lwmbs is licensed under Mulan PSL v2. You can use this
|
||||
* software according to the terms and conditions of the
|
||||
* Mulan PSL v2. You may obtain a copy of Mulan PSL v2 at:
|
||||
*
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
|
||||
* INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace SPC\builder\freebsd\library;
|
||||
|
||||
use SPC\builder\macos\library\MacOSLibraryBase;
|
||||
use SPC\exception\FileSystemException;
|
||||
use SPC\exception\RuntimeException;
|
||||
use SPC\exception\WrongUsageException;
|
||||
|
||||
class openssl extends BSDLibraryBase
|
||||
{
|
||||
public const NAME = 'openssl';
|
||||
|
||||
/**
|
||||
* @throws FileSystemException
|
||||
* @throws RuntimeException
|
||||
* @throws WrongUsageException
|
||||
*/
|
||||
protected function build(): void
|
||||
{
|
||||
[$lib,,$destdir] = SEPARATED_PATH;
|
||||
|
||||
// lib:zlib
|
||||
$extra = '';
|
||||
$ex_lib = '';
|
||||
$zlib = $this->builder->getLib('zlib');
|
||||
if ($zlib instanceof MacOSLibraryBase) {
|
||||
$extra = 'zlib';
|
||||
$ex_lib = trim($zlib->getStaticLibFiles() . ' ' . $ex_lib);
|
||||
}
|
||||
|
||||
shell()->cd($this->source_dir)
|
||||
->exec(
|
||||
"./Configure no-shared {$extra} " .
|
||||
'--prefix=/ ' . // use prefix=/
|
||||
"--libdir={$lib} " .
|
||||
'--openssldir=/etc/ssl ' .
|
||||
'BSD-' . arch2gnu($this->builder->getOption('arch'))
|
||||
)
|
||||
->exec('make clean')
|
||||
->exec("make -j{$this->builder->concurrency} CNF_EX_LIBS=\"{$ex_lib}\"")
|
||||
->exec("make install_sw DESTDIR={$destdir}");
|
||||
$this->patchPkgconfPrefix(['libssl.pc', 'openssl.pc', 'libcrypto.pc']);
|
||||
}
|
||||
}
|
||||
15
src/SPC/builder/freebsd/library/pkgconfig.php
Normal file
15
src/SPC/builder/freebsd/library/pkgconfig.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace SPC\builder\freebsd\library;
|
||||
|
||||
/**
|
||||
* gmp is a template library class for unix
|
||||
*/
|
||||
class pkgconfig extends BSDLibraryBase
|
||||
{
|
||||
use \SPC\builder\unix\library\pkgconfig;
|
||||
|
||||
public const NAME = 'pkg-config';
|
||||
}
|
||||
12
src/SPC/builder/freebsd/library/zlib.php
Normal file
12
src/SPC/builder/freebsd/library/zlib.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace SPC\builder\freebsd\library;
|
||||
|
||||
class zlib extends BSDLibraryBase
|
||||
{
|
||||
use \SPC\builder\unix\library\zlib;
|
||||
|
||||
public const NAME = 'zlib';
|
||||
}
|
||||
@@ -10,6 +10,7 @@ use SPC\builder\traits\UnixBuilderTrait;
|
||||
use SPC\exception\FileSystemException;
|
||||
use SPC\exception\RuntimeException;
|
||||
use SPC\exception\WrongUsageException;
|
||||
use SPC\store\FileSystem;
|
||||
use SPC\store\SourcePatcher;
|
||||
|
||||
class LinuxBuilder extends BuilderBase
|
||||
@@ -17,15 +18,9 @@ class LinuxBuilder extends BuilderBase
|
||||
/** Unix compatible builder methods */
|
||||
use UnixBuilderTrait;
|
||||
|
||||
/** @var string Using libc [musl,glibc] */
|
||||
public string $libc;
|
||||
|
||||
/** @var array Tune cflags */
|
||||
public array $tune_c_flags;
|
||||
|
||||
/** @var string pkg-config env, including PKG_CONFIG_PATH, PKG_CONFIG */
|
||||
public string $pkgconf_env;
|
||||
|
||||
/** @var bool Micro patch phar flag */
|
||||
private bool $phar_patched = false;
|
||||
|
||||
@@ -39,48 +34,55 @@ class LinuxBuilder extends BuilderBase
|
||||
$this->options = $options;
|
||||
|
||||
// ---------- set necessary options ----------
|
||||
// set C Compiler (default: alpine: gcc, others: musl-gcc)
|
||||
$this->setOptionIfNotExist('cc', match (SystemUtil::getOSRelease()['dist']) {
|
||||
'alpine' => 'gcc',
|
||||
default => 'musl-gcc'
|
||||
});
|
||||
// set C++ Compiler (default: g++)
|
||||
$this->setOptionIfNotExist('cxx', 'g++');
|
||||
// set C/C++ compilers (default: alpine: gcc, others: musl-cross-make)
|
||||
if (SystemUtil::isMuslDist()) {
|
||||
f_putenv("CC={$this->getOption('cc', 'gcc')}");
|
||||
f_putenv("CXX={$this->getOption('cxx', 'g++')}");
|
||||
f_putenv("AR={$this->getOption('ar', 'ar')}");
|
||||
f_putenv("LD={$this->getOption('ld', 'ld.gold')}");
|
||||
} else {
|
||||
$arch = arch2gnu(php_uname('m'));
|
||||
f_putenv("CC={$this->getOption('cc', "{$arch}-linux-musl-gcc")}");
|
||||
f_putenv("CXX={$this->getOption('cxx', "{$arch}-linux-musl-g++")}");
|
||||
f_putenv("AR={$this->getOption('ar', "{$arch}-linux-musl-ar")}");
|
||||
f_putenv("LD={$this->getOption('ld', 'ld.gold')}");
|
||||
f_putenv("PATH=/usr/local/musl/bin:/usr/local/musl/{$arch}-linux-musl/bin:" . BUILD_ROOT_PATH . '/bin:' . getenv('PATH'));
|
||||
|
||||
// set library path, some libraries need it. (We cannot use `putenv` here, because cmake will be confused)
|
||||
$this->setOptionIfNotExist('library_path', "LIBRARY_PATH=/usr/local/musl/{$arch}-linux-musl/lib");
|
||||
$this->setOptionIfNotExist('ld_library_path', "LD_LIBRARY_PATH=/usr/local/musl/{$arch}-linux-musl/lib");
|
||||
|
||||
// check musl-cross make installed if we use musl-cross-make
|
||||
if (str_ends_with(getenv('CC'), 'linux-musl-gcc') && !file_exists("/usr/local/musl/bin/{$arch}-linux-musl-gcc")) {
|
||||
throw new WrongUsageException('musl-cross-make not installed, please install it first. (You can use `doctor` command to install it)');
|
||||
}
|
||||
}
|
||||
|
||||
// set PKG_CONFIG
|
||||
f_putenv('PKG_CONFIG=' . BUILD_ROOT_PATH . '/bin/pkg-config');
|
||||
// set PKG_CONFIG_PATH
|
||||
f_putenv('PKG_CONFIG_PATH=' . BUILD_LIB_PATH . '/pkgconfig');
|
||||
|
||||
// set arch (default: current)
|
||||
$this->setOptionIfNotExist('arch', php_uname('m'));
|
||||
$this->setOptionIfNotExist('gnu-arch', arch2gnu($this->getOption('arch')));
|
||||
|
||||
// ---------- set necessary compile environments ----------
|
||||
// set libc
|
||||
$this->libc = 'musl'; // SystemUtil::selectLibc($this->cc);
|
||||
// concurrency
|
||||
$this->concurrency = SystemUtil::getCpuCount();
|
||||
// cflags
|
||||
$this->arch_c_flags = SystemUtil::getArchCFlags($this->getOption('cc'), $this->getOption('arch'));
|
||||
$this->arch_cxx_flags = SystemUtil::getArchCFlags($this->getOption('cxx'), $this->getOption('arch'));
|
||||
$this->tune_c_flags = SystemUtil::checkCCFlags(SystemUtil::getTuneCFlags($this->getOption('arch')), $this->getOption('cc'));
|
||||
$this->arch_c_flags = SystemUtil::getArchCFlags(getenv('CC'), $this->getOption('arch'));
|
||||
$this->arch_cxx_flags = SystemUtil::getArchCFlags(getenv('CXX'), $this->getOption('arch'));
|
||||
$this->tune_c_flags = SystemUtil::checkCCFlags(SystemUtil::getTuneCFlags($this->getOption('arch')), getenv('CC'));
|
||||
// cmake toolchain
|
||||
$this->cmake_toolchain_file = SystemUtil::makeCmakeToolchainFile(
|
||||
'Linux',
|
||||
$this->getOption('arch'),
|
||||
$this->arch_c_flags,
|
||||
$this->getOption('cc'),
|
||||
$this->getOption('cxx'),
|
||||
getenv('CC'),
|
||||
getenv('CXX'),
|
||||
);
|
||||
// pkg-config
|
||||
$vars = [
|
||||
'PKG_CONFIG' => BUILD_ROOT_PATH . '/bin/pkg-config',
|
||||
'PKG_CONFIG_PATH' => BUILD_LIB_PATH . '/pkgconfig',
|
||||
];
|
||||
$this->pkgconf_env = SystemUtil::makeEnvVarString($vars);
|
||||
// configure environment
|
||||
$this->configure_env = SystemUtil::makeEnvVarString([
|
||||
...$vars,
|
||||
'CC' => $this->getOption('cc'),
|
||||
'CXX' => $this->getOption('cxx'),
|
||||
'PATH' => BUILD_ROOT_PATH . '/bin:' . getenv('PATH'),
|
||||
]);
|
||||
// cross-compile does not support yet
|
||||
|
||||
// cross-compiling is not supported yet
|
||||
/*if (php_uname('m') !== $this->arch) {
|
||||
$this->cross_compile_prefix = SystemUtil::getCrossCompilePrefix($this->cc, $this->arch);
|
||||
logger()->info('using cross compile prefix: ' . $this->cross_compile_prefix);
|
||||
@@ -133,33 +135,16 @@ class LinuxBuilder extends BuilderBase
|
||||
} else {
|
||||
$extra_libs .= (empty($extra_libs) ? '' : ' ') . implode(' ', array_map(fn ($x) => "-Xcompiler {$x}", array_filter($this->getAllStaticLibFiles())));
|
||||
}
|
||||
// add libstdc++, some extensions or libraries need it (C++ cannot be linked statically)
|
||||
$extra_libs .= (empty($extra_libs) ? '' : ' ') . ($this->hasCppExtension() ? '-lstdc++ ' : '');
|
||||
// add libstdc++, some extensions or libraries need it
|
||||
$extra_libs .= (empty($extra_libs) ? '' : ' ') . ($this->hasCpp() ? '-lstdc++ ' : '');
|
||||
$this->setOption('extra-libs', $extra_libs);
|
||||
|
||||
$cflags = $this->arch_c_flags;
|
||||
$use_lld = '';
|
||||
|
||||
switch ($this->libc) {
|
||||
case 'musl_wrapper':
|
||||
case 'glibc':
|
||||
$cflags .= ' -static-libgcc -I"' . BUILD_INCLUDE_PATH . '"';
|
||||
break;
|
||||
case 'musl':
|
||||
if (str_ends_with($this->getOption('cc'), 'clang') && SystemUtil::findCommand('lld')) {
|
||||
$use_lld = '-Xcompiler -fuse-ld=lld';
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new WrongUsageException('libc ' . $this->libc . ' is not implemented yet');
|
||||
}
|
||||
|
||||
$envs = $this->pkgconf_env . ' ' . SystemUtil::makeEnvVarString([
|
||||
'CC' => $this->getOption('cc'),
|
||||
'CXX' => $this->getOption('cxx'),
|
||||
// prepare build php envs
|
||||
$envs_build_php = SystemUtil::makeEnvVarString([
|
||||
'CFLAGS' => $cflags,
|
||||
'LIBS' => '-ldl -lpthread',
|
||||
'PATH' => BUILD_ROOT_PATH . '/bin:' . getenv('PATH'),
|
||||
]);
|
||||
|
||||
SourcePatcher::patchBeforeBuildconf($this);
|
||||
@@ -178,9 +163,16 @@ class LinuxBuilder extends BuilderBase
|
||||
$maxExecutionTimers = '';
|
||||
$zts = '';
|
||||
}
|
||||
$disable_jit = $this->getOption('disable-opcache-jit', false) ? '--disable-opcache-jit ' : '';
|
||||
|
||||
$enableCli = ($build_target & BUILD_TARGET_CLI) === BUILD_TARGET_CLI;
|
||||
$enableFpm = ($build_target & BUILD_TARGET_FPM) === BUILD_TARGET_FPM;
|
||||
$enableMicro = ($build_target & BUILD_TARGET_MICRO) === BUILD_TARGET_MICRO;
|
||||
$enableEmbed = ($build_target & BUILD_TARGET_EMBED) === BUILD_TARGET_EMBED;
|
||||
|
||||
shell()->cd(SOURCE_PATH . '/php-src')
|
||||
->exec(
|
||||
"{$this->getOption('ld_library_path')} " .
|
||||
'./configure ' .
|
||||
'--prefix= ' .
|
||||
'--with-valgrind=no ' .
|
||||
@@ -189,40 +181,45 @@ class LinuxBuilder extends BuilderBase
|
||||
'--disable-all ' .
|
||||
'--disable-cgi ' .
|
||||
'--disable-phpdbg ' .
|
||||
'--enable-cli ' .
|
||||
'--enable-fpm ' .
|
||||
($enableCli ? '--enable-cli ' : '--disable-cli ') .
|
||||
($enableFpm ? '--enable-fpm ' : '--disable-fpm ') .
|
||||
($enableEmbed ? '--enable-embed=static ' : '--disable-embed ') .
|
||||
($enableMicro ? '--enable-micro=all-static ' : '--disable-micro ') .
|
||||
$disable_jit .
|
||||
$json_74 .
|
||||
$zts .
|
||||
$maxExecutionTimers .
|
||||
'--enable-micro=all-static ' .
|
||||
$this->makeExtensionArgs() . ' ' .
|
||||
$envs
|
||||
$envs_build_php
|
||||
);
|
||||
|
||||
SourcePatcher::patchBeforeMake($this);
|
||||
|
||||
$this->cleanMake();
|
||||
|
||||
if (($build_target & BUILD_TARGET_CLI) === BUILD_TARGET_CLI) {
|
||||
if ($enableCli) {
|
||||
logger()->info('building cli');
|
||||
$this->buildCli($extra_libs, $use_lld);
|
||||
$this->buildCli();
|
||||
}
|
||||
if (($build_target & BUILD_TARGET_FPM) === BUILD_TARGET_FPM) {
|
||||
if ($enableFpm) {
|
||||
logger()->info('building fpm');
|
||||
$this->buildFpm($extra_libs, $use_lld);
|
||||
$this->buildFpm();
|
||||
}
|
||||
if (($build_target & BUILD_TARGET_MICRO) === BUILD_TARGET_MICRO) {
|
||||
if ($enableMicro) {
|
||||
logger()->info('building micro');
|
||||
$this->buildMicro($extra_libs, $use_lld, $cflags);
|
||||
$this->buildMicro();
|
||||
}
|
||||
if ($enableEmbed) {
|
||||
logger()->info('building embed');
|
||||
if ($enableMicro) {
|
||||
FileSystem::replaceFileStr(SOURCE_PATH . '/php-src/Makefile', 'OVERALL_TARGET =', 'OVERALL_TARGET = libphp.la');
|
||||
}
|
||||
$this->buildEmbed();
|
||||
}
|
||||
|
||||
if (php_uname('m') === $this->getOption('arch')) {
|
||||
$this->sanityCheck($build_target);
|
||||
}
|
||||
|
||||
if ($this->phar_patched) {
|
||||
SourcePatcher::patchMicro(['phar'], true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -231,13 +228,9 @@ class LinuxBuilder extends BuilderBase
|
||||
* @throws RuntimeException
|
||||
* @throws FileSystemException
|
||||
*/
|
||||
public function buildCli(string $extra_libs, string $use_lld): void
|
||||
public function buildCli(): void
|
||||
{
|
||||
$vars = SystemUtil::makeEnvVarString([
|
||||
'EXTRA_CFLAGS' => '-g -Os -fno-ident ' . implode(' ', array_map(fn ($x) => "-Xcompiler {$x}", $this->tune_c_flags)),
|
||||
'EXTRA_LIBS' => $extra_libs,
|
||||
'EXTRA_LDFLAGS_PROGRAM' => "{$use_lld} -all-static",
|
||||
]);
|
||||
$vars = SystemUtil::makeEnvVarString($this->getBuildVars());
|
||||
shell()->cd(SOURCE_PATH . '/php-src')
|
||||
->exec('sed -i "s|//lib|/lib|g" Makefile')
|
||||
->exec("make -j{$this->concurrency} {$vars} cli");
|
||||
@@ -252,25 +245,23 @@ class LinuxBuilder extends BuilderBase
|
||||
/**
|
||||
* Build phpmicro sapi
|
||||
*
|
||||
* @throws RuntimeException
|
||||
* @throws FileSystemException
|
||||
* @throws RuntimeException
|
||||
* @throws WrongUsageException
|
||||
*/
|
||||
public function buildMicro(string $extra_libs, string $use_lld, string $cflags): void
|
||||
public function buildMicro(): void
|
||||
{
|
||||
if ($this->getPHPVersionID() < 80000) {
|
||||
throw new RuntimeException('phpmicro only support PHP >= 8.0!');
|
||||
throw new WrongUsageException('phpmicro only support PHP >= 8.0!');
|
||||
}
|
||||
if ($this->getExt('phar')) {
|
||||
$this->phar_patched = true;
|
||||
SourcePatcher::patchMicro(['phar']);
|
||||
}
|
||||
|
||||
$enable_fake_cli = $this->getOption('with-micro-fake-cli', false) ? ' -DPHP_MICRO_FAKE_CLI' : '';
|
||||
$vars = SystemUtil::makeEnvVarString([
|
||||
'EXTRA_CFLAGS' => '-g -Os -fno-ident ' . implode(' ', array_map(fn ($x) => "-Xcompiler {$x}", $this->tune_c_flags)) . $enable_fake_cli,
|
||||
'EXTRA_LIBS' => $extra_libs,
|
||||
'EXTRA_LDFLAGS_PROGRAM' => "{$cflags} {$use_lld} -all-static",
|
||||
]);
|
||||
$vars = SystemUtil::makeEnvVarString($this->getBuildVars([
|
||||
'EXTRA_CFLAGS' => $this->getOption('with-micro-fake-cli', false) ? ' -DPHP_MICRO_FAKE_CLI' : '',
|
||||
]));
|
||||
shell()->cd(SOURCE_PATH . '/php-src')
|
||||
->exec('sed -i "s|//lib|/lib|g" Makefile')
|
||||
->exec("make -j{$this->concurrency} {$vars} micro");
|
||||
@@ -280,6 +271,10 @@ class LinuxBuilder extends BuilderBase
|
||||
}
|
||||
|
||||
$this->deployBinary(BUILD_TARGET_MICRO);
|
||||
|
||||
if ($this->phar_patched) {
|
||||
SourcePatcher::patchMicro(['phar'], true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -288,14 +283,9 @@ class LinuxBuilder extends BuilderBase
|
||||
* @throws FileSystemException
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public function buildFpm(string $extra_libs, string $use_lld): void
|
||||
public function buildFpm(): void
|
||||
{
|
||||
$vars = SystemUtil::makeEnvVarString([
|
||||
'EXTRA_CFLAGS' => '-g -Os -fno-ident ' . implode(' ', array_map(fn ($x) => "-Xcompiler {$x}", $this->tune_c_flags)),
|
||||
'EXTRA_LIBS' => $extra_libs,
|
||||
'EXTRA_LDFLAGS_PROGRAM' => "{$use_lld} -all-static",
|
||||
]);
|
||||
|
||||
$vars = SystemUtil::makeEnvVarString($this->getBuildVars());
|
||||
shell()->cd(SOURCE_PATH . '/php-src')
|
||||
->exec('sed -i "s|//lib|/lib|g" Makefile')
|
||||
->exec("make -j{$this->concurrency} {$vars} fpm");
|
||||
@@ -306,4 +296,36 @@ class LinuxBuilder extends BuilderBase
|
||||
|
||||
$this->deployBinary(BUILD_TARGET_FPM);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build embed sapi
|
||||
*
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public function buildEmbed(): void
|
||||
{
|
||||
$vars = SystemUtil::makeEnvVarString($this->getBuildVars());
|
||||
|
||||
shell()
|
||||
->cd(SOURCE_PATH . '/php-src')
|
||||
->exec('sed -i "s|//lib|/lib|g" Makefile')
|
||||
->exec('make INSTALL_ROOT=' . BUILD_ROOT_PATH . " -j{$this->concurrency} {$vars} install");
|
||||
}
|
||||
|
||||
private function getBuildVars($input = []): array
|
||||
{
|
||||
$use_lld = '';
|
||||
if (str_ends_with(getenv('CC'), 'clang') && SystemUtil::findCommand('lld')) {
|
||||
$use_lld = '-Xcompiler -fuse-ld=lld';
|
||||
}
|
||||
$optimization = $this->getOption('no-strip', false) ? '-g -O0' : '-g0 -Os';
|
||||
$cflags = isset($input['EXTRA_CFLAGS']) && $input['EXTRA_CFLAGS'] ? " {$input['EXTRA_CFLAGS']}" : '';
|
||||
$libs = isset($input['EXTRA_LIBS']) && $input['EXTRA_LIBS'] ? " {$input['EXTRA_LIBS']}" : '';
|
||||
$ldflags = isset($input['EXTRA_LDFLAGS_PROGRAM']) && $input['EXTRA_LDFLAGS_PROGRAM'] ? " {$input['EXTRA_LDFLAGS_PROGRAM']}" : '';
|
||||
return [
|
||||
'EXTRA_CFLAGS' => "{$optimization} -fno-ident -fPIE " . implode(' ', array_map(fn ($x) => "-Xcompiler {$x}", $this->tune_c_flags)) . $cflags,
|
||||
'EXTRA_LIBS' => $this->getOption('extra-libs', '') . $libs,
|
||||
'EXTRA_LDFLAGS_PROGRAM' => "{$use_lld} -all-static" . $ldflags,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,19 @@ class SystemUtil
|
||||
'ver' => 'unknown',
|
||||
];
|
||||
switch (true) {
|
||||
case file_exists('/etc/centos-release'):
|
||||
$lines = file('/etc/centos-release');
|
||||
goto rh;
|
||||
case file_exists('/etc/redhat-release'):
|
||||
$lines = file('/etc/redhat-release');
|
||||
rh:
|
||||
foreach ($lines as $line) {
|
||||
if (preg_match('/release\s+(\d*(\.\d+)*)/', $line, $matches)) {
|
||||
$ret['dist'] = 'redhat';
|
||||
$ret['ver'] = $matches[1];
|
||||
}
|
||||
}
|
||||
break;
|
||||
case file_exists('/etc/os-release'):
|
||||
$lines = file('/etc/os-release');
|
||||
foreach ($lines as $line) {
|
||||
@@ -36,23 +49,15 @@ class SystemUtil
|
||||
$ret['dist'] = 'redhat';
|
||||
}
|
||||
break;
|
||||
case file_exists('/etc/centos-release'):
|
||||
$lines = file('/etc/centos-release');
|
||||
goto rh;
|
||||
case file_exists('/etc/redhat-release'):
|
||||
$lines = file('/etc/redhat-release');
|
||||
rh:
|
||||
foreach ($lines as $line) {
|
||||
if (preg_match('/release\s+(\d+(\.\d+)*)/', $line, $matches)) {
|
||||
$ret['dist'] = 'redhat';
|
||||
$ret['ver'] = $matches[1];
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
public static function isMuslDist(): bool
|
||||
{
|
||||
return static::getOSRelease()['dist'] === 'alpine';
|
||||
}
|
||||
|
||||
public static function getCpuCount(): int
|
||||
{
|
||||
$ncpu = 1;
|
||||
@@ -121,7 +126,7 @@ class SystemUtil
|
||||
|
||||
public static function checkCCFlag(string $flag, string $cc): string
|
||||
{
|
||||
[$ret] = shell()->execWithResult("echo | {$cc} -E -x c - {$flag}");
|
||||
[$ret] = shell()->execWithResult("echo | {$cc} -E -x c - {$flag} 2>/dev/null");
|
||||
if ($ret != 0) {
|
||||
return '';
|
||||
}
|
||||
|
||||
@@ -8,9 +8,6 @@ use SPC\builder\BuilderBase;
|
||||
use SPC\builder\LibraryBase;
|
||||
use SPC\builder\linux\LinuxBuilder;
|
||||
use SPC\builder\traits\UnixLibraryTrait;
|
||||
use SPC\exception\FileSystemException;
|
||||
use SPC\exception\RuntimeException;
|
||||
use SPC\exception\WrongUsageException;
|
||||
|
||||
abstract class LinuxLibraryBase extends LibraryBase
|
||||
{
|
||||
@@ -36,53 +33,4 @@ abstract class LinuxLibraryBase extends LibraryBase
|
||||
{
|
||||
return $this->builder;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws RuntimeException
|
||||
* @throws FileSystemException
|
||||
* @throws WrongUsageException
|
||||
*/
|
||||
public function tryBuild(bool $force_build = false): int
|
||||
{
|
||||
// 传入 true,表明直接编译
|
||||
if ($force_build) {
|
||||
logger()->info('Building required library [' . static::NAME . ']');
|
||||
$this->patchBeforeBuild();
|
||||
$this->build();
|
||||
return BUILD_STATUS_OK;
|
||||
}
|
||||
|
||||
// 看看这些库是不是存在,如果不存在,则调用编译并返回结果状态
|
||||
foreach ($this->getStaticLibs() as $name) {
|
||||
if (!file_exists(BUILD_LIB_PATH . "/{$name}")) {
|
||||
$this->tryBuild(true);
|
||||
return BUILD_STATUS_OK;
|
||||
}
|
||||
}
|
||||
// 头文件同理
|
||||
foreach ($this->getHeaders() as $name) {
|
||||
if (!file_exists(BUILD_INCLUDE_PATH . "/{$name}")) {
|
||||
$this->tryBuild(true);
|
||||
return BUILD_STATUS_OK;
|
||||
}
|
||||
}
|
||||
// pkg-config 做特殊处理,如果是 pkg-config 就检查有没有 pkg-config 二进制
|
||||
if (static::NAME === 'pkg-config' && !file_exists(BUILD_ROOT_PATH . '/bin/pkg-config')) {
|
||||
$this->tryBuild(true);
|
||||
return BUILD_STATUS_OK;
|
||||
}
|
||||
// 到这里说明所有的文件都存在,就跳过编译
|
||||
return BUILD_STATUS_ALREADY;
|
||||
}
|
||||
|
||||
protected function makeFakePkgconfs(): void
|
||||
{
|
||||
$workspace = BUILD_ROOT_PATH;
|
||||
if ($workspace === '/') {
|
||||
$workspace = '';
|
||||
}
|
||||
foreach ($this->pkgconfs as $name => $content) {
|
||||
file_put_contents(BUILD_LIB_PATH . "/pkgconfig/{$name}", "prefix={$workspace}\n" . $content);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,11 +10,13 @@ class icu extends LinuxLibraryBase
|
||||
|
||||
protected function build(): void
|
||||
{
|
||||
$root = BUILD_ROOT_PATH;
|
||||
$cppflag = 'CPPFLAGS="-DU_CHARSET_IS_UTF8=1 -DU_USING_ICU_NAMESPACE=1 -DU_STATIC_IMPLEMENTATION=1"';
|
||||
$cppflags = 'CPPFLAGS="-DU_CHARSET_IS_UTF8=1 -DU_USING_ICU_NAMESPACE=1 -DU_STATIC_IMPLEMENTATION=1"';
|
||||
$cxxflags = 'CXXFLAGS="-std=c++11"';
|
||||
$ldflags = 'LDFLAGS="-static"';
|
||||
shell()->cd($this->source_dir . '/source')
|
||||
->exec(
|
||||
"{$this->builder->configure_env} {$cppflag} ./runConfigureICU Linux " .
|
||||
"{$cppflags} {$cxxflags} {$ldflags} " .
|
||||
'./runConfigureICU Linux ' .
|
||||
'--enable-static ' .
|
||||
'--disable-shared ' .
|
||||
'--with-data-packaging=static ' .
|
||||
@@ -25,7 +27,7 @@ class icu extends LinuxLibraryBase
|
||||
'--enable-tools=yes ' .
|
||||
'--enable-tests=no ' .
|
||||
'--enable-samples=no ' .
|
||||
"--prefix={$root}"
|
||||
'--prefix=' . BUILD_ROOT_PATH
|
||||
)
|
||||
->exec('make clean')
|
||||
->exec("make -j{$this->builder->concurrency}")
|
||||
|
||||
12
src/SPC/builder/linux/library/ldap.php
Normal file
12
src/SPC/builder/linux/library/ldap.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace SPC\builder\linux\library;
|
||||
|
||||
class ldap extends LinuxLibraryBase
|
||||
{
|
||||
use \SPC\builder\unix\library\ldap;
|
||||
|
||||
public const NAME = 'ldap';
|
||||
}
|
||||
50
src/SPC/builder/linux/library/libffi.php
Normal file
50
src/SPC/builder/linux/library/libffi.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace SPC\builder\linux\library;
|
||||
|
||||
use SPC\exception\RuntimeException;
|
||||
|
||||
class libffi extends LinuxLibraryBase
|
||||
{
|
||||
public const NAME = 'libffi';
|
||||
|
||||
/**
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public function build(): void
|
||||
{
|
||||
[$lib, , $destdir] = SEPARATED_PATH;
|
||||
|
||||
/*$env = $this->builder->pkgconf_env . ' CFLAGS="' . $this->builder->arch_c_flags . '"';
|
||||
|
||||
$env .= match ($this->builder->libc) {
|
||||
'musl_wrapper' => " CC='{$this->builder->getOption('cc')} --static -idirafter " . BUILD_INCLUDE_PATH .
|
||||
($this->builder->getOption('arch') === php_uname('m') ? '-idirafter /usr/include/ ' : '') .
|
||||
"-idirafter /usr/include/{$this->builder->getOption('arch')}-linux-gnu/'",
|
||||
'musl', 'glibc' => " CC='{$this->builder->getOption('cc')}'",
|
||||
default => throw new RuntimeException('unsupported libc: ' . $this->builder->libc),
|
||||
};*/
|
||||
|
||||
shell()->cd($this->source_dir)
|
||||
->exec(
|
||||
'./configure ' .
|
||||
'--enable-static ' .
|
||||
'--disable-shared ' .
|
||||
"--host={$this->builder->getOption('arch')}-unknown-linux " .
|
||||
"--target={$this->builder->getOption('arch')}-unknown-linux " .
|
||||
'--prefix= ' . // use prefix=/
|
||||
"--libdir={$lib}"
|
||||
)
|
||||
->exec('make clean')
|
||||
->exec("make -j{$this->builder->concurrency}")
|
||||
->exec("make install DESTDIR={$destdir}");
|
||||
|
||||
if (is_file(BUILD_ROOT_PATH . '/lib64/libffi.a')) {
|
||||
copy(BUILD_ROOT_PATH . '/lib64/libffi.a', BUILD_ROOT_PATH . '/lib/libffi.a');
|
||||
unlink(BUILD_ROOT_PATH . '/lib64/libffi.a');
|
||||
}
|
||||
$this->patchPkgconfPrefix(['libffi.pc']);
|
||||
}
|
||||
}
|
||||
@@ -20,36 +20,14 @@ declare(strict_types=1);
|
||||
|
||||
namespace SPC\builder\linux\library;
|
||||
|
||||
use SPC\builder\linux\SystemUtil;
|
||||
use SPC\exception\FileSystemException;
|
||||
use SPC\exception\RuntimeException;
|
||||
use SPC\exception\WrongUsageException;
|
||||
use SPC\store\FileSystem;
|
||||
|
||||
class libpng extends LinuxLibraryBase
|
||||
{
|
||||
public const NAME = 'libpng';
|
||||
|
||||
/**
|
||||
* @throws FileSystemException
|
||||
*/
|
||||
public function patchBeforeBuild(): bool
|
||||
{
|
||||
FileSystem::replaceFileStr(
|
||||
SOURCE_PATH . '/libpng/configure',
|
||||
'-lz',
|
||||
BUILD_LIB_PATH . '/libz.a'
|
||||
);
|
||||
if (SystemUtil::getOSRelease()['dist'] === 'alpine') {
|
||||
FileSystem::replaceFileStr(
|
||||
SOURCE_PATH . '/libpng/configure',
|
||||
'-lm',
|
||||
'/usr/lib/libm.a'
|
||||
);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws FileSystemException
|
||||
* @throws RuntimeException
|
||||
@@ -66,8 +44,8 @@ class libpng extends LinuxLibraryBase
|
||||
->exec('chmod +x ./configure')
|
||||
->exec('chmod +x ./install-sh')
|
||||
->exec(
|
||||
"{$this->builder->configure_env} ./configure " .
|
||||
"--host={$this->builder->getOption('gnu-arch')}-unknown-linux " .
|
||||
'LDFLAGS="-L' . BUILD_LIB_PATH . '" ' .
|
||||
'./configure ' .
|
||||
'--disable-shared ' .
|
||||
'--enable-static ' .
|
||||
'--enable-hardware-optimizations ' .
|
||||
@@ -76,10 +54,8 @@ class libpng extends LinuxLibraryBase
|
||||
'--prefix='
|
||||
)
|
||||
->exec('make clean')
|
||||
->exec("make -j{$this->builder->concurrency} DEFAULT_INCLUDES='-I. -I" . BUILD_INCLUDE_PATH . "' LIBS= libpng16.la")
|
||||
->exec('make install-libLTLIBRARIES install-data-am DESTDIR=' . BUILD_ROOT_PATH)
|
||||
->cd(BUILD_LIB_PATH)
|
||||
->exec('ln -sf libpng16.a libpng.a');
|
||||
->exec("make -j{$this->builder->concurrency} DEFAULT_INCLUDES='-I{$this->source_dir} -I" . BUILD_INCLUDE_PATH . "' LIBS= libpng16.la")
|
||||
->exec('make install-libLTLIBRARIES install-data-am DESTDIR=' . BUILD_ROOT_PATH);
|
||||
$this->patchPkgconfPrefix(['libpng16.pc'], PKGCONF_PATCH_PREFIX);
|
||||
$this->cleanLaFiles();
|
||||
}
|
||||
|
||||
@@ -19,22 +19,19 @@ class libxml2 extends LinuxLibraryBase
|
||||
public function build(): void
|
||||
{
|
||||
$enable_zlib = $this->builder->getLib('zlib') ? 'ON' : 'OFF';
|
||||
// $enable_icu = $this->builder->getLib('icu') ? 'ON' : 'OFF';
|
||||
$enable_icu = $this->builder->getLib('icu') ? 'ON' : 'OFF';
|
||||
$enable_xz = $this->builder->getLib('xz') ? 'ON' : 'OFF';
|
||||
|
||||
FileSystem::resetDir($this->source_dir . '/build');
|
||||
shell()->cd($this->source_dir . '/build')
|
||||
->exec(
|
||||
"{$this->builder->configure_env} " . ' cmake ' .
|
||||
"-DCMAKE_TOOLCHAIN_FILE={$this->builder->cmake_toolchain_file} " .
|
||||
'-DCMAKE_BUILD_TYPE=Release ' .
|
||||
'-DCMAKE_INSTALL_PREFIX=' . escapeshellarg(BUILD_ROOT_PATH) . ' ' .
|
||||
'cmake ' .
|
||||
"{$this->builder->makeCmakeArgs()} " .
|
||||
'-DBUILD_SHARED_LIBS=OFF ' .
|
||||
'-DCMAKE_INSTALL_BINDIR=' . escapeshellarg(BUILD_ROOT_PATH . '/bin') . ' ' .
|
||||
'-DLIBXML2_WITH_ICONV=ON ' .
|
||||
'-DIconv_IS_BUILT_IN=OFF ' .
|
||||
'-DLIBXML2_WITH_ICONV=ON ' .
|
||||
"-DLIBXML2_WITH_ZLIB={$enable_zlib} " .
|
||||
'-DLIBXML2_WITH_ICU=OFF ' .
|
||||
"-DLIBXML2_WITH_ICU={$enable_icu} " .
|
||||
"-DLIBXML2_WITH_LZMA={$enable_xz} " .
|
||||
'-DLIBXML2_WITH_PYTHON=OFF ' .
|
||||
'-DLIBXML2_WITH_PROGRAMS=OFF ' .
|
||||
@@ -42,6 +39,12 @@ class libxml2 extends LinuxLibraryBase
|
||||
'..'
|
||||
)
|
||||
->exec("cmake --build . -j {$this->builder->concurrency}")
|
||||
->exec('make install');
|
||||
->exec('make install DESTDIR=' . BUILD_ROOT_PATH);
|
||||
|
||||
FileSystem::replaceFileStr(
|
||||
BUILD_LIB_PATH . '/pkgconfig/libxml-2.0.pc',
|
||||
'-licudata -licui18n -licuuc',
|
||||
'-licui18n -licuuc -licudata'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ class nghttp2 extends LinuxLibraryBase
|
||||
|
||||
shell()->cd($this->source_dir)
|
||||
->exec(
|
||||
"{$this->builder->configure_env} ./configure " .
|
||||
'./configure ' .
|
||||
'--enable-static ' .
|
||||
'--disable-shared ' .
|
||||
"--host={$this->builder->getOption('gnu-arch')}-unknown-linux " .
|
||||
|
||||
@@ -41,8 +41,8 @@ class openssl extends LinuxLibraryBase
|
||||
$extra = '';
|
||||
$ex_lib = '-ldl -pthread';
|
||||
|
||||
$env = $this->builder->pkgconf_env . " CFLAGS='{$this->builder->arch_c_flags}'";
|
||||
$env .= " CC='{$this->builder->getOption('cc')} -static -idirafter " . BUILD_INCLUDE_PATH .
|
||||
$env = "CFLAGS='{$this->builder->arch_c_flags}'";
|
||||
$env .= " CC='" . getenv('CC') . ' -static -idirafter ' . BUILD_INCLUDE_PATH .
|
||||
' -idirafter /usr/include/ ' .
|
||||
' -idirafter /usr/include/' . $this->builder->getOption('arch') . '-linux-gnu/ ' .
|
||||
"' ";
|
||||
@@ -60,11 +60,11 @@ class openssl extends LinuxLibraryBase
|
||||
|
||||
$ex_lib = trim($ex_lib);
|
||||
|
||||
$clang_postfix = SystemUtil::getCCType($this->builder->getOption('cc')) === 'clang' ? '-clang' : '';
|
||||
$clang_postfix = SystemUtil::getCCType(getenv('CC')) === 'clang' ? '-clang' : '';
|
||||
|
||||
shell()->cd($this->source_dir)
|
||||
->exec(
|
||||
"{$this->builder->configure_env} {$env} ./Configure no-shared {$extra} " .
|
||||
"{$env} ./Configure no-shared {$extra} " .
|
||||
'--prefix=/ ' .
|
||||
'--libdir=lib ' .
|
||||
'-static ' .
|
||||
|
||||
@@ -10,6 +10,7 @@ use SPC\builder\traits\UnixBuilderTrait;
|
||||
use SPC\exception\FileSystemException;
|
||||
use SPC\exception\RuntimeException;
|
||||
use SPC\exception\WrongUsageException;
|
||||
use SPC\store\FileSystem;
|
||||
use SPC\store\SourcePatcher;
|
||||
|
||||
class MacOSBuilder extends BuilderBase
|
||||
@@ -31,9 +32,16 @@ class MacOSBuilder extends BuilderBase
|
||||
|
||||
// ---------- set necessary options ----------
|
||||
// set C Compiler (default: clang)
|
||||
$this->setOptionIfNotExist('cc', 'clang');
|
||||
f_putenv('CC=' . $this->getOption('cc', 'clang'));
|
||||
// set C++ Composer (default: clang++)
|
||||
$this->setOptionIfNotExist('cxx', 'clang++');
|
||||
f_putenv('CXX=' . $this->getOption('cxx', 'clang++'));
|
||||
// set PATH
|
||||
f_putenv('PATH=' . BUILD_ROOT_PATH . '/bin:' . getenv('PATH'));
|
||||
// set PKG_CONFIG
|
||||
f_putenv('PKG_CONFIG=' . BUILD_ROOT_PATH . '/bin/pkg-config');
|
||||
// set PKG_CONFIG_PATH
|
||||
f_putenv('PKG_CONFIG_PATH=' . BUILD_LIB_PATH . '/pkgconfig/');
|
||||
|
||||
// set arch (default: current)
|
||||
$this->setOptionIfNotExist('arch', php_uname('m'));
|
||||
$this->setOptionIfNotExist('gnu-arch', arch2gnu($this->getOption('arch')));
|
||||
@@ -46,15 +54,6 @@ class MacOSBuilder extends BuilderBase
|
||||
$this->arch_cxx_flags = SystemUtil::getArchCFlags($this->getOption('arch'));
|
||||
// cmake toolchain
|
||||
$this->cmake_toolchain_file = SystemUtil::makeCmakeToolchainFile('Darwin', $this->getOption('arch'), $this->arch_c_flags);
|
||||
// configure environment
|
||||
$this->configure_env = SystemUtil::makeEnvVarString([
|
||||
'PKG_CONFIG' => BUILD_ROOT_PATH . '/bin/pkg-config',
|
||||
'PKG_CONFIG_PATH' => BUILD_LIB_PATH . '/pkgconfig/',
|
||||
'CC' => $this->getOption('cc'),
|
||||
'CXX' => $this->getOption('cxx'),
|
||||
'CFLAGS' => "{$this->arch_c_flags} -Wimplicit-function-declaration -Os",
|
||||
'PATH' => BUILD_ROOT_PATH . '/bin:' . getenv('PATH'),
|
||||
]);
|
||||
|
||||
// create pkgconfig and include dir (some libs cannot create them automatically)
|
||||
f_mkdir(BUILD_LIB_PATH . '/pkgconfig', recursive: true);
|
||||
@@ -133,7 +132,7 @@ class MacOSBuilder extends BuilderBase
|
||||
// add macOS frameworks
|
||||
$extra_libs .= (empty($extra_libs) ? '' : ' ') . $this->getFrameworks(true);
|
||||
// add libc++, some extensions or libraries need it (C++ cannot be linked statically)
|
||||
$extra_libs .= (empty($extra_libs) ? '' : ' ') . ($this->hasCppExtension() ? '-lc++ ' : '');
|
||||
$extra_libs .= (empty($extra_libs) ? '' : ' ') . ($this->hasCpp() ? '-lc++ ' : '');
|
||||
if (!$this->getOption('bloat', false)) {
|
||||
$extra_libs .= (empty($extra_libs) ? '' : ' ') . implode(' ', $this->getAllStaticLibFiles());
|
||||
} else {
|
||||
@@ -151,6 +150,11 @@ class MacOSBuilder extends BuilderBase
|
||||
$json_74 = $this->getPHPVersionID() < 80000 ? '--enable-json ' : '';
|
||||
$zts = $this->getOption('enable-zts', false) ? '--enable-zts --disable-zend-signals ' : '';
|
||||
|
||||
$enableCli = ($build_target & BUILD_TARGET_CLI) === BUILD_TARGET_CLI;
|
||||
$enableFpm = ($build_target & BUILD_TARGET_FPM) === BUILD_TARGET_FPM;
|
||||
$enableMicro = ($build_target & BUILD_TARGET_MICRO) === BUILD_TARGET_MICRO;
|
||||
$enableEmbed = ($build_target & BUILD_TARGET_EMBED) === BUILD_TARGET_EMBED;
|
||||
|
||||
shell()->cd(SOURCE_PATH . '/php-src')
|
||||
->exec(
|
||||
'./configure ' .
|
||||
@@ -162,39 +166,42 @@ class MacOSBuilder extends BuilderBase
|
||||
'--disable-all ' .
|
||||
'--disable-cgi ' .
|
||||
'--disable-phpdbg ' .
|
||||
'--enable-cli ' .
|
||||
'--enable-fpm ' .
|
||||
'--enable-micro ' .
|
||||
($enableCli ? '--enable-cli ' : '--disable-cli ') .
|
||||
($enableFpm ? '--enable-fpm ' : '--disable-fpm ') .
|
||||
($enableEmbed ? '--enable-embed=static ' : '--disable-embed ') .
|
||||
($enableMicro ? '--enable-micro ' : '--disable-micro ') .
|
||||
$json_74 .
|
||||
$zts .
|
||||
$this->makeExtensionArgs() . ' ' .
|
||||
$this->configure_env
|
||||
$this->makeExtensionArgs()
|
||||
);
|
||||
|
||||
SourcePatcher::patchBeforeMake($this);
|
||||
|
||||
$this->cleanMake();
|
||||
|
||||
if (($build_target & BUILD_TARGET_CLI) === BUILD_TARGET_CLI) {
|
||||
if ($enableCli) {
|
||||
logger()->info('building cli');
|
||||
$this->buildCli();
|
||||
}
|
||||
if (($build_target & BUILD_TARGET_FPM) === BUILD_TARGET_FPM) {
|
||||
if ($enableFpm) {
|
||||
logger()->info('building fpm');
|
||||
$this->buildFpm();
|
||||
}
|
||||
if (($build_target & BUILD_TARGET_MICRO) === BUILD_TARGET_MICRO) {
|
||||
if ($enableMicro) {
|
||||
logger()->info('building micro');
|
||||
$this->buildMicro();
|
||||
}
|
||||
if ($enableEmbed) {
|
||||
logger()->info('building embed');
|
||||
if ($enableMicro) {
|
||||
FileSystem::replaceFileStr(SOURCE_PATH . '/php-src/Makefile', 'OVERALL_TARGET =', 'OVERALL_TARGET = libphp.la');
|
||||
}
|
||||
$this->buildEmbed();
|
||||
}
|
||||
|
||||
if (php_uname('m') === $this->getOption('arch')) {
|
||||
$this->sanityCheck($build_target);
|
||||
}
|
||||
|
||||
if ($this->phar_patched) {
|
||||
SourcePatcher::patchMicro(['phar'], true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -207,7 +214,7 @@ class MacOSBuilder extends BuilderBase
|
||||
{
|
||||
$vars = SystemUtil::makeEnvVarString([
|
||||
'EXTRA_CFLAGS' => '-g -Os', // with debug information, but optimize for size
|
||||
'EXTRA_LIBS' => "{$this->getOption('extra-libs')} -lresolv", // link resolv library (macOS need it)
|
||||
'EXTRA_LIBS' => "{$this->getOption('extra-libs')} -lresolv", // link resolv library (macOS needs it)
|
||||
]);
|
||||
|
||||
$shell = shell()->cd(SOURCE_PATH . '/php-src');
|
||||
@@ -221,12 +228,14 @@ class MacOSBuilder extends BuilderBase
|
||||
/**
|
||||
* Build phpmicro sapi
|
||||
*
|
||||
* @throws FileSystemException|RuntimeException
|
||||
* @throws FileSystemException
|
||||
* @throws RuntimeException
|
||||
* @throws WrongUsageException
|
||||
*/
|
||||
public function buildMicro(): void
|
||||
{
|
||||
if ($this->getPHPVersionID() < 80000) {
|
||||
throw new RuntimeException('phpmicro only support PHP >= 8.0!');
|
||||
throw new WrongUsageException('phpmicro only support PHP >= 8.0!');
|
||||
}
|
||||
if ($this->getExt('phar')) {
|
||||
$this->phar_patched = true;
|
||||
@@ -237,7 +246,7 @@ class MacOSBuilder extends BuilderBase
|
||||
$vars = [
|
||||
// with debug information, optimize for size, remove identifiers, patch fake cli for micro
|
||||
'EXTRA_CFLAGS' => '-g -Os -fno-ident' . $enable_fake_cli,
|
||||
// link resolv library (macOS need it)
|
||||
// link resolv library (macOS needs it)
|
||||
'EXTRA_LIBS' => "{$this->getOption('extra-libs')} -lresolv",
|
||||
];
|
||||
if (!$this->getOption('no-strip', false)) {
|
||||
@@ -248,6 +257,10 @@ class MacOSBuilder extends BuilderBase
|
||||
shell()->cd(SOURCE_PATH . '/php-src')
|
||||
->exec("make -j{$this->concurrency} {$vars} micro");
|
||||
$this->deployBinary(BUILD_TARGET_MICRO);
|
||||
|
||||
if ($this->phar_patched) {
|
||||
SourcePatcher::patchMicro(['phar'], true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -260,7 +273,7 @@ class MacOSBuilder extends BuilderBase
|
||||
{
|
||||
$vars = SystemUtil::makeEnvVarString([
|
||||
'EXTRA_CFLAGS' => '-g -Os', // with debug information, but optimize for size
|
||||
'EXTRA_LIBS' => "{$this->getOption('extra-libs')} -lresolv", // link resolv library (macOS need it)
|
||||
'EXTRA_LIBS' => "{$this->getOption('extra-libs')} -lresolv", // link resolv library (macOS needs it)
|
||||
]);
|
||||
|
||||
$shell = shell()->cd(SOURCE_PATH . '/php-src');
|
||||
@@ -270,4 +283,29 @@ class MacOSBuilder extends BuilderBase
|
||||
}
|
||||
$this->deployBinary(BUILD_TARGET_FPM);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build embed sapi
|
||||
*
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public function buildEmbed(): void
|
||||
{
|
||||
$vars = SystemUtil::makeEnvVarString([
|
||||
'EXTRA_CFLAGS' => '-g -Os', // with debug information, but optimize for size
|
||||
'EXTRA_LIBS' => "{$this->getOption('extra-libs')} -lresolv", // link resolv library (macOS needs it)
|
||||
]);
|
||||
|
||||
shell()
|
||||
->cd(SOURCE_PATH . '/php-src')
|
||||
->exec('make INSTALL_ROOT=' . BUILD_ROOT_PATH . " -j{$this->concurrency} {$vars} install")
|
||||
// Workaround for https://github.com/php/php-src/issues/12082
|
||||
->exec('rm -Rf ' . BUILD_ROOT_PATH . '/lib/php-o')
|
||||
->exec('mkdir ' . BUILD_ROOT_PATH . '/lib/php-o')
|
||||
->cd(BUILD_ROOT_PATH . '/lib/php-o')
|
||||
->exec('ar x ' . BUILD_ROOT_PATH . '/lib/libphp.a')
|
||||
->exec('rm ' . BUILD_ROOT_PATH . '/lib/libphp.a')
|
||||
->exec('ar rcs ' . BUILD_ROOT_PATH . '/lib/libphp.a *.o')
|
||||
->exec('rm -Rf ' . BUILD_ROOT_PATH . '/lib/php-o');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,6 +44,11 @@ class curl extends MacOSLibraryBase
|
||||
'/NOT SYSTEMCONFIGURATION_FRAMEWORK/m',
|
||||
'FALSE'
|
||||
);
|
||||
FileSystem::replaceFileRegex(
|
||||
SOURCE_PATH . '/curl/CMakeLists.txt',
|
||||
'/NOT CORESERVICES_FRAMEWORK/m',
|
||||
'FALSE'
|
||||
);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ class glfw extends MacOSLibraryBase
|
||||
{
|
||||
// compile!
|
||||
shell()->cd(SOURCE_PATH . '/ext-glfw/vendor/glfw')
|
||||
->exec("{$this->builder->configure_env} cmake . {$this->builder->makeCmakeArgs()} -DBUILD_SHARED_LIBS=OFF -DGLFW_BUILD_EXAMPLES=OFF -DGLFW_BUILD_TESTS=OFF")
|
||||
->exec("cmake . {$this->builder->makeCmakeArgs()} -DBUILD_SHARED_LIBS=OFF -DGLFW_BUILD_EXAMPLES=OFF -DGLFW_BUILD_TESTS=OFF")
|
||||
->exec("make -j{$this->builder->concurrency}")
|
||||
->exec('make install DESTDIR=' . BUILD_ROOT_PATH);
|
||||
// patch pkgconf
|
||||
|
||||
@@ -12,7 +12,7 @@ class icu extends MacOSLibraryBase
|
||||
{
|
||||
$root = BUILD_ROOT_PATH;
|
||||
shell()->cd($this->source_dir . '/source')
|
||||
->exec("{$this->builder->configure_env} ./runConfigureICU MacOSX --enable-static --disable-shared --prefix={$root}")
|
||||
->exec("./runConfigureICU MacOSX --enable-static --disable-shared --prefix={$root}")
|
||||
->exec('make clean')
|
||||
->exec("make -j{$this->builder->concurrency}")
|
||||
->exec('make install');
|
||||
|
||||
12
src/SPC/builder/macos/library/ldap.php
Normal file
12
src/SPC/builder/macos/library/ldap.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace SPC\builder\macos\library;
|
||||
|
||||
class ldap extends MacOSLibraryBase
|
||||
{
|
||||
use \SPC\builder\unix\library\ldap;
|
||||
|
||||
public const NAME = 'ldap';
|
||||
}
|
||||
@@ -20,7 +20,7 @@ class libffi extends MacOSLibraryBase
|
||||
[, , $destdir] = SEPARATED_PATH;
|
||||
shell()->cd($this->source_dir)
|
||||
->exec(
|
||||
"{$this->builder->configure_env} ./configure " .
|
||||
'./configure ' .
|
||||
'--enable-static ' .
|
||||
'--disable-shared ' .
|
||||
"--host={$this->builder->getOption('arch')}-apple-darwin " .
|
||||
|
||||
@@ -18,7 +18,7 @@ class libmemcached extends MacOSLibraryBase
|
||||
shell()->cd($this->source_dir)
|
||||
->exec('chmod +x configure')
|
||||
->exec(
|
||||
"{$this->builder->configure_env} ./configure " .
|
||||
'./configure ' .
|
||||
'--enable-static --disable-shared ' .
|
||||
'--disable-sasl ' .
|
||||
"--prefix={$rootdir}"
|
||||
|
||||
@@ -44,7 +44,7 @@ class libpng extends MacOSLibraryBase
|
||||
->exec('chmod +x ./configure')
|
||||
->exec('chmod +x ./install-sh')
|
||||
->exec(
|
||||
"{$this->builder->configure_env} ./configure " .
|
||||
'./configure ' .
|
||||
"--host={$this->builder->getOption('gnu-arch')}-apple-darwin " .
|
||||
'--disable-shared ' .
|
||||
'--enable-static ' .
|
||||
|
||||
@@ -18,38 +18,27 @@ class libxml2 extends MacOSLibraryBase
|
||||
*/
|
||||
protected function build(): void
|
||||
{
|
||||
// macOS need to link iconv dynamically, we add it to extra-libs
|
||||
$extra_libs = $this->builder->getOption('extra-libs', '');
|
||||
if (!str_contains($extra_libs, '-liconv')) {
|
||||
$extra_libs .= ' -liconv';
|
||||
}
|
||||
$this->builder->setOption('extra-libs', $extra_libs);
|
||||
|
||||
$enable_zlib = $this->builder->getLib('zlib') ? 'ON' : 'OFF';
|
||||
// $enable_icu = $this->builder->getLib('icu') ? 'ON' : 'OFF';
|
||||
$enable_icu = $this->builder->getLib('icu') ? 'ON' : 'OFF';
|
||||
$enable_xz = $this->builder->getLib('xz') ? 'ON' : 'OFF';
|
||||
|
||||
[, , $destdir] = SEPARATED_PATH;
|
||||
|
||||
FileSystem::resetDir($this->source_dir . '/build');
|
||||
shell()->cd($this->source_dir . '/build')
|
||||
->exec(
|
||||
"{$this->builder->configure_env} " . ' cmake ' .
|
||||
'cmake ' .
|
||||
// '--debug-find ' .
|
||||
'-DCMAKE_BUILD_TYPE=Release ' .
|
||||
"{$this->builder->makeCmakeArgs()} " .
|
||||
'-DBUILD_SHARED_LIBS=OFF ' .
|
||||
'-DLIBXML2_WITH_ICONV=ON ' .
|
||||
"-DLIBXML2_WITH_ZLIB={$enable_zlib} " .
|
||||
'-DLIBXML2_WITH_ICU=OFF ' .
|
||||
"-DLIBXML2_WITH_ICU={$enable_icu} " .
|
||||
"-DLIBXML2_WITH_LZMA={$enable_xz} " .
|
||||
'-DLIBXML2_WITH_PYTHON=OFF ' .
|
||||
'-DLIBXML2_WITH_PROGRAMS=OFF ' .
|
||||
'-DLIBXML2_WITH_TESTS=OFF ' .
|
||||
"-DCMAKE_INSTALL_PREFIX={$destdir} " .
|
||||
"-DCMAKE_TOOLCHAIN_FILE={$this->builder->cmake_toolchain_file} " .
|
||||
'..'
|
||||
)
|
||||
->exec("cmake --build . -j {$this->builder->concurrency}")
|
||||
->exec('make install');
|
||||
->exec('make install DESTDIR=' . BUILD_ROOT_PATH);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ class nghttp2 extends MacOSLibraryBase
|
||||
|
||||
shell()->cd($this->source_dir)
|
||||
->exec(
|
||||
"{$this->builder->configure_env} " . ' ./configure ' .
|
||||
'./configure ' .
|
||||
'--enable-static ' .
|
||||
'--disable-shared ' .
|
||||
"--host={$this->builder->getOption('gnu-arch')}-apple-darwin " .
|
||||
|
||||
@@ -48,7 +48,7 @@ class openssl extends MacOSLibraryBase
|
||||
|
||||
shell()->cd($this->source_dir)
|
||||
->exec(
|
||||
"{$this->builder->configure_env} ./Configure no-shared {$extra} " .
|
||||
"./Configure no-shared {$extra} " .
|
||||
'--prefix=/ ' . // use prefix=/
|
||||
"--libdir={$lib} " .
|
||||
'--openssldir=/System/Library/OpenSSL ' .
|
||||
|
||||
@@ -21,9 +21,6 @@ trait UnixBuilderTrait
|
||||
/** @var string cmake toolchain file */
|
||||
public string $cmake_toolchain_file;
|
||||
|
||||
/** @var string configure environments */
|
||||
public string $configure_env;
|
||||
|
||||
/**
|
||||
* @throws WrongUsageException
|
||||
* @throws FileSystemException
|
||||
@@ -66,14 +63,23 @@ trait UnixBuilderTrait
|
||||
if ($ret !== 0 || trim(implode('', $output)) !== 'hello') {
|
||||
throw new RuntimeException('cli failed sanity check');
|
||||
}
|
||||
|
||||
foreach ($this->exts as $ext) {
|
||||
logger()->debug('testing ext: ' . $ext->getName());
|
||||
[$ret] = shell()->execWithResult(BUILD_ROOT_PATH . '/bin/php --ri "' . $ext->getDistName() . '"', false);
|
||||
if ($ret !== 0) {
|
||||
throw new RuntimeException('extension ' . $ext->getName() . ' failed compile check');
|
||||
}
|
||||
|
||||
if (file_exists(ROOT_DIR . '/src/globals/tests/' . $ext->getName() . '.php')) {
|
||||
[$ret] = shell()->execWithResult(BUILD_ROOT_PATH . '/bin/php ' . ROOT_DIR . '/src/globals/tests/' . $ext->getName() . '.php');
|
||||
// Trim additional content & escape special characters to allow inline usage
|
||||
$test = str_replace(
|
||||
['<?php', 'declare(strict_types=1);', "\n", '"', '$'],
|
||||
['', '', '', '\"', '\$'],
|
||||
file_get_contents(ROOT_DIR . '/src/globals/tests/' . $ext->getName() . '.php')
|
||||
);
|
||||
|
||||
[$ret] = shell()->execWithResult(BUILD_ROOT_PATH . '/bin/php -r "' . trim($test) . '"');
|
||||
if ($ret !== 0) {
|
||||
throw new RuntimeException('extension ' . $ext->getName() . ' failed sanity check');
|
||||
}
|
||||
@@ -136,12 +142,35 @@ trait UnixBuilderTrait
|
||||
*/
|
||||
public function makeCmakeArgs(): string
|
||||
{
|
||||
[$lib, $include] = SEPARATED_PATH;
|
||||
$extra = $this instanceof LinuxBuilder ? '-DCMAKE_C_COMPILER=' . $this->getOption('cc') . ' ' : '';
|
||||
return $extra . '-DCMAKE_BUILD_TYPE=Release ' .
|
||||
$extra = $this instanceof LinuxBuilder ? '-DCMAKE_C_COMPILER=' . getenv('CC') . ' ' : '';
|
||||
return $extra .
|
||||
'-DCMAKE_BUILD_TYPE=Release ' .
|
||||
'-DCMAKE_INSTALL_PREFIX=/ ' .
|
||||
"-DCMAKE_INSTALL_LIBDIR={$lib} " .
|
||||
"-DCMAKE_INSTALL_INCLUDEDIR={$include} " .
|
||||
'-DCMAKE_INSTALL_BINDIR=/bin ' .
|
||||
'-DCMAKE_INSTALL_LIBDIR=/lib ' .
|
||||
'-DCMAKE_INSTALL_INCLUDEDIR=/include ' .
|
||||
"-DCMAKE_TOOLCHAIN_FILE={$this->cmake_toolchain_file}";
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate configure flags
|
||||
*/
|
||||
public function makeAutoconfFlags(int $flag = AUTOCONF_ALL): string
|
||||
{
|
||||
$extra = '';
|
||||
// TODO: add auto pkg-config support
|
||||
if (($flag & AUTOCONF_LIBS) === AUTOCONF_LIBS) {
|
||||
$extra .= 'LIBS="' . BUILD_LIB_PATH . '" ';
|
||||
}
|
||||
if (($flag & AUTOCONF_CFLAGS) === AUTOCONF_CFLAGS) {
|
||||
$extra .= 'CFLAGS="-I' . BUILD_INCLUDE_PATH . '" ';
|
||||
}
|
||||
if (($flag & AUTOCONF_CPPFLAGS) === AUTOCONF_CPPFLAGS) {
|
||||
$extra .= 'CPPFLAGS="-I' . BUILD_INCLUDE_PATH . '" ';
|
||||
}
|
||||
if (($flag & AUTOCONF_LDFLAGS) === AUTOCONF_LDFLAGS) {
|
||||
$extra .= 'LDFLAGS="-L' . BUILD_LIB_PATH . '" ';
|
||||
}
|
||||
return $extra;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ trait UnixLibraryTrait
|
||||
* @throws FileSystemException
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public function patchPkgconfPrefix(array $files, int $patch_option = PKGCONF_PATCH_ALL): void
|
||||
public function patchPkgconfPrefix(array $files, int $patch_option = PKGCONF_PATCH_ALL, ?array $custom_replace = null): void
|
||||
{
|
||||
logger()->info('Patching library [' . static::NAME . '] pkgconfig');
|
||||
foreach ($files as $name) {
|
||||
@@ -81,6 +81,7 @@ trait UnixLibraryTrait
|
||||
$file = ($patch_option & PKGCONF_PATCH_EXEC_PREFIX) === PKGCONF_PATCH_EXEC_PREFIX ? preg_replace('/^exec_prefix=.*$/m', 'exec_prefix=${prefix}', $file) : $file;
|
||||
$file = ($patch_option & PKGCONF_PATCH_LIBDIR) === PKGCONF_PATCH_LIBDIR ? preg_replace('/^libdir=.*$/m', 'libdir=${prefix}/lib', $file) : $file;
|
||||
$file = ($patch_option & PKGCONF_PATCH_INCLUDEDIR) === PKGCONF_PATCH_INCLUDEDIR ? preg_replace('/^includedir=.*$/m', 'includedir=${prefix}/include', $file) : $file;
|
||||
$file = ($patch_option & PKGCONF_PATCH_CUSTOM) === PKGCONF_PATCH_CUSTOM && $custom_replace !== null ? preg_replace($custom_replace[0], $custom_replace[1], $file) : $file;
|
||||
FileSystem::writeFile($realpath, $file);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ trait brotli
|
||||
FileSystem::resetDir($this->source_dir . '/build-dir');
|
||||
shell()->cd($this->source_dir . '/build-dir')
|
||||
->exec(
|
||||
$this->builder->configure_env . ' cmake ' .
|
||||
'cmake ' .
|
||||
"{$this->builder->makeCmakeArgs()} " .
|
||||
'-DBUILD_SHARED_LIBS=OFF ' .
|
||||
'..'
|
||||
@@ -28,9 +28,9 @@ trait brotli
|
||||
->exec('make install DESTDIR=' . BUILD_ROOT_PATH);
|
||||
$this->patchPkgconfPrefix(['libbrotlicommon.pc', 'libbrotlidec.pc', 'libbrotlienc.pc']);
|
||||
shell()->cd(BUILD_ROOT_PATH . '/lib')
|
||||
->exec('ln -s libbrotlicommon-static.a libbrotlicommon.a')
|
||||
->exec('ln -s libbrotlidec-static.a libbrotlidec.a')
|
||||
->exec('ln -s libbrotlienc-static.a libbrotlienc.a');
|
||||
->exec('ln -s libbrotlicommon.a libbrotlicommon-static.a')
|
||||
->exec('ln -s libbrotlidec.a libbrotlidec-static.a')
|
||||
->exec('ln -s libbrotlienc.a libbrotlienc-static.a');
|
||||
foreach (FileSystem::scanDirFiles(BUILD_ROOT_PATH . '/lib/', false, true) as $filename) {
|
||||
if (str_starts_with($filename, 'libbrotli') && (str_contains($filename, '.so') || str_ends_with($filename, '.dylib'))) {
|
||||
unlink(BUILD_ROOT_PATH . '/lib/' . $filename);
|
||||
|
||||
@@ -9,8 +9,8 @@ trait bzip2
|
||||
protected function build(): void
|
||||
{
|
||||
shell()->cd($this->source_dir)
|
||||
->exec("make {$this->builder->configure_env} PREFIX='" . BUILD_ROOT_PATH . "' clean")
|
||||
->exec("make -j{$this->builder->concurrency} {$this->builder->configure_env} PREFIX='" . BUILD_ROOT_PATH . "' libbz2.a")
|
||||
->exec("make PREFIX='" . BUILD_ROOT_PATH . "' clean")
|
||||
->exec("make -j{$this->builder->concurrency} {$this->builder->getEnvString()} PREFIX='" . BUILD_ROOT_PATH . "' libbz2.a")
|
||||
->exec('cp libbz2.a ' . BUILD_LIB_PATH)
|
||||
->exec('cp bzlib.h ' . BUILD_INCLUDE_PATH);
|
||||
}
|
||||
|
||||
@@ -39,8 +39,8 @@ trait curl
|
||||
} else {
|
||||
$extra .= '-DUSE_NGHTTP2=OFF ';
|
||||
}
|
||||
// TODO: ldap is not supported yet
|
||||
$extra .= '-DCURL_DISABLE_LDAP=ON ';
|
||||
// lib:ldap
|
||||
$extra .= $this->builder->getLib('ldap') ? '-DCURL_DISABLE_LDAP=OFF ' : '-DCURL_DISABLE_LDAP=ON ';
|
||||
// lib:zstd
|
||||
$extra .= $this->builder->getLib('zstd') ? '-DCURL_ZSTD=ON ' : '-DCURL_ZSTD=OFF ';
|
||||
// lib:idn2
|
||||
@@ -52,7 +52,7 @@ trait curl
|
||||
// compile!
|
||||
shell()->cd($this->source_dir . '/build')
|
||||
->exec('sed -i.save s@\${CMAKE_C_IMPLICIT_LINK_LIBRARIES}@@ ../CMakeLists.txt')
|
||||
->exec("{$this->builder->configure_env} cmake {$this->builder->makeCmakeArgs()} -DBUILD_SHARED_LIBS=OFF -DBUILD_CURL_EXE=OFF {$extra} ..")
|
||||
->exec("cmake {$this->builder->makeCmakeArgs()} -DBUILD_SHARED_LIBS=OFF -DBUILD_CURL_EXE=OFF {$extra} ..")
|
||||
->exec("make -j{$this->builder->concurrency}")
|
||||
->exec('make install DESTDIR=' . BUILD_ROOT_PATH);
|
||||
// patch pkgconf
|
||||
|
||||
@@ -27,7 +27,7 @@ trait freetype
|
||||
|
||||
shell()->cd($this->source_dir)
|
||||
->exec(
|
||||
"{$this->builder->configure_env} ./configure " .
|
||||
'./configure ' .
|
||||
'--enable-static --disable-shared --without-harfbuzz --prefix= ' .
|
||||
$suggested
|
||||
)
|
||||
|
||||
@@ -17,7 +17,7 @@ trait gmp
|
||||
{
|
||||
shell()->cd($this->source_dir)
|
||||
->exec(
|
||||
"{$this->builder->configure_env} ./configure " .
|
||||
'./configure ' .
|
||||
'--enable-static --disable-shared ' .
|
||||
'--prefix='
|
||||
)
|
||||
|
||||
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace SPC\builder\unix\library;
|
||||
|
||||
use SPC\builder\linux\library\LinuxLibraryBase;
|
||||
use SPC\exception\FileSystemException;
|
||||
use SPC\exception\RuntimeException;
|
||||
use SPC\store\FileSystem;
|
||||
@@ -16,23 +17,33 @@ trait imagemagick
|
||||
*/
|
||||
protected function build(): void
|
||||
{
|
||||
$extra = '--without-jxl --without-xml --without-zstd --without-x --disable-openmp ';
|
||||
// libzip support
|
||||
$extra .= $this->builder->getLib('libzip') ? '--with-zip ' : '--without-zip ';
|
||||
// jpeg support
|
||||
$extra .= $this->builder->getLib('libjpeg') ? '--with-jpeg ' : '';
|
||||
// png support
|
||||
$extra .= $this->builder->getLib('libpng') ? '--with-png ' : '';
|
||||
// webp support
|
||||
$extra .= $this->builder->getLib('libwebp') ? '--with-webp ' : '';
|
||||
// zstd support
|
||||
// $extra .= $this->builder->getLib('zstd') ? '--with-zstd ' : '--without-zstd ';
|
||||
// freetype support
|
||||
$extra .= $this->builder->getLib('freetype') ? '--with-freetype ' : '--without-freetype ';
|
||||
// TODO: imagemagick build with bzip2 failed with bugs, we need to fix it in the future
|
||||
$extra = '--without-jxl --without-x --disable-openmp --without-bzlib ';
|
||||
$required_libs = '';
|
||||
$optional_libs = [
|
||||
'libzip' => 'zip',
|
||||
'libjpeg' => 'jpeg',
|
||||
'libpng' => 'png',
|
||||
'libwebp' => 'webp',
|
||||
'libxml2' => 'xml',
|
||||
'zlib' => 'zlib',
|
||||
'xz' => 'lzma',
|
||||
'zstd' => 'zstd',
|
||||
'freetype' => 'freetype',
|
||||
];
|
||||
foreach ($optional_libs as $lib => $option) {
|
||||
$extra .= $this->builder->getLib($lib) ? "--with-{$option} " : "--without-{$option} ";
|
||||
if ($this->builder->getLib($lib) instanceof LinuxLibraryBase) {
|
||||
$required_libs .= ' ' . $this->builder->getLib($lib)->getStaticLibFiles();
|
||||
}
|
||||
}
|
||||
|
||||
$ldflags = $this instanceof LinuxLibraryBase ? ('LDFLAGS="-static" ') : '';
|
||||
shell()->cd($this->source_dir)
|
||||
->exec(
|
||||
"{$this->builder->configure_env} ./configure " .
|
||||
$ldflags .
|
||||
"LIBS='{$required_libs}' " .
|
||||
'./configure ' .
|
||||
'--enable-static --disable-shared ' .
|
||||
$extra .
|
||||
'--prefix='
|
||||
|
||||
38
src/SPC/builder/unix/library/ldap.php
Normal file
38
src/SPC/builder/unix/library/ldap.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace SPC\builder\unix\library;
|
||||
|
||||
trait ldap
|
||||
{
|
||||
protected function build(): void
|
||||
{
|
||||
$alt = '';
|
||||
// openssl support
|
||||
$alt .= $this->builder->getLib('openssl') && $this->builder->getExt('zlib') ? '--with-tls=openssl ' : '';
|
||||
// gmp support
|
||||
$alt .= $this->builder->getLib('gmp') ? '--with-mp=gmp ' : '';
|
||||
// libsodium support
|
||||
$alt .= $this->builder->getLib('libsodium') ? '--with-argon2=libsodium ' : '';
|
||||
shell()->cd($this->source_dir)
|
||||
->exec(
|
||||
$this->builder->makeAutoconfFlags(AUTOCONF_LDFLAGS | AUTOCONF_CPPFLAGS) .
|
||||
' ./configure ' .
|
||||
'--enable-static ' .
|
||||
'--disable-shared ' .
|
||||
'--disable-slapd ' .
|
||||
'--disable-slurpd ' .
|
||||
'--without-systemd ' .
|
||||
'--without-cyrus-sasl ' .
|
||||
$alt .
|
||||
'--prefix='
|
||||
)
|
||||
->exec('make clean')
|
||||
// remove tests and doc to prevent compile failed with error: soelim not found
|
||||
->exec('sed -i -e "s/SUBDIRS= include libraries clients servers tests doc/SUBDIRS= include libraries clients servers/g" Makefile')
|
||||
->exec("make -j{$this->builder->concurrency}")
|
||||
->exec('make install DESTDIR=' . BUILD_ROOT_PATH);
|
||||
$this->patchPkgconfPrefix(['ldap.pc', 'lber.pc']);
|
||||
}
|
||||
}
|
||||
@@ -22,12 +22,7 @@ trait libavif
|
||||
FileSystem::resetDir($this->source_dir . '/build');
|
||||
// Start build
|
||||
shell()->cd($this->source_dir . '/build')
|
||||
->exec(
|
||||
"{$this->builder->configure_env} cmake " .
|
||||
$this->builder->makeCmakeArgs() . ' ' .
|
||||
'-DBUILD_SHARED_LIBS=OFF ' .
|
||||
'..'
|
||||
)
|
||||
->exec("cmake {$this->builder->makeCmakeArgs()} -DBUILD_SHARED_LIBS=OFF ..")
|
||||
->exec("cmake --build . -j {$this->builder->concurrency}")
|
||||
->exec('make install DESTDIR=' . BUILD_ROOT_PATH);
|
||||
// patch pkgconfig
|
||||
|
||||
@@ -21,7 +21,7 @@ trait libevent
|
||||
// Start build
|
||||
shell()->cd($this->source_dir . '/build')
|
||||
->exec(
|
||||
"{$this->builder->configure_env} cmake " .
|
||||
'cmake ' .
|
||||
'-DCMAKE_INSTALL_PREFIX=' . BUILD_ROOT_PATH . ' ' .
|
||||
"-DCMAKE_TOOLCHAIN_FILE={$this->builder->cmake_toolchain_file} " .
|
||||
'-DCMAKE_BUILD_TYPE=Release ' .
|
||||
|
||||
@@ -12,7 +12,7 @@ trait libiconv
|
||||
|
||||
shell()->cd($this->source_dir)
|
||||
->exec(
|
||||
"{$this->builder->configure_env} ./configure " .
|
||||
'./configure ' .
|
||||
'--enable-static ' .
|
||||
'--disable-shared ' .
|
||||
'--prefix='
|
||||
|
||||
@@ -23,7 +23,7 @@ trait libjpeg
|
||||
// Start build
|
||||
shell()->cd($this->source_dir . '/build')
|
||||
->exec(
|
||||
"{$this->builder->configure_env} cmake {$this->builder->makeCmakeArgs()} " .
|
||||
"cmake {$this->builder->makeCmakeArgs()} " .
|
||||
'-DENABLE_STATIC=ON ' .
|
||||
'-DENABLE_SHARED=OFF ' .
|
||||
'..'
|
||||
|
||||
@@ -10,7 +10,7 @@ trait libsodium
|
||||
{
|
||||
$root = BUILD_ROOT_PATH;
|
||||
shell()->cd($this->source_dir)
|
||||
->exec("{$this->builder->configure_env} ./configure --enable-static --disable-shared --prefix={$root}")
|
||||
->exec("./configure --enable-static --disable-shared --prefix={$root}")
|
||||
->exec('make clean')
|
||||
->exec("make -j{$this->builder->concurrency}")
|
||||
->exec('make install');
|
||||
|
||||
@@ -21,7 +21,7 @@ trait libssh2
|
||||
FileSystem::resetDir($this->source_dir . '/build');
|
||||
shell()->cd($this->source_dir . '/build')
|
||||
->exec(
|
||||
"{$this->builder->configure_env} " . ' cmake ' .
|
||||
'cmake ' .
|
||||
"{$this->builder->makeCmakeArgs()} " .
|
||||
'-DBUILD_SHARED_LIBS=OFF ' .
|
||||
'-DBUILD_EXAMPLES=OFF ' .
|
||||
@@ -29,7 +29,7 @@ trait libssh2
|
||||
"-DENABLE_ZLIB_COMPRESSION={$enable_zlib} " .
|
||||
'..'
|
||||
)
|
||||
->exec("cmake --build . -j {$this->builder->concurrency} --target libssh2")
|
||||
->exec("cmake --build . -j {$this->builder->concurrency}")
|
||||
->exec('make install DESTDIR=' . BUILD_ROOT_PATH);
|
||||
$this->patchPkgconfPrefix(['libssh2.pc']);
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ trait libwebp
|
||||
// Start build
|
||||
shell()->cd($this->source_dir . '/build')
|
||||
->exec(
|
||||
"{$this->builder->configure_env} cmake " .
|
||||
'cmake ' .
|
||||
$this->builder->makeCmakeArgs() . ' ' .
|
||||
'-DBUILD_SHARED_LIBS=OFF ' .
|
||||
'-DWEBP_BUILD_EXTRAS=ON ' .
|
||||
@@ -32,7 +32,10 @@ trait libwebp
|
||||
->exec("cmake --build . -j {$this->builder->concurrency}")
|
||||
->exec('make install DESTDIR=' . BUILD_ROOT_PATH);
|
||||
// patch pkgconfig
|
||||
$this->patchPkgconfPrefix(['libsharpyuv.pc', 'libwebp.pc', 'libwebpdecoder.pc', 'libwebpdemux.pc', 'libwebpmux.pc'], PKGCONF_PATCH_PREFIX);
|
||||
$this->patchPkgconfPrefix(['libsharpyuv.pc', 'libwebp.pc', 'libwebpdecoder.pc', 'libwebpdemux.pc', 'libwebpmux.pc'], PKGCONF_PATCH_PREFIX | PKGCONF_PATCH_LIBDIR);
|
||||
$this->patchPkgconfPrefix(['libsharpyuv.pc'], PKGCONF_PATCH_CUSTOM, ['/^includedir=.*$/m', 'includedir=${prefix}/include/webp']);
|
||||
$this->cleanLaFiles();
|
||||
// fix imagemagick binary linking issue
|
||||
$this->patchPkgconfPrefix(['libwebp.pc'], PKGCONF_PATCH_CUSTOM, ['/-lwebp$/m', '-lwebp -lsharpyuv']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,20 +4,34 @@ declare(strict_types=1);
|
||||
|
||||
namespace SPC\builder\unix\library;
|
||||
|
||||
use SPC\builder\linux\library\LinuxLibraryBase;
|
||||
use SPC\exception\FileSystemException;
|
||||
use SPC\exception\RuntimeException;
|
||||
use SPC\exception\WrongUsageException;
|
||||
|
||||
trait libxslt
|
||||
{
|
||||
/**
|
||||
* @throws FileSystemException
|
||||
* @throws RuntimeException
|
||||
* @throws WrongUsageException
|
||||
*/
|
||||
protected function build(): void
|
||||
{
|
||||
$required_libs = '';
|
||||
foreach ($this->getDependencies() as $dep) {
|
||||
if ($dep instanceof LinuxLibraryBase) {
|
||||
$required_libs .= ' ' . $dep->getStaticLibFiles();
|
||||
}
|
||||
}
|
||||
shell()->cd($this->source_dir)
|
||||
->exec(
|
||||
"{$this->builder->configure_env} ./configure " .
|
||||
'CFLAGS="-I' . BUILD_INCLUDE_PATH . '" ' .
|
||||
"{$this->builder->getOption('library_path')} " .
|
||||
"{$this->builder->getOption('ld_library_path')} " .
|
||||
'LDFLAGS="-L' . BUILD_LIB_PATH . '" ' .
|
||||
"LIBS='{$required_libs} -lstdc++' " .
|
||||
'./configure ' .
|
||||
'--enable-static --disable-shared ' .
|
||||
'--without-python ' .
|
||||
'--without-mem-debug ' .
|
||||
|
||||
@@ -60,7 +60,7 @@ EOF
|
||||
FileSystem::resetDir($this->source_dir . '/build');
|
||||
shell()->cd($this->source_dir . '/build')
|
||||
->exec(
|
||||
"{$this->builder->configure_env} cmake " .
|
||||
'cmake ' .
|
||||
// '--debug-find ' .
|
||||
'-DCMAKE_BUILD_TYPE=Release ' .
|
||||
'-DBUILD_TESTING=OFF ' .
|
||||
|
||||
@@ -29,7 +29,7 @@ trait libzip
|
||||
FileSystem::resetDir($this->source_dir . '/build');
|
||||
shell()->cd($this->source_dir . '/build')
|
||||
->exec(
|
||||
"{$this->builder->configure_env} " . ' cmake ' .
|
||||
'cmake ' .
|
||||
"{$this->builder->makeCmakeArgs()} " .
|
||||
'-DENABLE_GNUTLS=OFF ' .
|
||||
'-DENABLE_MBEDTLS=OFF ' .
|
||||
|
||||
@@ -10,7 +10,7 @@ trait ncurses
|
||||
{
|
||||
shell()->cd($this->source_dir)
|
||||
->exec(
|
||||
"{$this->builder->configure_env} ./configure " .
|
||||
'./configure ' .
|
||||
'--enable-static ' .
|
||||
'--disable-shared ' .
|
||||
'--enable-overwrite ' .
|
||||
|
||||
@@ -18,12 +18,7 @@ trait onig
|
||||
[,,$destdir] = SEPARATED_PATH;
|
||||
|
||||
shell()->cd($this->source_dir)
|
||||
->exec(
|
||||
"{$this->builder->configure_env} " . ' ./configure ' .
|
||||
'--enable-static ' .
|
||||
'--disable-shared ' .
|
||||
'--prefix='
|
||||
)
|
||||
->exec('./configure --enable-static --disable-shared --prefix=')
|
||||
->exec('make clean')
|
||||
->exec("make -j{$this->builder->concurrency}")
|
||||
->exec("make install DESTDIR={$destdir}");
|
||||
|
||||
@@ -8,13 +8,8 @@ trait pkgconfig
|
||||
{
|
||||
protected function build(): void
|
||||
{
|
||||
$macos_env = 'PKG_CONFIG_PATH="' . BUILD_LIB_PATH . '/pkgconfig/" ' .
|
||||
"CC='{$this->builder->getOption('cc')}' " .
|
||||
"CXX='{$this->builder->getOption('cxx')}' " .
|
||||
"CFLAGS='{$this->builder->arch_c_flags} -Wimplicit-function-declaration' ";
|
||||
$linux_env = 'PKG_CONFIG_PATH="' . BUILD_LIB_PATH . '/pkgconfig" ' .
|
||||
"CC='{$this->builder->getOption('cc')}' " .
|
||||
"CXX='{$this->builder->getOption('cxx')}' ";
|
||||
$macos_env = "CFLAGS='{$this->builder->arch_c_flags} -Wimplicit-function-declaration' ";
|
||||
$linux_env = 'LDFLAGS=--static ';
|
||||
|
||||
shell()->cd($this->source_dir)
|
||||
->exec(
|
||||
|
||||
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace SPC\builder\unix\library;
|
||||
|
||||
use SPC\builder\linux\library\LinuxLibraryBase;
|
||||
use SPC\builder\macos\library\MacOSLibraryBase;
|
||||
use SPC\exception\FileSystemException;
|
||||
use SPC\exception\RuntimeException;
|
||||
@@ -18,25 +19,39 @@ trait postgresql
|
||||
protected function build(): void
|
||||
{
|
||||
$builddir = BUILD_ROOT_PATH;
|
||||
$env = $this->builder->configure_env;
|
||||
$envs = $env;
|
||||
$packages = 'openssl zlib readline libxml-2.0'; // icu-uc icu-io icu-i18n libzstd
|
||||
$envs = '';
|
||||
$packages = 'openssl zlib readline libxml-2.0 zlib';
|
||||
$optional_packages = [
|
||||
'zstd' => 'libzstd',
|
||||
'ldap' => 'ldap',
|
||||
'libpam' => 'libpam',
|
||||
'libxslt' => 'libxslt',
|
||||
'icu' => 'icu-i18n',
|
||||
];
|
||||
foreach ($optional_packages as $lib => $pkg) {
|
||||
if ($this->getBuilder()->getLib($lib)) {
|
||||
$packages .= ' ' . $pkg;
|
||||
}
|
||||
}
|
||||
|
||||
$pkgconfig_executable = $builddir . '/bin/pkg-config';
|
||||
$output = shell()->execWithResult($env . " {$pkgconfig_executable} --cflags-only-I --static " . $packages);
|
||||
$output = shell()->execWithResult("pkg-config --cflags-only-I --static {$packages}");
|
||||
if (!empty($output[1][0])) {
|
||||
$cppflags = $output[1][0];
|
||||
$envs .= " CPPFLAGS=\"{$cppflags}\"";
|
||||
}
|
||||
$output = shell()->execWithResult($env . " {$pkgconfig_executable} --libs-only-L --static " . $packages);
|
||||
$output = shell()->execWithResult("pkg-config --libs-only-L --static {$packages}");
|
||||
if (!empty($output[1][0])) {
|
||||
$ldflags = $output[1][0];
|
||||
$envs .= $this instanceof MacOSLibraryBase ? " LDFLAGS=\"{$ldflags}\" " : " LDFLAGS=\"{$ldflags} -static\" ";
|
||||
}
|
||||
$output = shell()->execWithResult($env . " {$pkgconfig_executable} --libs-only-l --static " . $packages);
|
||||
$output = shell()->execWithResult("pkg-config --libs-only-l --static {$packages}");
|
||||
if (!empty($output[1][0])) {
|
||||
$libs = $output[1][0];
|
||||
$envs .= " LIBS=\"{$libs}\" ";
|
||||
$libcpp = '';
|
||||
if ($this->builder->getLib('icu')) {
|
||||
$libcpp = $this instanceof LinuxLibraryBase ? ' -lstdc++' : ' -lc++';
|
||||
}
|
||||
$envs .= " LIBS=\"{$libs}{$libcpp}\" ";
|
||||
}
|
||||
|
||||
FileSystem::resetDir($this->source_dir . '/build');
|
||||
@@ -44,7 +59,7 @@ trait postgresql
|
||||
# 有静态链接配置 参考文件: src/interfaces/libpq/Makefile
|
||||
shell()->cd($this->source_dir . '/build')
|
||||
->exec('sed -i.backup "s/invokes exit\'; exit 1;/invokes exit\';/" ../src/interfaces/libpq/Makefile')
|
||||
->exec(' sed -i.backup "293 s/^/#$/" ../src/Makefile.shlib')
|
||||
->exec('sed -i.backup "293 s/^/#$/" ../src/Makefile.shlib')
|
||||
->exec('sed -i.backup "441 s/^/#$/" ../src/Makefile.shlib');
|
||||
|
||||
// configure
|
||||
@@ -58,14 +73,13 @@ trait postgresql
|
||||
'--with-readline ' .
|
||||
'--with-libxml ' .
|
||||
($this->builder->getLib('icu') ? '--with-icu ' : '--without-icu ') .
|
||||
'--without-ldap ' .
|
||||
'--without-libxslt ' .
|
||||
($this->builder->getLib('ldap') ? '--with-ldap ' : '--without-ldap ') .
|
||||
($this->builder->getLib('libpam') ? '--with-pam ' : '--without-pam ') .
|
||||
($this->builder->getLib('libxslt') ? '--with-libxslt ' : '--without-libxslt ') .
|
||||
($this->builder->getLib('zstd') ? '--with-zstd ' : '--without-zstd ') .
|
||||
'--without-lz4 ' .
|
||||
'--without-zstd ' .
|
||||
'--without-perl ' .
|
||||
'--without-python ' .
|
||||
'--without-pam ' .
|
||||
'--without-ldap ' .
|
||||
'--without-bonjour ' .
|
||||
'--without-tcl '
|
||||
);
|
||||
|
||||
@@ -17,7 +17,7 @@ trait readline
|
||||
{
|
||||
shell()->cd($this->source_dir)
|
||||
->exec(
|
||||
"{$this->builder->configure_env} ./configure " .
|
||||
'./configure ' .
|
||||
'--enable-static=yes ' .
|
||||
'--enable-shared=no ' .
|
||||
'--prefix= ' .
|
||||
|
||||
@@ -20,15 +20,14 @@ trait snappy
|
||||
|
||||
shell()->cd($this->source_dir . '/cmake/build')
|
||||
->exec(
|
||||
"{$this->builder->configure_env} cmake " .
|
||||
'cmake ' .
|
||||
"-DCMAKE_TOOLCHAIN_FILE={$this->builder->cmake_toolchain_file} " .
|
||||
'-DCMAKE_BUILD_TYPE=Release ' .
|
||||
'-DCMAKE_INSTALL_PREFIX=' . escapeshellarg(BUILD_ROOT_PATH) . ' ' .
|
||||
"{$this->builder->makeCmakeArgs()} " .
|
||||
'-DSNAPPY_BUILD_TESTS=OFF ' .
|
||||
'-DSNAPPY_BUILD_BENCHMARKS=OFF ' .
|
||||
'../..'
|
||||
)
|
||||
->exec("cmake --build . -j {$this->builder->concurrency}")
|
||||
->exec('make install');
|
||||
->exec('make install DESTDIR=' . BUILD_ROOT_PATH);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ trait sqlite
|
||||
protected function build(): void
|
||||
{
|
||||
shell()->cd($this->source_dir)
|
||||
->exec("{$this->builder->configure_env} ./configure --enable-static --disable-shared --prefix=")
|
||||
->exec('./configure --enable-static --disable-shared --prefix=')
|
||||
->exec('make clean')
|
||||
->exec("make -j{$this->builder->concurrency}")
|
||||
->exec('make install DESTDIR=' . BUILD_ROOT_PATH);
|
||||
|
||||
@@ -17,7 +17,7 @@ trait xz
|
||||
{
|
||||
shell()->cd($this->source_dir)
|
||||
->exec(
|
||||
"{$this->builder->configure_env} ./configure " .
|
||||
'./configure ' .
|
||||
'--enable-static ' .
|
||||
'--disable-shared ' .
|
||||
"--host={$this->builder->getOption('gnu-arch')}-unknown-linux " .
|
||||
|
||||
@@ -18,7 +18,7 @@ trait zlib
|
||||
[,,$destdir] = SEPARATED_PATH;
|
||||
|
||||
shell()->cd($this->source_dir)
|
||||
->exec("{$this->builder->configure_env} ./configure --static --prefix=")
|
||||
->exec('./configure --static --prefix=')
|
||||
->exec('make clean')
|
||||
->exec("make -j{$this->builder->concurrency}")
|
||||
->exec("make install DESTDIR={$destdir}");
|
||||
|
||||
@@ -19,7 +19,7 @@ trait zstd
|
||||
FileSystem::resetDir($this->source_dir . '/build/cmake/build');
|
||||
shell()->cd($this->source_dir . '/build/cmake/build')
|
||||
->exec(
|
||||
"{$this->builder->configure_env} cmake " .
|
||||
'cmake ' .
|
||||
"{$this->builder->makeCmakeArgs()} " .
|
||||
'-DZSTD_BUILD_STATIC=ON ' .
|
||||
'-DZSTD_BUILD_SHARED=OFF ' .
|
||||
|
||||
@@ -7,6 +7,7 @@ namespace SPC\command;
|
||||
use SPC\builder\BuilderProvider;
|
||||
use SPC\exception\ExceptionHandler;
|
||||
use SPC\exception\WrongUsageException;
|
||||
use SPC\store\FileSystem;
|
||||
use SPC\store\SourcePatcher;
|
||||
use SPC\util\DependencyUtil;
|
||||
use SPC\util\LicenseDumper;
|
||||
@@ -25,9 +26,11 @@ class BuildCliCommand extends BuildCommand
|
||||
$this->addOption('build-micro', null, null, 'build micro');
|
||||
$this->addOption('build-cli', null, null, 'build cli');
|
||||
$this->addOption('build-fpm', null, null, 'build fpm');
|
||||
$this->addOption('build-all', null, null, 'build cli, micro, fpm');
|
||||
$this->addOption('build-embed', null, null, 'build embed');
|
||||
$this->addOption('build-all', null, null, 'build cli, micro, fpm, embed');
|
||||
$this->addOption('no-strip', null, null, 'build without strip, in order to debug and load external extensions');
|
||||
$this->addOption('enable-zts', null, null, 'enable ZTS support');
|
||||
$this->addOption('disable-opcache-jit', null, null, 'disable opcache jit');
|
||||
$this->addOption('with-hardcoded-ini', 'I', InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED, 'Patch PHP source code, inject hardcoded INI');
|
||||
$this->addOption('with-micro-fake-cli', null, null, 'Enable phpmicro fake cli');
|
||||
}
|
||||
@@ -40,16 +43,18 @@ class BuildCliCommand extends BuildCommand
|
||||
$extensions = array_map('trim', array_filter(explode(',', $this->getArgument('extensions'))));
|
||||
|
||||
$rule = BUILD_TARGET_NONE;
|
||||
$rule = $rule | ($this->getOption('build-cli') ? BUILD_TARGET_CLI : BUILD_TARGET_NONE);
|
||||
$rule = $rule | ($this->getOption('build-micro') ? BUILD_TARGET_MICRO : BUILD_TARGET_NONE);
|
||||
$rule = $rule | ($this->getOption('build-fpm') ? BUILD_TARGET_FPM : BUILD_TARGET_NONE);
|
||||
$rule = $rule | ($this->getOption('build-all') ? BUILD_TARGET_ALL : BUILD_TARGET_NONE);
|
||||
$rule |= ($this->getOption('build-cli') ? BUILD_TARGET_CLI : BUILD_TARGET_NONE);
|
||||
$rule |= ($this->getOption('build-micro') ? BUILD_TARGET_MICRO : BUILD_TARGET_NONE);
|
||||
$rule |= ($this->getOption('build-fpm') ? BUILD_TARGET_FPM : BUILD_TARGET_NONE);
|
||||
$rule |= ($this->getOption('build-embed') ? BUILD_TARGET_EMBED : BUILD_TARGET_NONE);
|
||||
$rule |= ($this->getOption('build-all') ? BUILD_TARGET_ALL : BUILD_TARGET_NONE);
|
||||
if ($rule === BUILD_TARGET_NONE) {
|
||||
$this->output->writeln('<error>Please add at least one build target!</error>');
|
||||
$this->output->writeln("<comment>\t--build-cli\tBuild php-cli SAPI</comment>");
|
||||
$this->output->writeln("<comment>\t--build-micro\tBuild phpmicro SAPI</comment>");
|
||||
$this->output->writeln("<comment>\t--build-fpm\tBuild php-fpm SAPI</comment>");
|
||||
$this->output->writeln("<comment>\t--build-all\tBuild all SAPI: cli, micro, fpm</comment>");
|
||||
$this->output->writeln("<comment>\t--build-embed\tBuild embed SAPI/libphp</comment>");
|
||||
$this->output->writeln("<comment>\t--build-all\tBuild all SAPI: cli, micro, fpm, embed</comment>");
|
||||
return static::FAILURE;
|
||||
}
|
||||
try {
|
||||
@@ -67,6 +72,10 @@ class BuildCliCommand extends BuildCommand
|
||||
logger()->warning('some extensions will be enabled due to dependencies: ' . implode(',', $not_included));
|
||||
}
|
||||
sleep(2);
|
||||
if ($this->input->getOption('with-clean')) {
|
||||
logger()->info('Cleaning source dir...');
|
||||
FileSystem::removeDir(SOURCE_PATH);
|
||||
}
|
||||
// compile libraries
|
||||
$builder->buildLibs($libraries);
|
||||
// check extensions
|
||||
|
||||
@@ -19,16 +19,17 @@ abstract class BuildCommand extends BaseCommand
|
||||
$this->addOption('arch', null, InputOption::VALUE_REQUIRED, 'architecture, "x64" or "arm64"', 'x64');
|
||||
break;
|
||||
case 'Linux':
|
||||
$this->addOption('no-system-static', null, null, 'do not use system static libraries');
|
||||
// no break
|
||||
case 'Darwin':
|
||||
$this->addOption('cc', null, InputOption::VALUE_REQUIRED, 'C compiler');
|
||||
$this->addOption('cxx', null, InputOption::VALUE_REQUIRED, 'C++ compiler');
|
||||
$this->addOption('ar', null, InputOption::VALUE_REQUIRED, 'ar');
|
||||
$this->addOption('ld', null, InputOption::VALUE_REQUIRED, 'ld');
|
||||
$this->addOption('arch', null, InputOption::VALUE_REQUIRED, 'architecture', php_uname('m'));
|
||||
break;
|
||||
}
|
||||
|
||||
$this->addOption('with-clean', null, null, 'fresh build, `make clean` before `make`');
|
||||
$this->addOption('with-clean', null, null, 'fresh build, remove `source` dir before `make`');
|
||||
$this->addOption('bloat', null, null, 'add all libraries into binary');
|
||||
$this->addOption('rebuild', 'r', null, 'Delete old build and rebuild');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,166 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace SPC\command;
|
||||
|
||||
use SPC\store\FileSystem;
|
||||
use Symfony\Component\Console\Attribute\AsCommand;
|
||||
use Symfony\Component\Console\Helper\ProgressBar;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
|
||||
use function Laravel\Prompts\confirm;
|
||||
use function Laravel\Prompts\text;
|
||||
|
||||
#[AsCommand('deploy', 'Deploy static-php-cli self to an .phar application')]
|
||||
class DeployCommand extends BaseCommand
|
||||
{
|
||||
public function configure(): void
|
||||
{
|
||||
$this->addArgument('target', InputArgument::OPTIONAL, 'The file or directory to pack.');
|
||||
$this->addOption('auto-phar-fix', null, InputOption::VALUE_NONE, 'Automatically fix ini option.');
|
||||
$this->addOption('overwrite', 'W', InputOption::VALUE_NONE, 'Overwrite existing files.');
|
||||
$this->addOption('with-no-dev', 'D', InputOption::VALUE_NONE, 'Automatically use non-dev composer dependencies to reduce size');
|
||||
$this->addOption('with-dev', 'd', InputOption::VALUE_NONE, 'Automatically use dev composer dependencies');
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \PharException
|
||||
*/
|
||||
public function handle(): int
|
||||
{
|
||||
$composer = require ROOT_DIR . '/vendor/composer/installed.php';
|
||||
if (($composer['root']['dev'] ?? false) === true) {
|
||||
if (!$this->getOption('with-no-dev')) {
|
||||
$this->output->writeln('<comment>Current static-php-cli dependencies have installed dev-dependencies</comment>');
|
||||
$this->output->writeln('<comment>If you want to remove, you can choose "Yes" to run command "composer update --no-dev" to remove.</comment>');
|
||||
$this->output->writeln('<comment>Or choose "No", just pack, deploy.</comment>');
|
||||
$ask = confirm('Do you want to remove dev-dependencies to reduce size of phar file?');
|
||||
} elseif (!$this->getOption('with-dev')) {
|
||||
$ask = true;
|
||||
} else {
|
||||
$ask = false;
|
||||
}
|
||||
if ($ask) {
|
||||
[$code] = shell()->execWithResult('composer update --no-dev');
|
||||
if ($code !== 0) {
|
||||
$this->output->writeln('<error>"composer update --no-dev" failed with exit code [' . $code . ']</error>');
|
||||
$this->output->writeln('<error>You may need to run this command by your own.</error>');
|
||||
return static::FAILURE;
|
||||
}
|
||||
$this->output->writeln('<info>Update successfully, you need to re-run deploy command to pack.</info>');
|
||||
return static::SUCCESS;
|
||||
}
|
||||
}
|
||||
// 首先得确认是不是关闭了readonly模式
|
||||
if (ini_get('phar.readonly') == 1) {
|
||||
if ($this->getOption('auto-phar-fix')) {
|
||||
$ask = true;
|
||||
} else {
|
||||
$this->output->writeln('<comment>pack command needs "phar.readonly" = "Off" !</comment>');
|
||||
$ask = confirm('Do you want to automatically set it and continue ?');
|
||||
// $ask = $prompt->requireBool('<comment>pack command needs "phar.readonly" = "Off" !</comment>' . PHP_EOL . 'If you want to automatically set it and continue, just Enter', true);
|
||||
}
|
||||
if ($ask) {
|
||||
global $argv;
|
||||
$args = array_merge(['-d', 'phar.readonly=0'], $_SERVER['argv'], ['--no-motd']);
|
||||
if (function_exists('pcntl_exec')) {
|
||||
$this->output->writeln('<info>Changing to phar.readonly=0 mode ...</info>');
|
||||
if (pcntl_exec(PHP_BINARY, $args) === false) {
|
||||
throw new \PharException('Switching to read write mode failed, please check the environment.');
|
||||
}
|
||||
} else {
|
||||
$this->output->writeln('<info>Now running command in child process.</info>');
|
||||
passthru(PHP_BINARY . ' -d phar.readonly=0 ' . implode(' ', $argv), $retcode);
|
||||
exit($retcode);
|
||||
}
|
||||
}
|
||||
}
|
||||
// 获取路径
|
||||
$path = WORKING_DIR;
|
||||
// 如果是目录,则将目录下的所有文件打包
|
||||
$phar_path = text('Please input the phar target filename', default: '/tmp/static-php-cli.phar');
|
||||
// $phar_path = $prompt->requireArgument('target', 'Please input the phar target filename', 'static-php-cli.phar');
|
||||
|
||||
if (FileSystem::isRelativePath($phar_path)) {
|
||||
$phar_path = WORKING_DIR . '/' . $phar_path;
|
||||
}
|
||||
if (file_exists($phar_path)) {
|
||||
if (!$this->getOption('overwrite')) {
|
||||
$this->output->writeln('<comment>The file "' . $phar_path . '" already exists.</comment>');
|
||||
$ask = confirm('Do you want to overwrite it?');
|
||||
} else {
|
||||
$ask = true;
|
||||
}
|
||||
if (!$ask) {
|
||||
$this->output->writeln('<comment>User canceled.</comment>');
|
||||
return static::FAILURE;
|
||||
}
|
||||
@unlink($phar_path);
|
||||
}
|
||||
$phar = new \Phar($phar_path);
|
||||
$phar->startBuffering();
|
||||
|
||||
$all = FileSystem::scanDirFiles($path, true, true);
|
||||
|
||||
$all = array_filter($all, function ($x) {
|
||||
$dirs = preg_match('/(^(config|src|vendor)\\/|^(composer\\.json|README\\.md|source\\.json|LICENSE|README-en\\.md)$)/', $x);
|
||||
return !($dirs !== 1);
|
||||
});
|
||||
sort($all);
|
||||
$map = [];
|
||||
foreach ($all as $v) {
|
||||
$map[$v] = $path . '/' . $v;
|
||||
}
|
||||
|
||||
$this->output->writeln('<info>Start packing files...</info>');
|
||||
try {
|
||||
foreach ($this->progress()->iterate($map) as $file => $origin_file) {
|
||||
$phar->addFromString($file, php_strip_whitespace($origin_file));
|
||||
}
|
||||
// $phar->buildFromIterator(new SeekableArrayIterator($map, new ProgressBar($output)));
|
||||
$phar->addFromString(
|
||||
'.phar-entry.php',
|
||||
str_replace(
|
||||
'/../vendor/autoload.php',
|
||||
'/vendor/autoload.php',
|
||||
file_get_contents(ROOT_DIR . '/bin/spc')
|
||||
)
|
||||
);
|
||||
$stub = '.phar-entry.php';
|
||||
$phar->setStub($phar->createDefaultStub($stub));
|
||||
} catch (\Throwable $e) {
|
||||
$this->output->writeln($e);
|
||||
return static::FAILURE;
|
||||
}
|
||||
$phar->addFromString('.prod', 'true');
|
||||
$phar->stopBuffering();
|
||||
$this->output->writeln(PHP_EOL . 'Done! Phar file is generated at "' . $phar_path . '".');
|
||||
if (file_exists(SOURCE_PATH . '/php-src/sapi/micro/micro.sfx')) {
|
||||
$this->output->writeln('Detected you have already compiled micro binary, I will make executable now for you!');
|
||||
file_put_contents(
|
||||
pathinfo($phar_path, PATHINFO_DIRNAME) . '/spc',
|
||||
file_get_contents(SOURCE_PATH . '/php-src/sapi/micro/micro.sfx') .
|
||||
file_get_contents($phar_path)
|
||||
);
|
||||
chmod(pathinfo($phar_path, PATHINFO_DIRNAME) . '/spc', 0755);
|
||||
$this->output->writeln('<info>Binary Executable: ' . pathinfo($phar_path, PATHINFO_DIRNAME) . '/spc</info>');
|
||||
}
|
||||
chmod($phar_path, 0755);
|
||||
$this->output->writeln('<info>Phar Executable: ' . $phar_path . '</info>');
|
||||
return static::SUCCESS;
|
||||
}
|
||||
|
||||
private function progress(): ProgressBar
|
||||
{
|
||||
$progress = new ProgressBar($this->output, 0);
|
||||
$progress->setBarCharacter('<fg=green>⚬</>');
|
||||
$progress->setEmptyBarCharacter('<fg=red>⚬</>');
|
||||
$progress->setProgressCharacter('<fg=green>➤</>');
|
||||
$progress->setFormat(
|
||||
"%current%/%max% [%bar%] %percent:3s%%\n🪅 %estimated:-20s% %memory:20s%" . PHP_EOL
|
||||
);
|
||||
return $progress;
|
||||
}
|
||||
}
|
||||
@@ -5,8 +5,12 @@ declare(strict_types=1);
|
||||
namespace SPC\command;
|
||||
|
||||
use SPC\doctor\CheckListHandler;
|
||||
use SPC\doctor\CheckResult;
|
||||
use SPC\exception\RuntimeException;
|
||||
use Symfony\Component\Console\Attribute\AsCommand;
|
||||
|
||||
use function Laravel\Prompts\confirm;
|
||||
|
||||
#[AsCommand('doctor', 'Diagnose whether the current environment can compile normally')]
|
||||
class DoctorCommand extends BaseCommand
|
||||
{
|
||||
@@ -18,14 +22,64 @@ class DoctorCommand extends BaseCommand
|
||||
public function handle(): int
|
||||
{
|
||||
try {
|
||||
$checker = new CheckListHandler($this->input, $this->output);
|
||||
$checker->runCheck($this->input->getOption('auto-fix') ? FIX_POLICY_AUTOFIX : FIX_POLICY_PROMPT);
|
||||
$checker = new CheckListHandler();
|
||||
|
||||
$fix_policy = $this->input->getOption('auto-fix') ? FIX_POLICY_AUTOFIX : FIX_POLICY_PROMPT;
|
||||
foreach ($checker->runChecks() as $check) {
|
||||
if ($check->limit_os !== null && $check->limit_os !== PHP_OS_FAMILY) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->output->write('Checking <comment>' . $check->item_name . '</comment> ... ');
|
||||
|
||||
$result = call_user_func($check->callback);
|
||||
if ($result === null) {
|
||||
$this->output->writeln('skipped');
|
||||
} elseif ($result instanceof CheckResult) {
|
||||
if ($result->isOK()) {
|
||||
$this->output->writeln($result->getMessage() ?? 'ok');
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
// Failed
|
||||
$this->output->writeln('<error>' . $result->getMessage() . '</error>');
|
||||
switch ($fix_policy) {
|
||||
case FIX_POLICY_DIE:
|
||||
throw new RuntimeException('Some check items can not be fixed !');
|
||||
case FIX_POLICY_PROMPT:
|
||||
if ($result->getFixItem() !== '') {
|
||||
$question = confirm('Do you want to fix it?');
|
||||
if ($question) {
|
||||
$checker->emitFix($this->output, $result);
|
||||
} else {
|
||||
throw new RuntimeException('You cancelled fix');
|
||||
}
|
||||
} else {
|
||||
throw new RuntimeException('Some check items can not be fixed !');
|
||||
}
|
||||
break;
|
||||
case FIX_POLICY_AUTOFIX:
|
||||
if ($result->getFixItem() !== '') {
|
||||
$this->output->writeln('Automatically fixing ' . $result->getFixItem() . ' ...');
|
||||
$checker->emitFix($this->output, $result);
|
||||
} else {
|
||||
throw new RuntimeException('Some check items can not be fixed !');
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->output->writeln('<info>Doctor check complete !</info>');
|
||||
} catch (\Throwable $e) {
|
||||
$this->output->writeln('<error>' . $e->getMessage() . '</error>');
|
||||
|
||||
pcntl_signal(SIGINT, SIG_IGN);
|
||||
|
||||
return static::FAILURE;
|
||||
}
|
||||
|
||||
return static::SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,8 +8,10 @@ use SPC\builder\traits\UnixSystemUtilTrait;
|
||||
use SPC\exception\DownloaderException;
|
||||
use SPC\exception\FileSystemException;
|
||||
use SPC\exception\RuntimeException;
|
||||
use SPC\exception\WrongUsageException;
|
||||
use SPC\store\Config;
|
||||
use SPC\store\Downloader;
|
||||
use SPC\util\DependencyUtil;
|
||||
use Symfony\Component\Console\Attribute\AsCommand;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
@@ -28,17 +30,23 @@ class DownloadCommand extends BaseCommand
|
||||
$this->addArgument('sources', InputArgument::REQUIRED, 'The sources will be compiled, comma separated');
|
||||
$this->addOption('shallow-clone', null, null, 'Clone shallow');
|
||||
$this->addOption('with-openssl11', null, null, 'Use openssl 1.1');
|
||||
$this->addOption('with-php', null, InputOption::VALUE_REQUIRED, 'version in major.minor format like 8.1', '8.1');
|
||||
$this->addOption('with-php', null, InputOption::VALUE_REQUIRED, 'version in major.minor format (default 8.2)', '8.2');
|
||||
$this->addOption('clean', null, null, 'Clean old download cache and source before fetch');
|
||||
$this->addOption('all', 'A', null, 'Fetch all sources that static-php-cli needed');
|
||||
$this->addOption('custom-url', 'U', InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED, 'Specify custom source download url, e.g "php-src:https://downloads.php.net/~eric/php-8.3.0beta1.tar.gz"');
|
||||
$this->addOption('from-zip', 'Z', InputOption::VALUE_REQUIRED, 'Fetch from zip archive');
|
||||
$this->addOption('for-extensions', 'e', InputOption::VALUE_REQUIRED, 'Fetch by extensions, e.g "openssl,mbstring"');
|
||||
$this->addOption('without-suggestions', null, null, 'Do not fetch suggested sources when using --for-extensions');
|
||||
}
|
||||
|
||||
public function initialize(InputInterface $input, OutputInterface $output): void
|
||||
{
|
||||
// --all 等于 "" "",也就是所有东西都要下载
|
||||
if ($input->getOption('all') || $input->getOption('clean') || $input->getOption('from-zip')) {
|
||||
if (
|
||||
$input->getOption('all')
|
||||
|| $input->getOption('clean')
|
||||
|| $input->getOption('from-zip')
|
||||
|| $input->getOption('for-extensions')
|
||||
) {
|
||||
$input->setArgument('sources', '');
|
||||
}
|
||||
parent::initialize($input, $output);
|
||||
@@ -51,130 +59,169 @@ class DownloadCommand extends BaseCommand
|
||||
*/
|
||||
public function handle(): int
|
||||
{
|
||||
// 删除旧资源
|
||||
if ($this->getOption('clean')) {
|
||||
logger()->warning('You are doing some operations that not recoverable: removing directories below');
|
||||
logger()->warning(SOURCE_PATH);
|
||||
logger()->warning(DOWNLOAD_PATH);
|
||||
logger()->warning(BUILD_ROOT_PATH);
|
||||
logger()->alert('I will remove these dir after 5 seconds !');
|
||||
sleep(5);
|
||||
if (PHP_OS_FAMILY === 'Windows') {
|
||||
f_passthru('rmdir /s /q ' . SOURCE_PATH);
|
||||
f_passthru('rmdir /s /q ' . DOWNLOAD_PATH);
|
||||
f_passthru('rmdir /s /q ' . BUILD_ROOT_PATH);
|
||||
} else {
|
||||
f_passthru('rm -rf ' . SOURCE_PATH . '/*');
|
||||
f_passthru('rm -rf ' . DOWNLOAD_PATH . '/*');
|
||||
f_passthru('rm -rf ' . BUILD_ROOT_PATH . '/*');
|
||||
}
|
||||
return static::FAILURE;
|
||||
}
|
||||
|
||||
// --from-zip
|
||||
if ($path = $this->getOption('from-zip')) {
|
||||
if (!file_exists($path)) {
|
||||
logger()->critical('File ' . $path . ' not exist or not a zip archive.');
|
||||
return static::FAILURE;
|
||||
}
|
||||
// remove old download files first
|
||||
if (is_dir(DOWNLOAD_PATH)) {
|
||||
try {
|
||||
if ($this->getOption('clean')) {
|
||||
logger()->warning('You are doing some operations that not recoverable: removing directories below');
|
||||
logger()->warning(SOURCE_PATH);
|
||||
logger()->warning(DOWNLOAD_PATH);
|
||||
logger()->warning(BUILD_ROOT_PATH);
|
||||
logger()->alert('I will remove these dir after 5 seconds !');
|
||||
sleep(5);
|
||||
f_passthru((PHP_OS_FAMILY === 'Windows' ? 'rmdir /s /q ' : 'rm -rf ') . DOWNLOAD_PATH);
|
||||
}
|
||||
// unzip command check
|
||||
if (PHP_OS_FAMILY !== 'Windows' && !$this->findCommand('unzip')) {
|
||||
logger()->critical('Missing unzip command, you need to install it first !');
|
||||
logger()->critical('You can use "bin/spc doctor" command to check and install required tools');
|
||||
if (PHP_OS_FAMILY === 'Windows') {
|
||||
f_passthru('rmdir /s /q ' . SOURCE_PATH);
|
||||
f_passthru('rmdir /s /q ' . DOWNLOAD_PATH);
|
||||
f_passthru('rmdir /s /q ' . BUILD_ROOT_PATH);
|
||||
} else {
|
||||
f_passthru('rm -rf ' . SOURCE_PATH . '/*');
|
||||
f_passthru('rm -rf ' . DOWNLOAD_PATH . '/*');
|
||||
f_passthru('rm -rf ' . BUILD_ROOT_PATH . '/*');
|
||||
}
|
||||
return static::FAILURE;
|
||||
}
|
||||
// create downloads
|
||||
try {
|
||||
if (PHP_OS_FAMILY !== 'Windows') {
|
||||
f_passthru('mkdir ' . DOWNLOAD_PATH . ' && cd ' . DOWNLOAD_PATH . ' && unzip ' . escapeshellarg($path));
|
||||
}
|
||||
// Windows TODO
|
||||
|
||||
if (!file_exists(DOWNLOAD_PATH . '/.lock.json')) {
|
||||
throw new RuntimeException('.lock.json not exist in "downloads/"');
|
||||
}
|
||||
} catch (RuntimeException $e) {
|
||||
logger()->critical('Extract failed: ' . $e->getMessage());
|
||||
// --from-zip
|
||||
if ($path = $this->getOption('from-zip')) {
|
||||
return $this->downloadFromZip($path);
|
||||
}
|
||||
|
||||
// Define PHP major version
|
||||
$ver = $this->php_major_ver = $this->getOption('with-php') ?? '8.1';
|
||||
define('SPC_BUILD_PHP_VERSION', $ver);
|
||||
preg_match('/^\d+\.\d+$/', $ver, $matches);
|
||||
if (!$matches) {
|
||||
logger()->error("bad version arg: {$ver}, x.y required!");
|
||||
return static::FAILURE;
|
||||
}
|
||||
logger()->info('Extract success');
|
||||
|
||||
// Use shallow-clone can reduce git resource download
|
||||
if ($this->getOption('shallow-clone')) {
|
||||
define('GIT_SHALLOW_CLONE', true);
|
||||
}
|
||||
|
||||
// To read config
|
||||
Config::getSource('openssl');
|
||||
|
||||
// use openssl 1.1
|
||||
if ($this->getOption('with-openssl11')) {
|
||||
logger()->debug('Using openssl 1.1');
|
||||
Config::$source['openssl']['regex'] = '/href="(?<file>openssl-(?<version>1.[^"]+)\.tar\.gz)\"/';
|
||||
}
|
||||
|
||||
// --for-extensions
|
||||
if ($for_ext = $this->getOption('for-extensions')) {
|
||||
$ext = array_map('trim', array_filter(explode(',', $for_ext)));
|
||||
$sources = $this->calculateSourcesByExt($ext, !$this->getOption('without-suggestions'));
|
||||
array_unshift($sources, 'php-src', 'micro', 'pkg-config');
|
||||
} else {
|
||||
// get source list that will be downloaded
|
||||
$sources = array_map('trim', array_filter(explode(',', $this->getArgument('sources'))));
|
||||
if (empty($sources)) {
|
||||
$sources = array_keys(Config::getSources());
|
||||
}
|
||||
}
|
||||
$chosen_sources = $sources;
|
||||
|
||||
// Process -U options
|
||||
$custom_urls = [];
|
||||
foreach ($this->input->getOption('custom-url') as $value) {
|
||||
[$source_name, $url] = explode(':', $value, 2);
|
||||
$custom_urls[$source_name] = $url;
|
||||
}
|
||||
|
||||
// Download them
|
||||
f_mkdir(DOWNLOAD_PATH);
|
||||
$cnt = count($chosen_sources);
|
||||
$ni = 0;
|
||||
foreach ($chosen_sources as $source) {
|
||||
++$ni;
|
||||
if (isset($custom_urls[$source])) {
|
||||
$config = Config::getSource($source);
|
||||
$new_config = [
|
||||
'type' => 'url',
|
||||
'url' => $custom_urls[$source],
|
||||
];
|
||||
if (isset($config['path'])) {
|
||||
$new_config['path'] = $config['path'];
|
||||
}
|
||||
if (isset($config['filename'])) {
|
||||
$new_config['filename'] = $config['filename'];
|
||||
}
|
||||
logger()->info("Fetching source {$source} from custom url [{$ni}/{$cnt}]");
|
||||
Downloader::downloadSource($source, $new_config, true);
|
||||
} else {
|
||||
logger()->info("Fetching source {$source} [{$ni}/{$cnt}]");
|
||||
Downloader::downloadSource($source, Config::getSource($source));
|
||||
}
|
||||
}
|
||||
$time = round(microtime(true) - START_TIME, 3);
|
||||
logger()->info('Download complete, used ' . $time . ' s !');
|
||||
return static::SUCCESS;
|
||||
}
|
||||
|
||||
// Define PHP major version
|
||||
$ver = $this->php_major_ver = $this->getOption('with-php') ?? '8.1';
|
||||
define('SPC_BUILD_PHP_VERSION', $ver);
|
||||
preg_match('/^\d+\.\d+$/', $ver, $matches);
|
||||
if (!$matches) {
|
||||
logger()->error("bad version arg: {$ver}, x.y required!");
|
||||
} catch (DownloaderException $e) {
|
||||
logger()->error($e->getMessage());
|
||||
return static::FAILURE;
|
||||
} catch (WrongUsageException $e) {
|
||||
logger()->critical($e->getMessage());
|
||||
return static::FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
// Use shallow-clone can reduce git resource download
|
||||
if ($this->getOption('shallow-clone')) {
|
||||
define('GIT_SHALLOW_CLONE', true);
|
||||
private function downloadFromZip(string $path): int
|
||||
{
|
||||
if (!file_exists($path)) {
|
||||
logger()->critical('File ' . $path . ' not exist or not a zip archive.');
|
||||
return static::FAILURE;
|
||||
}
|
||||
|
||||
// To read config
|
||||
Config::getSource('openssl');
|
||||
|
||||
// use openssl 1.1
|
||||
if ($this->getOption('with-openssl11')) {
|
||||
logger()->debug('Using openssl 1.1');
|
||||
// 手动修改配置
|
||||
Config::$source['openssl']['regex'] = '/href="(?<file>openssl-(?<version>1.[^"]+)\.tar\.gz)\"/';
|
||||
// remove old download files first
|
||||
if (is_dir(DOWNLOAD_PATH)) {
|
||||
logger()->warning('You are doing some operations that not recoverable: removing directories below');
|
||||
logger()->warning(DOWNLOAD_PATH);
|
||||
logger()->alert('I will remove these dir after 5 seconds !');
|
||||
sleep(5);
|
||||
f_passthru((PHP_OS_FAMILY === 'Windows' ? 'rmdir /s /q ' : 'rm -rf ') . DOWNLOAD_PATH);
|
||||
}
|
||||
|
||||
// get source list that will be downloaded
|
||||
$sources = array_map('trim', array_filter(explode(',', $this->getArgument('sources'))));
|
||||
if (empty($sources)) {
|
||||
$sources = array_keys(Config::getSources());
|
||||
// unzip command check
|
||||
if (PHP_OS_FAMILY !== 'Windows' && !$this->findCommand('unzip')) {
|
||||
logger()->critical('Missing unzip command, you need to install it first !');
|
||||
logger()->critical('You can use "bin/spc doctor" command to check and install required tools');
|
||||
return static::FAILURE;
|
||||
}
|
||||
$chosen_sources = $sources;
|
||||
|
||||
// Process -U options
|
||||
$custom_urls = [];
|
||||
foreach ($this->input->getOption('custom-url') as $value) {
|
||||
[$source_name, $url] = explode(':', $value, 2);
|
||||
$custom_urls[$source_name] = $url;
|
||||
}
|
||||
|
||||
// Download them
|
||||
f_mkdir(DOWNLOAD_PATH);
|
||||
$cnt = count($chosen_sources);
|
||||
$ni = 0;
|
||||
foreach ($chosen_sources as $source) {
|
||||
++$ni;
|
||||
if (isset($custom_urls[$source])) {
|
||||
$config = Config::getSource($source);
|
||||
$new_config = [
|
||||
'type' => 'url',
|
||||
'url' => $custom_urls[$source],
|
||||
];
|
||||
if (isset($config['path'])) {
|
||||
$new_config['path'] = $config['path'];
|
||||
}
|
||||
if (isset($config['filename'])) {
|
||||
$new_config['filename'] = $config['filename'];
|
||||
}
|
||||
logger()->info("Fetching source {$source} from custom url [{$ni}/{$cnt}]");
|
||||
Downloader::downloadSource($source, $new_config, true);
|
||||
} else {
|
||||
logger()->info("Fetching source {$source} [{$ni}/{$cnt}]");
|
||||
Downloader::downloadSource($source, Config::getSource($source));
|
||||
// create downloads
|
||||
try {
|
||||
if (PHP_OS_FAMILY !== 'Windows') {
|
||||
f_passthru('mkdir ' . DOWNLOAD_PATH . ' && cd ' . DOWNLOAD_PATH . ' && unzip ' . escapeshellarg($path));
|
||||
}
|
||||
// Windows TODO
|
||||
|
||||
if (!file_exists(DOWNLOAD_PATH . '/.lock.json')) {
|
||||
throw new RuntimeException('.lock.json not exist in "downloads/"');
|
||||
}
|
||||
} catch (RuntimeException $e) {
|
||||
logger()->critical('Extract failed: ' . $e->getMessage());
|
||||
return static::FAILURE;
|
||||
}
|
||||
// 打印拉取资源用时
|
||||
$time = round(microtime(true) - START_TIME, 3);
|
||||
logger()->info('Download complete, used ' . $time . ' s !');
|
||||
logger()->info('Extract success');
|
||||
return static::SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the sources by extensions
|
||||
*
|
||||
* @param array $extensions extension list
|
||||
* @throws FileSystemException
|
||||
* @throws WrongUsageException
|
||||
*/
|
||||
private function calculateSourcesByExt(array $extensions, bool $include_suggests = true): array
|
||||
{
|
||||
[$extensions, $libraries] = $include_suggests ? DependencyUtil::getAllExtLibsByDeps($extensions) : DependencyUtil::getExtLibsByDeps($extensions);
|
||||
$sources = [];
|
||||
foreach ($extensions as $extension) {
|
||||
if (Config::getExt($extension, 'type') === 'external') {
|
||||
$sources[] = Config::getExt($extension, 'source');
|
||||
}
|
||||
}
|
||||
foreach ($libraries as $library) {
|
||||
$sources[] = Config::getLib($library, 'source');
|
||||
}
|
||||
return array_values(array_unique($sources));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ class DumpLicenseCommand extends BaseCommand
|
||||
{
|
||||
public function configure(): void
|
||||
{
|
||||
$this->addOption('by-extensions', null, InputOption::VALUE_REQUIRED, 'Dump by extensions and related libraries', null);
|
||||
$this->addOption('for-extensions', null, InputOption::VALUE_REQUIRED, 'Dump by extensions and related libraries', null);
|
||||
$this->addOption('without-php', null, InputOption::VALUE_NONE, 'Dump without php-src');
|
||||
$this->addOption('by-libs', null, InputOption::VALUE_REQUIRED, 'Dump by libraries', null);
|
||||
$this->addOption('by-sources', null, InputOption::VALUE_REQUIRED, 'Dump by original sources (source.json)', null);
|
||||
@@ -35,9 +35,9 @@ class DumpLicenseCommand extends BaseCommand
|
||||
public function handle(): int
|
||||
{
|
||||
$dumper = new LicenseDumper();
|
||||
if ($this->getOption('by-extensions') !== null) {
|
||||
if ($this->getOption('for-extensions') !== null) {
|
||||
// 从参数中获取要编译的 extensions,并转换为数组
|
||||
$extensions = array_map('trim', array_filter(explode(',', $this->getOption('by-extensions'))));
|
||||
$extensions = array_map('trim', array_filter(explode(',', $this->getOption('for-extensions'))));
|
||||
// 根据提供的扩展列表获取依赖库列表并编译
|
||||
[$extensions, $libraries] = DependencyUtil::getExtLibsByDeps($extensions);
|
||||
$dumper->addExts($extensions);
|
||||
@@ -67,7 +67,7 @@ class DumpLicenseCommand extends BaseCommand
|
||||
$this->output->writeln('Dump target dir: ' . $this->getOption('dump-dir'));
|
||||
return static::SUCCESS;
|
||||
}
|
||||
$this->output->writeln('You must use one of "--by-extensions=", "--by-libs=", "--by-sources=" to dump');
|
||||
$this->output->writeln('You must use one of "--for-extensions=", "--by-libs=", "--by-sources=" to dump');
|
||||
return static::FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ namespace SPC\command\dev;
|
||||
|
||||
use SPC\command\BaseCommand;
|
||||
use SPC\exception\FileSystemException;
|
||||
use SPC\exception\RuntimeException;
|
||||
use SPC\exception\WrongUsageException;
|
||||
use SPC\store\Config;
|
||||
use SPC\util\DependencyUtil;
|
||||
@@ -13,20 +14,24 @@ use Symfony\Component\Console\Attribute\AsCommand;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
|
||||
use function Laravel\Prompts\table;
|
||||
|
||||
#[AsCommand('dev:extensions', 'Helper command that lists available extension details', ['list-ext'])]
|
||||
class AllExtCommand extends BaseCommand
|
||||
{
|
||||
public function configure(): void
|
||||
{
|
||||
$this->addArgument('extensions', InputArgument::OPTIONAL | InputArgument::IS_ARRAY, 'Extension name', null);
|
||||
$this->addArgument('extensions', InputArgument::OPTIONAL, 'List of extensions that will be displayed, comma separated');
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws FileSystemException
|
||||
* @throws WrongUsageException
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public function handle(): int
|
||||
{
|
||||
$extensions = $this->input->getArgument('extensions') ?: [];
|
||||
$extensions = array_map('trim', array_filter(explode(',', $this->getArgument('extensions') ?? '')));
|
||||
|
||||
$style = new SymfonyStyle($this->input, $this->output);
|
||||
$style->writeln($extensions ? 'Available extensions:' : 'Extensions:');
|
||||
@@ -59,7 +64,7 @@ class AllExtCommand extends BaseCommand
|
||||
if ($data === []) {
|
||||
$style->warning('Unknown extension selected: ' . implode(',', $extensions));
|
||||
} else {
|
||||
$style->table(
|
||||
table(
|
||||
['Extension', 'lib-depends', 'lib-suggests', 'ext-depends', 'ext-suggests', 'unix-only'],
|
||||
$data
|
||||
);
|
||||
|
||||
@@ -9,7 +9,7 @@ use Symfony\Component\Console\Attribute\AsCommand;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
#[AsCommand('dev:php-ver', 'Dev command')]
|
||||
#[AsCommand('dev:php-version', 'Returns version of PHP located source directory', ['dev:php-ver'])]
|
||||
class PhpVerCommand extends BaseCommand
|
||||
{
|
||||
public function initialize(InputInterface $input, OutputInterface $output): void
|
||||
@@ -22,11 +22,19 @@ class PhpVerCommand extends BaseCommand
|
||||
{
|
||||
// Find php from source/php-src
|
||||
$file = SOURCE_PATH . '/php-src/main/php_version.h';
|
||||
if (!file_exists($file)) {
|
||||
$this->output->writeln('<error>PHP source not found, maybe you need to extract first ?</error>');
|
||||
|
||||
return static::FAILURE;
|
||||
}
|
||||
|
||||
$result = preg_match('/#define PHP_VERSION "([^"]+)"/', file_get_contents($file), $match);
|
||||
if ($result === false) {
|
||||
$this->output->writeln('<error>PHP source not found, maybe you need to extract first ?</error>');
|
||||
|
||||
return static::FAILURE;
|
||||
}
|
||||
|
||||
$this->output->writeln('<info>' . $match[1] . '</info>');
|
||||
return static::SUCCESS;
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ use Symfony\Component\Console\Input\InputArgument;
|
||||
/**
|
||||
* Modify config file: sort lib, ext, source by name.
|
||||
*/
|
||||
#[AsCommand('dev:sort-config', 'After config edited, sort it by alphabet', ['sort-config'])]
|
||||
#[AsCommand('dev:sort-config', 'After config edited, sort it by alphabet', ['sort-config'], true)]
|
||||
class SortConfigCommand extends BaseCommand
|
||||
{
|
||||
public function configure(): void
|
||||
@@ -34,7 +34,7 @@ class SortConfigCommand extends BaseCommand
|
||||
$file = json_decode(FileSystem::readFile(ROOT_DIR . '/config/lib.json'), true);
|
||||
ConfigValidator::validateLibs($file);
|
||||
ksort($file);
|
||||
if (!file_put_contents(ROOT_DIR . '/config/lib.json', json_encode($file, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE))) {
|
||||
if (!file_put_contents(ROOT_DIR . '/config/lib.json', json_encode($file, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) . "\n")) {
|
||||
$this->output->writeln('<error>Write file lib.json failed!</error>');
|
||||
return static::FAILURE;
|
||||
}
|
||||
@@ -43,7 +43,7 @@ class SortConfigCommand extends BaseCommand
|
||||
$file = json_decode(FileSystem::readFile(ROOT_DIR . '/config/source.json'), true);
|
||||
ConfigValidator::validateSource($file);
|
||||
uksort($file, fn ($a, $b) => $a === 'php-src' ? -1 : ($b === 'php-src' ? 1 : ($a < $b ? -1 : 1)));
|
||||
if (!file_put_contents(ROOT_DIR . '/config/source.json', json_encode($file, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE))) {
|
||||
if (!file_put_contents(ROOT_DIR . '/config/source.json', json_encode($file, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) . "\n")) {
|
||||
$this->output->writeln('<error>Write file source.json failed!</error>');
|
||||
return static::FAILURE;
|
||||
}
|
||||
@@ -52,7 +52,7 @@ class SortConfigCommand extends BaseCommand
|
||||
$file = json_decode(FileSystem::readFile(ROOT_DIR . '/config/ext.json'), true);
|
||||
ConfigValidator::validateExts($file);
|
||||
ksort($file);
|
||||
if (!file_put_contents(ROOT_DIR . '/config/ext.json', json_encode($file, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE))) {
|
||||
if (!file_put_contents(ROOT_DIR . '/config/ext.json', json_encode($file, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) . "\n")) {
|
||||
$this->output->writeln('<error>Write file ext.json failed!</error>');
|
||||
return static::FAILURE;
|
||||
}
|
||||
|
||||
@@ -7,105 +7,62 @@ namespace SPC\doctor;
|
||||
use SPC\exception\FileSystemException;
|
||||
use SPC\exception\RuntimeException;
|
||||
use SPC\store\FileSystem;
|
||||
use Symfony\Component\Console\Helper\QuestionHelper;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Question\ConfirmationQuestion;
|
||||
|
||||
class CheckListHandler
|
||||
final class CheckListHandler
|
||||
{
|
||||
/** @var AsCheckItem[] */
|
||||
private array $check_list = [];
|
||||
|
||||
private array $fix_map = [];
|
||||
|
||||
public function __construct() {}
|
||||
|
||||
/**
|
||||
* @return array<AsCheckItem>
|
||||
* @throws \ReflectionException
|
||||
* @throws RuntimeException
|
||||
* @throws FileSystemException
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public function __construct(private readonly InputInterface $input, private readonly OutputInterface $output, bool $include_manual = false)
|
||||
public function runChecks(bool $include_manual = false): array
|
||||
{
|
||||
$this->loadCheckList($include_manual);
|
||||
return $this->loadCheckList($include_manual);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public function runSingleCheck(string $item_name, int $fix_policy = FIX_POLICY_DIE): void
|
||||
public function emitFix(OutputInterface $output, CheckResult $result): void
|
||||
{
|
||||
foreach ($this->check_list as $item) {
|
||||
if ($item->item_name === $item_name) {
|
||||
$this->check_list = [$item];
|
||||
break;
|
||||
}
|
||||
}
|
||||
$this->runCheck($fix_policy);
|
||||
}
|
||||
pcntl_signal(SIGINT, function () use ($output) {
|
||||
$output->writeln('<error>You cancelled fix</error>');
|
||||
});
|
||||
|
||||
/**
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public function runCheck(int $fix_policy = FIX_POLICY_DIE): void
|
||||
{
|
||||
foreach ($this->check_list as $item) {
|
||||
if ($item->limit_os !== null && $item->limit_os !== PHP_OS_FAMILY) {
|
||||
continue;
|
||||
}
|
||||
$this->output->write('Checking <comment>' . $item->item_name . '</comment> ... ');
|
||||
$result = call_user_func($item->callback);
|
||||
if ($result === null) {
|
||||
$this->output->writeln('skipped');
|
||||
} elseif ($result instanceof CheckResult) {
|
||||
if ($result->isOK()) {
|
||||
$this->output->writeln($result->getMessage() ?? 'ok');
|
||||
continue;
|
||||
}
|
||||
// Failed
|
||||
$this->output->writeln('<error>' . $result->getMessage() . '</error>');
|
||||
switch ($fix_policy) {
|
||||
case FIX_POLICY_DIE:
|
||||
throw new RuntimeException('Some check items can not be fixed !');
|
||||
case FIX_POLICY_PROMPT:
|
||||
if ($result->getFixItem() !== '') {
|
||||
$helper = new QuestionHelper();
|
||||
$question = new ConfirmationQuestion('Do you want to fix it? [Y/n] ', true);
|
||||
if ($helper->ask($this->input, $this->output, $question)) {
|
||||
$this->emitFix($result);
|
||||
} else {
|
||||
throw new RuntimeException('You cancelled fix');
|
||||
}
|
||||
} else {
|
||||
throw new RuntimeException('Some check items can not be fixed !');
|
||||
}
|
||||
break;
|
||||
case FIX_POLICY_AUTOFIX:
|
||||
if ($result->getFixItem() !== '') {
|
||||
$this->output->writeln('Automatically fixing ' . $result->getFixItem() . ' ...');
|
||||
$this->emitFix($result);
|
||||
} else {
|
||||
throw new RuntimeException('Some check items can not be fixed !');
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
$fix_result = call_user_func($this->fix_map[$result->getFixItem()], ...$result->getFixParams());
|
||||
pcntl_signal(SIGINT, SIG_IGN);
|
||||
|
||||
if ($fix_result) {
|
||||
$output->writeln('<info>Fix done</info>');
|
||||
} else {
|
||||
$output->writeln('<error>Fix failed</error>');
|
||||
throw new RuntimeException('Some check item are not fixed');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load Doctor check item list
|
||||
*
|
||||
* @return array<AsCheckItem>
|
||||
* @throws \ReflectionException
|
||||
* @throws RuntimeException
|
||||
* @throws FileSystemException
|
||||
*/
|
||||
private function loadCheckList(bool $include_manual = false): void
|
||||
private function loadCheckList(bool $include_manual = false): array
|
||||
{
|
||||
foreach (FileSystem::getClassesPsr4(__DIR__ . '/item', 'SPC\\doctor\\item') as $class) {
|
||||
$ref = new \ReflectionClass($class);
|
||||
foreach ($ref->getMethods() as $method) {
|
||||
$attr = $method->getAttributes();
|
||||
foreach ($attr as $a) {
|
||||
foreach ($method->getAttributes() as $a) {
|
||||
if (is_a($a->getName(), AsCheckItem::class, true)) {
|
||||
/** @var AsCheckItem $instance */
|
||||
$instance = $a->newInstance();
|
||||
@@ -126,26 +83,10 @@ class CheckListHandler
|
||||
}
|
||||
}
|
||||
}
|
||||
// sort check list by level
|
||||
usort($this->check_list, fn ($a, $b) => $a->level > $b->level ? -1 : ($a->level == $b->level ? 0 : 1));
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
private function emitFix(CheckResult $result): void
|
||||
{
|
||||
pcntl_signal(SIGINT, function () {
|
||||
$this->output->writeln('<error>You cancelled fix</error>');
|
||||
});
|
||||
$fix = $this->fix_map[$result->getFixItem()];
|
||||
$fix_result = call_user_func($fix, ...$result->getFixParams());
|
||||
pcntl_signal(SIGINT, SIG_IGN);
|
||||
if ($fix_result) {
|
||||
$this->output->writeln('<info>Fix done</info>');
|
||||
} else {
|
||||
$this->output->writeln('<error>Fix failed</error>');
|
||||
throw new RuntimeException('Some check item are not fixed');
|
||||
}
|
||||
// sort check list by level
|
||||
usort($this->check_list, fn (AsCheckItem $a, AsCheckItem $b) => $a->level > $b->level ? -1 : ($a->level == $b->level ? 0 : 1));
|
||||
|
||||
return $this->check_list;
|
||||
}
|
||||
}
|
||||
|
||||
66
src/SPC/doctor/item/BSDToolCheckList.php
Normal file
66
src/SPC/doctor/item/BSDToolCheckList.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace SPC\doctor\item;
|
||||
|
||||
use SPC\builder\traits\UnixSystemUtilTrait;
|
||||
use SPC\doctor\AsCheckItem;
|
||||
use SPC\doctor\AsFixItem;
|
||||
use SPC\doctor\CheckResult;
|
||||
use SPC\exception\RuntimeException;
|
||||
|
||||
class BSDToolCheckList
|
||||
{
|
||||
use UnixSystemUtilTrait;
|
||||
|
||||
/** @var string[] FreeBSD */
|
||||
public const REQUIRED_COMMANDS = [
|
||||
'curl',
|
||||
'make',
|
||||
'bison',
|
||||
'flex',
|
||||
'pkg-config',
|
||||
'git',
|
||||
'autoconf',
|
||||
'automake',
|
||||
'tar',
|
||||
'unzip',
|
||||
'xz',
|
||||
'gzip',
|
||||
'bzip2',
|
||||
'cmake',
|
||||
];
|
||||
|
||||
#[AsCheckItem('if necessary tools are installed', limit_os: 'BSD')]
|
||||
public function checkCliTools(): ?CheckResult
|
||||
{
|
||||
$missing = [];
|
||||
foreach (self::REQUIRED_COMMANDS as $cmd) {
|
||||
if ($this->findCommand($cmd) === null) {
|
||||
$missing[] = $cmd;
|
||||
}
|
||||
}
|
||||
if (!empty($missing)) {
|
||||
return CheckResult::fail('missing system commands: ' . implode(', ', $missing), 'build-tools-bsd', [$missing]);
|
||||
}
|
||||
return CheckResult::ok();
|
||||
}
|
||||
|
||||
#[AsFixItem('build-tools-bsd')]
|
||||
public function fixBuildTools(array $missing): bool
|
||||
{
|
||||
if (get_current_user() !== 'root') {
|
||||
$prefix = 'sudo ';
|
||||
logger()->warning('Current user is not root, using sudo for running command');
|
||||
} else {
|
||||
$prefix = '';
|
||||
}
|
||||
try {
|
||||
shell(true)->exec("ASSUME_ALWAYS_YES=yes {$prefix} pkg install -y " . implode(' ', $missing));
|
||||
} catch (RuntimeException) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -8,46 +8,105 @@ use SPC\builder\linux\SystemUtil;
|
||||
use SPC\doctor\AsCheckItem;
|
||||
use SPC\doctor\AsFixItem;
|
||||
use SPC\doctor\CheckResult;
|
||||
use SPC\exception\DownloaderException;
|
||||
use SPC\exception\FileSystemException;
|
||||
use SPC\exception\RuntimeException;
|
||||
use SPC\exception\WrongUsageException;
|
||||
use SPC\store\Downloader;
|
||||
use SPC\store\FileSystem;
|
||||
|
||||
class LinuxMuslCheck
|
||||
{
|
||||
/** @noinspection PhpUnused */
|
||||
#[AsCheckItem('if musl-libc is installed', limit_os: 'Linux')]
|
||||
public function checkMusl(): ?CheckResult
|
||||
#[AsCheckItem('if musl-wrapper is installed', limit_os: 'Linux', level: 800)]
|
||||
public function checkMusl(): CheckResult
|
||||
{
|
||||
$file = sprintf('/lib/ld-musl-%s.so.1', php_uname('m'));
|
||||
if (file_exists($file)) {
|
||||
if (SystemUtil::isMuslDist()) {
|
||||
return CheckResult::ok('musl-based distro, skipped');
|
||||
}
|
||||
|
||||
$musl_wrapper_lib = sprintf('/lib/ld-musl-%s.so.1', php_uname('m'));
|
||||
if (file_exists($musl_wrapper_lib) && file_exists('/usr/local/musl/lib/libc.a')) {
|
||||
return CheckResult::ok();
|
||||
}
|
||||
|
||||
// non-exist, need to recognize distro
|
||||
$distro = SystemUtil::getOSRelease();
|
||||
return match ($distro['dist']) {
|
||||
'ubuntu', 'alpine', 'debian' => CheckResult::fail('musl-libc is not installed on your system', 'fix-musl', [$distro]),
|
||||
default => CheckResult::fail('musl-libc is not installed on your system'),
|
||||
};
|
||||
return CheckResult::fail('musl-wrapper is not installed on your system', 'fix-musl-wrapper');
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws RuntimeException
|
||||
* @noinspection PhpUnused
|
||||
*/
|
||||
#[AsFixItem('fix-musl')]
|
||||
public function fixMusl(array $distro): bool
|
||||
#[AsCheckItem('if musl-cross-make is installed', limit_os: 'Linux', level: 799)]
|
||||
public function checkMuslCrossMake(): CheckResult
|
||||
{
|
||||
$install_cmd = match ($distro['dist']) {
|
||||
'ubuntu', 'debian' => 'apt-get install musl musl-tools -y',
|
||||
'alpine' => 'apk add musl musl-utils musl-dev',
|
||||
default => throw new RuntimeException('Current linux distro is not supported for auto-install musl packages'),
|
||||
};
|
||||
$prefix = '';
|
||||
if (get_current_user() !== 'root') {
|
||||
$prefix = 'sudo ';
|
||||
logger()->warning('Current user is not root, using sudo for running command');
|
||||
if (SystemUtil::isMuslDist()) {
|
||||
return CheckResult::ok('musl-based distro, skipped');
|
||||
}
|
||||
$arch = arch2gnu(php_uname('m'));
|
||||
$cross_compile_lib = "/usr/local/musl/{$arch}-linux-musl/lib/libc.a";
|
||||
$cross_compile_gcc = "/usr/local/musl/bin/{$arch}-linux-musl-gcc";
|
||||
if (file_exists($cross_compile_lib) && file_exists($cross_compile_gcc)) {
|
||||
return CheckResult::ok();
|
||||
}
|
||||
return CheckResult::fail('musl-cross-make is not installed on your system', 'fix-musl-cross-make');
|
||||
}
|
||||
|
||||
/** @noinspection PhpUnused */
|
||||
/**
|
||||
* @throws DownloaderException
|
||||
* @throws FileSystemException
|
||||
*/
|
||||
#[AsFixItem('fix-musl-wrapper')]
|
||||
public function fixMusl(): bool
|
||||
{
|
||||
try {
|
||||
shell(true)->exec($prefix . $install_cmd);
|
||||
$prefix = '';
|
||||
if (get_current_user() !== 'root') {
|
||||
$prefix = 'sudo ';
|
||||
logger()->warning('Current user is not root, using sudo for running command');
|
||||
}
|
||||
// The hardcoded version here is to be consistent with the version compiled by `musl-cross-toolchain`.
|
||||
$musl_version_name = 'musl-1.2.4';
|
||||
$musl_source = [
|
||||
'type' => 'url',
|
||||
'url' => "https://musl.libc.org/releases/{$musl_version_name}.tar.gz",
|
||||
];
|
||||
logger()->info('Downloading ' . $musl_source['url']);
|
||||
Downloader::downloadSource($musl_version_name, $musl_source);
|
||||
FileSystem::extractSource($musl_version_name, DOWNLOAD_PATH . "/{$musl_version_name}.tar.gz");
|
||||
logger()->info('Installing musl wrapper');
|
||||
shell()->cd(SOURCE_PATH . "/{$musl_version_name}")
|
||||
->exec('./configure --disable-gcc-wrapper')
|
||||
->exec('make -j')
|
||||
->exec("{$prefix}make install");
|
||||
// TODO: add path using putenv instead of editing /etc/profile
|
||||
return true;
|
||||
} catch (RuntimeException) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/** @noinspection PhpUnused */
|
||||
/**
|
||||
* @throws DownloaderException
|
||||
* @throws FileSystemException
|
||||
* @throws WrongUsageException
|
||||
*/
|
||||
#[AsFixItem('fix-musl-cross-make')]
|
||||
public function fixMuslCrossMake(): bool
|
||||
{
|
||||
try {
|
||||
$prefix = '';
|
||||
if (get_current_user() !== 'root') {
|
||||
$prefix = 'sudo ';
|
||||
logger()->warning('Current user is not root, using sudo for running command');
|
||||
}
|
||||
$arch = arch2gnu(php_uname('m'));
|
||||
$musl_compile_source = [
|
||||
'type' => 'url',
|
||||
'url' => "https://dl.static-php.dev/static-php-cli/deps/musl-toolchain/{$arch}-musl-toolchain.tgz",
|
||||
];
|
||||
logger()->info('Downloading ' . $musl_compile_source['url']);
|
||||
Downloader::downloadSource('musl-compile', $musl_compile_source);
|
||||
logger()->info('Extracting musl-cross');
|
||||
FileSystem::extractSource('musl-compile', DOWNLOAD_PATH . "/{$arch}-musl-toolchain.tgz");
|
||||
shell()->exec($prefix . 'cp -rf ' . SOURCE_PATH . '/musl-compile/* /usr/local/musl');
|
||||
return true;
|
||||
} catch (RuntimeException) {
|
||||
return false;
|
||||
|
||||
@@ -20,7 +20,7 @@ class LinuxToolCheckList
|
||||
'git', 'autoconf', 'automake',
|
||||
'tar', 'unzip', 'gzip',
|
||||
'bzip2', 'cmake', 'gcc',
|
||||
'g++', 'patch',
|
||||
'g++', 'patch', 'binutils-gold',
|
||||
];
|
||||
|
||||
public const TOOLS_DEBIAN = [
|
||||
@@ -31,14 +31,24 @@ class LinuxToolCheckList
|
||||
'xz',
|
||||
];
|
||||
|
||||
public const TOOLS_RHEL = [
|
||||
'perl', 'make', 'bison', 'flex',
|
||||
'git', 'autoconf', 'automake',
|
||||
'tar', 'unzip', 'gzip', 'gcc',
|
||||
'bzip2', 'cmake', 'patch',
|
||||
'xz', 'wget', // to get musl
|
||||
];
|
||||
|
||||
/** @noinspection PhpUnused */
|
||||
#[AsCheckItem('if necessary tools are installed', limit_os: 'Linux')]
|
||||
#[AsCheckItem('if necessary tools are installed', limit_os: 'Linux', level: 999)]
|
||||
public function checkCliTools(): ?CheckResult
|
||||
{
|
||||
$distro = SystemUtil::getOSRelease();
|
||||
|
||||
$required = match ($distro['dist']) {
|
||||
'alpine' => self::TOOLS_ALPINE,
|
||||
'almalinux' => self::TOOLS_RHEL,
|
||||
'rhel' => self::TOOLS_RHEL,
|
||||
default => self::TOOLS_DEBIAN,
|
||||
};
|
||||
$missing = [];
|
||||
@@ -49,7 +59,11 @@ class LinuxToolCheckList
|
||||
}
|
||||
if (!empty($missing)) {
|
||||
return match ($distro['dist']) {
|
||||
'ubuntu', 'alpine', 'debian' => CheckResult::fail(implode(', ', $missing) . ' not installed on your system', 'install-linux-tools', [$distro, $missing]),
|
||||
'ubuntu',
|
||||
'alpine',
|
||||
'rhel',
|
||||
'almalinux',
|
||||
'debian' => CheckResult::fail(implode(', ', $missing) . ' not installed on your system', 'install-linux-tools', [$distro, $missing]),
|
||||
default => CheckResult::fail(implode(', ', $missing) . ' not installed on your system'),
|
||||
};
|
||||
}
|
||||
@@ -80,7 +94,9 @@ class LinuxToolCheckList
|
||||
$install_cmd = match ($distro['dist']) {
|
||||
'ubuntu', 'debian' => 'apt-get install -y',
|
||||
'alpine' => 'apk add',
|
||||
default => throw new RuntimeException('Current linux distro is not supported for auto-install musl packages'),
|
||||
'rhel' => 'dnf install -y',
|
||||
'almalinux' => 'dnf install -y',
|
||||
default => throw new RuntimeException('Current linux distro does not have an auto-install script for musl packages yet.'),
|
||||
};
|
||||
$prefix = '';
|
||||
if (get_current_user() !== 'root') {
|
||||
@@ -88,7 +104,9 @@ class LinuxToolCheckList
|
||||
logger()->warning('Current user is not root, using sudo for running command');
|
||||
}
|
||||
try {
|
||||
shell(true)->exec($prefix . $install_cmd . ' ' . implode(' ', str_replace('xz', 'xz-utils', $missing)));
|
||||
$is_rhel = in_array($distro['dist'], ['rhel', 'almalinux']);
|
||||
$to_install = $is_rhel ? $missing : str_replace('xz', 'xz-utils', $missing);
|
||||
shell(true)->exec($prefix . $install_cmd . ' ' . implode(' ', $to_install));
|
||||
} catch (RuntimeException) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace SPC\doctor\item;
|
||||
|
||||
use SPC\builder\linux\SystemUtil;
|
||||
use SPC\builder\traits\UnixSystemUtilTrait;
|
||||
use SPC\doctor\AsCheckItem;
|
||||
use SPC\doctor\CheckResult;
|
||||
@@ -15,9 +16,10 @@ class OSCheckList
|
||||
#[AsCheckItem('if current OS are supported', level: 999)]
|
||||
public function checkOS(): ?CheckResult
|
||||
{
|
||||
if (!in_array(PHP_OS_FAMILY, ['Darwin', 'Linux'])) {
|
||||
if (!in_array(PHP_OS_FAMILY, ['Darwin', 'Linux', 'BSD'])) {
|
||||
return CheckResult::fail('Current OS is not supported');
|
||||
}
|
||||
return CheckResult::ok(PHP_OS_FAMILY . ' ' . php_uname('m') . ', supported');
|
||||
$distro = PHP_OS_FAMILY === 'Linux' ? (' ' . SystemUtil::getOSRelease()['dist']) : '';
|
||||
return CheckResult::ok(PHP_OS_FAMILY . ' ' . php_uname('m') . $distro . ', supported');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,6 +54,7 @@ class Config
|
||||
'Windows' => ['-windows', '-win', ''],
|
||||
'Darwin' => ['-macos', '-unix', ''],
|
||||
'Linux' => ['-linux', '-unix', ''],
|
||||
'BSD' => ['-freebsd', '-bsd', '-unix', ''],
|
||||
default => throw new WrongUsageException('OS ' . PHP_OS_FAMILY . ' is not supported'),
|
||||
};
|
||||
foreach ($m_key as $v) {
|
||||
@@ -98,6 +99,7 @@ class Config
|
||||
'Windows' => ['-windows', '-win', ''],
|
||||
'Darwin' => ['-macos', '-unix', ''],
|
||||
'Linux' => ['-linux', '-unix', ''],
|
||||
'BSD' => ['-freebsd', '-bsd', '-unix', ''],
|
||||
default => throw new WrongUsageException('OS ' . PHP_OS_FAMILY . ' is not supported'),
|
||||
};
|
||||
foreach ($m_key as $v) {
|
||||
|
||||
@@ -99,12 +99,18 @@ class Downloader
|
||||
hooks: [[CurlHook::class, 'setupGithubToken']],
|
||||
), true);
|
||||
$url = null;
|
||||
foreach ($data[0]['assets'] as $asset) {
|
||||
if (preg_match('|' . $source['match'] . '|', $asset['name'])) {
|
||||
$url = $asset['browser_download_url'];
|
||||
break;
|
||||
foreach ($data as $release) {
|
||||
if ($release['prerelease'] === true) {
|
||||
continue;
|
||||
}
|
||||
foreach ($release['assets'] as $asset) {
|
||||
if (preg_match('|' . $source['match'] . '|', $asset['name'])) {
|
||||
$url = $asset['browser_download_url'];
|
||||
break 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$url) {
|
||||
throw new DownloaderException("failed to find {$name} source");
|
||||
}
|
||||
@@ -255,10 +261,13 @@ class Downloader
|
||||
|
||||
if ($source === null) {
|
||||
logger()->warning('Source {name} unknown. Skipping.', ['name' => $name]);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (!is_dir(DOWNLOAD_PATH)) {
|
||||
FileSystem::createDir(DOWNLOAD_PATH);
|
||||
}
|
||||
|
||||
// load lock file
|
||||
if (!file_exists(DOWNLOAD_PATH . '/.lock.json')) {
|
||||
$lock = [];
|
||||
@@ -326,7 +335,7 @@ class Downloader
|
||||
logger()->warning('Deleting download file: ' . $filename);
|
||||
unlink(DOWNLOAD_PATH . '/' . $filename);
|
||||
}
|
||||
throw $e;
|
||||
throw new DownloaderException('Download failed! ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@ class FileSystem
|
||||
/**
|
||||
* @throws FileSystemException
|
||||
*/
|
||||
public static function replaceFileStr(string $filename, mixed $search = null, mixed $replace = null): bool|int
|
||||
public static function replaceFileStr(string $filename, mixed $search = null, mixed $replace = null): false|int
|
||||
{
|
||||
return self::replaceFile($filename, REPLACE_FILE_STR, $search, $replace);
|
||||
}
|
||||
@@ -63,7 +63,7 @@ class FileSystem
|
||||
/**
|
||||
* @throws FileSystemException
|
||||
*/
|
||||
public static function replaceFileRegex(string $filename, mixed $search = null, mixed $replace = null): bool|int
|
||||
public static function replaceFileRegex(string $filename, mixed $search = null, mixed $replace = null): false|int
|
||||
{
|
||||
return self::replaceFile($filename, REPLACE_FILE_PREG, $search, $replace);
|
||||
}
|
||||
@@ -71,7 +71,7 @@ class FileSystem
|
||||
/**
|
||||
* @throws FileSystemException
|
||||
*/
|
||||
public static function replaceFileUser(string $filename, mixed $callback = null): bool|int
|
||||
public static function replaceFileUser(string $filename, mixed $callback = null): false|int
|
||||
{
|
||||
return self::replaceFile($filename, REPLACE_FILE_USER, $callback);
|
||||
}
|
||||
@@ -132,6 +132,7 @@ class FileSystem
|
||||
break;
|
||||
case 'Linux':
|
||||
case 'Darwin':
|
||||
case 'BSD':
|
||||
f_passthru('cp -r "' . $src_path . '" "' . $dst_path . '"');
|
||||
break;
|
||||
}
|
||||
@@ -151,10 +152,13 @@ class FileSystem
|
||||
if (self::$_extract_hook === []) {
|
||||
SourcePatcher::init();
|
||||
}
|
||||
if (!is_dir(SOURCE_PATH)) {
|
||||
self::createDir(SOURCE_PATH);
|
||||
}
|
||||
if ($move_path !== null) {
|
||||
$move_path = SOURCE_PATH . '/' . $move_path;
|
||||
}
|
||||
logger()->info("extracting {$name} source");
|
||||
logger()->info("extracting {$name} source to " . ($move_path ?? SOURCE_PATH . "/{$name}") . ' ...');
|
||||
try {
|
||||
$target = $move_path ?? (SOURCE_PATH . "/{$name}");
|
||||
// Git source, just move
|
||||
@@ -163,8 +167,7 @@ class FileSystem
|
||||
self::emitSourceExtractHook($name);
|
||||
return;
|
||||
}
|
||||
|
||||
if (PHP_OS_FAMILY === 'Darwin' || PHP_OS_FAMILY === 'Linux') {
|
||||
if (in_array(PHP_OS_FAMILY, ['Darwin', 'Linux', 'BSD'])) {
|
||||
if (f_mkdir(directory: $target, recursive: true) !== true) {
|
||||
throw new FileSystemException('create ' . $name . 'source dir failed');
|
||||
}
|
||||
@@ -256,14 +259,13 @@ class FileSystem
|
||||
/**
|
||||
* 递归或非递归扫描目录,可返回相对目录的文件列表或绝对目录的文件列表
|
||||
*
|
||||
* @param string $dir 目录
|
||||
* @param bool $recursive 是否递归扫描子目录
|
||||
* @param bool|string $relative 是否返回相对目录,如果为true则返回相对目录,如果为false则返回绝对目录
|
||||
* @param bool $include_dir 非递归模式下,是否包含目录
|
||||
* @return array|false
|
||||
* @param string $dir 目录
|
||||
* @param bool $recursive 是否递归扫描子目录
|
||||
* @param bool|string $relative 是否返回相对目录,如果为true则返回相对目录,如果为false则返回绝对目录
|
||||
* @param bool $include_dir 非递归模式下,是否包含目录
|
||||
* @since 2.5
|
||||
*/
|
||||
public static function scanDirFiles(string $dir, bool $recursive = true, bool|string $relative = false, bool $include_dir = false): bool|array
|
||||
public static function scanDirFiles(string $dir, bool $recursive = true, bool|string $relative = false, bool $include_dir = false): array|false
|
||||
{
|
||||
$dir = self::convertPath($dir);
|
||||
// 不是目录不扫,直接 false 处理
|
||||
@@ -403,7 +405,7 @@ class FileSystem
|
||||
* @param mixed ...$args Arguments passed to file_put_contents
|
||||
* @throws FileSystemException
|
||||
*/
|
||||
public static function writeFile(string $path, mixed $content, ...$args): bool|string|int
|
||||
public static function writeFile(string $path, mixed $content, ...$args): bool|int|string
|
||||
{
|
||||
$dir = pathinfo($path, PATHINFO_DIRNAME);
|
||||
if (!is_dir($dir) && !mkdir($dir, 0755, true)) {
|
||||
@@ -446,7 +448,7 @@ class FileSystem
|
||||
/**
|
||||
* @throws FileSystemException
|
||||
*/
|
||||
private static function replaceFile(string $filename, int $replace_type = REPLACE_FILE_STR, mixed $callback_or_search = null, mixed $to_replace = null): bool|int
|
||||
private static function replaceFile(string $filename, int $replace_type = REPLACE_FILE_STR, mixed $callback_or_search = null, mixed $to_replace = null): false|int
|
||||
{
|
||||
logger()->debug('Replacing file with type[' . $replace_type . ']: ' . $filename);
|
||||
$file = self::readFile($filename);
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user