Compare commits

...

121 Commits

Author SHA1 Message Date
crazywhalecc
a3003d363e ttt 2026-04-02 08:43:31 +08:00
crazywhalecc
b5b4e8f622 ttt 2026-04-02 08:43:26 +08:00
crazywhalecc
d316ea81e4 Merge branch 'main' into v3-refactor/win-exts
# Conflicts:
#	config/env.ini
2026-03-31 15:13:23 +08:00
crazywhalecc
b96586e4d3 Add curl extension and enhance Windows build process 2026-03-31 15:10:47 +08:00
Marc
d535e4f102 libjpeg-turbo mustn't compile zlib symbols on its own (#1077) 2026-03-30 10:08:49 +07:00
henderkes
5a5f54bdcd brilliant to test php 8.1 2026-03-30 01:37:08 +07:00
henderkes
8f7897e13b test 2026-03-30 01:06:31 +07:00
henderkes
daae5f2a7c libjpeg-turbo mustn't compile zlib symbols on its own 2026-03-30 00:56:51 +07:00
crazywhalecc
844bb69f0d Fix ext-curl implementation 2026-03-27 22:30:39 +08:00
Marc
766f7fa34f hard code protobuf version while we're on v2 (#1075) 2026-03-26 12:37:32 +07:00
henderkes
ecf712b2b7 hard code protobuf version while we're on v2 2026-03-26 12:32:27 +07:00
crazywhalecc
94dd44e68d Add ext-amqp 2026-03-24 18:58:12 +08:00
crazywhalecc
2fa07700ef Fix zlib extension wrong arg 2026-03-24 18:55:04 +08:00
crazywhalecc
13a15b1a5a Use alpha1 as version number 2026-03-24 15:31:15 +08:00
Jerry Ma
d2c7fee8fa [3.0] Refactor windows libs (#1067) 2026-03-24 15:28:27 +08:00
crazywhalecc
9cd3125544 Patch configure script to include liblber for ldap dependency 2026-03-24 14:41:46 +08:00
crazywhalecc
590a94a723 Fix cli checks caused php testing fail 2026-03-24 14:41:32 +08:00
crazywhalecc
b625d80dc0 Fix tar command for unix 2026-03-24 13:30:17 +08:00
crazywhalecc
93c099dd31 Add xz 2026-03-24 12:31:45 +08:00
crazywhalecc
fcd0052d12 Add sqlite 2026-03-24 12:31:31 +08:00
crazywhalecc
6c52451c6c Add qdbm 2026-03-24 12:18:06 +08:00
crazywhalecc
175567fd11 Add missing postgresql license 2026-03-24 12:13:42 +08:00
crazywhalecc
bf05af7e16 Add pthreads4w 2026-03-24 12:13:22 +08:00
crazywhalecc
7c3022b7e3 Add postgresql (replace postgresql-win) 2026-03-24 12:07:57 +08:00
crazywhalecc
2a50015c12 Add download options for install-pkg command 2026-03-24 12:07:02 +08:00
crazywhalecc
1f42f1a479 Add libzip 2026-03-24 10:52:13 +08:00
crazywhalecc
41f5948392 Add libyaml 2026-03-23 17:11:47 +08:00
crazywhalecc
6d91f8b2d3 Add patch description for Windows static linking in libsodium 2026-03-23 17:11:37 +08:00
crazywhalecc
141c737380 Add libsodium 2026-03-23 16:50:13 +08:00
Jerry Ma
d35cbd7bf8 Add Windows builders for libaom and brotli (#1072) 2026-03-23 16:21:46 +08:00
crazywhalecc
d076df6b04 Bump version number 2026-03-23 16:21:24 +08:00
crazywhalecc
a99b6bebae Remove freetype useless lib suggestions 2026-03-23 16:08:09 +08:00
crazywhalecc
af97263596 Forward-port #1070 2026-03-22 20:19:31 +08:00
Hendrik Mennen
864678ab46 Merge branch 'main' into feat/windows-libaom-brotli 2026-03-22 13:12:47 +01:00
Hendrik Mennen
c03508a84b Improve zlib Windows library detection for future zlib versions (#1070)
Co-authored-by: Hendrik Mennen <hmennen@gambio.ec1.de>
2026-03-22 20:11:29 +08:00
Hendrik Mennen
963e2a084a Add Windows builders for libaom and brotli libraries
Both libraries are listed in lib.json and used as transitive dependencies
(libaom via libavif, brotli via freetype/curl) but had no Windows builder,
causing builds to fail with "library [X] is in the lib.json list but not
supported to compile".

libaom: Uses builddir instead of build to avoid collision with the
source tree's build/cmake/ directory. Matches the Unix builder's
AOM_TARGET_CPU=generic setting for portability.

brotli: Standard CMake build with shared libs and tools disabled.

Also adds static-libs-windows entry for libaom in lib.json.
2026-03-22 09:07:47 +01:00
crazywhalecc
508cfa67e5 Make openssl build faster 2026-03-21 18:43:05 +08:00
crazywhalecc
08dca4253d Add librabbitmq 2026-03-21 18:42:34 +08:00
crazywhalecc
e4434643ff Add jom to reduce openssl building time 2026-03-21 18:41:57 +08:00
crazywhalecc
adff728999 Add libffi-win 2026-03-21 18:04:15 +08:00
crazywhalecc
9af132d67e Add missing icu license file 2026-03-21 18:03:14 +08:00
crazywhalecc
a950f3d716 Add libaom 2026-03-21 17:54:34 +08:00
crazywhalecc
33f33439d1 Add libavif 2026-03-21 17:54:21 +08:00
crazywhalecc
36177e4948 Add libjpeg 2026-03-21 17:54:07 +08:00
crazywhalecc
801d41efeb Add libwebp 2026-03-21 17:53:49 +08:00
crazywhalecc
43d8c9d9d6 Add icu (replace old icu-static-win) 2026-03-21 12:44:17 +08:00
crazywhalecc
75dd01aa91 Enhance package download logic to handle binary-only packages and improve error messaging for installation failures 2026-03-21 12:43:39 +08:00
crazywhalecc
bf4d227a55 Add error handling for missing vswhere.exe in WindowsUtil 2026-03-21 12:42:47 +08:00
crazywhalecc
520767638f Add gmssl 2026-03-21 11:20:05 +08:00
crazywhalecc
5ff973e446 Add freetype 2026-03-21 11:12:24 +08:00
crazywhalecc
230be2ebe8 Add libpng 2026-03-21 11:12:13 +08:00
crazywhalecc
bd73b4a6dc phpstan 2026-03-21 00:34:31 +08:00
crazywhalecc
327bb8bc0f Add curl 2026-03-21 00:33:27 +08:00
crazywhalecc
deb979416f Add libiconv-win 2026-03-21 00:33:04 +08:00
crazywhalecc
f6e00c67cc Refactor LibraryPackage to skip pkg-config and static-bin checks on Windows 2026-03-21 00:32:02 +08:00
crazywhalecc
7df861696d Add libxml2 2026-03-21 00:31:45 +08:00
crazywhalecc
92861669c2 Add nghttp2 2026-03-21 00:31:30 +08:00
crazywhalecc
893f640469 Add nghttp3 2026-03-21 00:31:16 +08:00
crazywhalecc
eff7037e74 Add ngtcp2, remove suggested libs 2026-03-21 00:31:02 +08:00
crazywhalecc
1213cb578e Refactor WindowsUtil to cache Visual Studio search results and add CMake find modules 2026-03-21 00:30:30 +08:00
crazywhalecc
d1ec473f21 Allow set current working dir 2026-03-21 00:30:15 +08:00
crazywhalecc
19bfb6bc83 Add zstd 2026-03-21 00:29:35 +08:00
crazywhalecc
94c579a453 Add libssh2 2026-03-20 21:48:46 +08:00
crazywhalecc
d7d41f4d89 Add openssl 2026-03-20 21:47:27 +08:00
Marc
4c6b7a3d55 fix libde265 on ancient debian OS (#1064) 2026-03-20 19:48:01 +07:00
Marc
5404926a14 Merge branch 'main' into fix/lide265 2026-03-20 19:47:47 +07:00
Nils Silbernagel
295df19484 Add shared-extensions, frankenphp and zts to build-unix workflow (#1062)
Co-authored-by: crazywhalecc <jesse2061@outlook.com>
2026-03-20 20:37:25 +08:00
Jerry Ma
b970bf8e3a Fix gd build on PHP 8.5 (#1043) 2026-03-20 20:00:42 +08:00
Jerry Ma
54915028d7 Fix zlib produced lib file names from different zlib version (#1066) 2026-03-20 19:35:51 +08:00
crazywhalecc
03cd7e141c Add brotli libs 2026-03-20 18:09:29 +08:00
crazywhalecc
9f3e353699 Add bzip2 2026-03-20 18:04:30 +08:00
crazywhalecc
b21d5716e1 Add onig 2026-03-20 18:04:18 +08:00
crazywhalecc
464ddeb29d Fix file copy operation to handle identical source and destination paths 2026-03-20 18:03:58 +08:00
crazywhalecc
0c389d9069 Add zlib 2026-03-20 18:03:46 +08:00
crazywhalecc
1d2916fa8f Add brotli 2026-03-20 16:16:29 +08:00
crazywhalecc
46132ee1c8 Fix doctor lock path on Windows 2026-03-20 16:16:09 +08:00
crazywhalecc
3c9e868ce1 Add spc-debug script on Windows 2026-03-20 16:08:58 +08:00
crazywhalecc
c5efcc0c93 Fix wrongly using msys2 tar.exe 2026-03-20 16:07:28 +08:00
Jerry Ma
64d692e105 [3.0] Refactor extensions (#1038) 2026-03-20 16:05:35 +08:00
crazywhalecc
dc79ac9c9a Correct doctor fix 2026-03-20 11:32:15 +08:00
crazywhalecc
e9be3a41db Add homebrew llvm version toolchain support 2026-03-20 11:20:42 +08:00
Jerry Ma
00649d816e [3.0] Refactor new extensions (#1051) 2026-03-20 10:54:29 +09:00
crazywhalecc
11376cc6ad Use env and path injection instead of old style 2026-03-20 09:31:43 +08:00
crazywhalecc
c6207d8c7c Fix interactive install-pkg command 2026-03-20 09:31:24 +08:00
crazywhalecc
b0eff0ba6e Add protoc target 2026-03-20 09:31:05 +08:00
crazywhalecc
9d748a6e08 Add rust target 2026-03-20 09:30:52 +08:00
crazywhalecc
b0522205da Add support for package environment variables and path injection 2026-03-20 09:30:34 +08:00
crazywhalecc
beeb0b8721 Handle failure in fetching Zig version index 2026-03-20 09:29:45 +08:00
henderkes
823fe96942 attempt 2026-03-18 23:26:57 +07:00
henderkes
f2fa29809a why is it not failing here? 2026-03-18 18:37:16 +07:00
Marc
463ec546fa Merge branch 'main' into fix/lide265 2026-03-18 15:51:03 +07:00
crazywhalecc
9e2a5ce188 Add target htop 2026-03-18 15:01:06 +08:00
crazywhalecc
0b0ecd17c3 Allow curl building static executable 2026-03-18 15:00:58 +08:00
crazywhalecc
c81146bf18 Add ncursesw 2026-03-18 15:00:44 +08:00
crazywhalecc
c1f2fd49a6 Add ext-imap 2026-03-18 13:30:29 +08:00
henderkes
60b2aea09e fix libde265 on ancient debian OS? 2026-03-18 11:57:27 +07:00
Marc
4625c6a885 update default php version to 8.5 (#1058) 2026-03-11 15:09:07 +07:00
henderkes
85b0cd8b4b only disable when building ftp static, shared is fine 2026-03-11 13:54:24 +07:00
henderkes
1fcb74ad9b swoole-ftp conflicts with ftp 2026-03-11 13:42:38 +07:00
henderkes
1049a3ce66 curl is always supported now (swoole no longer supports php < 8.1) 2026-03-11 10:32:58 +07:00
henderkes
1b8b53d47f update swoole args for 6.2 2026-03-11 10:19:08 +07:00
henderkes
a232f578a4 test bulk 2026-03-11 10:11:39 +07:00
henderkes
70285cb53b actually update to 8.5 2026-03-11 09:48:50 +07:00
henderkes
a335d050cf cs fix 2026-03-11 09:46:41 +07:00
henderkes
ef4b2997a7 test 2026-03-11 09:45:56 +07:00
henderkes
901da8fa41 remove ldtl from odbc libs private (using built in ltdl) 2026-03-11 09:43:02 +07:00
henderkes
e49a5d7a50 make php 8.5 default 2026-03-11 09:42:39 +07:00
Jerry Ma
281b958075 Fix grpc build (#1055) 2026-03-10 20:35:51 +09:00
Marc
e31f64864e fix: FrankenPHP build args (#1057) 2026-03-10 18:13:34 +07:00
Kévin Dunglas
92f5b56c74 fix: FrankenPHP build args 2026-03-10 11:57:23 +01:00
Jerry Ma
2350d2d5ca Merge branch 'main' into fix/grpc-build 2026-03-10 14:52:21 +09:00
crazywhalecc
086c855a43 Use custom config.m4 for grpc extension 2026-03-10 13:49:53 +08:00
crazywhalecc
4fa5292913 Use custom config.m4 for grpc extension 2026-03-10 13:49:34 +08:00
Marc
9634b8bcda set custom binary name for frankenphp, allow linking against system openssl (fix mssql issues) (#1056) 2026-03-10 11:11:36 +07:00
Marc
5d5a50a33c Update src/SPC/builder/LibraryBase.php
Co-authored-by: Jerry Ma <jesse2061@outlook.com>
2026-03-10 10:57:49 +07:00
henderkes
1edf14e642 set custom binary name for frankenphp 2026-03-10 08:52:15 +07:00
henderkes
2277390a1a fix removeConfigureArgs in UnixAutoconfExecutor.php 2026-03-10 08:49:56 +07:00
henderkes
f93ad27c17 allow using some libs as system provided (work around mssql linking vs system openssl) 2026-03-10 08:47:38 +07:00
henderkes
b690566b39 simplify rm command 2026-03-10 08:43:48 +07:00
henderkes
16e772e1a8 add back in zig workaround as 0.16.x is not released yet 2026-03-10 08:42:17 +07:00
crazywhalecc
ad356b4a23 Fix grpc build 2026-03-09 20:12:14 +08:00
141 changed files with 3325 additions and 318 deletions

View File

@@ -29,6 +29,9 @@ on:
description: Extensions to build (comma separated)
required: true
type: string
shared-extensions:
description: Shared extensions to build (optional, comma separated)
type: string
extra-libs:
description: Extra libraries to build (optional, comma separated)
type: string
@@ -42,6 +45,14 @@ on:
build-fpm:
description: Build fpm binary
type: boolean
build-frankenphp:
description: Build frankenphp binary (requires ZTS)
type: boolean
default: false
enable-zts:
description: Enable ZTS
type: boolean
default: false
prefer-pre-built:
description: Prefer pre-built binaries (reduce build time)
type: boolean
@@ -73,6 +84,9 @@ on:
description: Extensions to build (comma separated)
required: true
type: string
shared-extensions:
description: Shared extensions to build (optional, comma separated)
type: string
extra-libs:
description: Extra libraries to build (optional, comma separated)
type: string
@@ -86,6 +100,14 @@ on:
build-fpm:
description: Build fpm binary
type: boolean
build-frankenphp:
description: Build frankenphp binary (requires ZTS)
type: boolean
default: false
enable-zts:
description: Enable ZTS
type: boolean
default: false
prefer-pre-built:
description: Prefer pre-built binaries (reduce build time)
type: boolean
@@ -152,8 +174,19 @@ jobs:
RUNS_ON="macos-15"
;;
esac
DOWN_CMD="$DOWN_CMD --with-php=${{ inputs.php-version }} --for-extensions=${{ inputs.extensions }} --ignore-cache-sources=php-src"
BUILD_CMD="$BUILD_CMD ${{ inputs.extensions }}"
STATIC_EXTS="${{ inputs.extensions }}"
SHARED_EXTS="${{ inputs['shared-extensions'] }}"
BUILD_FRANKENPHP="${{ inputs['build-frankenphp'] }}"
ENABLE_ZTS="${{ inputs['enable-zts'] }}"
ALL_EXTS="$STATIC_EXTS"
if [ -n "$SHARED_EXTS" ]; then
ALL_EXTS="$ALL_EXTS,$SHARED_EXTS"
fi
DOWN_CMD="$DOWN_CMD --with-php=${{ inputs.php-version }} --for-extensions=$ALL_EXTS --ignore-cache-sources=php-src"
BUILD_CMD="$BUILD_CMD $STATIC_EXTS"
if [ -n "$SHARED_EXTS" ]; then
BUILD_CMD="$BUILD_CMD --build-shared=$SHARED_EXTS"
fi
if [ -n "${{ inputs.extra-libs }}" ]; then
DOWN_CMD="$DOWN_CMD --for-libs=${{ inputs.extra-libs }}"
BUILD_CMD="$BUILD_CMD --with-libs=${{ inputs.extra-libs }}"
@@ -177,6 +210,12 @@ jobs:
if [ ${{ inputs.build-fpm }} == true ]; then
BUILD_CMD="$BUILD_CMD --build-fpm"
fi
if [ "$BUILD_FRANKENPHP" = "true" ]; then
BUILD_CMD="$BUILD_CMD --build-frankenphp"
fi
if [ "$ENABLE_ZTS" = "true" ]; then
BUILD_CMD="$BUILD_CMD --enable-zts"
fi
echo 'download='"$DOWN_CMD" >> "$GITHUB_OUTPUT"
echo 'build='"$BUILD_CMD" >> "$GITHUB_OUTPUT"
echo 'run='"$RUNS_ON" >> "$GITHUB_OUTPUT"
@@ -199,6 +238,27 @@ jobs:
env:
phpts: nts
- if: ${{ inputs['build-frankenphp'] == true }}
name: "Install go-xcaddy for FrankenPHP"
run: |
case "${{ inputs.os }}" in
linux-x86_64|linux-aarch64)
./bin/spc-alpine-docker install-pkg go-xcaddy
;;
linux-x86_64-glibc|linux-aarch64-glibc)
./bin/spc-gnu-docker install-pkg go-xcaddy
;;
macos-x86_64|macos-aarch64)
composer update --no-dev --classmap-authoritative
./bin/spc doctor --auto-fix
./bin/spc install-pkg go-xcaddy
;;
*)
echo "Unsupported OS for go-xcaddy install: ${{ inputs.os }}"
exit 1
;;
esac
# Cache downloaded source
- id: cache-download
uses: actions/cache@v4
@@ -245,7 +305,22 @@ jobs:
name: php-fpm-${{ inputs.php-version }}-${{ inputs.os }}
path: buildroot/bin/php-fpm
# Upload frankenphp executable
- if: ${{ inputs['build-frankenphp'] == true }}
name: "Upload FrankenPHP SAPI"
uses: actions/upload-artifact@v4
with:
name: php-frankenphp-${{ inputs.php-version }}-${{ inputs.os }}
path: buildroot/bin/frankenphp
# Upload extensions metadata
- if: ${{ inputs['shared-extensions'] != '' }}
name: "Upload shared extensions"
uses: actions/upload-artifact@v4
with:
name: php-shared-ext-${{ inputs.php-version }}-${{ inputs.os }}
path: |
buildroot/modules/*.so
- uses: actions/upload-artifact@v4
name: "Upload License Files"
with:

57
TODO.md Normal file
View File

@@ -0,0 +1,57 @@
# v3 TODO List
Tracking items identified during the v2 → v3 migration audit.
---
## Commands
- [ ] Implement `craft` command (drives full build from `craft.yml`; should be easier with v3 vendor/registry mode)
- [ ] Migrate `micro:combine` command (combine `micro.sfx` with PHP code + INI injection)
- [ ] Implement `dump-extensions` command (extract required extensions from `composer.json` / `composer.lock`)
- [ ] Design and implement v3 dev toolchain commands (WIP — needs design decision):
- [ ] `dev:extensions` / equivalent listing command
- [ ] `dev:php-version`, `dev:ext-version`, `dev:lib-version`
- [ ] Doc generation commands (`dev:gen-ext-docs`, `dev:gen-ext-dep-docs`, `dev:gen-lib-dep-docs`) — pending v3 doc design
---
## Source Patches (SourcePatcher → Artifact migration)
The following v2 `SourcePatcher` hooks are not yet migrated to v3 `src/Package/Artifact/` classes:
- [ ] Migrate `patchSQLSRVWin32` — removes `/sdl` compile flag to prevent Zend build failure on Windows
- [ ] Migrate `patchSQLSRVPhp85` — fixes `pdo_sqlsrv` directory layout for PHP 8.5
- [ ] Migrate `patchYamlWin32` — patches `config.w32` `_a.lib` detection logic for the `yaml` extension
- [ ] Migrate `patchImagickWith84` — applies PHP 8.4 compatibility patch for `imagick` based on version detection
---
## Extension Package Classes (Unix)
Extensions that had non-trivial v2 build logic and are missing a v3 `src/Package/Extension/` class:
- [x] `gettext` — macOS: fix `config.m4` bracket syntax for cross-version compatibility + append frameworks to linker flags (critical for macOS linking; this is a Unix-side gap, not Windows-only)
---
## Windows Extensions (Early Stage)
Windows extension support is still in early stage. The following extensions had Windows-specific configure args or patches in v2 and are pending v3 Windows implementation:
- [ ] `amqp` — Windows configure args
- [ ] `com_dotnet` — Windows-only extension
- [ ] `dom` — remove `dllmain.c` from `config.w32`
- [ ] `ev` — fix `PHP_EV_SHARED` in `config.w32`
- [ ] `gmssl` — add `CHECK_LIB("gmssl.lib")` to `config.w32`
- [ ] `intl` — fix `PHP_INTL_SHARED` in `config.w32`
- [ ] `lz4` — Windows configure args
- [ ] `mbregex` — Windows configure args
- [ ] `sqlsrv` / `pdo_sqlsrv` — complex conditional build logic (independent `sqlsrv` without `pdo_sqlsrv`)
- [ ] `xml` — remove `dllmain.c` from `config.w32`; handles `soap`, `xmlreader`, `xmlwriter`, `simplexml`
---
## Documentation
- [ ] Write v3 user documentation (currently zero v3 docs)

12
bin/spc-debug.ps1 Normal file
View File

@@ -0,0 +1,12 @@
$PHP_Exec = ".\runtime\php.exe"
if (-not(Test-Path $PHP_Exec)) {
$PHP_Exec = Get-Command php.exe -ErrorAction SilentlyContinue | Select-Object -ExpandProperty Definition
if (-not $PHP_Exec) {
Write-Host "Error: PHP not found, you need to install PHP on your system or use 'bin/setup-runtime'." -ForegroundColor Red
exit 1
}
}
& "$PHP_Exec" -d xdebug.mode=debug -d xdebug.client_host=127.0.0.1 -d xdebug.client_port=9003 -d xdebug.start_with_request=yes ("bin/spc") @args
exit $LASTEXITCODE

View File

@@ -0,0 +1,9 @@
ncurses:
binary: hosted
metadata:
license-files:
- COPYING
source:
type: filelist
url: 'https://ftp.gnu.org/pub/gnu/ncurses/'
regex: '/href="(?<file>ncurses-(?<version>[^"]+)\.tar\.gz)"/'

View File

@@ -134,6 +134,8 @@ OPENSSLDIR=""
; build target: macho or macho (possibly we could support macho-universal in the future)
; Currently we do not support universal and cross-compilation for macOS.
SPC_TARGET=native-macos
; Whether to use brew version of llvm or system version (valid options: 'system', 'brew', default: 'system')
SPC_USE_LLVM=system
; compiler environments (default value is defined by selected toolchain)
CC=${SPC_DEFAULT_CC}
CXX=${SPC_DEFAULT_CXX}

View File

@@ -252,6 +252,7 @@
"arg-type-unix": "enable-path",
"cpp-extension": true,
"lib-depends": [
"grpc",
"zlib",
"openssl",
"libcares"

View File

@@ -143,9 +143,7 @@
"zlib"
],
"lib-suggests": [
"libpng",
"bzip2",
"brotli"
"libpng"
]
},
"gettext": {
@@ -355,6 +353,9 @@
"static-libs-unix": [
"libaom.a"
],
"static-libs-windows": [
"aom.lib"
],
"cpp-library": true
},
"libargon2": {
@@ -493,7 +494,7 @@
"static-libs-windows": [
"libjpeg_a.lib"
],
"lib-suggests-windows": [
"lib-depends": [
"zlib"
]
},
@@ -862,6 +863,9 @@
},
"openssl": {
"source": "openssl",
"pkg-configs": [
"openssl"
],
"static-libs-unix": [
"libssl.a",
"libcrypto.a"
@@ -974,6 +978,11 @@
},
"unixodbc": {
"source": "unixodbc",
"pkg-configs": [
"odbc",
"odbccr",
"odbcinst"
],
"static-libs-unix": [
"libodbc.a",
"libodbccr.a",
@@ -1015,6 +1024,9 @@
},
"zlib": {
"source": "zlib",
"pkg-configs": [
"zlib"
],
"static-libs-unix": [
"libz.a"
],
@@ -1028,6 +1040,9 @@
},
"zstd": {
"source": "zstd",
"pkg-configs": [
"libzstd"
],
"static-libs-unix": [
"libzstd.a"
],

View File

@@ -16,6 +16,7 @@ ext-curl:
depends:
- curl
depends@windows:
- curl
- ext-zlib
- ext-openssl
php-extension:
@@ -342,6 +343,6 @@ ext-zlib:
- zlib
php-extension:
arg-type: custom
arg-type@windows: with
arg-type@windows: enable
build-with-php: true
build-shared: false

View File

@@ -10,6 +10,7 @@ ext-amqp:
depends:
- librabbitmq
depends@windows:
- librabbitmq
- ext-openssl
php-extension:
arg-type: '--with-amqp@shared_suffix@ --with-librabbitmq-dir=@build_root_path@'

View File

@@ -0,0 +1,15 @@
ext-imap:
type: php-extension
artifact:
source:
type: pecl
name: imap
metadata:
license-files: [LICENSE]
license: PHP-3.01
depends:
- imap
suggests:
- ext-openssl
php-extension:
arg-type: custom

View File

@@ -15,3 +15,7 @@ brotli:
- libbrotlicommon
- libbrotlidec
- libbrotlienc
static-libs@windows:
- brotlicommon.lib
- brotlidec.lib
- brotlienc.lib

View File

@@ -16,3 +16,6 @@ bzip2:
- bzlib.h
static-libs@unix:
- libbz2.a
static-libs@windows:
- libbz2.lib
- libbz2_a.lib

View File

@@ -11,6 +11,7 @@ freetype:
depends:
- zlib
suggests:
- libpng
- bzip2
- brotli
headers@unix:

View File

@@ -6,11 +6,20 @@ icu:
repo: unicode-org/icu
match: icu4c.+-src\.tgz
prefer-stable: true
binary:
windows-x86_64: { type: url, url: 'https://dl.static-php.dev/static-php-cli/deps/icu-static-windows-x64/icu-static-windows-x64.zip', extract: hosted }
metadata:
license-files: [LICENSE]
license-files: ['@/icu.txt']
license: ICU
headers@windows:
- unicode
lang: cpp
pkg-configs:
- icu-uc
- icu-i18n
- icu-io
static-libs@windows:
- icudt.lib
- icuin.lib
- icuio.lib
- icuuc.lib

View File

@@ -10,3 +10,5 @@ libaom:
lang: cpp
static-libs@unix:
- libaom.a
static-libs@windows:
- aom.lib

View File

@@ -16,3 +16,5 @@ libavif:
- libpng
static-libs@unix:
- libavif.a
static-libs@windows:
- avif.lib

View File

@@ -0,0 +1,12 @@
libffi-win:
type: library
artifact:
source:
type: git
rev: master
url: 'https://github.com/static-php/libffi-win.git'
metadata:
license-files: [LICENSE]
license: MIT
static-libs@windows:
- libffi.lib

View File

@@ -0,0 +1,13 @@
libiconv-win:
type: library
artifact:
source:
type: git
rev: master
url: 'https://github.com/static-php/libiconv-win.git'
metadata:
license-files: [source/COPYING]
license: GPL-3.0-or-later
static-libs@windows:
- libiconv.lib
- libiconv_a.lib

View File

@@ -7,6 +7,10 @@ libjpeg:
metadata:
license-files: [LICENSE.md]
license: IJG
suggests@windows:
- zlib
static-libs@unix:
- libjpeg.a
- libturbojpeg.a
static-libs@windows:
- libjpeg_a.lib

View File

@@ -14,3 +14,6 @@ libpng:
- zlib
static-libs@unix:
- libpng16.a
static-libs@windows:
- libpng16_static.lib
- libpng_a.lib

View File

@@ -12,3 +12,5 @@ librabbitmq:
- openssl
static-libs@unix:
- librabbitmq.a
static-libs@windows:
- rabbitmq.4.lib

View File

@@ -13,3 +13,5 @@ libsodium:
- libsodium
static-libs@unix:
- libsodium.a
static-libs@windows:
- libsodium.lib

View File

@@ -20,3 +20,5 @@ libssh2:
- libssh2
static-libs@unix:
- libssh2.a
static-libs@windows:
- libssh2.lib

View File

@@ -14,3 +14,8 @@ libwebp:
- libwebpdemux
- libwebpmux
- libsharpyuv
static-libs@windows:
- libwebp.lib
- libwebpdecoder.lib
- libwebpdemux.lib
- libsharpyuv.lib

View File

@@ -12,7 +12,13 @@ libxml2:
- libiconv
- zlib
- xz
depends@windows:
- zlib
- libiconv-win
headers:
- libxml2
pkg-configs:
- libxml-2.0
static-libs@windows:
- libxml2s.lib
- libxml2_a.lib

View File

@@ -13,3 +13,5 @@ libyaml:
- yaml.h
static-libs@unix:
- libyaml.a
static-libs@windows:
- yaml.lib

View File

@@ -8,9 +8,10 @@ libzip:
prefer-stable: true
metadata:
license-files: [LICENSE]
depends@unix:
license: BSD-3-Clause
depends:
- zlib
suggests@unix:
suggests:
- bzip2
- xz
- zstd
@@ -20,3 +21,5 @@ libzip:
- zipconf.h
static-libs@unix:
- libzip.a
static-libs@windows:
- libzip_a.lib

View File

@@ -1,12 +1,10 @@
ncurses:
type: library
artifact:
source:
type: filelist
url: 'https://ftp.gnu.org/pub/gnu/ncurses/'
regex: '/href="(?<file>ncurses-(?<version>[^"]+)\.tar\.gz)"/'
binary: hosted
metadata:
license-files: [COPYING]
artifact: ncurses
static-libs@unix:
- libncurses.a
ncursesw:
type: library
artifact: ncurses
static-libs@unix:
- libncursesw.a

View File

@@ -22,3 +22,5 @@ nghttp2:
- libnghttp2
static-libs@unix:
- libnghttp2.a
static-libs@windows:
- nghttp2.lib

View File

@@ -17,3 +17,5 @@ nghttp3:
- libnghttp3
static-libs@unix:
- libnghttp3.a
static-libs@windows:
- nghttp3.lib

View File

@@ -11,9 +11,6 @@ ngtcp2:
license: MIT
depends:
- openssl
suggests:
- nghttp3
- brotli
headers:
- ngtcp2
pkg-configs:
@@ -22,3 +19,5 @@ ngtcp2:
static-libs@unix:
- libngtcp2.a
- libngtcp2_crypto_ossl.a
static-libs@windows:
- ngtcp2.lib

View File

@@ -13,3 +13,6 @@ onig:
- oniguruma.h
static-libs@unix:
- libonig.a
static-libs@windows:
- onig.lib
- onig_a.lib

View File

@@ -16,8 +16,14 @@ openssl:
license: OpenSSL
depends:
- zlib
depends@windows:
- zlib
- jom
headers:
- openssl
static-libs@unix:
- libssl.a
- libcrypto.a
static-libs@windows:
- libssl.lib
- libcrypto.lib

View File

@@ -5,19 +5,25 @@ postgresql:
type: ghtagtar
repo: postgres/postgres
match: REL_18_\d+
binary:
windows-x86_64: { type: url, url: 'https://get.enterprisedb.com/postgresql/postgresql-16.8-1-windows-x64-binaries.zip', extract: { lib/libpq.lib: '{build_root_path}/lib/libpq.lib', lib/libpgport.lib: '{build_root_path}/lib/libpgport.lib', lib/libpgcommon.lib: '{build_root_path}/lib/libpgcommon.lib', include/libpq-fe.h: '{build_root_path}/include/libpq-fe.h', include/postgres_ext.h: '{build_root_path}/include/postgres_ext.h', include/pg_config_ext.h: '{build_root_path}/include/pg_config_ext.h', include/libpq/libpq-fs.h: '{build_root_path}/include/libpq/libpq-fs.h' } }
metadata:
license-files: [COPYRIGHT]
license-files: ['@/postgresql.txt']
license: PostgreSQL
depends:
depends@unix:
- libiconv
- libxml2
- openssl
- zlib
- libedit
suggests:
suggests@unix:
- icu
- libxslt
- ldap
- zstd
pkg-configs:
- libpq
static-libs@windows:
- libpq.lib
- libpgport.lib
- libpgcommon.lib

View File

@@ -0,0 +1,12 @@
pthreads4w:
type: library
artifact:
source:
type: git
rev: master
url: 'https://git.code.sf.net/p/pthreads4w/code'
metadata:
license-files: [LICENSE]
license: Apache-2.0
static-libs@windows:
- libpthreadVC3.lib

View File

@@ -10,3 +10,5 @@ qdbm:
license: 'GPL-2.0-only OR LGPL-2.1-only'
static-libs@unix:
- libqdbm.a
static-libs@windows:
- qdbm_a.lib

View File

@@ -10,3 +10,5 @@ sqlite:
- sqlite3ext.h
static-libs@unix:
- libsqlite3.a
static-libs@windows:
- libsqlite3_a.lib

View File

@@ -14,7 +14,13 @@ xz:
- libiconv
headers@unix:
- lzma
headers@windows:
- lzma
- lzma.h
pkg-configs:
- liblzma
static-libs@unix:
- liblzma.a
static-libs@windows:
- lzma.lib
- liblzma_a.lib

View File

@@ -14,3 +14,6 @@ zlib:
- zconf.h
static-libs@unix:
- libz.a
static-libs@windows:
- zlibstatic.lib
- zlib_a.lib

View File

@@ -17,3 +17,5 @@ zstd:
- libzstd
static-libs@unix:
- libzstd.a
static-libs@windows:
- zstd_static.lib

View File

@@ -1,5 +1,5 @@
curl:
type: library
type: target
artifact:
source:
type: ghrel
@@ -12,6 +12,10 @@ curl:
depends@unix:
- openssl
- zlib
depends@windows:
- zlib
- libssh2
- nghttp2
suggests@unix:
- libssh2
- brotli
@@ -23,11 +27,18 @@ curl:
- ldap
- idn2
- krb5
suggests@windows:
- brotli
- zstd
frameworks:
- CoreFoundation
- CoreServices
- SystemConfiguration
headers:
- curl
static-bins@unix:
- curl
static-libs@unix:
- libcurl.a
static-libs@windows:
- libcurl_a.lib

View File

@@ -2,5 +2,11 @@ go-xcaddy:
type: target
artifact:
binary: custom
env:
GOROOT: '{pkg_root_path}/go-xcaddy'
GOBIN: '{pkg_root_path}/go-xcaddy/bin'
GOPATH: '{pkg_root_path}/go-xcaddy/go'
path@unix:
- '{pkg_root_path}/go-xcaddy/bin'
static-bins:
- xcaddy

View File

@@ -0,0 +1,10 @@
htop:
type: target
artifact:
source:
type: ghrel
repo: htop-dev/htop
match: htop.+\.tar\.xz
prefer-stable: true
depends:
- ncursesw

View File

@@ -0,0 +1,7 @@
jom:
type: target
artifact:
binary:
windows-x86_64: { type: url, url: 'https://download.qt.io/official_releases/jom/jom.zip', extract: '{pkg_root_path}/jom' }
path@windows:
- '{pkg_root_path}\jom'

View File

@@ -0,0 +1,8 @@
protoc:
type: target
artifact:
binary:
linux-x86_64: { type: ghrel, repo: protocolbuffers/protobuf, match: 'protoc-([0-9.]+)-linux-x86_64\.zip', extract: '{pkg_root_path}/protoc' }
linux-aarch64: { type: ghrel, repo: protocolbuffers/protobuf, match: 'protoc-([0-9.]+)-linux-aarch_64\.zip', extract: '{pkg_root_path}/protoc' }
path:
- '{pkg_root_path}/protoc/bin'

View File

@@ -0,0 +1,6 @@
rust:
type: target
artifact:
binary: custom
path:
- '{pkg_root_path}/rust/bin'

View File

@@ -641,6 +641,7 @@
"libjpeg": {
"type": "ghtar",
"repo": "libjpeg-turbo/libjpeg-turbo",
"prefer-stable": true,
"license": {
"type": "file",
"path": "LICENSE.md"
@@ -1054,7 +1055,7 @@
},
"protobuf": {
"type": "url",
"url": "https://pecl.php.net/get/protobuf",
"url": "https://pecl.php.net/get/protobuf-5.34.1.tgz",
"path": "php-src/ext/protobuf",
"filename": "protobuf.tgz",
"license": {

View File

@@ -16,8 +16,10 @@ while also defining the extensions to compile.
1. Fork project.
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`.
3. Select `Run workflow`, fill in the PHP version you want to compile, the target type, and the list of static extensions. (comma separated, e.g. `bcmath,curl,mbstring`)
4. If you need shared extensions (for example `xdebug`), set `shared-extensions` (comma separated, e.g. `xdebug`).
5. If you need FrankenPHP, enable `build-frankenphp` and also enable `enable-zts`.
6. 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.

View File

@@ -14,7 +14,9 @@ Action 构建指的是直接使用 GitHub Action 进行编译。
1. Fork 本项目。
2. 进入项目的 Actions选择 CI 开头的 Workflow根据你需要的操作系统选择
3. 选择 `Run workflow`,填入你要编译的 PHP 版本、目标类型、扩展列表。(扩展列表使用英文逗号分割,例如 `bcmath,curl,mbstring`
4. 等待大约一段时间后,进入对应的任务中,获取 `Artifacts`
4. 如果需要共享扩展(例如 `xdebug`),请设置 `shared-extensions`(使用英文逗号分割,例如 `xdebug`
5. 如果需要 FrankenPHP请启用 `build-frankenphp`,同时也需要启用 `enable-zts`
6. 等待大约一段时间后,进入对应的任务中,获取 `Artifacts`
如果你选择了 `debug`,则会在构建时输出所有日志,包括编译的日志,以供排查错误。

View File

@@ -0,0 +1,85 @@
<?php
declare(strict_types=1);
namespace Package\Artifact;
use StaticPHP\Artifact\ArtifactDownloader;
use StaticPHP\Artifact\Downloader\DownloadResult;
use StaticPHP\Artifact\Downloader\Type\CheckUpdateResult;
use StaticPHP\Attribute\Artifact\AfterBinaryExtract;
use StaticPHP\Attribute\Artifact\CustomBinary;
use StaticPHP\Attribute\Artifact\CustomBinaryCheckUpdate;
use StaticPHP\Exception\DownloaderException;
use StaticPHP\Runtime\SystemTarget;
use StaticPHP\Util\System\LinuxUtil;
class rust
{
#[CustomBinary('rust', [
'linux-x86_64',
'linux-aarch64',
])]
public function downBinary(ArtifactDownloader $downloader): DownloadResult
{
// determine distro first
$distro = LinuxUtil::isMuslDist() ? 'musl' : 'gnu';
$arch = SystemTarget::getTargetArch();
// get latest rust version from link
$toml_config = default_shell()->executeCurl('https://static.rust-lang.org/dist/channel-rust-stable.toml', retries: $downloader->getRetry());
// parse toml by regex since we want to avoid adding a toml parser dependency just for this
$cnt = preg_match_all('/^version = "([^"]+)"$/m', $toml_config ?: '', $matches);
if (!$cnt) {
throw new DownloaderException('Failed to parse Rust version from channel config');
}
$versions = $matches[1];
// strip version num \d.\d.\d (some version number is like "x.x.x (abcdefg 1970-01-01)"
$versions = array_filter(array_map(fn ($v) => preg_match('/^(\d+\.\d+\.\d+)/', $v, $m) ? $m[1] : null, $versions));
usort($versions, 'version_compare');
$latest_version = end($versions);
if (!$latest_version) {
throw new DownloaderException('Could not determine latest Rust version');
}
// merge download link
$download_url = "https://static.rust-lang.org/dist/rust-{$latest_version}-{$arch}-unknown-linux-{$distro}.tar.xz";
$path = DOWNLOAD_PATH . DIRECTORY_SEPARATOR . basename($download_url);
default_shell()->executeCurlDownload($download_url, $path, retries: $downloader->getRetry());
return DownloadResult::archive(basename($path), ['url' => $download_url, 'version' => $latest_version], extract: PKG_ROOT_PATH . '/rust-install', verified: false, version: $latest_version);
}
#[CustomBinaryCheckUpdate('rust', [
'linux-x86_64',
'linux-aarch64',
])]
public function checkUpdateBinary(?string $old_version, ArtifactDownloader $downloader): CheckUpdateResult
{
$toml_config = default_shell()->executeCurl('https://static.rust-lang.org/dist/channel-rust-stable.toml', retries: $downloader->getRetry());
$cnt = preg_match_all('/^version = "([^"]+)"$/m', $toml_config ?: '', $matches);
if (!$cnt) {
throw new DownloaderException('Failed to parse Rust version from channel config');
}
$versions = array_filter(array_map(fn ($v) => preg_match('/^(\d+\.\d+\.\d+)/', $v, $m) ? $m[1] : null, $matches[1]));
usort($versions, 'version_compare');
$latest_version = end($versions);
if (!$latest_version) {
throw new DownloaderException('Could not determine latest Rust version');
}
return new CheckUpdateResult(
old: $old_version,
new: $latest_version,
needUpdate: $old_version === null || $latest_version !== $old_version,
);
}
#[AfterBinaryExtract('rust', [
'linux-x86_64',
'linux-aarch64',
])]
public function postExtractRust(string $target_path): void
{
$prefix = PKG_ROOT_PATH . '/rust';
shell()->exec("cd {$target_path} && ./install.sh --prefix={$prefix}");
}
}

View File

@@ -26,6 +26,9 @@ class zig
$index_json = default_shell()->executeCurl('https://ziglang.org/download/index.json', retries: $downloader->getRetry());
$index_json = json_decode($index_json ?: '', true);
$latest_version = null;
if ($index_json === null) {
throw new DownloaderException('Failed to fetch Zig version index');
}
foreach ($index_json as $version => $data) {
if ($version !== 'master') {
$latest_version = $version;

View File

@@ -0,0 +1,26 @@
<?php
declare(strict_types=1);
namespace Package\Extension;
use Package\Target\php;
use StaticPHP\Attribute\Package\BeforeStage;
use StaticPHP\Attribute\Package\Extension;
use StaticPHP\Attribute\PatchDescription;
#[Extension('curl')]
class curl
{
#[BeforeStage('php', [php::class, 'makeForWindows'], 'ext-curl')]
#[PatchDescription('Inject secur32.lib into SPC_EXTRA_LIBS for Schannel SSL support')]
public function addSecur32LibForWindows(): void
{
// curl on Windows uses Schannel (USE_WINDOWS_SSPI=ON, CURL_USE_SCHANNEL=ON),
// which requires secur32.lib for SSL/TLS functions (SslEncryptPackage, etc.).
$extra_libs = getenv('SPC_EXTRA_LIBS') ?: '';
if (!str_contains($extra_libs, 'secur32.lib')) {
putenv('SPC_EXTRA_LIBS=' . trim($extra_libs . ' secur32.lib'));
}
}
}

View File

@@ -0,0 +1,30 @@
<?php
declare(strict_types=1);
namespace Package\Extension;
use Package\Target\php;
use StaticPHP\Attribute\Package\BeforeStage;
use StaticPHP\Attribute\Package\Extension;
use StaticPHP\Attribute\PatchDescription;
use StaticPHP\Package\PackageInstaller;
use StaticPHP\Runtime\SystemTarget;
use StaticPHP\Util\FileSystem;
#[Extension('gettext')]
class gettext
{
#[BeforeStage('php', [php::class, 'buildconfForUnix'], 'ext-gettext')]
#[PatchDescription('Patch gettext extension config.m4 to fix library detection on macOS')]
public function patchBeforeBuildconf(PackageInstaller $installer): void
{
spc_skip_unless(SystemTarget::getTargetOS() === 'Darwin', 'gettext extension patch is only needed on macOS');
$php_src = $installer->getTargetPackage('php')->getSourceDir();
FileSystem::replaceFileStr(
"{$php_src}/ext/gettext/config.m4",
['AC_CHECK_LIB($GETTEXT_CHECK_IN_LIB', 'AC_CHECK_LIB([$GETTEXT_CHECK_IN_LIB'],
['AC_CHECK_LIB(intl', 'AC_CHECK_LIB([intl'] // new php versions use a bracket
);
}
}

View File

@@ -0,0 +1,55 @@
<?php
declare(strict_types=1);
namespace Package\Extension;
use Package\Target\php;
use StaticPHP\Attribute\Package\BeforeStage;
use StaticPHP\Attribute\Package\CustomPhpConfigureArg;
use StaticPHP\Attribute\Package\Extension;
use StaticPHP\Attribute\Package\Validate;
use StaticPHP\Exception\WrongUsageException;
use StaticPHP\Package\PackageBuilder;
use StaticPHP\Package\PackageInstaller;
use StaticPHP\Package\PhpExtensionPackage;
use StaticPHP\Util\FileSystem;
#[Extension('imap')]
class imap extends PhpExtensionPackage
{
#[Validate]
public function validate(PackageBuilder $builder): void
{
if ($builder->getOption('enable-zts')) {
throw new WrongUsageException('ext-imap is not thread safe, do not build it with ZTS builds');
}
}
#[BeforeStage('php', [php::class, 'buildconfForUnix'], 'ext-imap')]
public function patchBeforeBuildconf(PackageInstaller $installer): void
{
if ($installer->getLibraryPackage('openssl')) {
// sometimes imap with openssl does not contain zlib (required by openssl)
// we need to add it manually
FileSystem::replaceFileStr("{$this->getSourceDir()}/config.m4", 'TST_LIBS="$DLIBS $IMAP_SHARED_LIBADD"', 'TST_LIBS="$DLIBS $IMAP_SHARED_LIBADD -lz"');
}
// c-client is built with PASSWDTYPE=nul so libcrypt is not referenced.
FileSystem::replaceFileStr(
"{$this->getSourceDir()}/config.m4",
" PHP_CHECK_LIBRARY(crypt, crypt,\n [\n PHP_ADD_LIBRARY(crypt,, IMAP_SHARED_LIBADD)\n AC_DEFINE(HAVE_LIBCRYPT,1,[ ])\n ])",
' dnl Skipped: crypt check not needed (c-client built with PASSWDTYPE=nul)'
);
}
#[CustomPhpConfigureArg('Darwin')]
#[CustomPhpConfigureArg('Linux')]
public function getUnixConfigureArg(PackageInstaller $installer, PackageBuilder $builder): string
{
$arg = "--with-imap={$builder->getBuildRootPath()}";
if (($ssl = $installer->getLibraryPackage('openssl')) !== null) {
$arg .= " --with-imap-ssl={$ssl->getBuildRootPath()}";
}
return $arg;
}
}

View File

@@ -8,11 +8,19 @@ use StaticPHP\Attribute\Package\BuildFor;
use StaticPHP\Attribute\Package\Library;
use StaticPHP\Package\LibraryPackage;
use StaticPHP\Runtime\Executor\UnixCMakeExecutor;
use StaticPHP\Runtime\Executor\WindowsCMakeExecutor;
use StaticPHP\Util\FileSystem;
#[Library('brotli')]
class brotli
{
#[BuildFor('Windows')]
public function buildWin(LibraryPackage $package): void
{
WindowsCMakeExecutor::create($package)->build();
// FileSystem::copy("{$package->getLibDir()}\\onig.lib", "{$package->getLibDir()}\\onig_a.lib");
}
#[BuildFor('Linux')]
#[BuildFor('Darwin')]
public function build(LibraryPackage $lib): void

View File

@@ -20,6 +20,17 @@ class bzip2
FileSystem::replaceFileStr($lib->getSourceDir() . '/Makefile', 'CFLAGS=-Wall', 'CFLAGS=-fPIC -Wall');
}
#[BuildFor('Windows')]
public function buildWin(LibraryPackage $package): void
{
cmd()->cd($package->getSourceDir())
->exec('nmake /nologo /f Makefile.msc CFLAGS="-DWIN32 -MT -Ox -D_FILE_OFFSET_BITS=64 -nologo" clean')
->exec('nmake /nologo /f Makefile.msc CFLAGS="-DWIN32 -MT -Ox -D_FILE_OFFSET_BITS=64 -nologo" lib');
FileSystem::copy("{$package->getSourceDir()}\\libbz2.lib", "{$package->getLibDir()}\\libbz2.lib");
FileSystem::copy("{$package->getSourceDir()}\\libbz2.lib", "{$package->getLibDir()}\\libbz2_a.lib");
FileSystem::copy("{$package->getSourceDir()}\\bzlib.h", "{$package->getIncludeDir()}\\bzlib.h");
}
#[BuildFor('Linux')]
#[BuildFor('Darwin')]
public function build(LibraryPackage $lib, PackageBuilder $builder): void

View File

@@ -8,6 +8,7 @@ use StaticPHP\Attribute\Package\BuildFor;
use StaticPHP\Attribute\Package\Library;
use StaticPHP\Package\LibraryPackage;
use StaticPHP\Runtime\Executor\UnixCMakeExecutor;
use StaticPHP\Runtime\Executor\WindowsCMakeExecutor;
use StaticPHP\Util\FileSystem;
#[Library('freetype')]
@@ -33,4 +34,18 @@ class freetype
$lib->patchPkgconfPrefix(['freetype2.pc']);
FileSystem::replaceFileStr("{$lib->getBuildRootPath()}/lib/pkgconfig/freetype2.pc", ' -L/lib ', " -L{$lib->getBuildRootPath()}/lib ");
}
#[BuildFor('Windows')]
public function buildWin(LibraryPackage $lib): void
{
WindowsCMakeExecutor::create($lib)
->optionalPackage('libpng', ...cmake_boolean_args('FT_DISABLE_PNG', true))
->optionalPackage('bzip2', ...cmake_boolean_args('FT_DISABLE_BZIP2', true))
->optionalPackage('brotli', ...cmake_boolean_args('FT_DISABLE_BROTLI', true))
->addConfigureArgs('-DFT_DISABLE_HARFBUZZ=ON')
->build();
// freetype.lib to libfreetype_a.lib
FileSystem::copy("{$lib->getLibDir()}\\freetype.lib", "{$lib->getLibDir()}\\libfreetype_a.lib");
}
}

View File

@@ -8,6 +8,8 @@ use StaticPHP\Attribute\Package\BuildFor;
use StaticPHP\Attribute\Package\Library;
use StaticPHP\Package\LibraryPackage;
use StaticPHP\Runtime\Executor\UnixCMakeExecutor;
use StaticPHP\Runtime\Executor\WindowsCMakeExecutor;
use StaticPHP\Util\FileSystem;
#[Library('gmssl')]
class gmssl
@@ -18,4 +20,35 @@ class gmssl
{
UnixCMakeExecutor::create($lib)->build();
}
#[BuildFor('Windows')]
public function buildWin(LibraryPackage $lib): void
{
$buildDir = "{$lib->getSourceDir()}\\builddir";
// GmSSL requires NMake Makefiles generator on Windows
WindowsCMakeExecutor::create($lib)
->setBuildDir($buildDir)
->setCustomDefaultArgs(
'-G "NMake Makefiles"',
'-DWIN32=ON',
'-DBUILD_SHARED_LIBS=OFF',
'-DCMAKE_BUILD_TYPE=Release',
'-DCMAKE_C_FLAGS_RELEASE="/MT /O2 /Ob2 /DNDEBUG"',
'-DCMAKE_CXX_FLAGS_RELEASE="/MT /O2 /Ob2 /DNDEBUG"',
'-DCMAKE_INSTALL_PREFIX=' . escapeshellarg($lib->getBuildRootPath()),
'-B ' . escapeshellarg($buildDir),
)
->toStep(1)
->build();
// fix cmake_install.cmake install prefix (GmSSL overrides it internally)
$installCmake = "{$buildDir}\\cmake_install.cmake";
FileSystem::writeFile(
$installCmake,
'set(CMAKE_INSTALL_PREFIX "' . str_replace('\\', '/', $lib->getBuildRootPath()) . '")' . PHP_EOL . FileSystem::readFile($installCmake)
);
cmd()->cd($buildDir)->exec('nmake install XCFLAGS=/MT');
}
}

View File

@@ -8,6 +8,7 @@ use StaticPHP\Attribute\Package\BuildFor;
use StaticPHP\Attribute\Package\Library;
use StaticPHP\Package\LibraryPackage;
use StaticPHP\Runtime\Executor\UnixAutoconfExecutor;
use StaticPHP\Util\FileSystem;
#[Library('idn2')]
class idn2
@@ -29,5 +30,10 @@ class idn2
->make();
$lib->patchPkgconfPrefix(['libidn2.pc']);
$lib->patchLaDependencyPrefix();
// libunistring is in Libs.private of libidn2.pc, but CMake's pkg_check_modules
// does not follow Libs.private for static linking. Promote it to Libs so that
// consumers linking static binaries (e.g. the curl exe) can resolve _uc_* / _u32_* symbols.
$libidn2_pc = BUILD_ROOT_PATH . '/lib/pkgconfig/libidn2.pc';
FileSystem::replaceFileStr($libidn2_pc, 'Libs: -L${libdir} -lidn2', 'Libs: -L${libdir} -lidn2 -lunistring');
}
}

View File

@@ -4,8 +4,6 @@ declare(strict_types=1);
namespace Package\Library;
use Package\Target\php;
use StaticPHP\Attribute\Package\AfterStage;
use StaticPHP\Attribute\Package\BuildFor;
use StaticPHP\Attribute\Package\Library;
use StaticPHP\Attribute\Package\PatchBeforeBuild;
@@ -19,15 +17,6 @@ use StaticPHP\Util\SourcePatcher;
#[Library('imap')]
class imap
{
#[AfterStage('php', [php::class, 'patchUnixEmbedScripts'], 'imap')]
#[PatchDescription('Fix missing -lcrypt in php-config libs on glibc systems')]
public function afterPatchScripts(): void
{
if (SystemTarget::getLibc() === 'glibc') {
FileSystem::replaceFileRegex(BUILD_BIN_PATH . '/php-config', '/^libs="(.*)"$/m', 'libs="$1 -lcrypt"');
}
}
#[PatchBeforeBuild]
#[PatchDescription('Patch imap build system for Linux and macOS compatibility')]
public function patchBeforeBuild(LibraryPackage $lib): void
@@ -66,14 +55,24 @@ class imap
}
$libcVer = SystemTarget::getLibcVersion();
$extraLibs = $libcVer && version_compare($libcVer, '2.17', '<=') ? 'EXTRALDFLAGS="-ldl -lrt -lpthread"' : '';
shell()->cd($lib->getSourceDir())
->exec('make clean')
->exec('touch ip6')
->exec('chmod +x tools/an')
->exec('chmod +x tools/ua')
->exec('chmod +x src/osdep/unix/drivers')
->exec('chmod +x src/osdep/unix/mkauths')
->exec("yes | make slx {$ssl_options} EXTRACFLAGS='-fPIC -Wno-implicit-function-declaration -Wno-incompatible-function-pointer-types' {$extraLibs}");
try {
shell()->cd($lib->getSourceDir())
->exec('make clean')
->exec('touch ip6')
->exec('chmod +x tools/an')
->exec('chmod +x tools/ua')
->exec('chmod +x src/osdep/unix/drivers')
->exec('chmod +x src/osdep/unix/mkauths')
// PASSWDTYPE=nul avoids any crypt() symbol reference in c-client.a;
// zig-cc 0.15+ uses paths_first strategy and cannot find libcrypt outside of buildroot.
->exec("yes | make slx {$ssl_options} PASSWDTYPE=nul EXTRACFLAGS='-fPIC -Wno-implicit-function-declaration -Wno-incompatible-function-pointer-types' {$extraLibs}");
} catch (\Throwable $e) {
// slx target also builds bundled tools (mtest, etc.) which may fail to link -lcrypt dynamically
// (e.g. with zig-cc). We only need c-client.a, so tolerate the failure if it was built.
if (!file_exists("{$lib->getSourceDir()}/c-client/c-client.a")) {
throw $e;
}
}
try {
shell()
->exec("cp -rf {$lib->getSourceDir()}/c-client/c-client.a {$lib->getLibDir()}/libc-client.a")
@@ -94,16 +93,24 @@ class imap
$ssl_options = 'SSLTYPE=none';
}
$out = shell()->execWithResult('echo "-include $(xcrun --show-sdk-path)/usr/include/poll.h -include $(xcrun --show-sdk-path)/usr/include/time.h -include $(xcrun --show-sdk-path)/usr/include/utime.h"')[1][0];
shell()->cd($lib->getSourceDir())
->exec('make clean')
->exec('touch ip6')
->exec('chmod +x tools/an')
->exec('chmod +x tools/ua')
->exec('chmod +x src/osdep/unix/drivers')
->exec('chmod +x src/osdep/unix/mkauths')
->exec(
"echo y | make osx {$ssl_options} EXTRACFLAGS='-Wno-implicit-function-declaration -Wno-incompatible-function-pointer-types {$out}'"
);
try {
shell()->cd($lib->getSourceDir())
->exec('make clean')
->exec('touch ip6')
->exec('chmod +x tools/an')
->exec('chmod +x tools/ua')
->exec('chmod +x src/osdep/unix/drivers')
->exec('chmod +x src/osdep/unix/mkauths')
->exec(
"echo y | make osx {$ssl_options} EXTRACFLAGS='-Wno-implicit-function-declaration -Wno-incompatible-function-pointer-types {$out}'"
);
} catch (\Throwable $e) {
// osx target also builds bundled tools (mtest, etc.) which may fail to link.
// We only need c-client.a, so tolerate the failure if it was built.
if (!file_exists("{$lib->getSourceDir()}/c-client/c-client.a")) {
throw $e;
}
}
try {
shell()
->exec("cp -rf {$lib->getSourceDir()}/c-client/c-client.a {$lib->getLibDir()}/libc-client.a")

View File

@@ -10,6 +10,7 @@ use StaticPHP\Package\LibraryPackage;
use StaticPHP\Package\PackageInstaller;
use StaticPHP\Runtime\Executor\UnixAutoconfExecutor;
use StaticPHP\Runtime\SystemTarget;
use StaticPHP\Util\FileSystem;
use StaticPHP\Util\SPCConfigUtil;
#[Library('krb5')]
@@ -59,5 +60,11 @@ class krb5
'mit-krb5.pc',
'gssrpc.pc',
]);
// libkrb5support is in Libs.private of mit-krb5.pc, but CMake's pkg_check_modules
// does not follow Libs.private for static linking. Promote it to Libs so that
// consumers linking static binaries (e.g. the curl exe) can resolve _k5_* symbols.
$mit_krb5_pc = BUILD_ROOT_PATH . '/lib/pkgconfig/mit-krb5.pc';
FileSystem::replaceFileStr($mit_krb5_pc, 'Libs.private: -lkrb5support', 'Libs.private:');
FileSystem::replaceFileStr($mit_krb5_pc, '-lcom_err', '-lcom_err -lkrb5support');
}
}

View File

@@ -8,12 +8,28 @@ use StaticPHP\Attribute\Package\BuildFor;
use StaticPHP\Attribute\Package\Library;
use StaticPHP\Package\LibraryPackage;
use StaticPHP\Runtime\Executor\UnixCMakeExecutor;
use StaticPHP\Runtime\Executor\WindowsCMakeExecutor;
use StaticPHP\Toolchain\Interface\ToolchainInterface;
use StaticPHP\Toolchain\ZigToolchain;
#[Library('libaom')]
class libaom extends LibraryPackage
{
#[BuildFor('Windows')]
public function buildWin(): void
{
WindowsCMakeExecutor::create($this)
->setBuildDir("{$this->getSourceDir()}/builddir")
->addConfigureArgs(
'-DAOM_TARGET_CPU=generic',
'-DENABLE_TESTS=OFF',
'-DENABLE_EXAMPLES=OFF',
'-DENABLE_TOOLS=OFF',
'-DENABLE_DOCS=OFF',
)
->build();
}
#[BuildFor('Darwin')]
#[BuildFor('Linux')]
public function buildUnix(ToolchainInterface $toolchain): void

View File

@@ -6,12 +6,25 @@ namespace Package\Library;
use StaticPHP\Attribute\Package\BuildFor;
use StaticPHP\Attribute\Package\Library;
use StaticPHP\Attribute\Package\PatchBeforeBuild;
use StaticPHP\Package\LibraryPackage;
use StaticPHP\Runtime\Executor\UnixCMakeExecutor;
use StaticPHP\Runtime\Executor\WindowsCMakeExecutor;
use StaticPHP\Runtime\SystemTarget;
use StaticPHP\Util\FileSystem;
#[Library('libavif')]
class libavif
{
#[PatchBeforeBuild]
public function patchBeforeBuild(LibraryPackage $lib): void
{
// workaround for libavif 1.2.0 bug: MSVC does not support empty initializer list
if (SystemTarget::getTargetOS() === 'Windows') {
FileSystem::replaceFileStr($lib->getSourceDir() . '/src/read.c', 'avifFileType ftyp = {};', 'avifFileType ftyp = { 0 };');
}
}
#[BuildFor('Darwin')]
#[BuildFor('Linux')]
public function buildUnix(LibraryPackage $lib): void
@@ -27,4 +40,17 @@ class libavif
// patch pkgconfig
$lib->patchPkgconfPrefix(['libavif.pc']);
}
#[BuildFor('Windows')]
public function buildWin(LibraryPackage $lib): void
{
WindowsCMakeExecutor::create($lib)
->addConfigureArgs(
'-DAVIF_BUILD_APPS=OFF',
'-DAVIF_BUILD_TESTS=OFF',
'-DAVIF_LIBYUV=OFF',
'-DAVIF_ENABLE_GTEST=OFF',
)
->build();
}
}

View File

@@ -0,0 +1,47 @@
<?php
declare(strict_types=1);
namespace Package\Library;
use StaticPHP\Attribute\Package\BuildFor;
use StaticPHP\Attribute\Package\Library;
use StaticPHP\Attribute\Package\Validate;
use StaticPHP\DI\ApplicationContext;
use StaticPHP\Exception\EnvironmentException;
use StaticPHP\Package\LibraryPackage;
use StaticPHP\Util\FileSystem;
use StaticPHP\Util\System\WindowsUtil;
#[Library('libffi-win')]
class libffi_win
{
#[Validate]
public function validate(): void
{
$ver = WindowsUtil::findVisualStudio();
$vs_ver_dir = match ($ver['major_version']) {
'17' => '\win32\vs17_x64',
'16' => '\win32\vs16_x64',
default => throw new EnvironmentException("Current VS version {$ver['major_version']} is not supported!"),
};
ApplicationContext::set('libffi_win_vs_ver_dir', $vs_ver_dir);
}
#[BuildFor('Windows')]
public function build(LibraryPackage $lib): void
{
$vs_ver_dir = ApplicationContext::get('libffi_win_vs_ver_dir');
cmd()->cd("{$lib->getSourceDir()}{$vs_ver_dir}")
->exec('msbuild libffi-msvc.sln /t:Rebuild /p:Configuration=Release /p:Platform=x64');
FileSystem::createDir($lib->getLibDir());
FileSystem::createDir($lib->getIncludeDir());
FileSystem::copy("{$lib->getSourceDir()}{$vs_ver_dir}\\x64\\Release\\libffi.lib", "{$lib->getLibDir()}\\libffi.lib");
FileSystem::copy("{$lib->getSourceDir()}{$vs_ver_dir}\\x64\\Release\\libffi.pdb", "{$lib->getLibDir()}\\libffi.pdb");
FileSystem::copy("{$lib->getSourceDir()}\\include\\ffi.h", "{$lib->getIncludeDir()}\\ffi.h");
FileSystem::replaceFileStr("{$lib->getIncludeDir()}\\ffi.h", '#define LIBFFI_H', "#define LIBFFI_H\n#define FFI_BUILDING");
FileSystem::copy("{$lib->getSourceDir()}\\src\\x86\\ffitarget.h", "{$lib->getIncludeDir()}\\ffitarget.h");
FileSystem::copy("{$lib->getSourceDir()}\\fficonfig.h", "{$lib->getIncludeDir()}\\fficonfig.h");
}
}

View File

@@ -0,0 +1,43 @@
<?php
declare(strict_types=1);
namespace Package\Library;
use StaticPHP\Attribute\Package\BuildFor;
use StaticPHP\Attribute\Package\Library;
use StaticPHP\Attribute\Package\Validate;
use StaticPHP\DI\ApplicationContext;
use StaticPHP\Exception\EnvironmentException;
use StaticPHP\Package\LibraryPackage;
use StaticPHP\Util\FileSystem;
use StaticPHP\Util\System\WindowsUtil;
#[Library('libiconv-win')]
class libiconv_win
{
#[Validate]
public function validate(): void
{
$ver = WindowsUtil::findVisualStudio();
$vs_ver_dir = match ($ver['major_version']) {
'17' => '\MSVC17',
'16' => '\MSVC16',
default => throw new EnvironmentException("Current VS version {$ver['major_version']} is not supported yet!"),
};
ApplicationContext::set('vs_ver_dir', $vs_ver_dir);
}
#[BuildFor('Windows')]
public function build(LibraryPackage $lib): void
{
$vs_ver_dir = ApplicationContext::get('vs_ver_dir');
cmd()->cd("{$lib->getSourceDir()}{$vs_ver_dir}")
->exec('msbuild libiconv.sln /t:Rebuild /p:Configuration=Release /p:Platform=x64');
FileSystem::createDir($lib->getLibDir());
FileSystem::createDir($lib->getIncludeDir());
FileSystem::copy("{$lib->getSourceDir()}{$vs_ver_dir}\\x64\\lib\\libiconv.lib", "{$lib->getLibDir()}\\libiconv.lib");
FileSystem::copy("{$lib->getSourceDir()}{$vs_ver_dir}\\x64\\lib\\libiconv_a.lib", "{$lib->getLibDir()}\\libiconv_a.lib");
FileSystem::copy("{$lib->getSourceDir()}\\source\\include\\iconv.h", "{$lib->getIncludeDir()}\\iconv.h");
}
}

View File

@@ -8,6 +8,8 @@ use StaticPHP\Attribute\Package\BuildFor;
use StaticPHP\Attribute\Package\Library;
use StaticPHP\Package\LibraryPackage;
use StaticPHP\Runtime\Executor\UnixCMakeExecutor;
use StaticPHP\Runtime\Executor\WindowsCMakeExecutor;
use StaticPHP\Util\FileSystem;
#[Library('libjpeg')]
class libjpeg
@@ -25,4 +27,20 @@ class libjpeg
// patch pkgconfig
$lib->patchPkgconfPrefix(['libjpeg.pc', 'libturbojpeg.pc']);
}
#[BuildFor('Windows')]
public function buildWin(LibraryPackage $lib): void
{
WindowsCMakeExecutor::create($lib)
->addConfigureArgs(
'-DENABLE_SHARED=OFF',
'-DENABLE_STATIC=ON',
'-DBUILD_TESTING=OFF',
'-DWITH_JAVA=OFF',
'-DWITH_CRT_DLL=OFF',
)
->optionalPackage('zlib', '-DENABLE_ZLIB_COMPRESSION=ON', '-DENABLE_ZLIB_COMPRESSION=OFF')
->build();
FileSystem::copy("{$lib->getLibDir()}\\jpeg-static.lib", "{$lib->getLibDir()}\\libjpeg_a.lib");
}
}

View File

@@ -8,6 +8,8 @@ use StaticPHP\Attribute\Package\BuildFor;
use StaticPHP\Attribute\Package\Library;
use StaticPHP\Package\LibraryPackage;
use StaticPHP\Runtime\Executor\UnixAutoconfExecutor;
use StaticPHP\Runtime\Executor\WindowsCMakeExecutor;
use StaticPHP\Util\FileSystem;
#[Library('libpng')]
class libpng
@@ -44,4 +46,21 @@ class libpng
$lib->patchPkgconfPrefix(['libpng16.pc']);
$lib->patchLaDependencyPrefix();
}
#[BuildFor('Windows')]
public function buildWin(LibraryPackage $lib): void
{
WindowsCMakeExecutor::create($lib)
->addConfigureArgs(
'-DSKIP_INSTALL_PROGRAM=ON',
'-DSKIP_INSTALL_FILES=ON',
'-DPNG_STATIC=ON',
'-DPNG_SHARED=OFF',
'-DPNG_TESTS=OFF',
)
->build();
// libpng16_static.lib to libpng_a.lib
FileSystem::copy("{$lib->getLibDir()}\\libpng16_static.lib", "{$lib->getLibDir()}\\libpng_a.lib");
}
}

View File

@@ -8,6 +8,7 @@ use StaticPHP\Attribute\Package\BuildFor;
use StaticPHP\Attribute\Package\Library;
use StaticPHP\Package\LibraryPackage;
use StaticPHP\Runtime\Executor\UnixCMakeExecutor;
use StaticPHP\Runtime\Executor\WindowsCMakeExecutor;
#[Library('librabbitmq')]
class librabbitmq extends LibraryPackage
@@ -18,4 +19,11 @@ class librabbitmq extends LibraryPackage
{
UnixCMakeExecutor::create($this)->addConfigureArgs('-DBUILD_STATIC_LIBS=ON')->build();
}
#[BuildFor('Windows')]
public function buildWin(): void
{
WindowsCMakeExecutor::create($this)->build();
rename("{$this->getLibDir()}\\librabbitmq.4.lib", "{$this->getLibDir()}\\rabbitmq.4.lib");
}
}

View File

@@ -6,12 +6,27 @@ namespace Package\Library;
use StaticPHP\Attribute\Package\BuildFor;
use StaticPHP\Attribute\Package\Library;
use StaticPHP\Attribute\Package\PatchBeforeBuild;
use StaticPHP\Attribute\PatchDescription;
use StaticPHP\Exception\BuildFailureException;
use StaticPHP\Exception\EnvironmentException;
use StaticPHP\Package\LibraryPackage;
use StaticPHP\Runtime\Executor\UnixAutoconfExecutor;
use StaticPHP\Runtime\SystemTarget;
use StaticPHP\Util\FileSystem;
use StaticPHP\Util\System\WindowsUtil;
#[Library('libsodium')]
class libsodium
{
#[PatchBeforeBuild]
#[PatchDescription('Replace SODIUM_STATIC define guard with unconditional #if 1 for MSVC static linking')]
public function patchBeforeBuild(LibraryPackage $lib): void
{
spc_skip_if(SystemTarget::getTargetOS() !== 'Windows', 'This patch is only for Windows builds.');
FileSystem::replaceFileStr($lib->getSourceDir() . '\src\libsodium\include\sodium\export.h', '#ifdef SODIUM_STATIC', '#if 1');
}
#[BuildFor('Linux')]
#[BuildFor('Darwin')]
public function build(LibraryPackage $lib): void
@@ -21,4 +36,39 @@ class libsodium
// Patch pkg-config file
$lib->patchPkgconfPrefix(['libsodium.pc'], PKGCONF_PATCH_PREFIX);
}
#[BuildFor('Windows')]
public function buildWin(LibraryPackage $lib): void
{
$ver = WindowsUtil::findVisualStudio();
$vs_ver_dir = match ($ver['major_version']) {
'17' => '\vs2022',
'16' => '\vs2019',
default => throw new EnvironmentException("Current VS version {$ver['major_version']} is not supported yet!"),
};
cmd()->cd("{$lib->getSourceDir()}\\builds\\msvc{$vs_ver_dir}")
->exec('msbuild libsodium.sln /t:Rebuild /p:Configuration=StaticRelease /p:Platform=x64 /p:PreprocessorDefinitions="SODIUM_STATIC=1"');
FileSystem::createDir($lib->getLibDir());
FileSystem::createDir($lib->getIncludeDir());
// copy include
FileSystem::copyDir("{$lib->getSourceDir()}\\src\\libsodium\\include\\sodium", "{$lib->getIncludeDir()}\\sodium");
FileSystem::copy("{$lib->getSourceDir()}\\src\\libsodium\\include\\sodium.h", "{$lib->getIncludeDir()}\\sodium.h");
// copy lib
$ls = FileSystem::scanDirFiles("{$lib->getSourceDir()}\\bin");
$find = false;
foreach ($ls as $file) {
if (str_ends_with($file, 'libsodium.lib')) {
FileSystem::copy($file, "{$lib->getLibDir()}\\libsodium.lib");
$find = true;
}
if (str_ends_with($file, 'libsodium.pdb')) {
FileSystem::copy($file, "{$lib->getLibDir()}\\libsodium.pdb");
}
}
if (!$find) {
throw new BuildFailureException("Build libsodium success, but cannot find libsodium.lib in {$lib->getSourceDir()}\\bin .");
}
}
}

View File

@@ -8,10 +8,22 @@ use StaticPHP\Attribute\Package\BuildFor;
use StaticPHP\Attribute\Package\Library;
use StaticPHP\Package\LibraryPackage;
use StaticPHP\Runtime\Executor\UnixCMakeExecutor;
use StaticPHP\Runtime\Executor\WindowsCMakeExecutor;
#[Library('libssh2')]
class libssh2
{
#[BuildFor('Windows')]
public function buildWin(LibraryPackage $lib): void
{
WindowsCMakeExecutor::create($lib)
->addConfigureArgs(
'-DENABLE_ZLIB_COMPRESSION=ON',
'-DBUILD_TESTING=OFF'
)
->build();
}
#[BuildFor('Linux')]
#[BuildFor('Darwin')]
public function build(LibraryPackage $lib): void

View File

@@ -8,6 +8,7 @@ use StaticPHP\Attribute\Package\BuildFor;
use StaticPHP\Attribute\Package\Library;
use StaticPHP\Package\LibraryPackage;
use StaticPHP\Runtime\Executor\UnixCMakeExecutor;
use StaticPHP\Runtime\Executor\WindowsCMakeExecutor;
#[Library('libwebp')]
class libwebp extends LibraryPackage
@@ -41,4 +42,23 @@ int main() { return _mm256_cvtsi256_si32(_mm256_setzero_si256()); }';
$this->patchPkgconfPrefix(patch_option: PKGCONF_PATCH_PREFIX | PKGCONF_PATCH_LIBDIR);
$this->patchPkgconfPrefix(['libsharpyuv.pc'], PKGCONF_PATCH_CUSTOM, ['/^includedir=.*$/m', 'includedir=${prefix}/include/webp']);
}
#[BuildFor('Windows')]
public function buildWin(): void
{
WindowsCMakeExecutor::create($this)
->addConfigureArgs(
'-DWEBP_BUILD_EXTRAS=OFF',
'-DWEBP_BUILD_ANIM_UTILS=OFF',
'-DWEBP_BUILD_CWEBP=OFF',
'-DWEBP_BUILD_DWEBP=OFF',
'-DWEBP_BUILD_GIF2WEBP=OFF',
'-DWEBP_BUILD_IMG2WEBP=OFF',
'-DWEBP_BUILD_VWEBP=OFF',
'-DWEBP_BUILD_WEBPINFO=OFF',
'-DWEBP_BUILD_WEBPMUX=OFF',
'-DWEBP_BUILD_FUZZTEST=OFF',
)
->build();
}
}

View File

@@ -7,12 +7,33 @@ namespace Package\Library;
use StaticPHP\Attribute\Package\BuildFor;
use StaticPHP\Attribute\Package\Library;
use StaticPHP\Package\LibraryPackage;
use StaticPHP\Package\PackageInstaller;
use StaticPHP\Runtime\Executor\UnixCMakeExecutor;
use StaticPHP\Runtime\Executor\WindowsCMakeExecutor;
use StaticPHP\Util\FileSystem;
#[Library('libxml2')]
class libxml2
{
#[BuildFor('Windows')]
public function buildForWindows(LibraryPackage $lib, PackageInstaller $installer): void
{
$iconv_win = $installer->getLibraryPackage('libiconv-win');
WindowsCMakeExecutor::create($lib)
->addConfigureArgs(
'-DLIBXML2_WITH_ICONV=ON',
"-DIconv_LIBRARY={$iconv_win->getLibDir()}",
"-DIconv_INCLUDE_DIR={$iconv_win->getIncludeDir()}",
'-DLIBXML2_WITH_ZLIB=ON',
'-DLIBXML2_WITH_PYTHON=OFF',
'-DLIBXML2_WITH_LZMA=OFF',
'-DLIBXML2_WITH_PROGRAMS=OFF',
'-DLIBXML2_WITH_TESTS=OFF',
)
->build();
FileSystem::copy("{$lib->getLibDir()}\\libxml2s.lib", "{$lib->getLibDir()}\\libxml2_a.lib");
}
#[BuildFor('Linux')]
public function buildForLinux(LibraryPackage $lib): void
{

View File

@@ -6,16 +6,44 @@ namespace Package\Library;
use StaticPHP\Attribute\Package\BuildFor;
use StaticPHP\Attribute\Package\Library;
use StaticPHP\Attribute\Package\PatchBeforeBuild;
use StaticPHP\Attribute\PatchDescription;
use StaticPHP\Package\LibraryPackage;
use StaticPHP\Runtime\Executor\UnixAutoconfExecutor;
use StaticPHP\Runtime\Executor\WindowsCMakeExecutor;
use StaticPHP\Runtime\SystemTarget;
use StaticPHP\Util\FileSystem;
#[Library('libyaml')]
class libyaml
{
#[PatchBeforeBuild]
#[PatchDescription('Copy missing cmake helper files required for MSVC build (not included in libyaml git source)')]
public function patchBeforeBuild(LibraryPackage $lib): void
{
spc_skip_if(SystemTarget::getTargetOS() !== 'Windows', 'This patch is only for Windows builds.');
// check missing files: cmake\config.h.in and .\YamlConfig.cmake.in
if (!file_exists($lib->getSourceDir() . '\cmake\config.h.in')) {
FileSystem::createDir($lib->getSourceDir() . '\cmake');
FileSystem::copy(ROOT_DIR . '/src/globals/extra/libyaml_config.h.in', $lib->getSourceDir() . '\cmake\config.h.in');
}
if (!file_exists($lib->getSourceDir() . '\YamlConfig.cmake.in')) {
FileSystem::copy(ROOT_DIR . '/src/globals/extra/libyaml_yamlConfig.cmake.in', $lib->getSourceDir() . '\YamlConfig.cmake.in');
}
}
#[BuildFor('Darwin')]
#[BuildFor('Linux')]
public function buildUnix(LibraryPackage $lib): void
{
UnixAutoconfExecutor::create($lib)->configure()->make();
}
#[BuildFor('Windows')]
public function buildWin(LibraryPackage $lib): void
{
WindowsCMakeExecutor::create($lib)
->addConfigureArgs('-DBUILD_TESTING=OFF')
->build();
}
}

View File

@@ -8,6 +8,8 @@ use StaticPHP\Attribute\Package\BuildFor;
use StaticPHP\Attribute\Package\Library;
use StaticPHP\Package\LibraryPackage;
use StaticPHP\Runtime\Executor\UnixCMakeExecutor;
use StaticPHP\Runtime\Executor\WindowsCMakeExecutor;
use StaticPHP\Util\FileSystem;
#[Library('libzip')]
class libzip
@@ -33,4 +35,28 @@ class libzip
->build();
$lib->patchPkgconfPrefix(['libzip.pc'], PKGCONF_PATCH_PREFIX);
}
#[BuildFor('Windows')]
public function buildWin(LibraryPackage $lib): void
{
WindowsCMakeExecutor::create($lib)
->optionalPackage('bzip2', ...cmake_boolean_args('ENABLE_BZIP2'))
->optionalPackage('xz', ...cmake_boolean_args('ENABLE_LZMA'))
->optionalPackage('openssl', ...cmake_boolean_args('ENABLE_OPENSSL'))
->optionalPackage('zstd', ...cmake_boolean_args('ENABLE_ZSTD'))
->addConfigureArgs(
'-DENABLE_GNUTLS=OFF',
'-DENABLE_MBEDTLS=OFF',
'-DBUILD_DOC=OFF',
'-DBUILD_EXAMPLES=OFF',
'-DBUILD_REGRESS=OFF',
'-DBUILD_TOOLS=OFF',
'-DBUILD_OSSFUZZ=OFF',
)
->build();
FileSystem::copy(
$lib->getBuildRootPath() . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . 'zip.lib',
$lib->getBuildRootPath() . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . 'libzip_a.lib'
);
}
}

View File

@@ -13,6 +13,7 @@ use StaticPHP\Util\DirDiff;
use StaticPHP\Util\FileSystem;
#[Library('ncurses')]
#[Library('ncursesw')]
class ncurses
{
#[BuildFor('Darwin')]
@@ -21,37 +22,48 @@ class ncurses
{
$dirdiff = new DirDiff(BUILD_BIN_PATH);
UnixAutoconfExecutor::create($package)
$ac = UnixAutoconfExecutor::create($package)
->appendEnv([
'LDFLAGS' => $toolchain->isStatic() ? '-static' : '',
])
->configure(
'--enable-overwrite',
'--with-curses-h',
'--enable-pc-files',
'--enable-echo',
'--disable-widec',
'--with-normal',
'--with-ticlib',
'--without-tests',
'--without-dlsym',
'--without-debug',
'--enable-symlinks',
"--bindir={$package->getBinDir()}",
"--includedir={$package->getIncludeDir()}",
"--libdir={$package->getLibDir()}",
"--prefix={$package->getBuildRootPath()}",
)
]);
$wide = $package->getName() === 'ncurses' ? ['--disable-widec'] : [];
// Include standard system terminfo paths as fallback so binaries linking this ncurses
// (e.g. htop) can find terminfo on any target system without needing TERMINFO_DIRS set.
$terminfo_dirs = implode(':', [
"{$package->getBuildRootPath()}/share/terminfo",
'/etc/terminfo',
'/lib/terminfo',
'/usr/share/terminfo',
]);
$ac->configure(
'--enable-overwrite',
'--with-curses-h',
'--enable-pc-files',
'--enable-echo',
'--with-normal',
'--with-ticlib',
'--without-tests',
'--without-dlsym',
'--without-debug',
'--enable-symlinks',
"--with-terminfo-dirs={$terminfo_dirs}",
"--bindir={$package->getBinDir()}",
"--includedir={$package->getIncludeDir()}",
"--libdir={$package->getLibDir()}",
"--prefix={$package->getBuildRootPath()}",
...$wide,
)
->make();
$new_files = $dirdiff->getIncrementFiles(true);
foreach ($new_files as $file) {
@unlink(BUILD_BIN_PATH . '/' . $file);
}
shell()->cd(BUILD_ROOT_PATH)->exec('rm -rf share/terminfo');
shell()->cd(BUILD_ROOT_PATH)->exec('rm -rf lib/terminfo');
// shell()->cd(BUILD_ROOT_PATH)->exec('rm -rf share/terminfo');
// shell()->cd(BUILD_ROOT_PATH)->exec('rm -rf lib/terminfo');
$pkgconf_list = ['form.pc', 'menu.pc', 'ncurses++.pc', 'ncurses.pc', 'panel.pc', 'tic.pc'];
$suffix = $package->getName() === 'ncursesw' ? 'w' : '';
$pkgconf_list = ["form{$suffix}.pc", "menu{$suffix}.pc", "ncurses++{$suffix}.pc", "ncurses{$suffix}.pc", "panel{$suffix}.pc", "tic{$suffix}.pc"];
$package->patchPkgconfPrefix($pkgconf_list);
foreach ($pkgconf_list as $pkgconf) {

View File

@@ -8,10 +8,29 @@ use StaticPHP\Attribute\Package\BuildFor;
use StaticPHP\Attribute\Package\Library;
use StaticPHP\Package\LibraryPackage;
use StaticPHP\Runtime\Executor\UnixAutoconfExecutor;
use StaticPHP\Runtime\Executor\WindowsCMakeExecutor;
use StaticPHP\Util\FileSystem;
#[Library('nghttp2')]
class nghttp2
{
#[BuildFor('Windows')]
public function buildWin(LibraryPackage $lib): void
{
WindowsCMakeExecutor::create($lib)
->addConfigureArgs(
'-DENABLE_SHARED_LIB=OFF',
'-DENABLE_STATIC_LIB=ON',
'-DENABLE_STATIC_CRT=ON',
'-DENABLE_LIB_ONLY=ON',
'-DENABLE_DOC=OFF',
'-DBUILD_TESTING=OFF',
)
->build();
FileSystem::replaceFileStr($lib->getIncludeDir() . '\nghttp2\nghttp2.h', '#ifdef NGHTTP2_STATICLIB', '#if 1');
}
#[BuildFor('Linux')]
#[BuildFor('Darwin')]
public function build(LibraryPackage $lib): void

View File

@@ -8,10 +8,26 @@ use StaticPHP\Attribute\Package\BuildFor;
use StaticPHP\Attribute\Package\Library;
use StaticPHP\Package\LibraryPackage;
use StaticPHP\Runtime\Executor\UnixAutoconfExecutor;
use StaticPHP\Runtime\Executor\WindowsCMakeExecutor;
#[Library('nghttp3')]
class nghttp3
{
#[BuildFor('Windows')]
public function buildWin(LibraryPackage $lib): void
{
WindowsCMakeExecutor::create($lib)
->addConfigureArgs(
'-DENABLE_SHARED_LIB=OFF',
'-DENABLE_STATIC_LIB=ON',
'-DBUILD_STATIC_LIBS=ON',
'-DBUILD_SHARED_LIBS=OFF',
'-DENABLE_STATIC_CRT=ON',
'-DENABLE_LIB_ONLY=ON',
)
->build();
}
#[BuildFor('Linux')]
#[BuildFor('Darwin')]
public function build(LibraryPackage $lib): void

View File

@@ -8,10 +8,27 @@ use StaticPHP\Attribute\Package\BuildFor;
use StaticPHP\Attribute\Package\Library;
use StaticPHP\Package\LibraryPackage;
use StaticPHP\Runtime\Executor\UnixAutoconfExecutor;
use StaticPHP\Runtime\Executor\WindowsCMakeExecutor;
#[Library('ngtcp2')]
class ngtcp2
{
#[BuildFor('Windows')]
public function buildWin(LibraryPackage $lib): void
{
WindowsCMakeExecutor::create($lib)
->addConfigureArgs(
'-DENABLE_SHARED_LIB=OFF',
'-DENABLE_STATIC_LIB=ON',
'-DBUILD_STATIC_LIBS=ON',
'-DBUILD_SHARED_LIBS=OFF',
'-DENABLE_STATIC_CRT=ON',
'-DENABLE_LIB_ONLY=ON',
'-DENABLE_OPENSSL=ON',
)
->build();
}
#[BuildFor('Linux')]
#[BuildFor('Darwin')]
public function build(LibraryPackage $lib): void
@@ -26,18 +43,6 @@ class ngtcp2
]),
'--with-openssl=no'
)
->optionalPackage('nghttp3', ...ac_with_args('libnghttp3', true))
->optionalPackage(
'brotli',
fn (LibraryPackage $brotli) => implode(' ', [
'--with-brotlidec=yes',
"LIBBROTLIDEC_CFLAGS=\"-I{$brotli->getIncludeDir()}\"",
"LIBBROTLIDEC_LIBS=\"{$brotli->getStaticLibFiles()}\"",
'--with-libbrotlienc=yes',
"LIBBROTLIENC_CFLAGS=\"-I{$brotli->getIncludeDir()}\"",
"LIBBROTLIENC_LIBS=\"{$brotli->getStaticLibFiles()}\"",
])
)
->appendEnv(['PKG_CONFIG' => '$PKG_CONFIG --static'])
->configure('--enable-lib-only')
->make();

View File

@@ -6,13 +6,72 @@ namespace Package\Library;
use StaticPHP\Attribute\Package\BuildFor;
use StaticPHP\Attribute\Package\Library;
use StaticPHP\Attribute\Package\Validate;
use StaticPHP\DI\ApplicationContext;
use StaticPHP\Exception\EnvironmentException;
use StaticPHP\Package\LibraryPackage;
use StaticPHP\Package\PackageBuilder;
use StaticPHP\Runtime\SystemTarget;
use StaticPHP\Util\FileSystem;
use StaticPHP\Util\System\LinuxUtil;
use StaticPHP\Util\System\WindowsUtil;
#[Library('openssl')]
class openssl
{
#[Validate]
public function validate(): void
{
if (SystemTarget::getTargetOS() === 'Windows') {
global $argv;
$perl_path_native = PKG_ROOT_PATH . '\strawberry-perl-' . arch2gnu(php_uname('m')) . '-win\perl\bin\perl.exe';
$perl = file_exists($perl_path_native) ? ($perl_path_native) : WindowsUtil::findCommand('perl.exe');
if ($perl === null) {
throw new EnvironmentException(
'You need to install perl first!',
"Please run \"{$argv[0]} doctor\" to fix the environment.",
);
}
ApplicationContext::set('perl', $perl);
}
}
#[BuildFor('Windows')]
public function buildWin(LibraryPackage $lib, PackageBuilder $builder): void
{
$perl = ApplicationContext::get('perl');
$cmd = cmd()->cd($lib->getSourceDir())
->exec(
"{$perl} Configure zlib VC-WIN64A " .
'no-shared ' .
'--prefix=' . quote($lib->getBuildRootPath()) . ' ' .
'--with-zlib-lib=' . quote($lib->getLibDir()) . ' ' .
'--with-zlib-include=' . quote($lib->getIncludeDir()) . ' ' .
'--release ' .
'no-legacy ' .
'no-tests ' .
'/FS'
);
// patch zlib
FileSystem::replaceFileStr("{$lib->getSourceDir()}\\Makefile", 'ZLIB1', 'zlibstatic.lib');
// patch debug: https://stackoverflow.com/questions/18486243/how-do-i-build-openssl-statically-linked-against-windows-runtime
FileSystem::replaceFileStr("{$lib->getSourceDir()}\\Makefile", '/debug', '/incremental:no /opt:icf /dynamicbase /nxcompat /ltcg /nodefaultlib:msvcrt');
// build
$cmd->exec("jom.exe /j{$builder->concurrency} install_dev CNF_LDFLAGS=\"/NODEFAULTLIB:kernel32.lib /NODEFAULTLIB:msvcrt /NODEFAULTLIB:msvcrtd /DEFAULTLIB:libcmt /LIBPATH:{$lib->getLibDir()} zlibstatic.lib\"");
// copy necessary c files
FileSystem::copy("{$lib->getSourceDir()}\\ms\\applink.c", "{$lib->getIncludeDir()}\\openssl\\applink.c");
// patch cmake outputs
FileSystem::replaceFileRegex(
"{$lib->getLibDir()}\\cmake\\OpenSSL\\OpenSSLConfig.cmake",
'/set\(OPENSSL_LIBCRYPTO_DEPENDENCIES .*\)/m',
'set(OPENSSL_LIBCRYPTO_DEPENDENCIES "${OPENSSL_LIBRARY_DIR}" ws2_32.lib gdi32.lib advapi32.lib crypt32.lib user32.lib)'
);
}
#[BuildFor('Darwin')]
public function buildForDarwin(LibraryPackage $pkg): void
{

View File

@@ -73,6 +73,11 @@ class postgresql extends LibraryPackage
FileSystem::resetDir("{$this->getSourceDir()}/build");
if ($installer->isPackageResolved('ldap')) {
$ldap_libs = clean_spaces(implode(' ', PkgConfigUtil::getLibsArray('ldap')));
FileSystem::replaceFileStr("{$this->getSourceDir()}/configure", '-lldap', $ldap_libs);
}
// PHP source relies on the non-private encoding functions in libpgcommon.a
FileSystem::replaceFileStr(
"{$this->getSourceDir()}/src/common/Makefile",

View File

@@ -0,0 +1,34 @@
<?php
declare(strict_types=1);
namespace Package\Library;
use StaticPHP\Attribute\Package\BuildFor;
use StaticPHP\Attribute\Package\Library;
use StaticPHP\Package\LibraryPackage;
use StaticPHP\Util\FileSystem;
#[Library('pthreads4w')]
class pthreads4w
{
#[BuildFor('Windows')]
public function buildWin(LibraryPackage $lib): void
{
cmd()->cd($lib->getSourceDir())
->exec(
'nmake /E /nologo /f Makefile ' .
'DESTROOT=' . $lib->getBuildRootPath() . ' ' .
'XCFLAGS="/MT" ' . // no dll
'EHFLAGS="/I. /DHAVE_CONFIG_H /Os /Ob2 /D__PTW32_STATIC_LIB /D__PTW32_BUILD_INLINED" ' .
'pthreadVC3.inlined_static_stamp'
);
FileSystem::createDir($lib->getLibDir());
FileSystem::createDir($lib->getIncludeDir());
FileSystem::copy("{$lib->getSourceDir()}\\libpthreadVC3.lib", "{$lib->getLibDir()}\\libpthreadVC3.lib");
FileSystem::copy("{$lib->getSourceDir()}\\_ptw32.h", "{$lib->getIncludeDir()}\\_ptw32.h");
FileSystem::copy("{$lib->getSourceDir()}\\pthread.h", "{$lib->getIncludeDir()}\\pthread.h");
FileSystem::copy("{$lib->getSourceDir()}\\sched.h", "{$lib->getIncludeDir()}\\sched.h");
FileSystem::copy("{$lib->getSourceDir()}\\semaphore.h", "{$lib->getIncludeDir()}\\semaphore.h");
}
}

View File

@@ -23,4 +23,15 @@ class qdbm
$ac->make(SystemTarget::getTargetOS() === 'Darwin' ? 'mac' : '');
$lib->patchPkgconfPrefix(['qdbm.pc']);
}
#[BuildFor('Windows')]
public function buildWin(LibraryPackage $lib): void
{
cmd()->cd($lib->getSourceDir())
->exec('nmake /f VCMakefile');
FileSystem::createDir($lib->getLibDir());
FileSystem::createDir($lib->getIncludeDir());
FileSystem::copy("{$lib->getSourceDir()}\\qdbm_a.lib", "{$lib->getLibDir()}\\qdbm_a.lib");
FileSystem::copy("{$lib->getSourceDir()}\\depot.h", "{$lib->getIncludeDir()}\\depot.h");
}
}

View File

@@ -6,8 +6,11 @@ namespace Package\Library;
use StaticPHP\Attribute\Package\BuildFor;
use StaticPHP\Attribute\Package\Library;
use StaticPHP\Attribute\Package\PatchBeforeBuild;
use StaticPHP\Package\LibraryPackage;
use StaticPHP\Runtime\Executor\UnixAutoconfExecutor;
use StaticPHP\Runtime\SystemTarget;
use StaticPHP\Util\FileSystem;
#[Library('sqlite')]
class sqlite
@@ -19,4 +22,18 @@ class sqlite
UnixAutoconfExecutor::create($lib)->configure()->make();
$lib->patchPkgconfPrefix(['sqlite3.pc']);
}
#[PatchBeforeBuild]
public function patchBeforeBuild(LibraryPackage $lib): void
{
spc_skip_if(SystemTarget::getTargetOS() !== 'Windows', 'This patch is only for Windows builds.');
FileSystem::copy(ROOT_DIR . '/src/globals/extra/Makefile-sqlite', "{$lib->getSourceDir()}\\Makefile");
}
#[BuildFor('Windows')]
public function buildWin(LibraryPackage $lib): void
{
cmd()->cd($lib->getSourceDir())
->exec("nmake PREFIX={$lib->getBuildRootPath()} install-static");
}
}

View File

@@ -8,6 +8,8 @@ use StaticPHP\Attribute\Package\BuildFor;
use StaticPHP\Attribute\Package\Library;
use StaticPHP\Package\LibraryPackage;
use StaticPHP\Runtime\Executor\UnixAutoconfExecutor;
use StaticPHP\Runtime\Executor\WindowsCMakeExecutor;
use StaticPHP\Util\FileSystem;
#[Library('xz')]
class xz
@@ -27,4 +29,14 @@ class xz
$lib->patchPkgconfPrefix(['liblzma.pc']);
$lib->patchLaDependencyPrefix();
}
#[BuildFor('Windows')]
public function buildWin(LibraryPackage $lib): void
{
WindowsCMakeExecutor::create($lib)->build();
// copy lzma.lib to liblzma_a.lib
FileSystem::copy("{$lib->getLibDir()}\\lzma.lib", "{$lib->getLibDir()}\\liblzma_a.lib");
// patch lzma.h: make static API always available on Windows
FileSystem::replaceFileStr("{$lib->getIncludeDir()}\\lzma.h", 'defined(LZMA_API_STATIC)', 'defined(_WIN32)');
}
}

View File

@@ -8,6 +8,8 @@ use StaticPHP\Attribute\Package\BuildFor;
use StaticPHP\Attribute\Package\Library;
use StaticPHP\Package\LibraryPackage;
use StaticPHP\Runtime\Executor\UnixAutoconfExecutor;
use StaticPHP\Runtime\Executor\WindowsCMakeExecutor;
use StaticPHP\Util\FileSystem;
#[Library('zlib')]
class zlib
@@ -21,4 +23,29 @@ class zlib
// Patch pkg-config file
$lib->patchPkgconfPrefix(['zlib.pc'], PKGCONF_PATCH_PREFIX);
}
#[BuildFor('Windows')]
public function buildWin(LibraryPackage $lib): void
{
WindowsCMakeExecutor::create($lib)->build();
$detect_list = [
'zlibstatic.lib',
'zs.lib',
'libzs.lib',
'libz.lib',
];
foreach ($detect_list as $item) {
if (file_exists("{$lib->getLibDir()}\\{$item}")) {
FileSystem::copy("{$lib->getLibDir()}\\{$item}", "{$lib->getLibDir()}\\zlib_a.lib");
FileSystem::copy("{$lib->getLibDir()}\\{$item}", "{$lib->getLibDir()}\\zlibstatic.lib");
break;
}
}
FileSystem::removeFileIfExists("{$lib->getBinDir()}\\zlib.dll");
FileSystem::removeFileIfExists("{$lib->getLibDir()}\\zlib.lib");
FileSystem::removeFileIfExists("{$lib->getLibDir()}\\libz.dll");
FileSystem::removeFileIfExists("{$lib->getLibDir()}\\libz.lib");
FileSystem::removeFileIfExists("{$lib->getLibDir()}\\z.lib");
FileSystem::removeFileIfExists("{$lib->getLibDir()}\\z.dll");
}
}

View File

@@ -8,10 +8,24 @@ use StaticPHP\Attribute\Package\BuildFor;
use StaticPHP\Attribute\Package\Library;
use StaticPHP\Package\LibraryPackage;
use StaticPHP\Runtime\Executor\UnixCMakeExecutor;
use StaticPHP\Runtime\Executor\WindowsCMakeExecutor;
#[Library('zstd')]
class zstd
{
#[BuildFor('Windows')]
public function buildWin(LibraryPackage $package): void
{
WindowsCMakeExecutor::create($package)
->setWorkingDir("{$package->getSourceDir()}/build/cmake")
->setBuildDir("{$package->getSourceDir()}/build/cmake/build")
->addConfigureArgs(
'-DZSTD_BUILD_STATIC=ON',
'-DZSTD_BUILD_SHARED=OFF',
)
->build();
}
#[BuildFor('Linux')]
#[BuildFor('Darwin')]
public function build(LibraryPackage $lib): void

View File

@@ -2,25 +2,28 @@
declare(strict_types=1);
namespace Package\Library;
namespace Package\Target;
use StaticPHP\Attribute\Package\BuildFor;
use StaticPHP\Attribute\Package\Library;
use StaticPHP\Attribute\Package\PatchBeforeBuild;
use StaticPHP\Attribute\Package\Target;
use StaticPHP\Attribute\PatchDescription;
use StaticPHP\Package\LibraryPackage;
use StaticPHP\Runtime\Executor\UnixCMakeExecutor;
use StaticPHP\Runtime\Executor\WindowsCMakeExecutor;
use StaticPHP\Runtime\SystemTarget;
use StaticPHP\Util\FileSystem;
#[Library('curl')]
#[Target('curl')]
class curl
{
#[PatchBeforeBuild]
#[PatchDescription('Remove CMAKE_C_IMPLICIT_LINK_LIBRARIES and fix macOS framework detection')]
public function patchBeforeBuild(LibraryPackage $lib): bool
{
shell()->cd($lib->getSourceDir())->exec('sed -i.save s@\${CMAKE_C_IMPLICIT_LINK_LIBRARIES}@@ ./CMakeLists.txt');
if (SystemTarget::getTargetOS() !== 'Windows') {
shell()->cd($lib->getSourceDir())->exec('sed -i.save s@\${CMAKE_C_IMPLICIT_LINK_LIBRARIES}@@ ./CMakeLists.txt');
}
if (SystemTarget::getTargetOS() === 'Darwin') {
FileSystem::replaceFileRegex("{$lib->getSourceDir()}/CMakeLists.txt", '/NOT COREFOUNDATION_FRAMEWORK/m', 'FALSE');
FileSystem::replaceFileRegex("{$lib->getSourceDir()}/CMakeLists.txt", '/NOT SYSTEMCONFIGURATION_FRAMEWORK/m', 'FALSE');
@@ -29,6 +32,34 @@ class curl
return true;
}
#[BuildFor('Windows')]
public function buildWin(LibraryPackage $lib): void
{
WindowsCMakeExecutor::create($lib)
->optionalPackage('zstd', ...cmake_boolean_args('CURL_ZSTD'))
->optionalPackage('brotli', ...cmake_boolean_args('CURL_BROTLI'))
->addConfigureArgs(
'-DBUILD_CURL_EXE=OFF',
'-DZSTD_LIBRARY=zstd_static.lib',
'-DBUILD_TESTING=OFF',
'-DBUILD_EXAMPLES=OFF',
'-DUSE_LIBIDN2=OFF',
'-DCURL_USE_LIBPSL=OFF',
'-DUSE_WINDOWS_SSPI=ON',
'-DCURL_USE_SCHANNEL=ON',
'-DCURL_USE_OPENSSL=OFF',
'-DCURL_ENABLE_SSL=ON',
'-DUSE_NGHTTP2=ON',
'-DSHARE_LIB_OBJECT=OFF',
'-DCURL_USE_LIBSSH2=ON',
'-DENABLE_IPV6=ON',
)
->build();
// move libcurl.lib to libcurl_a.lib
rename("{$lib->getLibDir()}\\libcurl.lib", "{$lib->getLibDir()}\\libcurl_a.lib");
FileSystem::replaceFileStr("{$lib->getIncludeDir()}\\curl\\curl.h", '#ifdef CURL_STATICLIB', '#if 1');
}
#[BuildFor('Linux')]
#[BuildFor('Darwin')]
public function build(LibraryPackage $lib): void
@@ -48,20 +79,25 @@ class curl
->optionalPackage('idn2', ...cmake_boolean_args('CURL_USE_IDN2'))
->optionalPackage('libcares', '-DENABLE_ARES=ON')
->addConfigureArgs(
'-DBUILD_CURL_EXE=OFF',
'-DBUILD_CURL_EXE=ON',
'-DBUILD_LIBCURL_DOCS=OFF',
'-DCURL_USE_PKGCONFIG=ON',
)
->build();
// patch pkgconf
$lib->patchPkgconfPrefix(['libcurl.pc']);
// curl's CMake embeds krb5 link flags directly without following Requires.private chain,
// so -lkrb5support (from mit-krb5.pc Libs.private) is missing from libcurl.pc.
// Ensure -lkrb5support is present in libcurl.pc for downstream consumers.
// krb5.php already promotes it to Libs in mit-krb5.pc before the build, so
// CMake should have embedded it; this is a safety fallback if it was missed.
$pc_path = "{$lib->getLibDir()}/pkgconfig/libcurl.pc";
if (str_contains(FileSystem::readFile($pc_path), '-lgssapi_krb5')) {
FileSystem::replaceFileRegex($pc_path, '/-lcom_err$/m', '-lcom_err -lkrb5support');
$pc_content = FileSystem::readFile($pc_path);
if (str_contains($pc_content, '-lgssapi_krb5') && !str_contains($pc_content, '-lkrb5support')) {
FileSystem::replaceFileRegex($pc_path, '/-lcom_err\b/', '-lcom_err -lkrb5support');
}
shell()->cd("{$lib->getLibDir()}/cmake/CURL/")
->exec("sed -ie 's|\"/lib/libcurl.a\"|\"{$lib->getLibDir()}/libcurl.a\"|g' CURLTargets-release.cmake");
$lib->setOutput('Static curl executable path', BUILD_BIN_PATH . '/curl');
}
}

View File

@@ -1,26 +0,0 @@
<?php
declare(strict_types=1);
namespace Package\Target;
use StaticPHP\Attribute\Package\BeforeStage;
use StaticPHP\Attribute\Package\InitPackage;
use StaticPHP\Attribute\Package\Target;
use StaticPHP\Util\GlobalEnvManager;
#[Target('go-xcaddy')]
class go_xcaddy
{
#[InitPackage]
#[BeforeStage('frankenphp', 'build', 'go-xcaddy')]
public function init(): void
{
if (is_dir(PKG_ROOT_PATH . '/go-xcaddy/bin')) {
GlobalEnvManager::addPathIfNotExists(PKG_ROOT_PATH . '/go-xcaddy/bin');
GlobalEnvManager::putenv('GOROOT=' . PKG_ROOT_PATH . '/go-xcaddy');
GlobalEnvManager::putenv('GOBIN=' . PKG_ROOT_PATH . '/go-xcaddy/bin');
GlobalEnvManager::putenv('GOPATH=' . PKG_ROOT_PATH . '/go-xcaddy/go');
}
}
}

View File

@@ -0,0 +1,29 @@
<?php
declare(strict_types=1);
namespace Package\Target;
use StaticPHP\Attribute\Package\BuildFor;
use StaticPHP\Attribute\Package\Target;
use StaticPHP\Package\TargetPackage;
use StaticPHP\Runtime\Executor\UnixAutoconfExecutor;
use StaticPHP\Toolchain\Interface\ToolchainInterface;
#[Target('htop')]
class htop extends TargetPackage
{
#[BuildFor('Darwin')]
#[BuildFor('Linux')]
public function build(ToolchainInterface $toolchain): void
{
// htop's --enable-static adds -static to CFLAGS/LDFLAGS globally (not just for .a libraries),
// which causes zig-cc to fail on glibc targets. Only enable it for truly static (musl) builds.
UnixAutoconfExecutor::create($this)
->removeConfigureArgs('--disable-shared', '--enable-static')
->exec('./autogen.sh')
->addConfigureArgs($toolchain->isStatic() ? '--enable-static' : '--disable-static')
->configure()
->make(with_clean: false);
}
}

View File

@@ -12,6 +12,7 @@ use StaticPHP\Attribute\Package\BeforeStage;
use StaticPHP\Attribute\Package\Info;
use StaticPHP\Attribute\Package\InitPackage;
use StaticPHP\Attribute\Package\ResolveBuild;
use StaticPHP\Attribute\Package\Stage;
use StaticPHP\Attribute\Package\Target;
use StaticPHP\Attribute\Package\Validate;
use StaticPHP\Config\PackageConfig;
@@ -29,6 +30,7 @@ use StaticPHP\Toolchain\Interface\ToolchainInterface;
use StaticPHP\Toolchain\ToolchainManager;
use StaticPHP\Util\DependencyResolver;
use StaticPHP\Util\FileSystem;
use StaticPHP\Util\InteractiveTerm;
use StaticPHP\Util\SourcePatcher;
use StaticPHP\Util\V2CompatLayer;
use Symfony\Component\Console\Input\InputArgument;
@@ -339,6 +341,35 @@ class php extends TargetPackage
FileSystem::removeDir(BUILD_MODULES_PATH);
}
#[Stage('postInstall')]
public function postInstall(TargetPackage $package, PackageInstaller $installer): void
{
if ($package->getName() === 'frankenphp') {
$package->runStage([$this, 'smokeTestFrankenphpForUnix']);
return;
}
if ($package->getName() !== 'php') {
return;
}
if (SystemTarget::isUnix()) {
if ($installer->interactive) {
InteractiveTerm::indicateProgress('Running PHP smoke tests');
}
$package->runStage([$this, 'smokeTestForUnix']);
if ($installer->interactive) {
InteractiveTerm::finish('PHP smoke tests passed');
}
} elseif (SystemTarget::getTargetOS() === 'Windows') {
if ($installer->interactive) {
InteractiveTerm::indicateProgress('Running PHP smoke tests');
}
$package->runStage([$this, 'smokeTestForWindows']);
if ($installer->interactive) {
InteractiveTerm::finish('PHP smoke tests passed');
}
}
}
private function makeStaticExtensionString(PackageInstaller $installer): string
{
$arg = [];

View File

@@ -469,27 +469,6 @@ trait unix
$package->runStage([$this, 'unixBuildSharedExt']);
}
#[Stage('postInstall')]
public function postInstall(TargetPackage $package, PackageInstaller $installer): void
{
if ($package->getName() === 'frankenphp') {
$package->runStage([$this, 'smokeTestFrankenphpForUnix']);
return;
}
if ($package->getName() !== 'php') {
return;
}
if (SystemTarget::isUnix()) {
if ($installer->interactive) {
InteractiveTerm::indicateProgress('Running PHP smoke tests');
}
$package->runStage([$this, 'smokeTestForUnix']);
if ($installer->interactive) {
InteractiveTerm::finish('PHP smoke tests passed');
}
}
}
/**
* Patch phpize and php-config if needed
*/
@@ -662,7 +641,7 @@ trait unix
/**
* Generate micro extension test php code.
*/
private function generateMicroExtTests(PackageInstaller $installer): string
protected function generateMicroExtTests(PackageInstaller $installer): string
{
$php = "<?php\n\necho '[micro-test-start]' . PHP_EOL;\n";
foreach ($installer->getResolvedPackages(PhpExtensionPackage::class) as $ext) {

View File

@@ -8,10 +8,15 @@ use StaticPHP\Attribute\Package\BeforeStage;
use StaticPHP\Attribute\Package\BuildFor;
use StaticPHP\Attribute\Package\Stage;
use StaticPHP\Attribute\PatchDescription;
use StaticPHP\Config\PackageConfig;
use StaticPHP\Exception\PatchException;
use StaticPHP\Exception\SPCInternalException;
use StaticPHP\Exception\ValidationException;
use StaticPHP\Exception\WrongUsageException;
use StaticPHP\Package\LibraryPackage;
use StaticPHP\Package\PackageBuilder;
use StaticPHP\Package\PackageInstaller;
use StaticPHP\Package\PhpExtensionPackage;
use StaticPHP\Package\TargetPackage;
use StaticPHP\Util\FileSystem;
use StaticPHP\Util\InteractiveTerm;
@@ -52,9 +57,11 @@ trait windows
$cli = $installer->isPackageResolved('php-cli');
$cgi = $installer->isPackageResolved('php-cgi');
$micro = $installer->isPackageResolved('php-micro');
$embed = $installer->isPackageResolved('php-embed');
$args[] = $cli ? '--enable-cli=yes' : '--enable-cli=no';
$args[] = $cgi ? '--enable-cgi=yes' : '--enable-cgi=no';
$args[] = $micro ? '--enable-micro=yes' : '--enable-micro=no';
$args[] = $embed ? '--enable-embed=yes' : '--enable-embed=no';
// zts
$args[] = $package->getBuildOption('enable-zts', false) ? '--enable-zts=yes' : '--enable-zts=no';
@@ -98,18 +105,31 @@ trait windows
throw new PatchException('Windows Makefile patching for php.exe target', 'Cannot patch windows CLI Makefile, Makefile does not contain "$(BUILD_DIR)\php.exe:" line');
}
$lines[$line_num] = '$(BUILD_DIR)\php.exe: generated_files $(DEPS_CLI) $(PHP_GLOBAL_OBJS) $(CLI_GLOBAL_OBJS) $(STATIC_EXT_OBJS) $(ASM_OBJS) $(BUILD_DIR)\php.exe.res $(BUILD_DIR)\php.exe.manifest';
$lines[$line_num + 1] = "\t" . '"$(LINK)" /nologo $(PHP_GLOBAL_OBJS_RESP) $(CLI_GLOBAL_OBJS_RESP) $(STATIC_EXT_OBJS_RESP) $(STATIC_EXT_LIBS) $(ASM_OBJS) $(LIBS) $(LIBS_CLI) $(BUILD_DIR)\php.exe.res /out:$(BUILD_DIR)\php.exe $(LDFLAGS) $(LDFLAGS_CLI) /ltcg /nodefaultlib:msvcrt /nodefaultlib:msvcrtd /ignore:4286';
$lines[$line_num + 1] = "\t" . '"$(LINK) /nologo $(PHP_GLOBAL_OBJS_RESP) $(CLI_GLOBAL_OBJS_RESP) $(STATIC_EXT_OBJS_RESP) $(STATIC_EXT_LIBS) $(ASM_OBJS) $(LIBS) $(LIBS_CLI) $(BUILD_DIR)\php.exe.res /out:$(BUILD_DIR)\php.exe $(LDFLAGS) $(LDFLAGS_CLI) /ltcg /nodefaultlib:msvcrt /nodefaultlib:msvcrtd /ignore:4286';
FileSystem::writeFile("{$package->getSourceDir()}\\Makefile", implode("\r\n", $lines));
}
#[Stage]
public function makeCliForWindows(TargetPackage $package, PackageBuilder $builder): void
public function makeCliForWindows(TargetPackage $package, PackageBuilder $builder, PackageInstaller $installer): void
{
InteractiveTerm::setMessage('Building php: ' . ConsoleColor::yellow('php.exe'));
// extra lib
$extra_libs = getenv('SPC_EXTRA_LIBS') ?: '';
// Collect static-libs@windows from all resolved library packages.
// PHP's configure.bat only adds libs declared by enabled extensions via config.w32;
// transitive library-only deps (e.g. zlibstatic.lib needed by libcrypto.lib) are
// not covered. Inject them here so the final link step has all required symbols.
$resolved_libs = [];
foreach ($installer->getResolvedPackages(LibraryPackage::class) as $lib) {
foreach (PackageConfig::get($lib->getName(), 'static-libs', []) as $lib_file) {
if (file_exists("{$package->getLibDir()}\\{$lib_file}")) {
$resolved_libs[] = $lib_file;
}
}
}
$resolved_libs = array_unique($resolved_libs);
// extra lib
$extra_libs = trim((getenv('SPC_EXTRA_LIBS') ?: '') . ' ' . implode(' ', $resolved_libs));
// Add debug symbols for release build if --no-strip is specified
// We need to modify CFLAGS to replace /Ox with /Zi and add /DEBUG to LDFLAGS
$debug_overrides = '';
@@ -131,6 +151,68 @@ trait windows
$this->deployWindowsBinary($builder, $package, 'php-cli');
}
#[BeforeStage('php', [self::class, 'makeCgiForWindows'])]
#[PatchDescription('Patch Windows Makefile for CGI target')]
public function patchCGITarget(TargetPackage $package): void
{
// search Makefile code line contains "$(BUILD_DIR)\php-cgi.exe:"
$content = FileSystem::readFile("{$package->getSourceDir()}\\Makefile");
$lines = explode("\r\n", $content);
$line_num = 0;
$found = false;
foreach ($lines as $v) {
if (str_contains($v, '$(BUILD_DIR)\php-cgi.exe:')) {
$found = $line_num;
break;
}
++$line_num;
}
if ($found === false) {
throw new PatchException('Windows Makefile patching for php-cgi.exe target', 'Cannot patch windows CGI Makefile, Makefile does not contain "$(BUILD_DIR)\php-cgi.exe:" line');
}
$lines[$line_num] = '$(BUILD_DIR)\php-cgi.exe: $(DEPS_CGI) $(CGI_GLOBAL_OBJS) $(PHP_GLOBAL_OBJS) $(STATIC_EXT_OBJS) $(ASM_OBJS) $(BUILD_DIR)\php-cgi.exe.res $(BUILD_DIR)\php-cgi.exe.manifest';
$lines[$line_num + 1] = "\t" . '@"$(LINK)” /nologo $(PHP_GLOBAL_OBJS_RESP) $(CGI_GLOBAL_OBJS_RESP) $(STATIC_EXT_OBJS_RESP) $(STATIC_EXT_LIBS) $(ASM_OBJS) $(LIBS) $(LIBS_CGI) $(BUILD_DIR)\php-cgi.exe.res /out:$(BUILD_DIR)\php-cgi.exe $(LDFLAGS) $(LDFLAGS_CGI) /ltcg /nodefaultlib:msvcrt /nodefaultlib:msvcrtd /ignore:4286';
FileSystem::writeFile("{$package->getSourceDir()}\\Makefile", implode("\r\n", $lines));
// Patch cgi-static, comment ZEND_TSRMLS_CACHE_DEFINE()
FileSystem::replaceFileRegex("{$package->getSourceDir()}\\sapi\\cgi\\cgi_main.c", '/^ZEND_TSRMLS_CACHE_DEFINE\(\)/m', '// ZEND_TSRMLS_CACHE_DEFINE()');
}
#[Stage]
public function makeCgiForWindows(TargetPackage $package, PackageBuilder $builder, PackageInstaller $installer): void
{
InteractiveTerm::setMessage('Building php: ' . ConsoleColor::yellow('php-cgi.exe'));
// Collect static-libs@windows from all resolved library packages.
$resolved_libs = [];
foreach ($installer->getResolvedPackages(LibraryPackage::class) as $lib) {
foreach (PackageConfig::get($lib->getName(), 'static-libs', []) as $lib_file) {
if (file_exists("{$package->getLibDir()}\\{$lib_file}")) {
$resolved_libs[] = $lib_file;
}
}
}
$resolved_libs = array_unique($resolved_libs);
// extra lib
$extra_libs = trim((getenv('SPC_EXTRA_LIBS') ?: '') . ' ' . implode(' ', $resolved_libs));
// Add debug symbols for release build if --no-strip is specified
$debug_overrides = '';
if ($package->getBuildOption('no-strip', false)) {
$makefile_content = file_get_contents("{$package->getSourceDir()}\\Makefile");
if (preg_match('/^CFLAGS=(.+?)$/m', $makefile_content, $matches)) {
$cflags = $matches[1];
$cflags = str_replace('/Ox ', '/O2 /Zi ', $cflags);
$debug_overrides = '"CFLAGS=' . $cflags . '" "LDFLAGS=/DEBUG /LTCG /INCREMENTAL:NO" "LDFLAGS_CGI=/DEBUG" ';
}
}
cmd()->cd($package->getSourceDir())
->exec("nmake /nologo {$debug_overrides}LIBS_CGI=\"ws2_32.lib kernel32.lib advapi32.lib {$extra_libs}\" EXTRA_LD_FLAGS_PROGRAM= php-cgi.exe");
$this->deployWindowsBinary($builder, $package, 'php-cgi');
}
#[Stage]
public function makeForWindows(TargetPackage $package, PackageInstaller $installer): void
{
@@ -147,6 +229,193 @@ trait windows
if ($installer->isPackageResolved('php-micro')) {
$package->runStage([$this, 'makeMicroForWindows']);
}
if ($installer->isPackageResolved('php-embed')) {
$package->runStage([$this, 'makeEmbedForWindows']);
}
}
#[Stage]
public function makeMicroForWindows(TargetPackage $package, PackageBuilder $builder, PackageInstaller $installer): void
{
InteractiveTerm::setMessage('Building php: ' . ConsoleColor::yellow('micro.sfx'));
// workaround for fiber (originally from https://github.com/dixyes/lwmbs/blob/master/windows/MicroBuild.php)
$makefile = FileSystem::readFile("{$package->getSourceDir()}\\Makefile");
if ($this->getPHPVersionID() >= 80200 && str_contains($makefile, 'FIBER_ASM_ARCH')) {
$makefile .= "\r\n" . '$(MICRO_SFX): $(BUILD_DIR)\Zend\jump_$(FIBER_ASM_ARCH)_ms_pe_masm.obj $(BUILD_DIR)\Zend\make_$(FIBER_ASM_ARCH)_ms_pe_masm.obj' . "\r\n\r\n";
} elseif ($this->getPHPVersionID() >= 80400 && str_contains($makefile, 'FIBER_ASM_ABI')) {
$makefile .= "\r\n" . '$(MICRO_SFX): $(BUILD_DIR)\Zend\jump_$(FIBER_ASM_ABI).obj $(BUILD_DIR)\Zend\make_$(FIBER_ASM_ABI).obj' . "\r\n\r\n";
}
FileSystem::writeFile("{$package->getSourceDir()}\\Makefile", $makefile);
// Collect static-libs@windows from all resolved library packages.
$resolved_libs = [];
foreach ($installer->getResolvedPackages(LibraryPackage::class) as $lib) {
foreach (PackageConfig::get($lib->getName(), 'static-libs', []) as $lib_file) {
if (file_exists("{$package->getLibDir()}\\{$lib_file}")) {
$resolved_libs[] = $lib_file;
}
}
}
$resolved_libs = array_unique($resolved_libs);
// extra lib
$extra_libs = trim((getenv('SPC_EXTRA_LIBS') ?: '') . ' ' . implode(' ', $resolved_libs));
// Add debug symbols for release build if --no-strip is specified
$debug_overrides = '';
if ($package->getBuildOption('no-strip', false)) {
$makefile_content = file_get_contents("{$package->getSourceDir()}\\Makefile");
if (preg_match('/^CFLAGS=(.+?)$/m', $makefile_content, $matches)) {
$cflags = $matches[1];
$cflags = str_replace('/Ox ', '/O2 /Zi ', $cflags);
$debug_overrides = '"CFLAGS=' . $cflags . '" "LDFLAGS=/DEBUG /LTCG /INCREMENTAL:NO" "LDFLAGS_MICRO=/DEBUG" ';
}
}
$fake_cli = $package->getBuildOption('with-micro-fake-cli', false) ? ' /DPHP_MICRO_FAKE_CLI' : '';
// phar patch for micro
$phar_patched = false;
if ($installer->isPackageResolved('ext-phar')) {
$phar_patched = true;
SourcePatcher::patchMicroPhar(self::getPHPVersionID());
}
try {
cmd()->cd($package->getSourceDir())
->exec("nmake /nologo {$debug_overrides}LIBS_MICRO=\"ws2_32.lib shell32.lib {$extra_libs}\" CFLAGS_MICRO=\"/DZEND_ENABLE_STATIC_TSRMLS_CACHE=1{$fake_cli}\" EXTRA_LD_FLAGS_PROGRAM= micro");
} finally {
if ($phar_patched) {
SourcePatcher::unpatchMicroPhar();
}
}
$this->deployWindowsBinary($builder, $package, 'php-micro');
}
#[BeforeStage('php', [self::class, 'makeEmbedForWindows'])]
#[PatchDescription('Patch Windows Makefile for embed static library target')]
public function patchEmbedTarget(TargetPackage $package): void
{
$makefile_path = "{$package->getSourceDir()}\\Makefile";
$content = FileSystem::readFile($makefile_path);
// PHP's configure.bat generates PHP_LDFLAGS with /nodefaultlib:libcmt to avoid CRT
// duplication in a normal /MD build. But our static build compiles everything with /MT,
// so every .obj file has DEFAULTLIB:LIBCMT embedded. Removing /nodefaultlib:libcmt lets
// the linker pick up libcmt.lib. We also exclude the dynamic CRT (/nodefaultlib:msvcrt
// /nodefaultlib:msvcrtd) to keep the DLL dependency-free, consistent with CLI/CGI/micro.
$content = str_replace(
'PHP_LDFLAGS=$(DLL_LDFLAGS) /nodefaultlib:libcmt /def:$(PHPDEF)',
'PHP_LDFLAGS=$(DLL_LDFLAGS) /nodefaultlib:msvcrt /nodefaultlib:msvcrtd /def:$(PHPDEF) /ltcg /ignore:4286',
$content
);
// Patch embed lib target to build a REAL static library instead of just an import lib.
// The default embed target only includes embed SAPI objects and links against php8.lib (import lib).
// We need to include PHP core objects (PHP_GLOBAL_OBJS) and static extension objects (STATIC_EXT_OBJS)
// to create a self-contained static library that doesn't require php8.dll at runtime.
$major = intdiv($this->getPHPVersionID(), 10000);
$embed_lib = "php{$major}embed.lib";
// Find and replace the embed lib build rule
// Actual Makefile format (note the backslash before $(PHPLIB)):
// $(BUILD_DIR)\php8embed.lib: $(DEPS_EMBED) $(EMBED_GLOBAL_OBJS) $(BUILD_DIR)\$(PHPLIB) $(BUILD_DIR)\php8embed.lib.res $(BUILD_DIR)\php8embed.lib.manifest
// @$(MAKE_LIB) /nologo /out:$(BUILD_DIR)\php8embed.lib $(ARFLAGS) $(EMBED_GLOBAL_OBJS_RESP) $(BUILD_DIR)\$(PHPLIB) $(ARFLAGS_EMBED) $(LIBS_EMBED) $(BUILD_DIR)\php8embed.lib.res
$lines = explode("\r\n", $content);
$new_lines = [];
$i = 0;
while ($i < count($lines)) {
$line = $lines[$i];
// Check if this is the embed lib target dependency line (contains the lib name and $(BUILD_DIR)\$(PHPLIB))
if (str_contains($line, "\$(BUILD_DIR)\\{$embed_lib}:") && str_contains($line, '$(BUILD_DIR)\$(PHPLIB)')) {
// Replace the dependency line
// Original: $(BUILD_DIR)\php8embed.lib: $(DEPS_EMBED) $(EMBED_GLOBAL_OBJS) $(BUILD_DIR)\$(PHPLIB) $(BUILD_DIR)\php8embed.lib.res $(BUILD_DIR)\php8embed.lib.manifest
// New: $(BUILD_DIR)\php8embed.lib: $(DEPS_EMBED) $(EMBED_GLOBAL_OBJS) $(PHP_GLOBAL_OBJS) $(STATIC_EXT_OBJS) $(ASM_OBJS) $(BUILD_DIR)\php8embed.lib.res $(BUILD_DIR)\php8embed.lib.manifest
$new_deps = "\$(BUILD_DIR)\\{$embed_lib}: \$(DEPS_EMBED) \$(EMBED_GLOBAL_OBJS) \$(PHP_GLOBAL_OBJS) \$(STATIC_EXT_OBJS) \$(ASM_OBJS) \$(BUILD_DIR)\\{$embed_lib}.res \$(BUILD_DIR)\\{$embed_lib}.manifest";
$new_lines[] = $new_deps;
// Skip the original line (we replaced it)
++$i;
// Now look for the lib.exe command line (should be the next non-empty line starting with tab)
while ($i < count($lines) && trim($lines[$i]) === '') {
$new_lines[] = $lines[$i];
++$i;
}
// Replace the lib.exe command to include PHP_GLOBAL_OBJS_RESP and STATIC_EXT_OBJS_RESP
// Original: @$(MAKE_LIB) /nologo /out:$(BUILD_DIR)\php8embed.lib $(ARFLAGS) $(EMBED_GLOBAL_OBJS_RESP) $(BUILD_DIR)\$(PHPLIB) $(ARFLAGS_EMBED) $(LIBS_EMBED) $(BUILD_DIR)\php8embed.lib.res
// New: @$(MAKE_LIB) /nologo /out:$(BUILD_DIR)\php8embed.lib $(ARFLAGS) $(EMBED_GLOBAL_OBJS_RESP) $(PHP_GLOBAL_OBJS_RESP) $(STATIC_EXT_OBJS_RESP) $(ASM_OBJS) $(STATIC_EXT_LIBS) $(ARFLAGS_EMBED) $(LIBS_EMBED) $(BUILD_DIR)\php8embed.lib.res
if ($i < count($lines) && str_contains($lines[$i], '$(MAKE_LIB)')) {
$cmd_line = $lines[$i];
// Remove $(BUILD_DIR)\$(PHPLIB) from the command (note the backslash)
$cmd_line = str_replace(' $(BUILD_DIR)\$(PHPLIB)', '', $cmd_line);
// Add PHP_GLOBAL_OBJS_RESP and STATIC_EXT_OBJS_RESP after EMBED_GLOBAL_OBJS_RESP
$cmd_line = str_replace(
'$(EMBED_GLOBAL_OBJS_RESP)',
'$(EMBED_GLOBAL_OBJS_RESP) $(PHP_GLOBAL_OBJS_RESP) $(STATIC_EXT_OBJS_RESP) $(ASM_OBJS) $(STATIC_EXT_LIBS)',
$cmd_line
);
$new_lines[] = $cmd_line;
++$i;
}
} else {
$new_lines[] = $line;
++$i;
}
}
$content = implode("\r\n", $new_lines);
FileSystem::writeFile($makefile_path, $content);
}
#[Stage]
public function makeEmbedForWindows(TargetPackage $package, PackageBuilder $builder, PackageInstaller $installer): void
{
$major = intdiv($this->getPHPVersionID(), 10000);
$embed_lib = "php{$major}embed.lib";
InteractiveTerm::setMessage('Building php: ' . ConsoleColor::yellow($embed_lib));
// Add debug symbols for release build if --no-strip is specified
$debug_overrides = '';
if ($package->getBuildOption('no-strip', false)) {
$makefile_content = file_get_contents("{$package->getSourceDir()}\\Makefile");
if (preg_match('/^CFLAGS=(.+?)$/m', $makefile_content, $matches)) {
$cflags = $matches[1];
$cflags = str_replace('/Ox ', '/O2 /Zi ', $cflags);
$debug_overrides = '"CFLAGS=' . $cflags . '" "LDFLAGS=/DEBUG /LTCG /INCREMENTAL:NO" ';
}
}
// Build the embed static library (patched to include PHP core and extension objects)
cmd()->cd($package->getSourceDir())
->exec("nmake /nologo {$debug_overrides}{$embed_lib}");
// Deploy: php8embed.lib is now a REAL static library containing all PHP code
$rel_type = 'Release'; // TODO: Debug build support
$ts = $builder->getOption('enable-zts') ? '_TS' : '';
$build_dir = "{$package->getSourceDir()}\\x64\\{$rel_type}{$ts}";
// copy static embed lib to buildroot/lib
$embed_lib_src = "{$build_dir}\\{$embed_lib}";
if (file_exists($embed_lib_src)) {
FileSystem::copy($embed_lib_src, "{$package->getLibDir()}\\{$embed_lib}");
$package->setOutput('Static library path for embed SAPI', "{$package->getLibDir()}\\{$embed_lib}");
}
// Note: We no longer deploy php8.dll because the embed static library is self-contained.
// All PHP core code, extensions, and embed SAPI are statically linked into php8embed.lib.
// copy .pdb debug info if --no-strip
$debug_dir = BUILD_ROOT_PATH . '\debug';
if ($builder->getOption('no-strip', false)) {
$pdb = "{$build_dir}\\php{$major}embed.pdb";
if (file_exists($pdb)) {
FileSystem::createDir($debug_dir);
FileSystem::copy($pdb, "{$debug_dir}\\php{$major}embed.pdb");
}
}
// Install PHP headers for embed SAPI development
$this->installPhpHeadersForWindows($package, $installer);
}
#[BuildFor('Windows')]
@@ -215,6 +484,195 @@ trait windows
}
}
#[Stage]
public function smokeTestForWindows(PackageBuilder $builder, TargetPackage $package, PackageInstaller $installer): void
{
// analyse --no-smoke-test option
$no_smoke_test = $builder->getOption('no-smoke-test');
$option = match ($no_smoke_test) {
false => false,
null => 'all',
default => parse_comma_list($no_smoke_test),
};
$valid_tests = ['cli', 'cgi', 'micro', 'micro-exts', 'embed'];
// compat: --without-micro-ext-test is equivalent to --no-smoke-test=micro-exts
if ($builder->getOption('without-micro-ext-test', false)) {
$valid_tests = array_diff($valid_tests, ['micro-exts']);
}
if (is_array($option)) {
foreach ($option as $test) {
if (!in_array($test, $valid_tests, true)) {
throw new WrongUsageException("Invalid value for --no-smoke-test: {$test}. Valid values are: " . implode(', ', $valid_tests));
}
$valid_tests = array_diff($valid_tests, [$test]);
}
} elseif ($option === 'all') {
$valid_tests = [];
}
// remove all .dll from buildroot/bin/
$dlls = glob(BUILD_BIN_PATH . '\*.dll') ?: [];
foreach ($dlls as $dll) {
@unlink($dll);
}
if (in_array('cli', $valid_tests, true) && $installer->isPackageResolved('php-cli')) {
$package->runStage([$this, 'smokeTestCliForWindows']);
}
if (in_array('cgi', $valid_tests, true) && $installer->isPackageResolved('php-cgi')) {
$package->runStage([$this, 'smokeTestCgiForWindows']);
}
if (in_array('micro', $valid_tests, true) && $installer->isPackageResolved('php-micro')) {
$skipExtTest = !in_array('micro-exts', $valid_tests, true);
$package->runStage([$this, 'smokeTestMicroForWindows'], ['skipExtTest' => $skipExtTest]);
}
if (in_array('embed', $valid_tests, true) && $installer->isPackageResolved('php-embed')) {
$package->runStage([$this, 'smokeTestEmbedForWindows'], ['installer' => $installer]);
}
}
#[Stage]
public function smokeTestCliForWindows(PackageInstaller $installer): void
{
InteractiveTerm::setMessage('Running basic php-cli smoke test');
[$ret, $output] = cmd()->execWithResult(BUILD_BIN_PATH . '\php.exe -n -r "echo \"hello\";"');
$raw_output = implode('', $output);
if ($ret !== 0 || trim($raw_output) !== 'hello') {
throw new ValidationException("cli failed smoke test. code: {$ret}, output: {$raw_output}", validation_module: 'php-cli smoke test');
}
$exts = $installer->getResolvedPackages(PhpExtensionPackage::class);
foreach ($exts as $ext) {
InteractiveTerm::setMessage('Running php-cli smoke test for ' . ConsoleColor::yellow($ext->getExtensionName()) . ' extension');
$ext->runSmokeTestCliWindows();
}
}
#[Stage]
public function smokeTestCgiForWindows(): void
{
InteractiveTerm::setMessage('Running basic php-cgi smoke test');
FileSystem::writeFile(SOURCE_PATH . '\php-cgi-test.php', '<?php echo "<h1>Hello, World!</h1>"; ?>');
[$ret, $output] = cmd()->execWithResult(BUILD_BIN_PATH . '\php-cgi.exe -n -f ' . SOURCE_PATH . '\php-cgi-test.php');
$raw_output = implode("\n", $output);
if ($ret !== 0 || !str_contains($raw_output, 'Hello, World!')) {
throw new ValidationException("cgi failed smoke test. code: {$ret}, output: {$raw_output}", validation_module: 'php-cgi smoke test');
}
}
#[Stage]
public function smokeTestMicroForWindows(PackageInstaller $installer, bool $skipExtTest = false): void
{
$micro_sfx = BUILD_BIN_PATH . '\micro.sfx';
InteractiveTerm::setMessage('Running php-micro smoke test');
$content = $skipExtTest
? '<?php echo "[micro-test-start][micro-test-end]";'
: $this->generateMicroExtTests($installer);
$test_file = SOURCE_PATH . '\micro_ext_test.exe';
if (file_exists($test_file)) {
@unlink($test_file);
}
file_put_contents($test_file, file_get_contents($micro_sfx) . $content);
[$ret, $out] = cmd()->execWithResult($test_file);
$raw_out = trim(implode('', $out));
if ($ret !== 0 || !str_starts_with($raw_out, '[micro-test-start]') || !str_ends_with($raw_out, '[micro-test-end]')) {
throw new ValidationException(
"micro_ext_test failed. code: {$ret}, output: {$raw_out}",
validation_module: 'phpmicro sanity check item [micro_ext_test]'
);
}
}
#[Stage]
public function smokeTestEmbedForWindows(PackageInstaller $installer, TargetPackage $package): void
{
$test_dir = SOURCE_PATH . '\embed-test';
FileSystem::createDir($test_dir);
// Create embed.c test file (Windows version)
$embed_c = <<<'C_CODE'
#include <sapi/embed/php_embed.h>
int main(int argc, char **argv) {
PHP_EMBED_START_BLOCK(argc, argv)
zend_file_handle file_handle;
zend_stream_init_filename(&file_handle, "embed.php");
if (!php_execute_script(&file_handle)) {
php_printf("Failed to execute PHP script.\n");
}
PHP_EMBED_END_BLOCK()
return 0;
}
C_CODE;
FileSystem::writeFile($test_dir . '\embed.c', $embed_c);
// Create embed.php test file
FileSystem::writeFile($test_dir . '\embed.php', "<?php\n\ndeclare(strict_types=1);\necho 'hello' . PHP_EOL;\n");
// Get build configuration using spc-config
$util = new \StaticPHP\Util\SPCConfigUtil();
$config = $util->config(array_map(fn ($x) => $x->getName(), $installer->getResolvedPackages()));
// Build the embed test executable using cl.exe
// Note: MSVCToolchain already initialized the VC environment, no need for vcvarsall
InteractiveTerm::setMessage('Running php-embed build smoke test');
// For Windows, we need to use PHP source directory headers directly
// because Windows PHP doesn't use php_config.h like Unix
$source_dir = $package->getSourceDir();
$rel_type = 'Release';
$ts = $package->getBuildOption('enable-zts', false) ? '_TS' : '';
$build_dir = "{$source_dir}\\x64\\{$rel_type}{$ts}";
// Build include flags pointing to source dirs (like PHP Windows build does)
// Note: embed.c uses #include <sapi/embed/php_embed.h>, so we need $source_dir itself
$include_flags = sprintf(
'/I"%s" /I"%s\main" /I"%s\Zend" /I"%s\TSRM" /I"%s" ' .
'/D ZEND_WIN32=1 /D PHP_WIN32=1 /D WIN32 /D _WINDOWS /D WINDOWS=1 /D _MBCS /D _USE_MATH_DEFINES',
$build_dir,
$source_dir,
$source_dir,
$source_dir,
$source_dir
);
// MSVC cl.exe format: compiler flags must come before /link, linker flags after
// ldflags contains /LIBPATH which must be after /link
$compile_cmd = sprintf(
'cl.exe /nologo /O2 /MT /Z7 %s embed.c /Fe:embed.exe /link /LIBPATH:"%s\lib" %s %s',
$include_flags,
BUILD_ROOT_PATH,
$config['libs'],
'kernel32.lib ole32.lib user32.lib advapi32.lib shell32.lib ws2_32.lib dnsapi.lib psapi.lib bcrypt.lib' // Windows system libs (match Makefile LIBS)
);
// Log command explicitly (workaround for cmd() not logging complex commands properly)
logger()->debug('Embed smoke test compile command: ' . $compile_cmd);
[$ret, $out] = cmd()->cd($test_dir)->execWithResult($compile_cmd);
if ($ret !== 0) {
throw new ValidationException(
'embed failed to build. Error message: ' . implode("\n", $out),
validation_module: 'php-embed build smoke test'
);
}
// Run the embed test
InteractiveTerm::setMessage('Running php-embed run smoke test');
[$ret, $output] = cmd()->cd($test_dir)->execWithResult('embed.exe');
$raw_output = implode('', $output);
if ($ret !== 0 || trim($raw_output) !== 'hello') {
throw new ValidationException(
'embed failed to run. Error message: ' . $raw_output,
validation_module: 'php-embed run smoke test'
);
}
}
protected function deployWindowsBinary(PackageBuilder $builder, TargetPackage $package, string $sapi): void
{
$rel_type = 'Release'; // TODO: Debug build support
@@ -231,9 +689,95 @@ trait windows
$builder->deployBinary($src_file, $dst_file);
// make debug info file path
// copy .pdb debug info file
if ($builder->getOption('no-strip', false) && file_exists("{$src[0]}\\{$src[2]}")) {
FileSystem::createDir($debug_dir);
FileSystem::copy("{$src[0]}\\{$src[2]}", "{$debug_dir}\\{$src[2]}");
}
// with-upx-pack for cli, cgi and micro
if ($builder->getOption('with-upx-pack', false)) {
if (in_array($sapi, ['php-cli', 'php-cgi', 'php-micro'], true)) {
cmd()->exec(getenv('UPX_EXEC') . ' --best ' . escapeshellarg($dst_file));
}
}
}
/**
* Install PHP headers to buildroot/include for embed SAPI development.
* This mirrors the 'make install-headers' behavior on Unix.
*/
private function installPhpHeadersForWindows(TargetPackage $package, PackageInstaller $installer): void
{
InteractiveTerm::setMessage('Installing PHP headers for embed SAPI');
$source_dir = $package->getSourceDir();
$include_dir = $package->getIncludeDir();
$php_include_dir = "{$include_dir}\\php";
// Create directory structure
FileSystem::createDir("{$php_include_dir}\\main");
FileSystem::createDir("{$php_include_dir}\\Zend");
FileSystem::createDir("{$php_include_dir}\\TSRM");
FileSystem::createDir("{$php_include_dir}\\sapi\\embed");
// Copy main/*.h
foreach (glob("{$source_dir}\\main\\*.h") as $h) {
FileSystem::copy($h, "{$php_include_dir}\\main\\" . basename($h));
}
// Copy Zend/*.h
foreach (glob("{$source_dir}\\Zend\\*.h") as $h) {
$target = "{$php_include_dir}\\Zend\\" . basename($h);
FileSystem::copy($h, $target);
// Fix GCC-specific #warning directive not supported by MSVC
if (basename($h) === 'zend_atomic.h') {
FileSystem::replaceFileStr($target, '#warning No atomics support detected. Please open an issue with platform details.', '#pragma message("No atomics support detected. Please open an issue with platform details.")');
}
}
// Copy TSRM/*.h
foreach (glob("{$source_dir}\\TSRM\\*.h") as $h) {
FileSystem::copy($h, "{$php_include_dir}\\TSRM\\" . basename($h));
}
// Copy embed SAPI header
FileSystem::copy("{$source_dir}\\sapi\\embed\\php_embed.h", "{$php_include_dir}\\sapi\\embed\\php_embed.h");
// Copy generated config.h (config.w32.h on Windows) to php_config.h
$rel_type = 'Release';
$ts = $package->getBuildOption('enable-zts', false) ? '_TS' : '';
$build_dir = "{$source_dir}\\x64\\{$rel_type}{$ts}";
// Always copy config.w32.h from source (it's used for both build and headers)
if (file_exists("{$source_dir}\\main\\config.w32.h")) {
FileSystem::copy("{$source_dir}\\main\\config.w32.h", "{$php_include_dir}\\main\\php_config.h");
}
// Windows: zend_config.w32.h must be copied as zend_config.h for Zend headers to work
if (file_exists("{$source_dir}\\Zend\\zend_config.w32.h")) {
FileSystem::copy("{$source_dir}\\Zend\\zend_config.w32.h", "{$php_include_dir}\\Zend\\zend_config.h");
}
// Copy extension headers for enabled extensions
foreach ($installer->getResolvedPackages(PhpExtensionPackage::class) as $ext) {
$ext_name = $ext->getExtensionName();
$ext_dir = "{$source_dir}\\ext\\{$ext_name}";
if (is_dir($ext_dir)) {
$target_ext_dir = "{$php_include_dir}\\ext\\{$ext_name}";
FileSystem::createDir($target_ext_dir);
foreach (glob("{$ext_dir}\\*.h") as $h) {
FileSystem::copy($h, "{$target_ext_dir}\\" . basename($h));
}
// Also copy any arginfo headers
foreach (glob("{$ext_dir}\\*_arginfo.h") as $h) {
if (!file_exists("{$target_ext_dir}\\" . basename($h))) {
FileSystem::copy($h, "{$target_ext_dir}\\" . basename($h));
}
}
}
}
$package->setOutput('PHP headers path for embed SAPI', $php_include_dir);
}
}

View File

@@ -34,7 +34,7 @@ use Symfony\Component\Console\Application;
*/
final class ConsoleApplication extends Application
{
public const string VERSION = '2.8.3';
public const string VERSION = '2.8.4';
public function __construct()
{

View File

@@ -96,7 +96,8 @@ class Extension
fn ($x) => $x->getStaticLibFiles(),
$this->getLibraryDependencies(recursive: true)
);
return implode(' ', $ret);
$libs = implode(' ', $ret);
return deduplicate_flags($libs);
}
/**

View File

@@ -365,6 +365,27 @@ abstract class LibraryBase
protected function isLibraryInstalled(): bool
{
if ($pkg_configs = Config::getLib(static::NAME, 'pkg-configs', [])) {
$pkg_config_path = getenv('PKG_CONFIG_PATH') ?: '';
$search_paths = array_unique(array_filter(explode(is_unix() ? ':' : ';', $pkg_config_path)));
foreach ($pkg_configs as $name) {
$found = false;
foreach ($search_paths as $path) {
if (file_exists($path . "/{$name}.pc")) {
$found = true;
break;
}
}
if (!$found) {
return false;
}
}
// allow using system dependencies if pkg_config_path is explicitly defined
if (count($search_paths) > 1) {
return true;
}
}
foreach (Config::getLib(static::NAME, 'static-libs', []) as $name) {
if (!file_exists(BUILD_LIB_PATH . "/{$name}")) {
return false;

View File

@@ -11,7 +11,6 @@ use SPC\store\FileSystem;
use SPC\util\CustomExt;
use SPC\util\GlobalEnvManager;
use SPC\util\SPCConfigUtil;
use SPC\util\SPCTarget;
#[CustomExt('grpc')]
class grpc extends Extension
@@ -21,18 +20,50 @@ class grpc extends Extension
if ($this->builder instanceof WindowsBuilder) {
throw new ValidationException('grpc extension does not support windows yet');
}
// Fix deprecated PHP API usage in call.c
FileSystem::replaceFileStr(
$this->source_dir . '/src/php/ext/grpc/call.c',
"{$this->source_dir}/src/php/ext/grpc/call.c",
'zend_exception_get_default(TSRMLS_C),',
'zend_ce_exception,',
);
if (SPCTarget::getTargetOS() === 'Darwin') {
FileSystem::replaceFileRegex(
$this->source_dir . '/config.m4',
'/GRPC_LIBDIR=.*$/m',
'GRPC_LIBDIR=' . BUILD_LIB_PATH . "\n" . 'LDFLAGS="$LDFLAGS -framework CoreFoundation"'
);
}
$config_m4 = <<<'M4'
PHP_ARG_ENABLE(grpc, [whether to enable grpc support], [AS_HELP_STRING([--enable-grpc], [Enable grpc support])])
if test "$PHP_GRPC" != "no"; then
PHP_ADD_INCLUDE(PHP_EXT_SRCDIR()/include)
PHP_ADD_INCLUDE(PHP_EXT_SRCDIR()/src/php/ext/grpc)
GRPC_LIBDIR=@@build_lib_path@@
PHP_ADD_LIBPATH($GRPC_LIBDIR)
PHP_ADD_LIBRARY(grpc,,GRPC_SHARED_LIBADD)
LIBS="-lpthread $LIBS"
PHP_ADD_LIBRARY(pthread)
case $host in
*darwin*)
PHP_ADD_LIBRARY(c++,1,GRPC_SHARED_LIBADD)
;;
*)
PHP_ADD_LIBRARY(stdc++,1,GRPC_SHARED_LIBADD)
PHP_ADD_LIBRARY(rt,,GRPC_SHARED_LIBADD)
PHP_ADD_LIBRARY(rt)
;;
esac
PHP_NEW_EXTENSION(grpc, @grpc_c_files@, $ext_shared, , -DGRPC_POSIX_FORK_ALLOW_PTHREAD_ATFORK=1)
PHP_SUBST(GRPC_SHARED_LIBADD)
PHP_INSTALL_HEADERS([ext/grpc], [php_grpc.h])
fi
M4;
$replace = get_pack_replace();
// load grpc c files from src/php/ext/grpc
$c_files = glob($this->source_dir . '/src/php/ext/grpc/*.c');
$replace['@grpc_c_files@'] = implode(" \\\n ", array_map(fn ($f) => 'src/php/ext/grpc/' . basename($f), $c_files));
$config_m4 = str_replace(array_keys($replace), array_values($replace), $config_m4);
file_put_contents($this->source_dir . '/config.m4', $config_m4);
copy($this->source_dir . '/src/php/ext/grpc/php_grpc.h', $this->source_dir . '/php_grpc.h');
return true;
}
@@ -48,7 +79,6 @@ class grpc extends Extension
public function patchBeforeMake(): bool
{
parent::patchBeforeMake();
// add -Wno-strict-prototypes
GlobalEnvManager::putenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS=' . getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS') . ' -Wno-strict-prototypes');
return true;
}

View File

@@ -50,19 +50,16 @@ class swoole extends Extension
// commonly used feature: coroutine-time
$arg .= ' --enable-swoole-coro-time --with-pic';
$arg .= ' --enable-swoole-ssh --enable-swoole-curl';
$arg .= $this->builder->getOption('enable-zts') ? ' --enable-swoole-thread --disable-thread-context' : ' --disable-swoole-thread --enable-thread-context';
// required features: curl, openssl (but curl hook is buggy for php 8.0)
$arg .= $this->builder->getPHPVersionID() >= 80100 ? ' --enable-swoole-curl' : ' --disable-swoole-curl';
$arg .= ' --enable-openssl';
// additional features that only require libraries
$arg .= $this->builder->getLib('libcares') ? ' --enable-cares' : '';
$arg .= $this->builder->getLib('brotli') ? (' --enable-brotli --with-brotli-dir=' . BUILD_ROOT_PATH) : '';
$arg .= $this->builder->getLib('nghttp2') ? (' --with-nghttp2-dir=' . BUILD_ROOT_PATH) : '';
$arg .= $this->builder->getLib('zstd') ? ' --enable-zstd' : '';
$arg .= $this->builder->getLib('liburing') ? ' --enable-iouring' : '';
$arg .= $this->builder->getLib('liburing') ? ' --enable-iouring --enable-uring-socket' : '';
$arg .= $this->builder->getExt('sockets') ? ' --enable-sockets' : '';
// enable additional features that require the pdo extension, but conflict with pdo_* extensions
@@ -74,6 +71,7 @@ class swoole extends Extension
$config = (new SPCConfigUtil($this->builder))->getLibraryConfig($this->builder->getLib('unixodbc'));
$arg .= ' --with-swoole-odbc=unixODBC,' . BUILD_ROOT_PATH . ' SWOOLE_ODBC_LIBS="' . $config['libs'] . '"';
}
$arg .= $this->builder->getExt('ftp')?->isBuildStatic() ? ' --disable-swoole-ftp' : ' --enable-swoole-ftp';
if ($this->getExtVersion() >= '6.1.0') {
$arg .= ' --enable-swoole-stdext';

View File

@@ -162,7 +162,7 @@ class LinuxBuilder extends UnixBuilderBase
throw new WrongUsageException(
"You're building against musl libc statically (the default on Linux), but you're trying to build shared extensions.\n" .
'Static musl libc does not implement `dlopen`, so your php binary is not able to load shared extensions.' . "\n" .
'Either use SPC_LIBC=glibc to link against glibc on a glibc OS, or use SPC_TARGET="native-native-musl -dynamic" to link against musl libc dynamically using `zig cc`.'
'Either use SPC_LIBC=glibc to link against glibc on a glibc OS, use SPC_TARGET="native-native-musl -dynamic" to link against musl libc dynamically using `zig cc` or use SPC_MUSL_DYNAMIC=true on alpine.'
);
}
logger()->info('Building shared extensions...');

View File

@@ -72,6 +72,10 @@ trait UnixSystemUtilTrait
if (!is_file($symbol_file)) {
throw new SPCInternalException("The symbol file {$symbol_file} does not exist, please check if nm command is available.");
}
// https://github.com/ziglang/zig/issues/24662
if (ToolchainManager::getToolchainClass() === ZigToolchain::class) {
return '-Wl,--export-dynamic'; // needs release 0.16, can be removed then
}
// macOS/zig
if (SPCTarget::getTargetOS() !== 'Linux' || ToolchainManager::getToolchainClass() === ZigToolchain::class) {
return "-Wl,-exported_symbols_list,{$symbol_file}";

View File

@@ -457,6 +457,7 @@ abstract class UnixBuilderBase extends BuilderBase
'XCADDY_GO_BUILD_FLAGS' => '-buildmode=pie ' .
'-ldflags \"-linkmode=external ' . $extLdFlags . ' ' .
'-X \'github.com/caddyserver/caddy/v2/modules/caddyhttp.ServerHeader=FrankenPHP Caddy\' ' .
'-X \'github.com/caddyserver/caddy/v2.CustomBinaryName=frankenphp\' ' .
'-X \'github.com/caddyserver/caddy/v2.CustomVersion=FrankenPHP ' .
"v{$frankenPhpVersion} PHP {$libphpVersion} Caddy'\\\" " .
"-tags={$muslTags}nobadger,nomysql,nopgx{$nobrotli}{$nowatcher}",

Some files were not shown because too many files have changed in this diff Show More