Skip to content

Commit 758b697

Browse files
committed
Update docs
1 parent 4dbbf05 commit 758b697

File tree

9 files changed

+159
-76
lines changed

9 files changed

+159
-76
lines changed

README-zh.md

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,17 @@ static-php-cli(简称 `spc`)有许多特性:
4343

4444
如果你不想自行编译 PHP,可以从本项目现有的示例 Action 下载 Artifact,也可以从自托管的服务器下载。
4545

46-
- [扩展组合 - common](https://dl.static-php.dev/static-php-cli/common/):common 组合包含了约 [30+](https://dl.static-php.dev/static-php-cli/common/README.txt) 个常用扩展,体积为 7.5MB 左右。
47-
- [扩展组合 - bulk](https://dl.static-php.dev/static-php-cli/bulk/):bulk 组合包含了 [50+](https://dl.static-php.dev/static-php-cli/bulk/README.txt) 个扩展,体积为 25MB 左右。
48-
- [扩展组合 - minimal](https://dl.static-php.dev/static-php-cli/minimal/):minimal 组合包含了 [5](https://dl.static-php.dev/static-php-cli/minimal/README.txt) 个扩展,体积为 3MB 左右。
46+
| 组合名称 | 组合扩展数 | 系统 | 备注 |
47+
|---------------------------------------------------------------------|----------------------------------------------------------------------------|-------------|--------------|
48+
| [common](https://dl.static-php.dev/static-php-cli/common/) | [30+](https://dl.static-php.dev/static-php-cli/common/README.txt) | Linux/macOS | 体积为 7.5MB 左右 |
49+
| [bulk](https://dl.static-php.dev/static-php-cli/bulk/) | [50+](https://dl.static-php.dev/static-php-cli/bulk/README.txt) | Linux/macOS | 体积为 25MB 左右 |
50+
| [minimal](https://dl.static-php.dev/static-php-cli/minimal/) | [5](https://dl.static-php.dev/static-php-cli/minimal/README.txt) | Linux/macOS | 体积为 3MB 左右 |
51+
| [spc-min](https://dl.static-php.dev/static-php-cli/windows/spc-min) | [5](https://dl.static-php.dev/static-php-cli/windows/spc-min/README.txt) | Windows | 体积为 3MB 左右 |
52+
| [spc-max](https://dl.static-php.dev/static-php-cli/windows/spc-max) | [40+](https://dl.static-php.dev/static-php-cli/windows/spc-max/README.txt) | Windows | 体积为 8.5MB 左右 |
4953

5054
> Linux 和 Windows 默认启用了 UPX 压缩,可减小 30~50% 的 PHP 二进制体积。
5155
> macOS 当前不支持 UPX,所以上述预编译的 macOS 版本体积可能较大。
5256
53-
对于 Windows 系统,目前支持的扩展较少,故仅提供 SPC 自身运行的最小扩展组合的 `cli``micro`[扩展组合 - spc-min](https://dl.static-php.dev/static-php-cli/windows/spc-min/)
54-
5557
## 使用 static-php-cli 构建 PHP
5658

5759
### 编译环境需求
@@ -110,7 +112,7 @@ static-php-cli(简称 `spc`)有许多特性:
110112

111113
如果你选择了 `debug`,则会在构建时输出所有日志,包括编译的日志,以供排查错误。
112114

113-
### 本地构建(使用 spc 二进制)
115+
### 本地构建(使用 spc 二进制,推荐
114116

115117
该项目提供了 static-php-cli 的二进制文件:`spc`
116118
您可以使用 `spc` 二进制文件,无需安装任何运行时(用起来就像 golang 程序)。
@@ -144,6 +146,8 @@ chmod +x ./spc
144146

145147
### 本地构建(使用 git 源码)
146148

149+
如果你需要修改 static-php-cli 源码,或者使用 spc 二进制构建有问题,你可以使用 git 源码下载 static-php-cli。
150+
147151
```bash
148152
# clone 仓库即可
149153
git clone https://github.com/crazywhalecc/static-php-cli.git
@@ -177,14 +181,16 @@ bin/spc --version
177181
./bin/spc download --all
178182
# 只拉取编译指定扩展需要的所有依赖(推荐)
179183
./bin/spc download --for-extensions="openssl,pcntl,mbstring,pdo_sqlite"
184+
# 下载依赖时,优先下载有预编译的库(节省编译依赖的时间)
185+
./bin/spc download --for-extensions="openssl,curl,mbstring,mbregex" --prefer-pre-built
180186
# 下载编译不同版本的 PHP (--with-php=x.y,推荐 7.3 ~ 8.3)
181187
./bin/spc download --for-extensions="openssl,curl,mbstring" --with-php=8.1
182188

183189
# 构建包含 bcmath,openssl,tokenizer,sqlite3,pdo_sqlite,ftp,curl 扩展的 php-cli 和 micro.sfx
184190
./bin/spc build "bcmath,openssl,tokenizer,sqlite3,pdo_sqlite,ftp,curl" --build-cli --build-micro
185191
# 编译线程安全版本 (--enable-zts)
186192
./bin/spc build "curl,phar" --enable-zts --build-cli
187-
# 编译后使用 UPX 减小可执行文件体积 (--with-upx-pack) (至少压缩至原来的 30~50%)
193+
# 编译后使用 UPX 减小可执行文件体积 (仅 Linux、Windows 可用) (至少压缩至原来的 30~50%)
188194
./bin/spc build "curl,phar" --enable-zts --build-cli --with-upx-pack
189195
```
190196

README.md

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,17 @@ If you don't want to build or want to test first, you can download example pre-c
4949
Below are several precompiled static-php binaries with different extension combinations,
5050
which can be downloaded directly according to your needs.
5151

52-
- [Extension-Combination - common](https://dl.static-php.dev/static-php-cli/common/): `common` contains about [30+](https://dl.static-php.dev/static-php-cli/common/README.txt) commonly used extensions, and the size is about 7.5MB.
53-
- [Extension-Combination - bulk](https://dl.static-php.dev/static-php-cli/bulk/): `bulk` contains [50+](https://dl.static-php.dev/static-php-cli/bulk/README.txt) extensions and is about 25MB in size.
54-
- [Extension-Combination - minimal](https://dl.static-php.dev/static-php-cli/minimal/): `minimal` contains [5](https://dl.static-php.dev/static-php-cli/minimal/README.txt) extensions and is about 3MB in size.
52+
| Combination | Extension Count | OS | Comment |
53+
|----------------------------------------------------------------------|---------------------------------------------------------------------------|--------------|--------------------------------|
54+
| [common](https://dl.static-php.dev/static-php-cli/common/) | [30+](https://dl.static-php.dev/static-php-cli/common/README.txt) | Linux, macOS | The binary size is about 7.5MB |
55+
| [bulk](https://dl.static-php.dev/static-php-cli/bulk/) | [50+](https://dl.static-php.dev/static-php-cli/bulk/README.txt) | Linux, macOS | The binary size is about 25MB |
56+
| [minimal](https://dl.static-php.dev/static-php-cli/minimal/) | [5](https://dl.static-php.dev/static-php-cli/minimal/README.txt) | Linux, macOS | The binary size is about 3MB |
57+
| [spc-min](https://dl.static-php.dev/static-php-cli/windows/spc-min/) | [5](https://dl.static-php.dev/static-php-cli/windows/spc-min/README.txt) | Windows | The binary size is about 3MB |
58+
| [spc-max](https://dl.static-php.dev/static-php-cli/windows/spc-max/) | [10](https://dl.static-php.dev/static-php-cli/windows/spc-max/README.txt) | Windows | The binary size is about 8.5MB |
5559

5660
> Linux and Windows supports UPX compression for binaries, which can reduce the size of the binary by 30% to 50%.
5761
> macOS does not support UPX compression, so the size of the pre-built binaries for mac is larger.
5862
59-
For Windows systems, there are currently fewer extensions supported,
60-
so only `cli` and `micro` that run the minimum extension combination of SPC itself are provided: [Extension-Combination - spc-min](https://dl.static-php.dev/static-php-cli/windows/spc-min/).
61-
6263
## Build
6364

6465
### Compilation Requirements
@@ -97,6 +98,7 @@ Currently supported PHP versions for compilation:
9798
| 8.1 | :heavy_check_mark: | PHP official has security fixes only |
9899
| 8.2 | :heavy_check_mark: | |
99100
| 8.3 | :heavy_check_mark: | |
101+
| 8.4 | :x: | WIP |
100102

101103
### Supported Extensions
102104

@@ -121,7 +123,7 @@ and at the same time define the extensions to be compiled by yourself.
121123

122124
If you enable `debug`, all logs will be output at build time, including compiled logs, for troubleshooting.
123125

124-
### Build Locally (using SPC binary)
126+
### Build Locally (using SPC binary, recommended)
125127

126128
This project provides a binary file of static-php-cli: `spc`.
127129
You can use `spc` binary instead of installing any runtime like golang app.
@@ -155,6 +157,9 @@ Self-hosted `spc` is built by GitHub Actions, you can also download from Actions
155157

156158
### Build Locally (using git source)
157159

160+
If you need to modify the static-php-cli source code, or have problems using the spc binary build,
161+
you can download static-php-cli using the git source code.
162+
158163
```bash
159164
# just clone me!
160165
git clone https://github.com/crazywhalecc/static-php-cli.git
@@ -188,14 +193,16 @@ Basic usage for building php with some extensions:
188193
./bin/spc download --all
189194
# only fetch necessary sources by needed extensions (recommended)
190195
./bin/spc download --for-extensions="openssl,pcntl,mbstring,pdo_sqlite"
196+
# download pre-built libraries first (save time for compiling dependencies)
197+
./bin/spc download --for-extensions="openssl,curl,mbstring,mbregex" --prefer-pre-built
191198
# download different PHP version (--with-php=x.y, recommend 7.3 ~ 8.3)
192199
./bin/spc download --for-extensions="openssl,curl,mbstring" --with-php=8.1
193200

194201
# with bcmath,openssl,tokenizer,sqlite3,pdo_sqlite,ftp,curl extension, build both CLI and phpmicro SAPI
195202
./bin/spc build "bcmath,openssl,tokenizer,sqlite3,pdo_sqlite,ftp,curl" --build-cli --build-micro
196203
# build thread-safe (ZTS) version (--enable-zts)
197204
./bin/spc build "curl,phar" --enable-zts --build-cli
198-
# build, pack executable with UPX (--with-upx-pack) (reduce binary size for 30~50%)
205+
# build, pack executable with UPX (linux and windows only) (reduce binary size for 30~50%)
199206
./bin/spc build "curl,phar" --enable-zts --build-cli --with-upx-pack
200207
```
201208

docs/.vitepress/components/CliGenerator.vue

Lines changed: 95 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@
1010
<h2>{{ I18N[lang].selectExt }}{{ checkedExts.length > 0 ? (' (' + checkedExts.length + ')') : '' }}</h2>
1111
<div class="box">
1212
<div v-for="(item, index) in ext" class="ext-item">
13-
<input type="checkbox" :id="index" :value="index" v-model="checkedExts" :disabled="extDisableList.indexOf(index) !== -1">
14-
<label :for="index">{{ index }}</label>
13+
<span v-if="isSupported(index, selectedSystem)">
14+
<input type="checkbox" :id="index" :value="index" v-model="checkedExts" :disabled="extDisableList.indexOf(index) !== -1">
15+
<label :for="index">{{ index }}</label>
16+
</span>
17+
1518
</div>
1619
</div>
1720
<div class="my-btn" v-if="selectedSystem !== 'windows'" @click="selectCommon">{{ I18N[lang].selectCommon }}</div>
@@ -46,59 +49,80 @@
4649
<p>{{ I18N[lang].windowsSAPIUnavailable }}</p>
4750
</div>
4851
<h2>{{ I18N[lang].buildOptions }}</h2>
49-
<div class="option-line">
50-
<span class="option-title">{{ I18N[lang].buildEnvironment }}</span>
51-
<select v-model="selectedEnv">
52-
<option value="native">{{ I18N[lang].buildEnvNative }}</option>
53-
<option value="spc">{{ I18N[lang].buildEnvSpc }}</option>
54-
<option value="docker" v-if="selectedSystem !== 'windows'">{{ I18N[lang].buildEnvDocker }}</option>
55-
</select>
56-
</div>
57-
<div v-if="selectedEnv === 'spc'" class="option-line">
58-
<span class="option-title">{{ I18N[lang].selectedArch }}</span>
59-
<select v-model="selectedArch">
60-
<option value="x86_64">x86_64 (amd64)</option>
61-
<option value="aarch64" v-if="selectedSystem !== 'windows'">aarch64 (arm64)</option>
62-
</select>
63-
</div>
64-
<div class="option-line">
65-
<span class="option-title">{{ I18N[lang].downloadPhpVersion }}</span>
66-
<select v-model="selectedPhpVersion">
67-
<option v-for="item in availablePhpVersions" :value="item">{{ item }}</option>
68-
</select>
69-
</div>
70-
<div class="option-line">
71-
<span class="option-title">{{ I18N[lang].useDebug }}</span>
72-
<input type="radio" id="debug-yes" :value="1" v-model="debug" />
73-
<label for="debug-yes">{{ I18N[lang].yes }}</label>
74-
75-
<input type="radio" id="debug-no" :value="0" v-model="debug" />
76-
<label for="debug-no">{{ I18N[lang].no }}</label>
77-
</div>
78-
<div class="option-line">
79-
<span class="option-title">{{ I18N[lang].useZTS }}</span>
80-
<input type="radio" id="zts-yes" :value="1" v-model="zts" />
81-
<label for="zts-yes">{{ I18N[lang].yes }}</label>
52+
<!-- Refactor all build options in table -->
53+
<table>
54+
<!-- buildEnvironment -->
55+
<tr>
56+
<td>{{ I18N[lang].buildEnvironment }}</td>
57+
<td>
58+
<select v-model="selectedEnv">
59+
<option value="native">{{ I18N[lang].buildEnvNative }}</option>
60+
<option value="spc">{{ I18N[lang].buildEnvSpc }}</option>
61+
<option value="docker" v-if="selectedSystem !== 'windows'">{{ I18N[lang].buildEnvDocker }}</option>
62+
</select>
63+
</td>
64+
</tr>
65+
<!-- Download PHP version -->
66+
<tr>
67+
<td>{{ I18N[lang].downloadPhpVersion }}</td>
68+
<td>
69+
<select v-model="selectedPhpVersion">
70+
<option v-for="item in availablePhpVersions" :value="item">{{ item }}</option>
71+
</select>
72+
</td>
73+
</tr>
74+
<!-- Enable debug message -->
75+
<tr>
76+
<td>{{ I18N[lang].useDebug }}</td>
77+
<td>
78+
<input type="radio" id="debug-yes" :value="1" v-model="debug" />
79+
<label for="debug-yes">{{ I18N[lang].yes }}</label>
80+
<input type="radio" id="debug-no" :value="0" v-model="debug" />
81+
<label for="debug-no">{{ I18N[lang].no }}</label>
82+
</td>
83+
</tr>
84+
<!-- Enable ZTS -->
85+
<tr>
86+
<td>{{ I18N[lang].useZTS }}</td>
87+
<td>
88+
<input type="radio" id="zts-yes" :value="1" v-model="zts" />
89+
<label for="zts-yes">{{ I18N[lang].yes }}</label>
90+
<input type="radio" id="zts-no" :value="0" v-model="zts" />
91+
<label for="zts-no">{{ I18N[lang].no }}</label>
92+
</td>
93+
</tr>
94+
<!-- download corresponding extensions -->
95+
<tr>
96+
<td>{{ I18N[lang].resultShowDownload }}</td>
97+
<td>
98+
<input type="radio" id="show-download-yes" :value="1" v-model="downloadByExt" />
99+
<label for="show-download-yes">{{ I18N[lang].yes }}</label>
100+
<input type="radio" id="show-download-no" :value="0" v-model="downloadByExt" />
101+
<label for="show-download-no">{{ I18N[lang].no }}</label>
102+
</td>
103+
</tr>
104+
<!-- Download pre-built -->
105+
<tr>
106+
<td>{{ I18N[lang].usePreBuilt }}</td>
107+
<td>
108+
<input type="radio" id="pre-built-yes" :value="1" v-model="preBuilt" />
109+
<label for="pre-built-yes">{{ I18N[lang].yes }}</label>
110+
<input type="radio" id="pre-built-no" :value="0" v-model="preBuilt" />
111+
<label for="pre-built-no">{{ I18N[lang].no }}</label>
112+
</td>
113+
</tr>
114+
<!-- Enable UPX -->
115+
<tr v-if="selectedSystem !== 'macos'">
116+
<td>{{ I18N[lang].useUPX }}</td>
117+
<td>
118+
<input type="radio" id="upx-yes" :value="1" v-model="enableUPX" />
119+
<label for="upx-yes">{{ I18N[lang].yes }}</label>
120+
<input type="radio" id="upx-no" :value="0" v-model="enableUPX" />
121+
<label for="upx-no">{{ I18N[lang].no }}</label>
122+
</td>
123+
</tr>
124+
</table>
82125

83-
<input type="radio" id="zts-no" :value="0" v-model="zts" />
84-
<label for="zts-no">{{ I18N[lang].no }}</label>
85-
</div>
86-
<div class="option-line">
87-
<span class="option-title">{{ I18N[lang].resultShowDownload }}</span>
88-
<input type="radio" id="show-download-yes" :value="1" v-model="downloadByExt" />
89-
<label for="show-download-yes">{{ I18N[lang].yes }}</label>
90-
91-
<input type="radio" id="show-download-no" :value="0" v-model="downloadByExt" />
92-
<label for="show-download-no">{{ I18N[lang].no }}</label>
93-
</div>
94-
<div class="option-line" v-if="selectedSystem !== 'macos'">
95-
<span class="option-title">{{ I18N[lang].useUPX }}</span>
96-
<input type="radio" id="upx-yes" :value="1" v-model="enableUPX" />
97-
<label for="upx-yes">{{ I18N[lang].yes }}</label>
98-
99-
<input type="radio" id="upx-no" :value="0" v-model="enableUPX" />
100-
<label for="upx-no">{{ I18N[lang].no }}</label>
101-
</div>
102126
<h2>{{ I18N[lang].hardcodedINI }}</h2>
103127
<textarea class="textarea" :placeholder="I18N[lang].hardcodedINIPlacehoder" v-model="hardcodedINIData" rows="5" />
104128
<h2>{{ I18N[lang].resultShow }}</h2>
@@ -116,11 +140,11 @@
116140
</div>
117141
<div v-if="downloadByExt" class="command-container">
118142
<b>{{ I18N[lang].downloadExtOnlyCommand }}</b>
119-
<div class="command-preview">{{ spcCommand }} download --with-php={{ selectedPhpVersion }} --for-extensions "{{ extList }}"{{ debug ? ' --debug' : '' }}</div>
143+
<div class="command-preview">{{ spcCommand }} download --with-php={{ selectedPhpVersion }} --for-extensions "{{ extList }}"{{ preBuilt ? ' --prefer-pre-built' : '' }}{{ debug ? ' --debug' : '' }}</div>
120144
</div>
121145
<div v-else class="command-container">
122146
<b>{{ I18N[lang].downloadAllCommand }}</b>
123-
<div class="command-preview">{{ spcCommand }} download --all --with-php={{ selectedPhpVersion }}{{ debug ? ' --debug' : '' }}</div>
147+
<div class="command-preview">{{ spcCommand }} download --all --with-php={{ selectedPhpVersion }}{{ preBuilt ? ' --prefer-pre-built' : '' }}{{ debug ? ' --debug' : '' }}</div>
124148
</div>
125149
<div class="command-container" v-if="enableUPX">
126150
<b>{{ I18N[lang].downloadUPXCommand }}</b>
@@ -162,6 +186,14 @@ const osList = [
162186
{ os: 'windows', label: 'Windows', disabled: false },
163187
];
164188
189+
const isSupported = (extName, os) => {
190+
// Convert os to target: linux->Linux, macos->Darwin, windows->Windows (using map)
191+
const a = new Map([['linux', 'Linux'], ['macos', 'Darwin'], ['windows', 'Windows']]);
192+
const osName = a.get(os);
193+
const osSupport = ext.value[extName]?.support?.[osName] ?? 'yes';
194+
return osSupport === 'yes' || osSupport === 'partial';
195+
};
196+
165197
const availablePhpVersions = [
166198
'7.4',
167199
'8.0',
@@ -201,8 +233,9 @@ const I18N = {
201233
depTips: '选择扩展后,不可选中的项目为必需的依赖,编译的依赖库列表中可选的为现有扩展和依赖库的可选依赖。选择可选依赖后,将生成 --with-libs 参数。',
202234
microUnavailable: 'micro 不支持 PHP 7.4 及更早版本!',
203235
windowsSAPIUnavailable: 'Windows 目前不支持 fpm、embed 构建!',
204-
useUPX: '是否开启 UPX 压缩(减小二进制体积,但很少见的情况下 micro SAPI 无法使用',
236+
useUPX: '是否开启 UPX 压缩(减小二进制体积)',
205237
windowsDownSPCWarning: 'Windows 下请手动下载 spc.exe 二进制文件并解压到当前目录!',
238+
usePreBuilt: '如果可能,下载预编译的依赖库(减少编译时间)',
206239
},
207240
en: {
208241
selectExt: 'Select Extensions',
@@ -234,8 +267,9 @@ const I18N = {
234267
depTips: 'After selecting the extensions, the unselectable items are essential dependencies. In the compiled dependencies list, optional dependencies consist of existing extensions and optional dependencies of libraries. Optional dependencies will be added in --with-libs parameter.',
235268
microUnavailable: 'Micro does not support PHP 7.4 and earlier versions!',
236269
windowsSAPIUnavailable: 'Windows does not support fpm and embed build!',
237-
useUPX: 'Enable UPX compression (reduce binary size, but in rare cases micro SAPI doesn\'t work with UPX)',
270+
useUPX: 'Enable UPX compression (reduce binary size)',
238271
windowsDownSPCWarning: 'Please download the spc.exe binary file manually and extract it to the current directory on Windows!',
272+
usePreBuilt: 'Download pre-built dependencies if possible (reduce compile time)',
239273
}
240274
};
241275
@@ -305,6 +339,9 @@ const zts = ref(0);
305339
// chosen download by extensions
306340
const downloadByExt = ref(1);
307341
342+
// use pre-built
343+
const preBuilt = ref(1);
344+
308345
// chosen upx
309346
const enableUPX = ref(0);
310347

0 commit comments

Comments
 (0)