Skip to content

Commit b01bbef

Browse files
authored
V3c/refactor pgo br (#1228)
2 parents b0007ed + 2491c5d commit b01bbef

16 files changed

Lines changed: 335 additions & 58 deletions

File tree

‎README-zh.md‎

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33
[![Chinese readme](https://img.shields.io/badge/README-%E4%B8%AD%E6%96%87%20%F0%9F%87%A8%F0%9F%87%B3-moccasin?style=flat-square)](README-zh.md)
44
[![English readme](https://img.shields.io/badge/README-English%20%F0%9F%87%AC%F0%9F%87%A7-moccasin?style=flat-square)](README.md)
55
[![Releases](https://img.shields.io/packagist/v/crazywhalecc/static-php-cli?include_prereleases&label=Release&style=flat-square)](https://github.com/crazywhalecc/static-php-cli/releases)
6-
[![CI](https://img.shields.io/github/actions/workflow/status/crazywhalecc/static-php-cli/tests.yml?branch=main&label=Build%20Test&style=flat-square)](https://github.com/crazywhalecc/static-php-cli/actions/workflows/tests.yml)
7-
[![License](https://img.shields.io/badge/License-MIT-blue.svg?style=flat-square)](https://github.com/crazywhalecc/static-php-cli/blob/main/LICENSE)
6+
[![CI](https://img.shields.io/github/actions/workflow/status/crazywhalecc/static-php-cli/tests.yml?branch=v3&label=Build%20Test&style=flat-square)](https://github.com/crazywhalecc/static-php-cli/actions/workflows/tests.yml)
7+
[![License](https://img.shields.io/badge/License-MIT-blue.svg?style=flat-square)](https://github.com/crazywhalecc/static-php-cli/blob/v3/LICENSE)
88
[![Discord](https://img.shields.io/discord/nrSRbpMJ?label=Discord&logo=discord&style=flat-square)](https://discord.gg/xf6Rd4pEAk)
99

1010
**StaticPHP** 是一个强大的工具,用于构建可移植的可执行文件,包括 PHP、扩展等。
1111

1212
> [!IMPORTANT]
13-
> 我们正准备发布 **v3** 版本,届时项目名称将从 **static-php-cli** 更改为 **StaticPHP**。
14-
> 此分支对应 v3 版本。v2 版本请查看 [v2 分支](https://github.com/crazywhalecc/static-php-cli/tree/main)。
15-
> 请更新您的参考资料,并关注正式版发布。
13+
> **v3** 是当前默认分支。项目名称现为 **StaticPHP**,仓库名保持 `static-php-cli` 不变。
14+
> v2 版本请查看 [v2 分支](https://github.com/crazywhalecc/static-php-cli/tree/main)。
15+
> 敬请关注正式版发布。
1616
1717
## 特性
1818

@@ -40,15 +40,15 @@
4040
### 1. 下载 spc 二进制
4141

4242
```bash
43-
# For Linux x86_64
43+
# Linux x86_64
4444
curl -fsSL -o spc https://dl.static-php.dev/v3/spc-bin/nightly/spc-linux-x86_64
45-
# For Linux aarch64
45+
# Linux aarch64
4646
curl -fsSL -o spc https://dl.static-php.dev/v3/spc-bin/nightly/spc-linux-aarch64
47-
# macOS x86_64 (Intel)
47+
# macOS x86_64(Intel)
4848
curl -fsSL -o spc https://dl.static-php.dev/v3/spc-bin/nightly/spc-macos-x86_64
49-
# macOS aarch64 (Apple)
49+
# macOS aarch64(Apple)
5050
curl -fsSL -o spc https://dl.static-php.dev/v3/spc-bin/nightly/spc-macos-aarch64
51-
# Windows (x86_64, win10 build 17063 or later, please install VS2022 first)
51+
# Windows(x86_64,需 Windows 10 build 17063 或更高版本,请先安装带 C++ 工具的 Visual Studio 2022)
5252
curl.exe -fsSL -o spc.exe https://dl.static-php.dev/v3/spc-bin/nightly/spc-windows-x64.exe
5353
```
5454

@@ -58,14 +58,17 @@ curl.exe -fsSL -o spc.exe https://dl.static-php.dev/v3/spc-bin/nightly/spc-windo
5858
chmod +x ./spc
5959
```
6060

61+
> [!TIP]
62+
> 建议在首次构建前运行 `./spc doctor --auto-fix`,检查并安装所需的构建依赖(必要时 spc 也会自动提醒你)。
63+
6164
### 2. 构建静态 PHP
6265

6366
首先,创建 `craft.yml` 文件,并从 [扩展列表](https://static-php.dev/en/guide/extensions.html) 或 [命令生成器](https://static-php.dev/en/guide/cli-generator.html) 指定要包含的扩展:
6467

6568
```yml
66-
# PHP version support: 8.1, 8.2, 8.3, 8.4, 8.5, 8.6 (pre-release)
69+
# PHP 版本支持:8.1、8.2、8.3、8.4、8.5、8.6(预发布)
6770
php-version: 8.5
68-
# Put your extension list here
71+
# 在此填写你的扩展列表
6972
extensions: "apcu,bcmath,calendar,ctype,curl,dba,dom,exif,fileinfo,filter,gd,iconv,mbregex,mbstring,mysqli,mysqlnd,opcache,openssl,pcntl,pdo,pdo_mysql,pdo_sqlite,phar,posix,readline,redis,session,simplexml,sockets,sodium,sqlite3,tokenizer,xml,xmlreader,xmlwriter,xsl,zip,zlib"
7073
sapi:
7174
- cli
@@ -102,16 +105,26 @@ echo '<?php echo "Hello world!\n";' > a.php
102105
当前 README 包含基础用法。有关 StaticPHP 的完整功能集,
103106
请访问 <https://static-php.dev>。
104107

108+
如果你从 v2 迁移,请参阅 [迁移指南](https://static-php.dev/zh/guide/migrate-from-v2.html)。
109+
105110
## 直接下载
106111

107-
如果你暂时不想构建,或只想先测试,可以从 [Actions](https://github.com/static-php/hosted/actions/workflows/build-php-bulk.yml) 下载示例预编译产物,或从自托管服务器下载。
112+
如果你暂时不想构建,或只想先测试,可以从 [Actions](https://github.com/static-php/hosted/actions/workflows/v3-php-bin-unix.yml)([Windows](https://github.com/static-php/hosted/actions/workflows/v3-php-bin-windows.yml))下载示例预编译产物,或从自托管服务器下载。
108113

109-
我们为每个 PHP 版本提供 2 种扩展集合:
114+
以下是几个具有不同扩展组合的预编译静态 PHP 二进制文件,
115+
你可以根据需要直接下载。
110116

111-
- **gigantic**:尽可能包含更多扩展,二进制大小约 100-150MB。
112-
- **base**:仅包含 StaticPHP 自身使用的少量扩展,二进制大小约 10MB。
117+
| 组合名称 | 扩展数量 | 系统 | 备注 |
118+
|-----------------------------------------------------------|-------------------------------------------------------------|----------------|------------------------------|
119+
| [common](https://dl.static-php.dev/v3/php-bin/common/) | [37](https://dl.static-php.dev/v3/php-bin/common/README.txt) | Linux, macOS | 二进制文件大小约为 13MB |
120+
| [bulk](https://dl.static-php.dev/v3/php-bin/bulk/) | [56](https://dl.static-php.dev/v3/php-bin/bulk/README.txt) | Linux, macOS | 二进制文件大小约为 30MB |
121+
| [gnu-bulk](https://dl.static-php.dev/v3/php-bin/gnu-bulk/) | [56](https://dl.static-php.dev/v3/php-bin/gnu-bulk/README.txt) | Linux | 使用共享 glibc |
122+
| [minimal](https://dl.static-php.dev/v3/php-bin/minimal/) | [7](https://dl.static-php.dev/v3/php-bin/minimal/README.txt) | Linux, macOS | 二进制文件大小约为 3MB |
123+
| [spc-min](https://dl.static-php.dev/v3/php-bin/spc-min/) | [7](https://dl.static-php.dev/v3/php-bin/spc-min/README.txt) | Windows | 二进制文件大小约为 3MB |
124+
| [spc-max](https://dl.static-php.dev/v3/php-bin/spc-max/) | [50](https://dl.static-php.dev/v3/php-bin/spc-max/README.txt) | Windows | 二进制文件大小约为 9MB |
113125

114-
> WIP
126+
> Linux 和 Windows 二进制文件均经过 UPX 压缩,可以将二进制文件大小减少 30% 到 50%。
127+
> macOS 不支持 UPX 压缩,因此 mac 的预构建二进制文件大小较大。
115128
116129
### 在线构建(使用 GitHub Actions)
117130

@@ -120,8 +133,8 @@ echo '<?php echo "Hello world!\n";' > a.php
120133
并同时自定义要编译的扩展列表。
121134

122135
1. Fork 此仓库。
123-
2. 进入项目的 Actions 并选择 `CI`。
124-
3. 选择 `Run workflow`,填写你要编译的 PHP 版本、目标类型和扩展列表。(扩展用逗号分隔,例如 `bcmath,curl,mbstring`)
136+
2. 进入项目的 Actions 并选择 `CI on Unix`(Windows 构建请选择 `CI on x86_64 Windows`)。
137+
3. 选择 `Run workflow`,填写目标系统(`os`)、PHP 版本(`php-version`)和扩展列表(`extensions`,扩展用逗号分隔,例如 `bcmath,curl,mbstring`)。
125138
4. 等待工作流执行完成后,进入对应运行记录并下载 `Artifacts`。
126139

127140
如果你启用 `debug`,构建时将输出所有日志,包括编译日志,便于排查问题。
@@ -146,6 +159,10 @@ echo '<?php echo "Hello world!\n";' > a.php
146159

147160
<a href="https://nativephp.com/"><img src="/docs/public/images/nativephp-logo.svg" width="300" alt="NativePHP Logo" /></a>
148161

162+
<img src="https://resources.jetbrains.com/storage/products/company/brand/logos/jb_beam.png" alt="JetBrains Logo" width="96" />
163+
164+
**[JetBrains](https://github.com/JetBrains)** 为核心贡献者提供 <a href="https://www.jetbrains.com/community/opensource">开源开发许可证</a>
165+
149166
## 开源许可证
150167

151168
本项目本身采用 MIT 许可证。

‎README.md‎

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33
[![Chinese readme](https://img.shields.io/badge/README-%E4%B8%AD%E6%96%87%20%F0%9F%87%A8%F0%9F%87%B3-moccasin?style=flat-square)](README-zh.md)
44
[![English readme](https://img.shields.io/badge/README-English%20%F0%9F%87%AC%F0%9F%87%A7-moccasin?style=flat-square)](README.md)
55
[![Releases](https://img.shields.io/packagist/v/crazywhalecc/static-php-cli?include_prereleases&label=Release&style=flat-square)](https://github.com/crazywhalecc/static-php-cli/releases)
6-
[![CI](https://img.shields.io/github/actions/workflow/status/crazywhalecc/static-php-cli/tests.yml?branch=main&label=Build%20Test&style=flat-square)](https://github.com/crazywhalecc/static-php-cli/actions/workflows/tests.yml)
7-
[![License](https://img.shields.io/badge/License-MIT-blue.svg?style=flat-square)](https://github.com/crazywhalecc/static-php-cli/blob/main/LICENSE)
6+
[![CI](https://img.shields.io/github/actions/workflow/status/crazywhalecc/static-php-cli/tests.yml?branch=v3&label=Build%20Test&style=flat-square)](https://github.com/crazywhalecc/static-php-cli/actions/workflows/tests.yml)
7+
[![License](https://img.shields.io/badge/License-MIT-blue.svg?style=flat-square)](https://github.com/crazywhalecc/static-php-cli/blob/v3/LICENSE)
88
[![Discord](https://img.shields.io/discord/nrSRbpMJ?label=Discord&logo=discord&style=flat-square)](https://discord.gg/xf6Rd4pEAk)
99

1010
**StaticPHP** is a powerful tool designed for building portable executables including PHP, extensions, and more.
1111

1212
> [!IMPORTANT]
13-
> We are preparing to release **v3**, which will include a project rename from **static-php-cli** to **StaticPHP**.
14-
> And this branch is for v3. For v2, please check the [v2 branch](https://github.com/crazywhalecc/static-php-cli/tree/main).
15-
> Please update your references and stay tuned for the official release.
13+
> **v3** is the current default branch. The project is now called **StaticPHP**, while the repository keeps its `static-php-cli` name.
14+
> For v2, please check the [v2 branch](https://github.com/crazywhalecc/static-php-cli/tree/main).
15+
> Stay tuned for the official release.
1616
1717
## Features
1818

@@ -48,7 +48,7 @@ curl -fsSL -o spc https://dl.static-php.dev/v3/spc-bin/nightly/spc-linux-aarch64
4848
curl -fsSL -o spc https://dl.static-php.dev/v3/spc-bin/nightly/spc-macos-x86_64
4949
# macOS aarch64 (Apple)
5050
curl -fsSL -o spc https://dl.static-php.dev/v3/spc-bin/nightly/spc-macos-aarch64
51-
# Windows (x86_64, win10 build 17063 or later, please install VS2022 first)
51+
# Windows (x86_64, Windows 10 build 17063 or later, install Visual Studio 2022 with C++ tools first)
5252
curl.exe -fsSL -o spc.exe https://dl.static-php.dev/v3/spc-bin/nightly/spc-windows-x64.exe
5353
```
5454

@@ -58,6 +58,9 @@ For macOS and Linux, add execute permission first:
5858
chmod +x ./spc
5959
```
6060

61+
> [!TIP]
62+
> Before the first build, it is recommended to run `./spc doctor --auto-fix` to check and install the required build dependencies (spc will also remind you automatically when needed).
63+
6164
### 2. Build Static PHP
6265

6366
First, create a `craft.yml` file and specify which extensions you want to include from [extension list](https://static-php.dev/en/guide/extensions.html) or [command generator](https://static-php.dev/en/guide/cli-generator.html):
@@ -102,16 +105,26 @@ echo '<?php echo "Hello world!\n";' > a.php
102105
The current README contains basic usage. For the complete feature set of StaticPHP,
103106
see <https://static-php.dev>.
104107

108+
If you are migrating from v2, check out the [migration guide](https://static-php.dev/en/guide/migrate-from-v2.html).
109+
105110
## Direct Download
106111

107-
If you do not want to build yet or just want to test first, you can download example pre-compiled artifacts from [Actions](https://github.com/static-php/hosted/actions/workflows/build-php-bulk.yml) or from a self-hosted server.
112+
If you do not want to build yet or just want to test first, you can download example pre-compiled artifacts from [Actions](https://github.com/static-php/hosted/actions/workflows/v3-php-bin-unix.yml) ([Windows](https://github.com/static-php/hosted/actions/workflows/v3-php-bin-windows.yml)) or from a self-hosted server.
108113

109-
We offer 2 types of extension sets for each PHP version:
114+
Below are several precompiled static-php binaries with different extension combinations,
115+
which can be downloaded directly according to your needs.
110116

111-
- **gigantic**: Includes as many extensions as possible, the binary size is about 100-150MB.
112-
- **base**: Only includes a few extensions used by StaticPHP itself, the binary size is about 10MB.
117+
| Combination | Extension Count | OS | Comment |
118+
|------------------------------------------------------------|------------------------------------------------------------------|--------------|---------------------------------|
119+
| [common](https://dl.static-php.dev/v3/php-bin/common/) | [37](https://dl.static-php.dev/v3/php-bin/common/README.txt) | Linux, macOS | The binary size is about 13MB |
120+
| [bulk](https://dl.static-php.dev/v3/php-bin/bulk/) | [56](https://dl.static-php.dev/v3/php-bin/bulk/README.txt) | Linux, macOS | The binary size is about 30MB |
121+
| [gnu-bulk](https://dl.static-php.dev/v3/php-bin/gnu-bulk/) | [56](https://dl.static-php.dev/v3/php-bin/gnu-bulk/README.txt) | Linux | Using shared glibc |
122+
| [minimal](https://dl.static-php.dev/v3/php-bin/minimal/) | [7](https://dl.static-php.dev/v3/php-bin/minimal/README.txt) | Linux, macOS | The binary size is about 3MB |
123+
| [spc-min](https://dl.static-php.dev/v3/php-bin/spc-min/) | [7](https://dl.static-php.dev/v3/php-bin/spc-min/README.txt) | Windows | The binary size is about 3MB |
124+
| [spc-max](https://dl.static-php.dev/v3/php-bin/spc-max/) | [50](https://dl.static-php.dev/v3/php-bin/spc-max/README.txt) | Windows | The binary size is about 9MB |
113125

114-
> WIP
126+
> Linux and Windows binaries are compressed with UPX, which can reduce the size of the binary by 30% to 50%.
127+
> macOS does not support UPX compression, so the size of the pre-built binaries for macOS is larger.
115128
116129
### Build Online (using GitHub Actions)
117130

@@ -120,8 +133,8 @@ you can use GitHub Actions to easily build a statically compiled PHP
120133
while defining your own extension list.
121134

122135
1. Fork this repository.
123-
2. Go to the Actions of the project and select `CI`.
124-
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`)
136+
2. Go to the Actions of the project and select `CI on Unix` (or `CI on x86_64 Windows` for Windows builds).
137+
3. Select `Run workflow`, fill in the target OS (`os`), the PHP version (`php-version`), and the list of extensions (`extensions`, comma separated, e.g. `bcmath,curl,mbstring`).
125138
4. After waiting for the workflow to finish, open the corresponding run and download `Artifacts`.
126139

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

‎docs/.vitepress/components/Contributors.vue‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ const fetchContributors = async () => {
5959
error.value = '';
6060
6161
const response = await fetch(
62-
'https://api.github.com/repos/crazywhalecc/static-php-cli/contributors?per_page=24'
62+
'https://api.github.com/repos/crazywhalecc/static-php-cli/contributors?per_page=50'
6363
);
6464
6565
if (!response.ok) {

‎src/Package/Extension/rar.php‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use StaticPHP\Package\PhpExtensionPackage;
1212
use StaticPHP\Runtime\SystemTarget;
1313
use StaticPHP\Util\FileSystem;
14+
use StaticPHP\Util\SourcePatcher;
1415

1516
#[Extension('rar')]
1617
class rar extends PhpExtensionPackage
@@ -24,4 +25,40 @@ public function patchBeforeBuildconf(): void
2425
FileSystem::replaceFileStr("{$this->getBuildDir()}/config.m4", '-Wall -fvisibility=hidden', '-Wall -Wno-incompatible-function-pointer-types -fvisibility=hidden');
2526
}
2627
}
28+
29+
/**
30+
* php-rar 4.3.1+ GitHub release tarballs omit rar.map, but config.m4 probes
31+
* and links every build with -Wl,--version-script=$ext_srcdir/rar.map. The
32+
* configure probe links an executable, where ld.lld tolerates the missing
33+
* file, so configure reports "yes" and the real shared-library link fails
34+
* with "cannot find version script". Recreate the file (content matches
35+
* upstream master) when missing, before configure on both the shared
36+
* phpize path and the static in-tree path.
37+
*/
38+
#[BeforeStage('ext-rar', [self::class, 'configureForUnix'])]
39+
#[BeforeStage('php', [php::class, 'buildconfForUnix'], 'ext-rar')]
40+
#[PatchDescription('Recreate rar.map omitted from php-rar release tarballs but required by config.m4')]
41+
public function patchMissingRarMap(): void
42+
{
43+
$mapFile = "{$this->getBuildDir()}/rar.map";
44+
if (!file_exists($mapFile)) {
45+
FileSystem::writeFile($mapFile, "{ global: get_module; local: *; };\n");
46+
}
47+
}
48+
49+
/**
50+
* unrar's __builtin_cpu_supports() (GCC extension) resolves to __cpu_model at
51+
* link time, which zig's compiler-rt does not provide, so static builds (and,
52+
* with -z defs, shared ones) fail with "undefined symbol: __cpu_model".
53+
* Patch both __GNUC__ fallbacks (unrar/system.cpp, unrar/rijndael.cpp) to
54+
* __get_cpuid(), the same logic unrar already uses for _MSC_VER. Patch before
55+
* configure on both the shared phpize path and the static in-tree path.
56+
*/
57+
#[BeforeStage('ext-rar', [self::class, 'configureForUnix'])]
58+
#[BeforeStage('php', [php::class, 'buildconfForUnix'], 'ext-rar')]
59+
#[PatchDescription('Replace unrar __builtin_cpu_supports with __get_cpuid for zig-cc static link compatibility')]
60+
public function patchUnrarCpuDetectionForZig(): void
61+
{
62+
SourcePatcher::patchFile('rar_unrar_get_cpuid.patch', $this->getBuildDir());
63+
}
2764
}

0 commit comments

Comments
 (0)