Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config/env.ini
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ LD=${SPC_DEFAULT_LD}
; default compiler flags, used in CMake toolchain file, openssl and pkg-config build
SPC_DEFAULT_CFLAGS="--target=${MAC_ARCH}-apple-darwin -O3 -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -ffunction-sections -fdata-sections"
SPC_DEFAULT_CXXFLAGS="${SPC_DEFAULT_CFLAGS}"
SPC_DEFAULT_LDFLAGS="-Wl,-dead_strip"
SPC_DEFAULT_LDFLAGS=""

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated both performance pages to describe the macOS default and why symbols referenced by dynamically loaded shared extensions must be retained. Commit: 4f6edd44.

; phpmicro patches, for more info, see: https://github.com/easysoft/phpmicro/tree/master/patches
SPC_MICRO_PATCHES=cli_checks,macos_iconv

Expand Down
18 changes: 18 additions & 0 deletions config/pkg/ext/ext-pqcrypto.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
ext-pqcrypto:
type: php-extension
artifact:
source:
type: ghtagtar
repo: paragonie/ext-pqcrypto
match: /v\d+\.\d+\.\d+$
metadata:
license-files: [LICENSE]
license: ISC
php-extension:
build-shared: true
native-libc: true
os:
- Linux
- Darwin
support:
Windows: 'no'
6 changes: 0 additions & 6 deletions config/pkg/target/rust.yml

This file was deleted.

1 change: 1 addition & 0 deletions docs/en/develop/doctor-module.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ The exact list is target-aware. The current core Registry provides these groups:
| Common | At least one Registry is loaded; the host OS is Linux, macOS, or Windows |
| Linux | Distribution build-tool baseline, CMake 3.22+, `re2c` 1.0.3+, and Linux headers on musl distributions |
| macOS | Homebrew or MacPorts, required build commands, GNU Bison 3+, and the selected Homebrew/MacPorts LLVM variant |
| Linux and macOS with `--with-rust` | Host Rust tools and libclang |
| Windows target | `vswhere`, Visual Studio C++ tools, Git `patch.exe`, managed MSYS2, `7za.exe`, and the initialized MSVC command environment |
| Unix target | StaticPHP-managed and functional `pkg-config` |
| Zig toolchain | Installed StaticPHP `zig` tool package |
Expand Down
4 changes: 3 additions & 1 deletion docs/en/develop/package-model.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ ext-{ext-name}: # Package name must start with ext- prefix
build-static: true # Optional, whether inline static building (compiled into PHP) is allowed, default true
build-with-php: true # Optional, true means the extension is built together via the PHP source tree
# (used for built-in extensions)
native-libc: true # Optional, true means the build links host objects (e.g. Rust via
# ext-php-rs), so the target libc must match the build host; default false

# display-name affects the php --ri argument in smoke tests and the license export display name
# If not set, defaults to the extension name (the part after ext-); if set to empty string, skips --ri check
Expand Down Expand Up @@ -215,7 +217,7 @@ Allowed fields for `library`:
# List of directories injected into the global PATH after the package is installed.
# Path placeholders are supported (see below for details).
path:
- '{pkg_root_path}/rust/bin'
- '{pkg_root_path}/my-tool/bin'

# Environment variables set after the package is installed (overwrites existing values).
# Path placeholders are supported.
Expand Down
2 changes: 1 addition & 1 deletion docs/en/develop/performance.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ One caveat up front: no build configuration is fastest for every workload. Resul
A default StaticPHP build is already an optimized build. Without passing any extra flags you get:

- **`-O3` optimization** for PHP and all dependency libraries, favoring runtime speed over compile time and code size.
- **Dead code elimination**: `-ffunction-sections -fdata-sections` combined with `--gc-sections` (Linux) or `-Wl,-dead_strip` (macOS) removes unused functions and data, keeping binaries smaller.
- **Dead code elimination**: `-ffunction-sections -fdata-sections` combined with `--gc-sections` on Linux removes unused functions and data, keeping binaries smaller. macOS does not enable dead stripping by default: symbols that appear unused to the static linker may still be referenced by dynamically loaded shared extensions, so retaining them preserves extension compatibility.
- **Cheaper ELF symbol handling** on Linux: `-fno-semantic-interposition` and `-fno-plt` let the compiler avoid indirection that only matters for interposable shared libraries.
- **Link hardening** on Linux: `relro`, `-z now`, `noexecstack`, `--as-needed`.
- **Link-time code generation on Windows**: StaticPHP rewrites the final CLI/CGI/micro/embed link rules to include `/LTCG`.
Expand Down
4 changes: 3 additions & 1 deletion docs/en/develop/system-build-tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,14 @@ During a build, `PKG_CONFIG_PATH` starts with `buildroot/lib/pkgconfig`, and Sta

## Package Build Executors

Package classes use three common executor implementations:
Package classes use the following build executors.

