From c39155898afce474695544eeddc0af5ad7109b55 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Mon, 20 Apr 2026 11:30:40 +0800 Subject: [PATCH] Add deps-map component and related command --- .gitignore | 1 + docs/.vitepress/components/DepsMap.vue | 589 ++++++++++++++++++ docs/.vitepress/deps-map.data.js | 23 + docs/.vitepress/theme/index.ts | 4 + docs/en/guide/cli-reference.md | 448 +++++++++++-- docs/en/guide/deps-map.md | 21 +- docs/zh/guide/cli-reference.md | 360 ++++++++++- docs/zh/guide/deps-map.md | 18 +- package.json | 1 + .../Command/Dev/GenDepsDataCommand.php | 95 +++ src/StaticPHP/ConsoleApplication.php | 2 + 11 files changed, 1466 insertions(+), 96 deletions(-) create mode 100644 docs/.vitepress/components/DepsMap.vue create mode 100644 docs/.vitepress/deps-map.data.js create mode 100644 src/StaticPHP/Command/Dev/GenDepsDataCommand.php diff --git a/.gitignore b/.gitignore index f804c264..7145f323 100644 --- a/.gitignore +++ b/.gitignore @@ -53,6 +53,7 @@ packlib_files.txt /docs/.vitepress/dist/ /docs/.vitepress/cache/ /docs/.vitepress/ext-data.json +/docs/.vitepress/deps-data.json package-lock.json pnpm-lock.yaml diff --git a/docs/.vitepress/components/DepsMap.vue b/docs/.vitepress/components/DepsMap.vue new file mode 100644 index 00000000..c86040b7 --- /dev/null +++ b/docs/.vitepress/components/DepsMap.vue @@ -0,0 +1,589 @@ + + + + + diff --git a/docs/.vitepress/deps-map.data.js b/docs/.vitepress/deps-map.data.js new file mode 100644 index 00000000..1a26aab7 --- /dev/null +++ b/docs/.vitepress/deps-map.data.js @@ -0,0 +1,23 @@ +import { readFileSync, existsSync } from 'node:fs' +import { resolve, dirname } from 'node:path' +import { fileURLToPath } from 'node:url' + +const __dirname = dirname(fileURLToPath(import.meta.url)) +const DATA_PATH = resolve(__dirname, 'deps-data.json') + +export default { + watch: [DATA_PATH], + + load() { + if (!existsSync(DATA_PATH)) { + console.warn( + '[deps-map.data.js] deps-data.json not found. ' + + 'Run `bin/spc dev:gen-deps-data` to generate it.' + ) + return { packages: {}, missing: true } + } + + const raw = JSON.parse(readFileSync(DATA_PATH, 'utf-8')) + return { packages: raw.packages ?? {}, missing: false } + }, +} diff --git a/docs/.vitepress/theme/index.ts b/docs/.vitepress/theme/index.ts index 06771bcf..d8a45423 100644 --- a/docs/.vitepress/theme/index.ts +++ b/docs/.vitepress/theme/index.ts @@ -3,9 +3,13 @@ import DefaultTheme from 'vitepress/theme' import {inBrowser, useData} from "vitepress"; import {watchEffect} from "vue"; import './style.css'; +import DepsMap from '../components/DepsMap.vue'; export default { ...DefaultTheme, + enhanceApp({ app }) { + app.component('DepsMap', DepsMap) + }, setup() { const { lang } = useData() watchEffect(() => { diff --git a/docs/en/guide/cli-reference.md b/docs/en/guide/cli-reference.md index d9ec8416..3ca5b527 100644 --- a/docs/en/guide/cli-reference.md +++ b/docs/en/guide/cli-reference.md @@ -22,26 +22,26 @@ spc download [artifacts] [options] ### Options -| Option | Short | Description | -|---|---|---| -| `--for-extensions=` | `-e` | Download artifacts needed by the given extensions | -| `--for-libs=` | `-l` | Download artifacts needed by the given libraries | -| `--for-packages=` | | Download artifacts needed by the given packages | -| `--without-suggests` | | Skip suggested packages when using `--for-extensions` | -| `--clean` | | Delete existing download cache before fetching | -| `--with-php=` | | PHP version in `major.minor` format (default: `8.4`) | -| `--prefer-binary` | `-p` | Prefer pre-built binaries over source archives | -| `--prefer-source` | | Prefer source archives over pre-built binaries | -| `--source-only` | | Only download source artifacts | -| `--binary-only` | | Only download binary artifacts | -| `--parallel=` | `-P` | Number of parallel downloads (default: `1`) | -| `--retry=` | `-R` | Number of retries on failure (default: `0`) | -| `--ignore-cache=` | | Force re-download the specified artifacts | -| `--no-alt` | | Do not use alternative mirror URLs | -| `--no-shallow-clone` | | Do not clone git repositories shallowly | -| `--custom-url=` | `-U` | Override the download URL for a source | -| `--custom-git=` | `-G` | Override with a custom git repository | -| `--custom-local=` | `-L` | Use a local path as a source override | +| Option | Short | Description | +|---------------------------------|-------|-------------------------------------------------------| +| `--for-extensions=` | `-e` | Download artifacts needed by the given extensions | +| `--for-libs=` | `-l` | Download artifacts needed by the given libraries | +| `--for-packages=` | | Download artifacts needed by the given packages | +| `--without-suggests` | | Skip suggested packages when using `--for-extensions` | +| `--clean` | | Delete existing download cache before fetching | +| `--with-php=` | | PHP version in `major.minor` format (default: `8.4`) | +| `--prefer-binary` | `-p` | Prefer pre-built binaries over source archives | +| `--prefer-source` | | Prefer source archives over pre-built binaries | +| `--source-only` | | Only download source artifacts | +| `--binary-only` | | Only download binary artifacts | +| `--parallel=` | `-P` | Number of parallel downloads (default: `1`) | +| `--retry=` | `-R` | Number of retries on failure (default: `0`) | +| `--ignore-cache=` | | Force re-download the specified artifacts | +| `--no-alt` | | Do not use alternative mirror URLs | +| `--no-shallow-clone` | | Do not clone git repositories shallowly | +| `--custom-url=` | `-U` | Override the download URL for a source | +| `--custom-git=` | `-G` | Override with a custom git repository | +| `--custom-local=` | `-L` | Use a local path as a source override | ### Examples @@ -81,67 +81,73 @@ All `download` options are also available on `build:php` with the `--dl-` prefix These flags apply only to the combined `build:php` target. To build a specific SAPI in isolation, use its dedicated command (e.g. `spc build:php-cli`). -| Option | Description | -|---|---| -| `--build-cli` | Build the `cli` SAPI (`php` / `php.exe`) | -| `--build-fpm` | Build `php-fpm` (Linux and macOS only) | -| `--build-cgi` | Build `php-cgi` | -| `--build-micro` | Build `micro.sfx` | -| `--build-embed` | Build the embed static library (`libphp.a` / `php8embed.lib`) | -| `--build-frankenphp` | Build the FrankenPHP binary | +| Option | Description | +|----------------------|---------------------------------------------------------------| +| `--build-cli` | Build the `cli` SAPI (`php` / `php.exe`) | +| `--build-fpm` | Build `php-fpm` (Linux and macOS only) | +| `--build-cgi` | Build `php-cgi` | +| `--build-micro` | Build `micro.sfx` | +| `--build-embed` | Build the embed static library (`libphp.a` / `php8embed.lib`) | +| `--build-frankenphp` | Build the FrankenPHP binary | ### Common Build Options {#common-build-options} -| Option | Short | Description | -|---|---|---| -| `--no-strip` | | Keep debug symbols; do not strip the binary | -| `--with-upx-pack` | | Compress the output binary with UPX (install first with `spc install-pkg upx`; Linux and Windows only) | -| `--disable-opcache-jit` | | Disable OPcache JIT | -| `--with-config-file-path=` | | Directory where PHP looks for `php.ini` (default: `/usr/local/etc/php`) | -| `--with-config-file-scan-dir=` | | Directory PHP scans for additional `.ini` files (default: `/usr/local/etc/php/conf.d`) | -| `--with-hardcoded-ini=` | `-I` | Bake an INI setting into the binary at compile time (repeatable) | -| `--enable-zts` | | Enable thread-safe (ZTS) mode | -| `--no-smoke-test` | | Skip the post-build smoke tests | -| `--with-suggests` | `-L` / `-E` | Also resolve and install suggested packages | -| `--with-packages=` | | Additional packages to install alongside the build | -| `--no-download` | | Skip the download step (use existing cached files) | -| `--with-added-patch=` | `-P` | Inject an external PHP patch script (repeatable) | -| `--build-shared=` | `-D` | Extensions to compile as shared `.so` / `.dll` instead of static | +| Option | Short | Description | +|--------------------------------------|-------|--------------------------------------------------------------------------------------------------------| +| `--no-strip` | | Keep debug symbols; do not strip the binary | +| `--with-upx-pack` | | Compress the output binary with UPX (install first with `spc install-pkg upx`; Linux and Windows only) | +| `--disable-opcache-jit` | | Disable OPcache JIT | +| `--with-config-file-path=` | | Directory where PHP looks for `php.ini` (default: `/usr/local/etc/php`) | +| `--with-config-file-scan-dir=` | | Directory PHP scans for additional `.ini` files (default: `/usr/local/etc/php/conf.d`) | +| `--with-hardcoded-ini=` | `-I` | Bake an INI setting into the binary at compile time (repeatable) | +| `--enable-zts` | | Enable thread-safe (ZTS) mode | +| `--no-smoke-test` | | Skip the post-build smoke tests | +| `--with-suggests` | | Also resolve and install suggested packages | +| `--with-packages=` | | Additional packages to install alongside the build | +| `--no-download` | | Skip the download step (use existing cached files) | +| `--build-shared=` | `-D` | Extensions to compile as shared `.so` / `.dll` instead of static | ### micro Options {#micro-options} -| Option | Description | -|---|---| -| `--with-micro-fake-cli` | Make `micro`'s `PHP_SAPI` report `cli` instead of `micro` | -| `--without-micro-ext-test` | Disable the post-build extension test for `micro.sfx` | -| `--with-micro-logo=` | Embed a custom `.ico` icon into `micro.sfx` (Windows only) | -| `--enable-micro-win32` | Build `micro.sfx` as a Win32 GUI application instead of a console app (Windows only) | +| Option | Description | +|----------------------------|--------------------------------------------------------------------------------------| +| `--with-micro-fake-cli` | Make `micro`'s `PHP_SAPI` report `cli` instead of `micro` | +| `--without-micro-ext-test` | Disable the post-build extension test for `micro.sfx` | +| `--with-micro-logo=` | Embed a custom `.ico` icon into `micro.sfx` (Windows only) | +| `--enable-micro-win32` | Build `micro.sfx` as a Win32 GUI application instead of a console app (Windows only) | ### frankenphp Options {#frankenphp-options} -| Option | Description | -|---|---| -| `--enable-zts` | Required for FrankenPHP; enables thread-safe mode | -| `--with-frankenphp-app=` | Embed a directory into the FrankenPHP binary | +| Option | Description | +|--------------------------------|---------------------------------------------------| +| `--enable-zts` | Required for FrankenPHP; enables thread-safe mode | +| `--with-frankenphp-app=` | Embed a directory into the FrankenPHP binary | ### embed Options {#embed-options} -| Option | Description | -|---|---| +| Option | Description | +|-------------------------|-----------------------------------------------------------------------| | `--build-shared=` | Compile specific extensions as shared libraries (requires embed SAPI) | ### Download Pass-through Options {#download-options} All downloader options are available with the `--dl-` prefix: -| Option | Description | -|---|---| -| `--dl-with-php=` | PHP version to download (default: `8.4`) | -| `--dl-prefer-binary` | Prefer pre-built binaries for dependencies | -| `--dl-parallel=` | Number of parallel downloads | -| `--dl-retry=` | Number of retries on failure | -| `--dl-custom-url=` | Override a source download URL | -| `--dl-custom-git=` | Override with a custom git repository | +| Option | Description | +|------------------------------------|--------------------------------------------| +| `--dl-with-php=` | PHP version to download (default: `8.4`) | +| `--dl-prefer-binary` | Prefer pre-built binaries for dependencies | +| `--dl-parallel=` | Number of parallel downloads | +| `--dl-retry=` | Number of retries on failure | +| `--dl-custom-url=` | Override a source download URL | +| `--dl-custom-git=` | Override with a custom git repository | + +Downloader options passed to `build:php` are used by the automatic downloader that runs before the build. +This allows you to control the download behavior without needing a separate `spc download` command. + +```bash +spc build:php "bcmath,openssl,curl" --build-cli --dl-with-php=8.3 --dl-prefer-binary --dl-parallel=4 +``` ### Examples @@ -177,6 +183,42 @@ spc build:php-embed "bcmath,openssl" spc build:frankenphp "bcmath,openssl,curl" --enable-zts ``` +## build:libs + +Build one or more library packages from source. + +```bash +spc build:libs [options] +``` + +`libraries` (required): Comma-separated list of library package names to build (e.g. `"openssl,curl,zlib"`). + +All `download` options are available with the `--dl-` prefix. + +### Options + +| Option | Short | Description | +|---|---|---| +| `--with-suggests` | `-L`, `-E` | Also resolve and install suggested packages | +| `--with-packages=` | | Additional packages to install alongside the build, comma-separated | +| `--no-download` | | Skip downloading artifacts (use existing cached files) | + +### Examples + +```bash +# Build a single library +spc build:libs openssl + +# Build multiple libraries +spc build:libs "openssl,curl,zlib" + +# Build with suggested packages included +spc build:libs openssl --with-suggests + +# Skip the download step +spc build:libs openssl --no-download +``` + ## craft Read a `craft.yml` and run the full build pipeline automatically. @@ -195,10 +237,10 @@ Diagnose whether the current environment can compile PHP normally. spc doctor [--auto-fix[=never]] ``` -| Option | Description | -|---|---| -| `--auto-fix` | Automatically fix detected issues using the system package manager | -| `--auto-fix=never` | Report issues but never attempt automatic fixes | +| Option | Description | +|--------------------|--------------------------------------------------------------------| +| `--auto-fix` | Automatically fix detected issues using the system package manager | +| `--auto-fix=never` | Report issues but never attempt automatic fixes | ## dev:shell @@ -209,3 +251,275 @@ spc dev:shell ``` Useful for compiling small programs against `libphp.a` (embed SAPI) or inspecting the build environment manually. + +## check-update + +Check whether newer versions are available for downloaded artifacts. + +```bash +spc check-update [artifact] [options] +``` + +`artifact` (optional): Artifact names to check, comma-separated. Defaults to all currently downloaded artifacts. + +### Options + +| Option | Short | Description | +|---|---|---| +| `--json` | | Output results in JSON format | +| `--bare` | | Check without requiring the artifact to be downloaded first (old version will be `null`) | +| `--parallel=` | `-p` | Number of parallel update checks (default: `10`) | +| `--with-php=` | | PHP version context in `major.minor` format (default: `8.4`) | + +### Examples + +```bash +# Check all downloaded artifacts +spc check-update + +# Check specific artifacts +spc check-update "openssl,curl" + +# Output as JSON +spc check-update --json + +# Check without requiring a prior download +spc check-update "openssl" --bare +``` + +## dump-extensions + +Analyse a Composer project and output the list of PHP extensions it requires. + +```bash +spc dump-extensions [path] [options] +``` + +`path` (optional): Path to the project root (default: `.`). + +### Options + +| Option | Short | Description | +|---|---|---| +| `--format=` | `-F` | Output format (default: `default`) | +| `--no-ext-output=` | `-N` | When no extensions are found, output this default comma-separated list instead of exiting with failure | +| `--no-dev` | | Exclude dev dependencies | +| `--no-spc-filter` | `-S` | Do not apply the SPC filter when determining required extensions | + +### Examples + +```bash +# Analyse the current directory +spc dump-extensions + +# Analyse a specific directory +spc dump-extensions /path/to/project + +# Exclude dev dependencies +spc dump-extensions --no-dev + +# Fall back to a default list when no extensions are found +spc dump-extensions --no-ext-output="bcmath,openssl" +``` + +## dump-license + +Export open-source license files for artifacts. + +```bash +spc dump-license [artifacts] [options] +``` + +`artifacts` (optional): Specific artifacts whose licenses should be dumped, comma-separated (e.g. `"php-src,openssl,curl"`). + +### Options + +| Option | Short | Description | +|---|---|---| +| `--for-extensions=` | `-e` | Dump by extension names (automatically includes `php-src`), e.g. `"openssl,mbstring"` | +| `--for-libs=` | `-l` | Dump by library names, e.g. `"openssl,zlib"` | +| `--for-packages=` | `-p` | Dump by package names, e.g. `"php,libssl"` | +| `--dump-dir=` | `-d` | Directory to write license files (default: `buildroot/license`) | +| `--without-suggests` | | Do not include licenses for suggested packages | + +### Examples + +```bash +# Dump licenses for the extensions you compiled +spc dump-license --for-extensions="bcmath,openssl,curl" + +# Dump licenses for specific artifacts +spc dump-license "php-src,openssl" + +# Write licenses to a custom directory +spc dump-license --for-extensions="bcmath,openssl" --dump-dir=/tmp/licenses +``` + +## extract + +Extract downloaded artifacts to their target locations in the source tree. + +```bash +spc extract [artifacts] [options] +``` + +`artifacts` (optional): Specific artifacts to extract, comma-separated (e.g. `"php-src,openssl,curl"`). + +### Options + +| Option | Short | Description | +|---|---|---| +| `--for-extensions=` | `-e` | Extract artifacts needed by the given extensions, e.g. `"openssl,mbstring"` | +| `--for-libs=` | `-l` | Extract artifacts needed by the given libraries, e.g. `"libcares,openssl"` | +| `--for-packages=` | | Extract artifacts needed by the given packages, e.g. `"php,libssl,libcurl"` | +| `--without-suggests` | | Skip suggested packages when using `--for-extensions` | +| `--source-only` | | Force extraction from source even if a pre-built binary is available | + +### Examples + +```bash +# Extract artifacts for a set of extensions +spc extract --for-extensions="bcmath,openssl,curl" + +# Extract specific artifacts +spc extract "php-src,openssl" + +# Force source extraction +spc extract --for-extensions="bcmath,openssl" --source-only +``` + +## install-pkg + +Install additional helper packages (e.g. UPX, toolchains). Aliases: `i`, `install-package`. + +```bash +spc install-pkg [options] +``` + +`package` (required): The name of the package to install. + +All `download` options are available with the `--dl-` prefix. + +### Examples + +```bash +# Install the UPX compressor +spc install-pkg upx +``` + +## micro:combine + +Merge `micro.sfx` with a PHP or PHAR file to produce a standalone executable. + +```bash +spc micro:combine [options] +``` + +`file` (required): Path to the PHP or PHAR file to combine. + +### Options + +| Option | Short | Description | +|---|---|---| +| `--with-micro=` | `-M` | Path to a custom `micro.sfx` (default: `buildroot/bin/micro.sfx`) | +| `--with-ini-set=` | `-I` | Inject an INI setting into the binary (repeatable) | +| `--with-ini-file=` | `-N` | Inject INI settings from a file | +| `--output=` | `-O` | Output file name (default: `my-app`) | + +### Examples + +```bash +# Combine a PHP script +spc micro:combine app.php + +# Combine a PHAR with a custom output name +spc micro:combine app.phar --output my-app + +# Inject INI settings +spc micro:combine app.php -I "memory_limit=512M" -I "disable_functions=system" + +# Inject from an INI file +spc micro:combine app.php --with-ini-file=custom.ini + +# Use a custom micro.sfx +spc micro:combine app.php --with-micro=/path/to/micro.sfx +``` + +## reset + +Clean build directories and reset the build environment. + +```bash +spc reset [options] +``` + +By default, removes `buildroot/` and `source/`. + +### Options + +| Option | Short | Description | +|---|---|---| +| `--with-pkgroot` | | Also remove the `pkgroot/` directory | +| `--with-download` | | Also remove the `downloads/` directory | +| `--yes` | `-y` | Skip the confirmation prompt | + +### Examples + +```bash +# Clean build directories (will prompt for confirmation) +spc reset + +# Also clear the download cache +spc reset --with-download + +# Full clean without prompting +spc reset --with-pkgroot --with-download --yes +``` + +## spc-config + +Output compiler and linker flags needed to link your own program against the PHP embed static library. + +```bash +spc spc-config [extensions] [options] +``` + +`extensions` (optional): Comma-separated list of extensions to include. + +### Options + +| Option | Short | Description | +|---|---|---| +| `--with-libs=` | | Additional libraries to include, comma-separated | +| `--with-packages=` | `-p` | Additional packages to include, comma-separated | +| `--with-suggested-libs` | `-L` | Include suggested libraries | +| `--with-suggests` | | Include all suggested packages | +| `--with-suggested-exts` | `-E` | Include suggested extensions | +| `--includes` | | Output only `-I` include paths (`CFLAGS`) | +| `--libs` | | Output only `-L` and `-l` linker flags (`LDFLAGS` + `LIBS`) | +| `--libs-only-deps` | | Output only `-l` dependency flags | +| `--absolute-libs` | | Use absolute paths for library files | +| `--no-php` | | Do not link against the PHP library | + +### Examples + +```bash +# Output full compiler + linker flags +spc spc-config "bcmath,openssl,curl" + +# Output include paths only +spc spc-config "bcmath,openssl" --includes + +# Output linker flags only +spc spc-config "bcmath,openssl" --libs + +# Use absolute library paths +spc spc-config "bcmath,openssl" --libs --absolute-libs +``` +Enter an interactive shell with StaticPHP's build environment pre-loaded (compiler wrappers, `buildroot/`, `pkgroot/` paths, etc. on `PATH`). + +```bash +spc dev:shell +``` + +Useful for compiling small programs against `libphp.a` (embed SAPI) or inspecting the build environment manually. diff --git a/docs/en/guide/deps-map.md b/docs/en/guide/deps-map.md index d1897393..1a66c91d 100644 --- a/docs/en/guide/deps-map.md +++ b/docs/en/guide/deps-map.md @@ -1,4 +1,19 @@ -# Dependency Table +--- +aside: false +--- - +# Dependency Map + +This page lists all supported packages (extensions and libraries) together with their dependency relationships. + +- **Required Dependencies**: packages that are always built alongside the selected package. +- **Suggested Dependencies**: packages that are not built by default; enable them with `--with-suggests` or by specifying them manually. +- **Required By / Suggested By**: which other packages need or suggest this package. + +Run the following command to generate the dependency data (source mode required): + +```bash +bin/spc dev:gen-deps-data +``` + + diff --git a/docs/zh/guide/cli-reference.md b/docs/zh/guide/cli-reference.md index c98e5c44..e4a37f9a 100644 --- a/docs/zh/guide/cli-reference.md +++ b/docs/zh/guide/cli-reference.md @@ -92,30 +92,29 @@ spc build:php [options] ### 通用构建选项 {#common-build-options} -| 选项 | 缩写 | 说明 | -|---|---|---| -| `--no-strip` | | 保留调试符号,不精简二进制 | -| `--with-upx-pack` | | 用 UPX 压缩产物(需先 `spc install-pkg upx`;仅 Linux 和 Windows)| -| `--disable-opcache-jit` | | 禁用 OPcache JIT | -| `--with-config-file-path=` | | PHP 查找 `php.ini` 的目录(默认:`/usr/local/etc/php`)| -| `--with-config-file-scan-dir=` | | PHP 扫描追加 `.ini` 文件的目录(默认:`/usr/local/etc/php/conf.d`)| -| `--with-hardcoded-ini=` | `-I` | 编译时将 INI 配置硬编码进二进制(可重复使用)| -| `--enable-zts` | | 启用线程安全(ZTS)模式 | -| `--no-smoke-test` | | 跳过构建后的冒烟测试 | -| `--with-suggests` | `-L` / `-E` | 同时解析并安装建议包 | -| `--with-packages=` | | 额外安装的包 | -| `--no-download` | | 跳过下载步骤(使用已有缓存)| -| `--with-added-patch=` | `-P` | 注入外部 PHP 补丁脚本(可重复使用)| -| `--build-shared=` | `-D` | 指定编译为共享 `.so` / `.dll` 的扩展 | +| 选项 | 缩写 | 说明 | +|--------------------------------------|------|--------------------------------------------------------| +| `--no-strip` | | 保留调试符号,不精简二进制 | +| `--with-upx-pack` | | 用 UPX 压缩产物(需先 `spc install-pkg upx`;仅 Linux 和 Windows) | +| `--disable-opcache-jit` | | 禁用 OPcache JIT | +| `--with-config-file-path=` | | PHP 查找 `php.ini` 的目录(默认:`/usr/local/etc/php`) | +| `--with-config-file-scan-dir=` | | PHP 扫描追加 `.ini` 文件的目录(默认:`/usr/local/etc/php/conf.d`) | +| `--with-hardcoded-ini=` | `-I` | 编译时将 INI 配置硬编码进二进制(可重复使用) | +| `--enable-zts` | | 启用线程安全(ZTS)模式 | +| `--no-smoke-test` | | 跳过构建后的冒烟测试 | +| `--with-suggests` | | 同时解析并安装建议包 | +| `--with-packages=` | | 额外安装的包 | +| `--no-download` | | 跳过下载步骤(使用已有缓存) | +| `--build-shared=` | `-D` | 指定编译为共享 `.so` / `.dll` 的扩展 | ### micro 专用选项 {#micro-options} -| 选项 | 说明 | -|---|---| -| `--with-micro-fake-cli` | 让 `micro` 的 `PHP_SAPI` 报告为 `cli` 而非 `micro` | -| `--without-micro-ext-test` | 跳过构建后的 `micro.sfx` 扩展测试 | -| `--with-micro-logo=` | 为 `micro.sfx` 嵌入自定义 `.ico` 图标(仅 Windows)| -| `--enable-micro-win32` | 将 `micro.sfx` 构建为 Win32 GUI 程序而非控制台程序(仅 Windows)| +| 选项 | 说明 | +|----------------------------|--------------------------------------------------| +| `--with-micro-fake-cli` | 让 `micro` 的 `PHP_SAPI` 报告为 `cli` 而非 `micro` | +| `--without-micro-ext-test` | 跳过构建后的 `micro.sfx` 扩展测试 | +| `--with-micro-logo=` | 为 `micro.sfx` 嵌入自定义 `.ico` 图标(仅 Windows) | +| `--enable-micro-win32` | 将 `micro.sfx` 构建为 Win32 GUI 程序而非控制台程序(仅 Windows) | ### frankenphp 专用选项 {#frankenphp-options} @@ -143,6 +142,13 @@ spc build:php [options] | `--dl-custom-url=` | 覆盖指定源的下载地址 | | `--dl-custom-git=` | 覆盖为自定义 git 仓库 | +Downloader 选项传递给 `build:php` 命令时,会被自动下载器在构建前使用。 +这样你就可以直接通过构建命令控制下载行为,无需单独执行 `spc download` 命令。 + +```bash +spc build:php "bcmath,openssl,curl" --build-cli --dl-with-php=8.3 --dl-prefer-binary --dl-parallel=4 +``` + ### 示例 ```bash @@ -177,6 +183,42 @@ spc build:php-embed "bcmath,openssl" spc build:frankenphp "bcmath,openssl,curl" --enable-zts ``` +## build:libs + +从源码构建一个或多个库包。 + +```bash +spc build:libs [options] +``` + +`libraries`(必填):要构建的库包名称列表,逗号分隔(如 `"openssl,curl,zlib"`)。 + +支持所有 `download` 命令的选项,加 `--dl-` 前缀传递。 + +### 选项 + +| 选项 | 缩写 | 说明 | +|---|---|---| +| `--with-suggests` | `-L`、`-E` | 同时解析并安装建议包 | +| `--with-packages=` | | 额外安装的包,逗号分隔 | +| `--no-download` | | 跳过下载步骤(使用已有缓存) | + +### 示例 + +```bash +# 构建单个库 +spc build:libs openssl + +# 构建多个库 +spc build:libs "openssl,curl,zlib" + +# 构建时包含建议包 +spc build:libs openssl --with-suggests + +# 跳过下载步骤 +spc build:libs openssl --no-download +``` + ## craft 读取 `craft.yml` 并自动完成全流程构建。 @@ -195,10 +237,10 @@ spc craft [path/to/craft.yml] spc doctor [--auto-fix[=never]] ``` -| 选项 | 说明 | -|---|---| -| `--auto-fix` | 自动修复检测到的问题(使用系统包管理器)| -| `--auto-fix=never` | 仅报告问题,不尝试自动修复 | +| 选项 | 说明 | +|--------------------|----------------------| +| `--auto-fix` | 自动修复检测到的问题(使用系统包管理器) | +| `--auto-fix=never` | 仅报告问题,不尝试自动修复 | ## dev:shell @@ -210,3 +252,271 @@ spc dev:shell 可用于在 embed SAPI 的 `libphp.a` 上编译小型 C 程序,或手动检查构建环境。 +## check-update + +检查指定制品是否有可用更新。 + +```bash +spc check-update [artifact] [options] +``` + +`artifact`(可选):要检查更新的制品名称,逗号分隔。默认检查所有已下载的制品。 + +### 选项 + +| 选项 | 缩写 | 说明 | +|---|---|---| +| `--json` | | 以 JSON 格式输出结果 | +| `--bare` | | 检查时不要求制品已下载(旧版本显示为 null)| +| `--parallel=` | `-p` | 并行检查数(默认 `10`)| +| `--with-php=` | | PHP 版本上下文,格式为 `major.minor`(默认 `8.4`)| + +### 示例 + +```bash +# 检查所有已下载制品 +spc check-update + +# 检查指定制品 +spc check-update "openssl,curl" + +# 以 JSON 格式输出 +spc check-update --json + +# 无需先下载即可检查 +spc check-update "openssl" --bare +``` + +## dump-extensions + +从 Composer 项目中分析所需的 PHP 扩展列表。 + +```bash +spc dump-extensions [path] [options] +``` + +`path`(可选):项目根目录路径,默认为当前目录(`.`)。 + +### 选项 + +| 选项 | 缩写 | 说明 | +|---|---|---| +| `--format=` | `-F` | 输出格式(默认 `default`)| +| `--no-ext-output=` | `-N` | 未找到扩展时输出的默认组合(逗号分隔),而不是以失败退出 | +| `--no-dev` | | 不包含 dev 依赖 | +| `--no-spc-filter` | `-S` | 不使用 SPC 过滤器筛选扩展 | + +### 示例 + +```bash +# 分析当前目录的 Composer 项目 +spc dump-extensions + +# 分析指定目录 +spc dump-extensions /path/to/project + +# 不包含 dev 依赖 +spc dump-extensions --no-dev + +# 未找到扩展时输出默认组合 +spc dump-extensions --no-ext-output="bcmath,openssl" +``` + +## dump-license + +导出制品的开源许可证文件。 + +```bash +spc dump-license [artifacts] [options] +``` + +`artifacts`(可选):要导出许可证的制品名称,逗号分隔(如 `"php-src,openssl,curl"`)。 + +### 选项 + +| 选项 | 缩写 | 说明 | +|---|---|---| +| `--for-extensions=` | `-e` | 按扩展名导出(自动包含 php-src),如 `"openssl,mbstring"` | +| `--for-libs=` | `-l` | 按库名导出,如 `"openssl,zlib"` | +| `--for-packages=` | `-p` | 按包名导出,如 `"php,libssl"` | +| `--dump-dir=` | `-d` | 许可证输出目录(默认 `buildroot/license`)| +| `--without-suggests` | | 不包含建议包的许可证 | + +### 示例 + +```bash +# 按扩展名导出许可证 +spc dump-license --for-extensions="bcmath,openssl,curl" + +# 导出指定制品的许可证 +spc dump-license "php-src,openssl" + +# 指定输出目录 +spc dump-license --for-extensions="bcmath,openssl" --dump-dir=/tmp/licenses +``` + +## extract + +将已下载的制品解压到对应的目标位置。 + +```bash +spc extract [artifacts] [options] +``` + +`artifacts`(可选):要解压的制品名称,逗号分隔(如 `"php-src,openssl,curl"`)。 + +### 选项 + +| 选项 | 缩写 | 说明 | +|---|---|---| +| `--for-extensions=` | `-e` | 按扩展名解压所需制品,如 `"openssl,mbstring"` | +| `--for-libs=` | `-l` | 按库名解压所需制品,如 `"libcares,openssl"` | +| `--for-packages=` | | 按包名解压所需制品,如 `"php,libssl,libcurl"` | +| `--without-suggests` | | 使用 `--for-extensions` 时跳过建议包 | +| `--source-only` | | 强制解压源码,即使已有预编译二进制 | + +### 示例 + +```bash +# 按扩展名解压 +spc extract --for-extensions="bcmath,openssl,curl" + +# 解压指定制品 +spc extract "php-src,openssl" + +# 强制解压源码 +spc extract --for-extensions="bcmath,openssl" --source-only +``` + +## install-pkg + +安装额外的辅助包(如 UPX、工具链等)。别名:`i`、`install-package`。 + +```bash +spc install-pkg [options] +``` + +`package`(必填):要安装的包名称。 + +支持所有 `download` 命令的选项,加 `--dl-` 前缀传递。 + +### 示例 + +```bash +# 安装 UPX 压缩工具 +spc install-pkg upx + +# 安装时优先使用预编译二进制(默认行为) +spc install-pkg upx +``` + +## micro:combine + +将 `micro.sfx` 与 PHP/PHAR 文件合并为独立可执行文件。 + +```bash +spc micro:combine [options] +``` + +`file`(必填):要合并的 PHP 或 PHAR 文件路径。 + +### 选项 + +| 选项 | 缩写 | 说明 | +|---|---|---| +| `--with-micro=` | `-M` | 指定自定义 `micro.sfx` 文件路径(默认使用 `buildroot/bin/micro.sfx`)| +| `--with-ini-set=` | `-I` | 合并时注入 INI 配置(可重复使用)| +| `--with-ini-file=` | `-N` | 合并时注入 INI 文件 | +| `--output=` | `-O` | 自定义输出文件名(默认 `my-app`)| + +### 示例 + +```bash +# 合并 PHP 文件 +spc micro:combine app.php + +# 合并 PHAR 文件并指定输出名 +spc micro:combine app.phar --output my-app + +# 注入 INI 配置 +spc micro:combine app.php -I "memory_limit=512M" -I "disable_functions=system" + +# 注入 INI 文件 +spc micro:combine app.php --with-ini-file=custom.ini + +# 使用自定义 micro.sfx +spc micro:combine app.php --with-micro=/path/to/micro.sfx +``` + +## reset + +清理构建目录,重置构建环境。 + +```bash +spc reset [options] +``` + +默认清理 `buildroot/` 和 `source/` 目录。 + +### 选项 + +| 选项 | 缩写 | 说明 | +|---|---|---| +| `--with-pkgroot` | | 同时删除 `pkgroot/` 目录 | +| `--with-download` | | 同时删除 `downloads/` 目录 | +| `--yes` | `-y` | 跳过确认提示 | + +### 示例 + +```bash +# 清理构建目录(会提示确认) +spc reset + +# 同时清理下载缓存 +spc reset --with-download + +# 完全清理(不提示) +spc reset --with-pkgroot --with-download --yes +``` + +## spc-config + +输出静态编译所需的编译器和链接器标志,适用于将 PHP embed 库链接到自定义程序。 + +```bash +spc spc-config [extensions] [options] +``` + +`extensions`(可选):要包含的扩展名列表,逗号分隔。 + +### 选项 + +| 选项 | 缩写 | 说明 | +|---|---|---| +| `--with-libs=` | | 额外包含的库,逗号分隔 | +| `--with-packages=` | `-p` | 额外包含的包,逗号分隔 | +| `--with-suggested-libs` | `-L` | 包含建议库 | +| `--with-suggests` | | 包含所有建议包 | +| `--with-suggested-exts` | `-E` | 包含建议扩展 | +| `--includes` | | 仅输出 `-I` 头文件路径(`CFLAGS`)| +| `--libs` | | 仅输出 `-L` 和 `-l` 链接标志(`LDFLAGS + LIBS`)| +| `--libs-only-deps` | | 仅输出依赖库的 `-l` 标志 | +| `--absolute-libs` | | 使用库文件的绝对路径输出 | +| `--no-php` | | 不链接 PHP 库 | + +### 示例 + +```bash +# 输出完整编译标志 +spc spc-config "bcmath,openssl,curl" + +# 仅输出头文件路径 +spc spc-config "bcmath,openssl" --includes + +# 仅输出链接标志 +spc spc-config "bcmath,openssl" --libs + +# 使用绝对路径 +spc spc-config "bcmath,openssl" --libs --absolute-libs +``` + diff --git a/docs/zh/guide/deps-map.md b/docs/zh/guide/deps-map.md index 5dc795bd..04615a29 100644 --- a/docs/zh/guide/deps-map.md +++ b/docs/zh/guide/deps-map.md @@ -1,3 +1,19 @@ +--- +aside: false +--- + # 依赖关系图 - +这里列出了所有支持的包(扩展、库)及其依赖关系。 + +- **必需依赖**:构建该包时会强制一同构建的包。 +- **可选依赖**:默认不构建,使用 `--with-suggests` 参数可启用,或在构建命令中手动指定。 +- **被依赖**:其他哪些包需要当前包。 + +运行以下命令生成依赖数据(需要在源码模式下): + +```bash +bin/spc dev:gen-deps-data +``` + + diff --git a/package.json b/package.json index da1bbb88..53b6988a 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,7 @@ "docs:preview": "vitepress preview docs" }, "devDependencies": { + "mermaid": "^11.0.0", "vitepress": "^2.0.0-alpha.5", "vue": "^3.2.47" } diff --git a/src/StaticPHP/Command/Dev/GenDepsDataCommand.php b/src/StaticPHP/Command/Dev/GenDepsDataCommand.php new file mode 100644 index 00000000..2067ea8c --- /dev/null +++ b/src/StaticPHP/Command/Dev/GenDepsDataCommand.php @@ -0,0 +1,95 @@ +output->writeln('This command is only available in source mode.'); + return static::USER_ERROR; + } + + $all = PackageConfig::getAll(); + $packages = []; + + foreach ($all as $pkg_name => $config) { + $type = $config['type'] ?? 'unknown'; + + // Build platform-specific dep/suggest data + $platforms = []; + foreach (self::PLATFORMS as $platform) { + $platforms[$platform] = [ + 'depends' => $this->resolvePlatformList($config, 'depends', $platform), + 'suggests' => $this->resolvePlatformList($config, 'suggests', $platform), + ]; + } + + $entry = [ + 'type' => $type, + 'platforms' => $platforms, + ]; + + // For php-extension, add OS support info + if ($type === 'php-extension') { + $os_list = $config['php-extension']['os'] ?? null; + if ($os_list !== null) { + $entry['os'] = $os_list; + } + } + + $packages[$pkg_name] = $entry; + } + + // Sort by type then name for readability + uksort($packages, function ($a, $b) use ($packages) { + $ta = $packages[$a]['type']; + $tb = $packages[$b]['type']; + if ($ta !== $tb) { + return strcmp($ta, $tb); + } + return strcmp($a, $b); + }); + + $output_data = [ + 'generated_at' => date('c'), + 'packages' => $packages, + ]; + + $output_path = ROOT_DIR . '/docs/.vitepress/deps-data.json'; + file_put_contents($output_path, json_encode($output_data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . PHP_EOL); + + $this->output->writeln('Generated ' . $output_path . ' with ' . count($packages) . ' packages.'); + return static::SUCCESS; + } + + /** + * Resolve the value of a platform-specific array field, applying the suffix fallback chain. + * + * Fallback rules (same as PackageConfig::get): + * linux : @linux → @unix → (base) + * macos : @macos → @unix → (base) + * windows : @windows → (base) + */ + private function resolvePlatformList(array $config, string $field, string $platform): array + { + return match ($platform) { + 'linux' => $config["{$field}@linux"] ?? $config["{$field}@unix"] ?? $config[$field] ?? [], + 'macos' => $config["{$field}@macos"] ?? $config["{$field}@unix"] ?? $config[$field] ?? [], + 'windows' => $config["{$field}@windows"] ?? $config[$field] ?? [], + default => $config[$field] ?? [], + }; + } +} diff --git a/src/StaticPHP/ConsoleApplication.php b/src/StaticPHP/ConsoleApplication.php index 07a81d27..06234f76 100644 --- a/src/StaticPHP/ConsoleApplication.php +++ b/src/StaticPHP/ConsoleApplication.php @@ -11,6 +11,7 @@ use StaticPHP\Command\CraftCommand; use StaticPHP\Command\Dev\DumpCapabilitiesCommand; use StaticPHP\Command\Dev\DumpStagesCommand; use StaticPHP\Command\Dev\EnvCommand; +use StaticPHP\Command\Dev\GenDepsDataCommand; use StaticPHP\Command\Dev\GenExtDocsCommand; use StaticPHP\Command\Dev\IsInstalledCommand; use StaticPHP\Command\Dev\LintConfigCommand; @@ -83,6 +84,7 @@ class ConsoleApplication extends Application new DumpCapabilitiesCommand(), new PackageInfoCommand(), new GenExtDocsCommand(), + new GenDepsDataCommand(), ]); // add additional commands from registries