| Executor | Platform and build system | Current behavior |
|---|---|---|
| `UnixAutoconfExecutor` | Linux/macOS, Autoconf | Adds static/PIC and `buildroot` prefix arguments, runs `configure`, parallel `make`, and optionally `make install` |
| `UnixCMakeExecutor` | Linux/macOS, CMake | Generates a toolchain file rooted at `buildroot`, pins StaticPHP's compilers and pkg-config, disables shared libraries, then configures, builds, and installs |
| `UnixCargoExecutor` | Linux/macOS, Cargo | Runs locked release builds with the host's Rust toolchain and resolves CFLAGS for the selected C toolchain. Returns the Cargo release directory |
| `UnixExtPhpRsExecutor` | Native Linux/macOS, ext-php-rs | Builds shared and static Rust extensions. For static builds, StaticPHP automatically builds a matching PHP CLI and headers for bindgen when needed. |
| `WindowsCMakeExecutor` | Windows, CMake/MSVC | Uses the x64 Visual Studio generator, the static MSVC runtime, a StaticPHP CMake toolchain file, and `cmake --build --target install` |

The executors initialize package-specific include, library, and environment paths and use the configured build concurrency. Unix Autoconf failures preserve `config.log`, and the Unix CMake executor copies available configure/error/output logs to `SPC_LOGS_DIR`. The Windows CMake executor currently relies on the general shell and output logs instead of collecting those CMake files separately.
Expand Down
3 changes: 2 additions & 1 deletion docs/en/guide/cli-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,13 +236,14 @@ If no path is given, `craft.yml` in the current working directory is used. See [
Diagnose whether the current environment can compile PHP normally.

```bash
spc doctor [--auto-fix[=never]]
spc doctor [--auto-fix[=never]] [--with-rust]
```

| Option | Description |
|--------------------|--------------------------------------------------------------------|
| `--auto-fix` | Automatically fix detected issues using the system package manager |
| `--auto-fix=never` | Report issues but never attempt automatic fixes |
| `--with-rust` | Check and install Rust tools |

## dev:shell

Expand Down
1 change: 1 addition & 0 deletions docs/zh/develop/doctor-module.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ bin/spc doctor
| 通用 | 至少加载了一个 Registry;宿主 OS 是 Linux、macOS 或 Windows |
| Linux | 发行版构建工具基线、CMake 3.22+、`re2c` 1.0.3+,以及 musl 发行版的 Linux headers |
| macOS | Homebrew 或 MacPorts、必需构建命令、GNU Bison 3+,以及选定的 Homebrew/MacPorts LLVM 变体 |
| Linux 和 macOS,启用 `--with-rust` | 宿主机的 Rust 工具和 libclang |
| Windows target | `vswhere`、Visual Studio C++ 工具、Git `patch.exe`、受管理的 MSYS2、`7za.exe` 和初始化后的 MSVC 命令环境 |
| Unix target | 由 StaticPHP 管理且可以正常执行的 `pkg-config` |
| Zig toolchain | 已安装 StaticPHP 的 `zig` Tool Package |
Expand Down
4 changes: 3 additions & 1 deletion docs/zh/develop/package-model.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ ext-{ext-name}: # 包名必须以 ext- 前缀开头
build-shared: true # 可选,是否允许构建为共享扩展(.so),默认 true
build-static: true # 可选,是否允许内联静态构建(编译进 PHP),默认 true
build-with-php: true # 可选,true 表示该扩展通过 PHP 源码树一同编译(内置扩展使用)
native-libc: true # 可选,true 表示构建会链接宿主机对象文件(如通过 ext-php-rs 的 Rust),
# 因此目标 libc 必须与构建宿主机一致;默认 false

# display-name 影响 smoke test 中 php --ri 的参数及许可证导出显示名称
# 不填时默认使用扩展名(ext- 后缀部分);填空字符串则跳过 --ri 检查
Expand Down Expand Up @@ -208,7 +210,7 @@ openssl:

# 包安装完成后注入到全局 PATH 的目录列表,支持路径占位符(见下方说明)
path:
- '{pkg_root_path}/rust/bin'
- '{pkg_root_path}/my-tool/bin'

# 包安装完成后设置的环境变量(覆盖已有值),支持路径占位符
env:
Expand Down
2 changes: 1 addition & 1 deletion docs/zh/develop/performance.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
默认的 StaticPHP 构建就是优化过的构建。不传任何额外参数,你就能得到:

- **`-O3` 优化**:PHP 和所有依赖库都偏向运行速度而非编译时间和代码体积。
- **无用代码消除**:`-ffunction-sections -fdata-sections` 配合 `--gc-sections`(Linux)或 `-Wl,-dead_strip`(macOS),移除未使用的函数和数据,保持二进制精简。
- **无用代码消除**:在 Linux 上,`-ffunction-sections -fdata-sections` 配合 `--gc-sections` 可移除未使用的函数和数据,让二进制更精简。macOS 默认不启用 dead stripping:静态链接器认为未使用的符号仍可能被动态加载的共享扩展引用,因此保留这些符号有助于确保扩展兼容性。
- **更低成本的 ELF 符号处理**(Linux):`-fno-semantic-interposition` 和 `-fno-plt` 避免只在可插入(interposable)共享库场景下才需要的间接调用。
- **链接加固**(Linux):`relro`、`-z now`、`noexecstack`、`--as-needed`。
- **Windows 链接时代码生成**:StaticPHP 改写最终 CLI/CGI/micro/embed 的链接规则并加入 `/LTCG`。
Expand Down
4 changes: 3 additions & 1 deletion docs/zh/develop/system-build-tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,14 @@ Doctor 可以通过 `pkg-config` 工具 Package 安装预构建版本。如果

## Package 构建 Executor

Package 类使用三种通用 Executor 实现:
Package 类使用以下构建 Executor。

| Executor | 平台与构建系统 | 当前行为 |
|---|---|---|
| `UnixAutoconfExecutor` | Linux/macOS,Autoconf | 添加静态/PIC 和 `buildroot` 前缀参数,执行 `configure`、并行 `make`,并可选执行 `make install` |
| `UnixCMakeExecutor` | Linux/macOS,CMake | 生成以 `buildroot` 为根的 toolchain 文件,固定使用 StaticPHP 的编译器和 pkg-config,禁用共享库,然后执行配置、构建和安装 |
| `UnixCargoExecutor` | Linux/macOS,Cargo | 使用宿主机的 Rust 工具链执行锁定依赖版本的 release 构建,根据所选 C 工具链解析 CFLAGS,并返回 Cargo release 输出目录 |
| `UnixExtPhpRsExecutor` | Linux/macOS 原生构建,ext-php-rs | 构建共享和静态 Rust 扩展。静态构建时,StaticPHP 会按需自动构建与目标配置匹配的 PHP CLI 和头文件,供 bindgen 使用。 |
| `WindowsCMakeExecutor` | Windows,CMake/MSVC | 使用 x64 Visual Studio generator、静态 MSVC runtime 和 StaticPHP CMake toolchain 文件,并执行 `cmake --build --target install` |

Executor 会初始化 Package 专属的 include、library 和环境路径,并使用配置的构建并发数。Unix Autoconf 失败时会保留 `config.log`,Unix CMake Executor 会把可用的配置/错误/输出日志复制到 `SPC_LOGS_DIR`。Windows CMake Executor 当前依赖通用 shell 和 output 日志,不会另行收集这些 CMake 文件。
Expand Down
3 changes: 2 additions & 1 deletion docs/zh/guide/cli-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,13 +236,14 @@ spc craft [path/to/craft.yml]
检查当前环境是否满足编译要求。

```bash
spc doctor [--auto-fix[=never]]
spc doctor [--auto-fix[=never]] [--with-rust]
```

| 选项 | 说明 |
|--------------------|----------------------|
| `--auto-fix` | 自动修复检测到的问题(使用系统包管理器) |
| `--auto-fix=never` | 仅报告问题,不尝试自动修复 |
| `--with-rust` | 检查并安装 Rust 工具 |

## dev:shell

Expand Down
85 changes: 0 additions & 85 deletions src/Package/Artifact/rust.php

This file was deleted.

43 changes: 43 additions & 0 deletions src/Package/Extension/pqcrypto.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

declare(strict_types=1);

namespace Package\Extension;

use Package\Target\php;
use StaticPHP\Attribute\Package\BeforeStage;
use StaticPHP\Attribute\Package\BuildFor;
use StaticPHP\Attribute\Package\Extension;
use StaticPHP\Attribute\Package\Validate;
use StaticPHP\Package\PhpExtensionPackage;
use StaticPHP\Runtime\Executor\UnixExtPhpRsExecutor;

#[Extension('pqcrypto')]
class pqcrypto extends PhpExtensionPackage
{
#[Validate]
public function validateBuild(): void
{
(new UnixExtPhpRsExecutor($this))->validate();
}

public function getInTreeSourceRoot(): string
{
return $this->isBuildStatic() ? (new UnixExtPhpRsExecutor($this))->prepareGlue() : $this->getSourceRoot();
}

#[BeforeStage('php', [php::class, 'configureForUnix'], 'ext-pqcrypto')]
public function buildStatic(php $package): void
{
if ($this->isBuildStatic()) {
(new UnixExtPhpRsExecutor($this))->buildStatic($package);
}
}

#[BuildFor('Linux')]
#[BuildFor('Darwin')]
public function build(): void
{
(new UnixExtPhpRsExecutor($this))->buildShared();
}
}
2 changes: 1 addition & 1 deletion src/Package/Target/php.php
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ public function syncExtensionSources(PackageInstaller $installer): void
if ($ext->getArtifact() === null) {
continue;
}
$source_root = $ext->getSourceRoot();
$source_root = $ext->getInTreeSourceRoot();
if (!is_dir($source_root)) {
continue;
}
Expand Down
Loading
Loading