Compare commits

..

25 Commits

Author SHA1 Message Date
henderkes
637eadef0b phpstan 2026-03-10 08:36:30 +07:00
henderkes
3fee7deb6d force curl to absorb all k5 symbols 2026-03-10 08:36:30 +07:00
henderkes
d85f556a93 cs fix 2026-03-10 08:36:30 +07:00
henderkes
9564bae62b ld library path has to be set 2026-03-10 08:36:30 +07:00
henderkes
32678782fc cs fix 2026-03-10 08:36:30 +07:00
henderkes
1e6ddb86f2 support static-only libs 2026-03-10 08:36:30 +07:00
henderkes
fed477c81d lzma support was removed last year 2026-03-10 08:36:30 +07:00
henderkes
c3825a356b patch libxml2 for zig 2026-03-10 08:36:30 +07:00
henderkes
3d4b87b107 zig hasn't released 0.16 yet 2026-03-10 08:36:30 +07:00
henderkes
74906b89a2 libuuid fix 2026-03-10 08:36:30 +07:00
henderkes
1b2a09cb48 fix test 2026-03-10 08:36:30 +07:00
henderkes
7e9e3fb4fe fix krb5 liburing (no --enable-shared option) 2026-03-10 08:36:30 +07:00
henderkes
2511ee8a4c fix krb5 (can't do shared build with zig) 2026-03-10 08:36:30 +07:00
henderkes
17d699d4a5 fix xz shared build 2026-03-10 08:36:30 +07:00
henderkes
fa670cce4a fix pgsql shared build 2026-03-10 08:36:30 +07:00
henderkes
53385d5e2b cs fix 2026-03-10 08:36:30 +07:00
henderkes
ed1e02823a bring back setting, some libraries don't build a static version if the shared one should also be built... 2026-03-10 08:36:30 +07:00
henderkes
cc69a169a8 php-cs-fixer 2026-03-10 08:36:30 +07:00
henderkes
bae2eae2b0 bring back lib info 2026-03-10 08:36:30 +07:00
henderkes
b518237bb2 fix test 2026-03-10 08:36:30 +07:00
henderkes
17acb966de simplify 2026-03-10 08:36:30 +07:00
henderkes
101b4febb9 need to build zstd static 2026-03-10 08:36:30 +07:00
henderkes
7b8f1c4747 fixetyfix 2026-03-10 08:36:30 +07:00
henderkes
179626f989 need static libs because of lib.json 2026-03-10 08:36:30 +07:00
henderkes
cf69c02624 allow building and linking with shared instead of static libs 2026-03-10 08:36:30 +07:00
111 changed files with 421 additions and 1975 deletions

View File

@@ -29,9 +29,6 @@ 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
@@ -45,14 +42,6 @@ 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
@@ -84,9 +73,6 @@ 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
@@ -100,14 +86,6 @@ 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
@@ -174,19 +152,8 @@ jobs:
RUNS_ON="macos-15"
;;
esac
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
DOWN_CMD="$DOWN_CMD --with-php=${{ inputs.php-version }} --for-extensions=${{ inputs.extensions }} --ignore-cache-sources=php-src"
BUILD_CMD="$BUILD_CMD ${{ inputs.extensions }}"
if [ -n "${{ inputs.extra-libs }}" ]; then
DOWN_CMD="$DOWN_CMD --for-libs=${{ inputs.extra-libs }}"
BUILD_CMD="$BUILD_CMD --with-libs=${{ inputs.extra-libs }}"
@@ -210,12 +177,6 @@ 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"
@@ -238,27 +199,6 @@ 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
@@ -305,22 +245,7 @@ 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:

View File

@@ -32,13 +32,10 @@ jobs:
php-version: '8.4'
extensions: curl, openssl, mbstring
ini-values: memory_limit=-1
tools: pecl, composer
- name: "Install dependencies"
run: composer install --no-progress --prefer-dist --optimize-autoloader
tools: pecl, composer, php-cs-fixer
- name: Run PHP-CS-Fixer fix
run: vendor/bin/php-cs-fixer fix --dry-run --diff --ansi
run: php-cs-fixer fix --dry-run --diff --ansi
phpstan:
runs-on: ubuntu-latest

106
composer.lock generated
View File

@@ -2602,75 +2602,6 @@
},
"time": "2025-04-07T20:06:18+00:00"
},
{
"name": "ergebnis/agent-detector",
"version": "1.1.1",
"source": {
"type": "git",
"url": "https://github.com/ergebnis/agent-detector.git",
"reference": "5b654a9f1ff8a5d2ce6a57568df5ae8801c87f64"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/ergebnis/agent-detector/zipball/5b654a9f1ff8a5d2ce6a57568df5ae8801c87f64",
"reference": "5b654a9f1ff8a5d2ce6a57568df5ae8801c87f64",
"shasum": ""
},
"require": {
"php": "~7.4.0 || ~8.0.0 || ~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0 || ~8.5.0 || ~8.6.0"
},
"require-dev": {
"ergebnis/composer-normalize": "^2.50.0",
"ergebnis/license": "^2.7.0",
"ergebnis/php-cs-fixer-config": "^6.60.2",
"ergebnis/phpstan-rules": "^2.13.1",
"ergebnis/phpunit-slow-test-detector": "^2.24.0",
"ergebnis/rector-rules": "^1.16.0",
"fakerphp/faker": "^1.24.1",
"infection/infection": "^0.26.6",
"phpstan/extension-installer": "^1.4.3",
"phpstan/phpstan": "^2.1.46",
"phpstan/phpstan-deprecation-rules": "^2.0.4",
"phpstan/phpstan-phpunit": "^2.0.16",
"phpstan/phpstan-strict-rules": "^2.0.10",
"phpunit/phpunit": "^9.6.34",
"rector/rector": "^2.4.1"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-main": "1.0-dev"
},
"composer-normalize": {
"indent-size": 2,
"indent-style": "space"
}
},
"autoload": {
"psr-4": {
"Ergebnis\\AgentDetector\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Andreas Möller",
"email": "am@localheinz.com",
"homepage": "https://localheinz.com"
}
],
"description": "Provides a detector for detecting the presence of an agent.",
"homepage": "https://github.com/ergebnis/agent-detector",
"support": {
"issues": "https://github.com/ergebnis/agent-detector/issues",
"security": "https://github.com/ergebnis/agent-detector/blob/main/.github/SECURITY.md",
"source": "https://github.com/ergebnis/agent-detector"
},
"time": "2026-04-10T13:45:13+00:00"
},
{
"name": "evenement/evenement",
"version": "v3.0.2",
@@ -2933,23 +2864,22 @@
},
{
"name": "friendsofphp/php-cs-fixer",
"version": "v3.95.1",
"version": "v3.92.3",
"source": {
"type": "git",
"url": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer.git",
"reference": "a9727678fbd12997f1d9de8f4a37824ed9df1065"
"reference": "2ba8f5a60f6f42fb65758cfb3768434fa2d1c7e8"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/PHP-CS-Fixer/PHP-CS-Fixer/zipball/a9727678fbd12997f1d9de8f4a37824ed9df1065",
"reference": "a9727678fbd12997f1d9de8f4a37824ed9df1065",
"url": "https://api.github.com/repos/PHP-CS-Fixer/PHP-CS-Fixer/zipball/2ba8f5a60f6f42fb65758cfb3768434fa2d1c7e8",
"reference": "2ba8f5a60f6f42fb65758cfb3768434fa2d1c7e8",
"shasum": ""
},
"require": {
"clue/ndjson-react": "^1.3",
"composer/semver": "^3.4",
"composer/xdebug-handler": "^3.0.5",
"ergebnis/agent-detector": "^1.1.1",
"ext-filter": "*",
"ext-hash": "*",
"ext-json": "*",
@@ -2960,7 +2890,7 @@
"react/event-loop": "^1.5",
"react/socket": "^1.16",
"react/stream": "^1.4",
"sebastian/diff": "^4.0.6 || ^5.1.1 || ^6.0.2 || ^7.0 || ^8.0",
"sebastian/diff": "^4.0.6 || ^5.1.1 || ^6.0.2 || ^7.0",
"symfony/console": "^5.4.47 || ^6.4.24 || ^7.0 || ^8.0",
"symfony/event-dispatcher": "^5.4.45 || ^6.4.24 || ^7.0 || ^8.0",
"symfony/filesystem": "^5.4.45 || ^6.4.24 || ^7.0 || ^8.0",
@@ -2974,18 +2904,18 @@
"symfony/stopwatch": "^5.4.45 || ^6.4.24 || ^7.0 || ^8.0"
},
"require-dev": {
"facile-it/paraunit": "^1.3.1 || ^2.8.0",
"infection/infection": "^0.32.6",
"justinrainbow/json-schema": "^6.8.0",
"keradus/cli-executor": "^2.3",
"facile-it/paraunit": "^1.3.1 || ^2.7",
"infection/infection": "^0.31.0",
"justinrainbow/json-schema": "^6.5",
"keradus/cli-executor": "^2.2",
"mikey179/vfsstream": "^1.6.12",
"php-coveralls/php-coveralls": "^2.9.1",
"php-cs-fixer/phpunit-constraint-isidenticalstring": "^1.8",
"php-cs-fixer/phpunit-constraint-xmlmatchesxsd": "^1.8",
"phpunit/phpunit": "^9.6.34 || ^10.5.63 || ^11.5.55",
"php-coveralls/php-coveralls": "^2.9",
"php-cs-fixer/phpunit-constraint-isidenticalstring": "^1.6",
"php-cs-fixer/phpunit-constraint-xmlmatchesxsd": "^1.6",
"phpunit/phpunit": "^9.6.25 || ^10.5.53 || ^11.5.34",
"symfony/polyfill-php85": "^1.33",
"symfony/var-dumper": "^5.4.48 || ^6.4.32 || ^7.4.4 || ^8.0.8",
"symfony/yaml": "^5.4.45 || ^6.4.30 || ^7.4.1 || ^8.0.8"
"symfony/var-dumper": "^5.4.48 || ^6.4.24 || ^7.3.2 || ^8.0",
"symfony/yaml": "^5.4.45 || ^6.4.24 || ^7.3.2 || ^8.0"
},
"suggest": {
"ext-dom": "For handling output formats in XML",
@@ -3026,7 +2956,7 @@
],
"support": {
"issues": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/issues",
"source": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/tree/v3.95.1"
"source": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/tree/v3.92.3"
},
"funding": [
{
@@ -3034,7 +2964,7 @@
"type": "github"
}
],
"time": "2026-04-12T17:00:09+00:00"
"time": "2025-12-18T10:45:02+00:00"
},
{
"name": "humbug/box",
@@ -7643,5 +7573,5 @@
"ext-zlib": "*"
},
"platform-dev": {},
"plugin-api-version": "2.9.0"
"plugin-api-version": "2.6.0"
}

View File

@@ -79,6 +79,7 @@ SPC_MICRO_PATCHES=static_extensions_win32,cli_checks,disable_huge_page,vcruntime
SPC_LIBC=musl
; uncomment to link libc dynamically on musl
; SPC_MUSL_DYNAMIC=true
SPC_LINK_STATIC=true
; Recommended: specify your target here. Zig toolchain will be used.
; examples:
@@ -93,12 +94,11 @@ SPC_LIBC=musl
CC=${SPC_LINUX_DEFAULT_CC}
CXX=${SPC_LINUX_DEFAULT_CXX}
AR=${SPC_LINUX_DEFAULT_AR}
RANLIB=${SPC_LINUX_DEFAULT_RANLIB}
LD=${SPC_LINUX_DEFAULT_LD}
; default compiler flags, used in CMake toolchain file, openssl and pkg-config build
SPC_DEFAULT_C_FLAGS="-fPIC -Os"
SPC_DEFAULT_CXX_FLAGS="-fPIC -Os"
SPC_DEFAULT_LD_FLAGS=""
SPC_DEFAULT_LD_FLAGS="-Wl,--as-needed"
; upx executable path
UPX_EXEC=${PKG_ROOT_PATH}/bin/upx
; phpmicro patches, for more info, see: https://github.com/easysoft/phpmicro/tree/master/patches
@@ -116,7 +116,7 @@ SPC_CMD_VAR_PHP_EMBED_TYPE="static"
; EXTRA_CFLAGS for `configure` and `make` php
SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS="-g -fstack-protector-strong -fno-ident -fPIE ${SPC_DEFAULT_C_FLAGS}"
; EXTRA_LDFLAGS for `make` php, can use -release to set a soname for libphp.so
SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS=""
SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS="-Wl,--as-needed"
; optional, path to openssl conf. This affects where openssl will look for the default CA.
; default on Debian/Alpine: /etc/ssl, default on RHEL: /etc/pki/tls
@@ -149,8 +149,6 @@ SPC_CMD_PREFIX_PHP_CONFIGURE="./configure --prefix= --with-valgrind=no --enable-
SPC_CMD_VAR_PHP_EMBED_TYPE="static"
; EXTRA_CFLAGS for `configure` and `make` php
SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS="-g -fstack-protector-strong -fpic -fpie -Werror=unknown-warning-option ${SPC_DEFAULT_C_FLAGS}"
; EXTRA_LDFLAGS for `make` php, can use -release to set a soname for libphp.so
SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS=""
; minimum compatible macOS version (LLVM vars, availability not guaranteed)
MACOSX_DEPLOYMENT_TARGET=12.0

View File

@@ -43,19 +43,6 @@
"calendar": {
"type": "builtin"
},
"clickhouse": {
"support": {
"Windows": "wip",
"BSD": "wip"
},
"type": "external",
"source": "ext-clickhouse",
"arg-type": "custom",
"cpp-extension": true,
"lib-suggests": [
"openssl"
]
},
"com_dotnet": {
"support": {
"BSD": "no",
@@ -76,8 +63,7 @@
],
"ext-depends-windows": [
"zlib",
"openssl",
"brotli"
"openssl"
]
},
"dba": {
@@ -87,19 +73,6 @@
"qdbm"
]
},
"decimal": {
"type": "external",
"source": "ext-decimal",
"arg-type": "custom",
"lib-depends": [
"libmpdec"
]
},
"deepclone": {
"type": "external",
"source": "deepclone",
"arg-type": "enable"
},
"dio": {
"support": {
"BSD": "wip"
@@ -173,30 +146,6 @@
"exif": {
"type": "builtin"
},
"fastchart": {
"support": {
"Windows": "wip",
"BSD": "wip"
},
"type": "external",
"source": "ext-fastchart",
"lib-depends": [
"freetype"
],
"lib-suggests": [
"libpng",
"libjpeg",
"libwebp"
]
},
"fastjson": {
"support": {
"Windows": "wip",
"BSD": "wip"
},
"type": "external",
"source": "ext-fastjson"
},
"ffi": {
"support": {
"Linux": "partial",
@@ -287,7 +236,6 @@
"support": {
"BSD": "wip"
},
"arg-type": "with-path",
"type": "external",
"source": "ext-gmssl",
"lib-depends": [
@@ -304,7 +252,6 @@
"arg-type-unix": "enable-path",
"cpp-extension": true,
"lib-depends": [
"grpc",
"zlib",
"openssl",
"libcares"

View File

@@ -109,7 +109,8 @@
"krb5"
],
"lib-suggests-windows": [
"brotli"
"brotli",
"zstd"
],
"frameworks": [
"CoreFoundation",
@@ -123,7 +124,7 @@
"libfastlz.a"
],
"headers": [
"fastlz.h"
"fastlz/fastlz.h"
]
},
"freetype": {
@@ -142,7 +143,9 @@
"zlib"
],
"lib-suggests": [
"libpng"
"libpng",
"bzip2",
"brotli"
]
},
"gettext": {
@@ -300,6 +303,9 @@
},
"krb5": {
"source": "krb5",
"target": [
"static"
],
"pkg-configs": [
"krb5-gssapi"
],
@@ -352,9 +358,6 @@
"static-libs-unix": [
"libaom.a"
],
"static-libs-windows": [
"aom.lib"
],
"cpp-library": true
},
"libargon2": {
@@ -454,7 +457,6 @@
},
"libheif": {
"source": "libheif",
"cpp-library": true,
"static-libs-unix": [
"libheif.a"
],
@@ -494,7 +496,7 @@
"static-libs-windows": [
"libjpeg_a.lib"
],
"lib-depends": [
"lib-suggests-windows": [
"zlib"
]
},
@@ -529,18 +531,6 @@
"maxminddb_config.h"
]
},
"libmpdec": {
"source": "libmpdec",
"static-libs-unix": [
"libmpdec.a"
],
"static-libs-windows": [
"libmpdec_a.lib"
],
"headers": [
"mpdecimal.h"
]
},
"libmemcached": {
"source": "libmemcached",
"cpp-library": true,
@@ -775,6 +765,7 @@
"xz"
],
"lib-suggests-windows": [
"zstd",
"openssl"
]
},
@@ -1011,9 +1002,6 @@
],
"headers": [
"wtr/watcher-c.h"
],
"frameworks": [
"CoreServices"
]
},
"xz": {
@@ -1041,7 +1029,7 @@
"pkg-configs": [
"zlib"
],
"static-libs-unix": [
"static-libs": [
"libz.a"
],
"static-libs-windows": [
@@ -1061,10 +1049,8 @@
"libzstd.a"
],
"static-libs-windows": [
[
"zstd.lib",
"zstd_static.lib"
]
"zstd.lib",
"zstd_static.lib"
],
"headers-unix": [
"zdict.h",

View File

@@ -84,25 +84,6 @@
"path": "COPYING"
}
},
"ext-decimal": {
"type": "ghtagtar",
"repo": "php-decimal/ext-decimal",
"match": "v2\\.\\d.*",
"path": "php-src/ext/decimal",
"license": {
"type": "file",
"path": "LICENSE"
}
},
"deepclone": {
"type": "ghtagtar",
"repo": "symfony/php-ext-deepclone",
"path": "php-src/ext/deepclone",
"license": {
"type": "file",
"path": "LICENSE"
}
},
"dio": {
"type": "url",
"url": "https://pecl.php.net/get/dio",
@@ -124,19 +105,10 @@
}
},
"ext-brotli": {
"type": "ghtagtar",
"repo": "kjdev/php-ext-brotli",
"type": "git",
"path": "php-src/ext/brotli",
"license": {
"type": "file",
"path": "LICENSE"
}
},
"ext-clickhouse": {
"type": "ghtagtar",
"repo": "iliaal/php_clickhouse",
"match": "tarball/refs/tags/\\d",
"path": "php-src/ext/clickhouse",
"rev": "master",
"url": "https://github.com/kjdev/php-ext-brotli",
"license": {
"type": "file",
"path": "LICENSE"
@@ -171,24 +143,6 @@
"path": "LICENSE"
}
},
"ext-fastchart": {
"type": "ghtagtar",
"repo": "iliaal/fastchart",
"path": "php-src/ext/fastchart",
"license": {
"type": "file",
"path": "LICENSE"
}
},
"ext-fastjson": {
"type": "ghtagtar",
"repo": "iliaal/fastjson",
"path": "php-src/ext/fastjson",
"license": {
"type": "file",
"path": "LICENSE"
}
},
"ext-glfw": {
"type": "git",
"url": "https://github.com/mario-deluna/php-glfw",
@@ -273,7 +227,7 @@
},
"ext-rdkafka": {
"type": "ghtar",
"repo": "php-rdkafka/php-rdkafka",
"repo": "arnaud-lb/php-rdkafka",
"path": "php-src/ext/rdkafka",
"license": {
"type": "file",
@@ -360,9 +314,10 @@
}
},
"ext-zstd": {
"type": "ghtar",
"repo": "kjdev/php-ext-zstd",
"type": "git",
"path": "php-src/ext/zstd",
"rev": "master",
"url": "https://github.com/kjdev/php-ext-zstd",
"license": {
"type": "file",
"path": "LICENSE"
@@ -419,9 +374,9 @@
}
},
"gmssl": {
"type": "git",
"url": "https://github.com/guanzhi/GmSSL.git",
"rev": "master",
"type": "ghtar",
"repo": "guanzhi/GmSSL",
"provide-pre-built": true,
"license": {
"type": "file",
"path": "LICENSE"
@@ -507,8 +462,10 @@
}
},
"krb5": {
"type": "url",
"url": "https://web.mit.edu/kerberos/dist/krb5/1.22/krb5-1.22.2.tar.gz",
"type": "ghtagtar",
"repo": "krb5/krb5",
"match": "krb5.+-final",
"prefer-stable": true,
"license": {
"type": "file",
"path": "NOTICE"
@@ -684,7 +641,6 @@
"libjpeg": {
"type": "ghtar",
"repo": "libjpeg-turbo/libjpeg-turbo",
"prefer-stable": true,
"license": {
"type": "file",
"path": "LICENSE.md"
@@ -726,14 +682,6 @@
"path": "LICENSE"
}
},
"libmpdec": {
"type": "url",
"url": "https://www.bytereef.org/software/mpdecimal/releases/mpdecimal-4.0.1.tar.gz",
"license": {
"type": "file",
"path": "COPYRIGHT.txt"
}
},
"libmemcached": {
"type": "ghtagtar",
"repo": "awesomized/libmemcached",
@@ -1026,7 +974,7 @@
"openssl": {
"type": "ghrel",
"repo": "openssl/openssl",
"match": "openssl-3.+\\.tar\\.gz",
"match": "openssl.+\\.tar\\.gz",
"prefer-stable": true,
"alt": {
"type": "filelist",
@@ -1220,6 +1168,7 @@
"path": "php-src/ext/swoole",
"type": "ghtar",
"repo": "swoole/swoole-src",
"match": "v6\\.+",
"prefer-stable": true,
"license": {
"type": "file",

View File

@@ -16,10 +16,8 @@ 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 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`.
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`.
If you enable `debug`, all logs will be output at build time, including compiled logs, for troubleshooting.

View File

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

View File

@@ -14,7 +14,6 @@ parameters:
- PHP_OS_FAMILY
excludePaths:
analyseAndScan:
- ./src/globals/ext-tests/decimal.php
- ./src/globals/ext-tests/swoole.php
- ./src/globals/ext-tests/swoole.phpt
- ./src/globals/test-extensions.php

View File

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

View File

@@ -29,7 +29,7 @@ abstract class BuilderBase
/** @var array<int, string> extension names */
protected array $ext_list = [];
/** @var array<int, string> all libraries being built (resolved dep list) */
/** @var array<int, string> library names */
protected array $lib_list = [];
/** @var bool compile libs only (just mark it) */
@@ -143,7 +143,7 @@ abstract class BuilderBase
*
* @internal
*/
public function proveExts(array $static_extensions, array $shared_extensions = [], bool $skip_check_deps = false, bool $skip_extract = false, int $build_target = BUILD_TARGET_NONE): void
public function proveExts(array $static_extensions, array $shared_extensions = [], bool $skip_check_deps = false, bool $skip_extract = false): void
{
// judge ext
foreach ($static_extensions as $ext) {
@@ -171,9 +171,7 @@ abstract class BuilderBase
SourceManager::initSource(exts: [...$static_extensions, ...$shared_extensions]);
$this->emitPatchPoint('after-exts-extract');
// patch micro
if (($build_target & BUILD_TARGET_MICRO) === BUILD_TARGET_MICRO) {
SourcePatcher::patchMicro();
}
SourcePatcher::patchMicro();
}
foreach ([...$static_extensions, ...$shared_extensions] as $extension) {

View File

@@ -11,10 +11,8 @@ use SPC\exception\ValidationException;
use SPC\exception\WrongUsageException;
use SPC\store\Config;
use SPC\store\FileSystem;
use SPC\toolchain\ToolchainManager;
use SPC\toolchain\ZigToolchain;
use SPC\util\GlobalEnvManager;
use SPC\util\SPCConfigUtil;
use SPC\util\SPCTarget;
class Extension
{
@@ -186,6 +184,14 @@ class Extension
*/
public function patchBeforeMake(): bool
{
if (SPCTarget::getTargetOS() === 'Linux' && $this->isBuildShared() && ($objs = getenv('SPC_EXTRA_RUNTIME_OBJECTS'))) {
FileSystem::replaceFileRegex(
SOURCE_PATH . '/php-src/Makefile',
"/^(shared_objects_{$this->getName()}\\s*=.*)$/m",
"$1 {$objs}",
);
return true;
}
return false;
}
@@ -225,7 +231,7 @@ class Extension
if (preg_match('/^(.*_SHARED_LIBADD\s*=\s*)(.*)$/m', $makefileContent, $matches)) {
$prefix = $matches[1];
$currentLibs = trim($matches[2]);
$newLibs = clean_spaces("{$currentLibs} {$staticLibs} {$lstdcpp}");
$newLibs = trim("{$currentLibs} {$staticLibs} {$lstdcpp}");
$deduplicatedLibs = deduplicate_flags($newLibs);
FileSystem::replaceFileRegex(
@@ -235,6 +241,13 @@ class Extension
);
}
if ($objs = getenv('SPC_EXTRA_RUNTIME_OBJECTS')) {
FileSystem::replaceFileRegex(
$this->source_dir . '/Makefile',
"/^(shared_objects_{$this->getName()}\\s*=.*)$/m",
"$1 {$objs}",
);
}
return true;
}
@@ -530,24 +543,15 @@ class Extension
*/
protected function getSharedExtensionEnv(): array
{
$compiler_extra = getenv('SPC_COMPILER_EXTRA') ?: '';
if (!str_contains($compiler_extra, '-lcompiler_rt') && ToolchainManager::getToolchainClass() === ZigToolchain::class) {
$compiler_extra = trim($compiler_extra . ' -lcompiler_rt');
GlobalEnvManager::putenv("SPC_COMPILER_EXTRA={$compiler_extra}");
}
$config = (new SPCConfigUtil($this->builder, ['no_php' => true]))->getExtensionConfig($this);
[$staticLibs, $sharedLibs] = $this->splitLibsIntoStaticAndShared($config['libs']);
$preStatic = PHP_OS_FAMILY === 'Darwin' ? '' : '-Wl,--start-group ';
$postStatic = PHP_OS_FAMILY === 'Darwin' ? '' : ' -Wl,--end-group ';
$extraLd = trim((string) getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS'));
if (PHP_OS_FAMILY !== 'Darwin') {
$extraLd = trim($extraLd . ' -Wl,-Bsymbolic');
}
return [
'CFLAGS' => $config['cflags'],
'CXXFLAGS' => $config['cflags'],
'LDFLAGS' => $config['ldflags'],
'EXTRA_LDFLAGS' => $extraLd,
'EXTRA_LDFLAGS' => getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS'),
'LIBS' => clean_spaces("{$preStatic} {$staticLibs} {$postStatic} {$sharedLibs}"),
'LD_LIBRARY_PATH' => BUILD_LIB_PATH,
];

View File

@@ -365,7 +365,8 @@ abstract class LibraryBase
protected function isLibraryInstalled(): bool
{
if ($pkg_configs = Config::getLib(static::NAME, 'pkg-configs', [])) {
$pkg_configs = Config::getLib(static::NAME, 'pkg-configs', []);
if (count($pkg_configs) !== 0) {
$pkg_config_path = getenv('PKG_CONFIG_PATH') ?: '';
$search_paths = array_unique(array_filter(explode(is_unix() ? ':' : ';', $pkg_config_path)));
@@ -381,13 +382,14 @@ abstract class LibraryBase
return false;
}
}
// allow using system dependencies if pkg_config_path is explicitly defined
if (count($search_paths) > 1) {
return true;
}
return true; // allow using system dependencies if pkg_config_path is explicitly defined
}
foreach (Config::getLib(static::NAME, 'static-libs', []) as $name) {
if (!file_exists(BUILD_LIB_PATH . "/{$name}")) {
$sharedLib = str_replace('.a', '.so', $name);
if (!getenv('SPC_LINK_STATIC') && file_exists(BUILD_LIB_PATH . "/{$sharedLib}")) {
continue;
}
return false;
}
}
@@ -396,20 +398,6 @@ abstract class LibraryBase
return false;
}
}
$pkg_config_path = getenv('PKG_CONFIG_PATH') ?: '';
$search_paths = array_filter(explode(is_unix() ? ':' : ';', $pkg_config_path));
foreach (Config::getLib(static::NAME, 'pkg-configs', []) as $name) {
$found = false;
foreach ($search_paths as $path) {
if (file_exists($path . "/{$name}.pc")) {
$found = true;
break;
}
}
if (!$found) {
return false;
}
}
foreach (Config::getLib(static::NAME, 'bin', []) as $name) {
if (!file_exists(BUILD_BIN_PATH . "/{$name}")) {
return false;

View File

@@ -1,21 +0,0 @@
<?php
declare(strict_types=1);
namespace SPC\builder\extension;
use SPC\builder\Extension;
use SPC\util\CustomExt;
#[CustomExt('clickhouse')]
class clickhouse extends Extension
{
public function getUnixConfigureArg(bool $shared = false): string
{
$arg = '--enable-clickhouse' . ($shared ? '=shared' : '');
if ($this->builder->getLib('openssl')) {
$arg .= ' --enable-clickhouse-openssl';
}
return $arg;
}
}

View File

@@ -1,46 +0,0 @@
<?php
declare(strict_types=1);
namespace SPC\builder\extension;
use SPC\builder\Extension;
use SPC\store\FileSystem;
use SPC\util\CustomExt;
#[CustomExt('decimal')]
class decimal extends Extension
{
// TODO: remove this when https://github.com/php-decimal/ext-decimal/issues/92 is merged
public function patchBeforeBuildconf(): bool
{
FileSystem::replaceFileStr(
$this->source_dir . '/php_decimal.c',
[
'zend_module_entry decimal_module_entry',
'ZEND_GET_MODULE(decimal)',
],
[
'zend_module_entry php_decimal_module_entry',
'ZEND_GET_MODULE(php_decimal)',
]
);
FileSystem::replaceFileStr(
$this->source_dir . '/config.w32',
'ARG_WITH("decimal", "for decimal support", "no");',
'ARG_WITH("decimal", "for decimal support", "no");' . "\n" .
'ADD_EXTENSION_DEP("decimal", "json");'
);
return true;
}
public function getUnixConfigureArg(bool $shared = false): string
{
return '--enable-decimal --with-libmpdec-path="' . BUILD_ROOT_PATH . '"';
}
public function getWindowsConfigureArg(bool $shared = false): string
{
return '--with-decimal';
}
}

View File

@@ -11,6 +11,7 @@ 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
@@ -20,59 +21,18 @@ 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,',
);
// Fix include path conflict with pdo_sqlsrv: grpc's PHP ext dir is added to the global include path via
$grpc_php_dir = "{$this->source_dir}/src/php/ext/grpc";
if (file_exists("{$grpc_php_dir}/version.h")) {
copy("{$grpc_php_dir}/version.h", "{$grpc_php_dir}/php_grpc_version.h");
unlink("{$grpc_php_dir}/version.h");
FileSystem::replaceFileStr("{$grpc_php_dir}/php_grpc.h", '#include "version.h"', '#include "php_grpc_version.h"');
FileSystem::replaceFileStr("{$grpc_php_dir}/php_grpc.c", '#include "version.h"', '#include "php_grpc_version.h"');
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;
}
@@ -88,6 +48,7 @@ M4;
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

@@ -5,22 +5,11 @@ declare(strict_types=1);
namespace SPC\builder\extension;
use SPC\builder\Extension;
use SPC\store\FileSystem;
use SPC\util\CustomExt;
#[CustomExt('mongodb')]
class mongodb extends Extension
{
public function patchBeforeBuildconf(): bool
{
FileSystem::replaceFileRegex(
SOURCE_PATH . '/php-src/ext/mongodb/config.m4',
'/^(\s+)(src\/libmongoc\/)/m',
'$1${ac_config_dir}/$2'
);
return true;
}
public function getUnixConfigureArg(bool $shared = false): string
{
$arg = ' --enable-mongodb' . ($shared ? '=shared' : '') . ' ';

View File

@@ -58,10 +58,7 @@ class opcache extends Extension
) {
$opcache_jit = ' --disable-opcache-jit';
}
if ($phpVersionID < 80500) {
return '--enable-opcache' . ($shared ? '=shared' : '') . $opcache_jit;
}
return trim($opcache_jit);
return '--enable-opcache' . ($shared ? '=shared' : '') . $opcache_jit;
}
public function getDistName(): string

View File

@@ -25,8 +25,8 @@ class pgsql extends Extension
{
if ($this->builder->getPHPVersionID() >= 80400) {
$libfiles = $this->getLibFilesString();
$libfiles = str_replace(BUILD_LIB_PATH . '/lib', '-l', $libfiles);
$libfiles = str_replace('.a', '', $libfiles);
$libfiles = deduplicate_flags($libfiles);
$libfiles = clean_spaces($libfiles);
return '--with-pgsql' . ($shared ? '=shared' : '') .
' PGSQL_CFLAGS=-I' . BUILD_INCLUDE_PATH .
' PGSQL_LIBS="-L' . BUILD_LIB_PATH . ' ' . $libfiles . '"';

View File

@@ -33,14 +33,4 @@ class sqlsrv extends Extension
}
return false;
}
public function patchBeforeMake(): bool
{
$makefile = SOURCE_PATH . '/php-src/Makefile';
$makeContent = file_get_contents($makefile);
$makeContent = preg_replace('/^(CFLAGS_(?:PDO_)?SQLSRV=.*?)\s+\/W4\b/m', '$1', $makeContent);
$makeContent = preg_replace('/^(CFLAGS_(?:PDO_)?SQLSRV=.*?)\s+\/WX\b/m', '$1', $makeContent);
file_put_contents($makefile, $makeContent);
return true;
}
}

View File

@@ -50,16 +50,19 @@ 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') && getenv('SPC_LIBC') !== 'glibc' ? ' --enable-iouring --enable-uring-socket' : '--disable-iouring';
$arg .= $this->builder->getLib('liburing') ? ' --enable-iouring' : '';
$arg .= $this->builder->getExt('sockets') ? ' --enable-sockets' : '';
// enable additional features that require the pdo extension, but conflict with pdo_* extensions
@@ -71,7 +74,6 @@ 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

@@ -7,7 +7,6 @@ namespace SPC\builder\extension;
use SPC\builder\Extension;
use SPC\store\SourcePatcher;
use SPC\util\CustomExt;
use SPC\util\GlobalEnvManager;
#[CustomExt('xlswriter')]
class xlswriter extends Extension
@@ -29,13 +28,6 @@ class xlswriter extends Extension
public function patchBeforeMake(): bool
{
$patched = parent::patchBeforeMake();
// Remove when https://github.com/viest/php-ext-xlswriter/pull/560 is merged
if (PHP_OS_FAMILY !== 'Windows') {
GlobalEnvManager::putenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS=' . getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS') . ' -std=gnu17');
$patched = true;
}
if (PHP_OS_FAMILY === 'Windows') {
// fix windows build with openssl extension duplicate symbol bug
SourcePatcher::patchFile('spc_fix_xlswriter_win32.patch', $this->source_dir);
@@ -48,10 +40,4 @@ class xlswriter extends Extension
}
return $patched;
}
// Remove when https://github.com/viest/php-ext-xlswriter/pull/560 is merged
protected function getExtraEnv(): array
{
return ['CFLAGS' => '-std=gnu17'];
}
}

View File

@@ -65,8 +65,6 @@ class BSDBuilder extends UnixBuilderBase
('--with-config-file-path=' . $this->getOption('with-config-file-path') . ' ') : '';
$config_file_scan_dir = $this->getOption('with-config-file-scan-dir', false) ?
('--with-config-file-scan-dir=' . $this->getOption('with-config-file-scan-dir') . ' ') : '';
$sysconfdir = $this->getOption('with-sysconfdir', false) ?
('--sysconfdir=' . $this->getOption('with-sysconfdir') . ' ') : '';
$enableCli = ($build_target & BUILD_TARGET_CLI) === BUILD_TARGET_CLI;
$enableFpm = ($build_target & BUILD_TARGET_FPM) === BUILD_TARGET_FPM;
@@ -91,7 +89,6 @@ class BSDBuilder extends UnixBuilderBase
($enableMicro ? '--enable-micro ' : '--disable-micro ') .
$config_file_path .
$config_file_scan_dir .
$sysconfdir .
$json_74 .
$zts .
$this->makeStaticExtensionArgs()

View File

@@ -1,12 +0,0 @@
<?php
declare(strict_types=1);
namespace SPC\builder\freebsd\library;
class libmpdec extends BSDLibraryBase
{
use \SPC\builder\unix\library\libmpdec;
public const NAME = 'libmpdec';
}

View File

@@ -42,7 +42,7 @@ class openssl extends BSDLibraryBase
shell()->cd($this->source_dir)->initializeEnv($this)
->exec(
"./Configure no-shared {$extra} " .
"./Configure {$extra} " .
'--prefix=/ ' . // use prefix=/
"--libdir={$lib} " .
'--openssldir=/etc/ssl ' .

View File

@@ -11,10 +11,7 @@ use SPC\store\Config;
use SPC\store\DirDiff;
use SPC\store\FileSystem;
use SPC\store\SourcePatcher;
use SPC\toolchain\ToolchainManager;
use SPC\toolchain\ZigToolchain;
use SPC\util\GlobalEnvManager;
use SPC\util\PgoManager;
use SPC\util\SPCConfigUtil;
use SPC\util\SPCTarget;
@@ -23,8 +20,6 @@ class LinuxBuilder extends UnixBuilderBase
/** @var bool Micro patch phar flag */
private bool $phar_patched = false;
private ?PgoManager $pgo = null;
public function __construct(array $options = [])
{
$this->options = $options;
@@ -51,8 +46,6 @@ class LinuxBuilder extends UnixBuilderBase
*/
public function buildPHP(int $build_target = BUILD_TARGET_NONE): void
{
$this->pgo = PgoManager::fromBuilder($this, $build_target);
$cflags = $this->arch_c_flags;
f_putenv('CFLAGS=' . $cflags);
@@ -72,8 +65,7 @@ class LinuxBuilder extends UnixBuilderBase
// php 8.5 contains opcache extension by default,
// if opcache_jit is enabled for 8.5 or opcache enabled,
// we need to disable undefined behavior sanitizer.
$compiler_extra = getenv('SPC_COMPILER_EXTRA') ?: '';
f_putenv('SPC_COMPILER_EXTRA=' . trim($compiler_extra . ' -fno-sanitize=undefined'));
f_putenv('SPC_COMPILER_EXTRA=-fno-sanitize=undefined');
}
if ($this->getOption('enable-zts', false)) {
@@ -88,8 +80,6 @@ class LinuxBuilder extends UnixBuilderBase
('--with-config-file-path=' . $this->getOption('with-config-file-path') . ' ') : '';
$config_file_scan_dir = $this->getOption('with-config-file-scan-dir', false) ?
('--with-config-file-scan-dir=' . $this->getOption('with-config-file-scan-dir') . ' ') : '';
$sysconfdir = $this->getOption('with-sysconfdir', false) ?
('--sysconfdir=' . $this->getOption('with-sysconfdir') . ' ') : '';
$enableCli = ($build_target & BUILD_TARGET_CLI) === BUILD_TARGET_CLI;
$enableFpm = ($build_target & BUILD_TARGET_FPM) === BUILD_TARGET_FPM;
@@ -104,6 +94,7 @@ class LinuxBuilder extends UnixBuilderBase
'CFLAGS' => getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS'),
'CPPFLAGS' => '-I' . BUILD_INCLUDE_PATH, // . ' -Dsomethinghere', // . $musl_flag,
'LDFLAGS' => '-L' . BUILD_LIB_PATH,
'LD_LIBRARY_PATH' => BUILD_LIB_PATH,
// 'LIBS' => SPCTarget::getRuntimeLibs(), // do not pass static libraries here yet, they may contain polyfills for libc functions!
]);
@@ -127,7 +118,6 @@ class LinuxBuilder extends UnixBuilderBase
($enableCgi ? '--enable-cgi ' : '--disable-cgi ') .
$config_file_path .
$config_file_scan_dir .
$sysconfdir .
$json_74 .
$zts .
$maxExecutionTimers .
@@ -137,40 +127,35 @@ class LinuxBuilder extends UnixBuilderBase
$this->emitPatchPoint('before-php-make');
SourcePatcher::patchBeforeMake($this);
PgoManager::patchBeforeMake($this);
$this->cleanMake();
$pgo = $this->pgo;
$needsClean = false;
$sapiBuilds = [
['cli', $enableCli, true, fn () => $this->buildCli()],
['fpm', $enableFpm, true, fn () => $this->buildFpm()],
['cgi', $enableCgi, true, fn () => $this->buildCgi()],
['micro', $enableMicro, true, fn () => $this->buildMicro()],
['embed', $enableEmbed, true, function () use ($enableMicro): void {
if ($enableMicro) {
FileSystem::replaceFileStr(SOURCE_PATH . '/php-src/Makefile', 'OVERALL_TARGET =', 'OVERALL_TARGET = libphp.la');
}
$this->buildEmbed();
}],
// frankenphp doesn't rebuild php-src; xcaddy links against the deployed libphp.so
['frankenphp', $enableFrankenphp, false, fn () => $this->buildFrankenphp()],
];
foreach ($sapiBuilds as [$sapi, $enabled, $rebuildsPhpSrc, $build]) {
if (!$enabled) {
continue;
if ($enableCli) {
logger()->info('building cli');
$this->buildCli();
}
if ($enableFpm) {
logger()->info('building fpm');
$this->buildFpm();
}
if ($enableCgi) {
logger()->info('building cgi');
$this->buildCgi();
}
if ($enableMicro) {
logger()->info('building micro');
$this->buildMicro();
}
if ($enableEmbed) {
logger()->info('building embed');
if ($enableMicro) {
FileSystem::replaceFileStr(SOURCE_PATH . '/php-src/Makefile', 'OVERALL_TARGET =', 'OVERALL_TARGET = libphp.la');
}
if ($pgo) {
if ($needsClean && $rebuildsPhpSrc) {
$this->cleanMake();
}
$pgo->applyForSapi($sapi);
$needsClean = $needsClean || $rebuildsPhpSrc;
}
logger()->info('building ' . $sapi);
$build();
$this->buildEmbed();
}
if ($enableFrankenphp) {
logger()->info('building frankenphp');
$this->buildFrankenphp();
}
$shared_extensions = array_map('trim', array_filter(explode(',', $this->getOption('build-shared'))));
if (!empty($shared_extensions)) {
@@ -178,7 +163,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, use SPC_TARGET="native-native-musl -dynamic" to link against musl libc dynamically using `zig cc` or use SPC_MUSL_DYNAMIC=true on alpine.'
'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`.'
);
}
logger()->info('Building shared extensions...');
@@ -282,11 +267,6 @@ class LinuxBuilder extends UnixBuilderBase
*/
protected function buildEmbed(): void
{
$compiler_extra = getenv('SPC_COMPILER_EXTRA') ?: '';
if (!str_contains($compiler_extra, '-lcompiler_rt') && ToolchainManager::getToolchainClass() === ZigToolchain::class) {
$compiler_extra = trim($compiler_extra . ' -lcompiler_rt');
GlobalEnvManager::putenv("SPC_COMPILER_EXTRA={$compiler_extra}");
}
$sharedExts = array_filter($this->exts, static fn ($ext) => $ext->isBuildShared());
$sharedExts = array_filter($sharedExts, static function ($ext) {
return Config::getExt($ext->getName(), 'build-with-php') === true;
@@ -337,21 +317,14 @@ class LinuxBuilder extends UnixBuilderBase
*/
private function getMakeExtraVars(): array
{
$config = (new SPCConfigUtil($this, ['libs_only_deps' => true, 'absolute_libs' => true]))->config(array_keys($this->getExts(false)), [], $this->getOption('with-suggested-exts'), $this->lib_list);
$config = (new SPCConfigUtil($this, ['libs_only_deps' => true]))->config($this->ext_list, $this->lib_list, $this->getOption('with-suggested-exts'), $this->getOption('with-suggested-libs'));
$static = SPCTarget::isStatic() ? '-all-static' : '';
$lib = BUILD_LIB_PATH;
$extra_ldflags = (string) getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS');
if (getenv('SPC_CMD_VAR_PHP_EMBED_TYPE') === 'shared'
&& !str_contains($extra_ldflags, '-avoid-version')
&& !preg_match('/-release\s+\S+/', $extra_ldflags)) {
$extra_ldflags = trim($extra_ldflags . ' -avoid-version -module');
}
$extra_ldflags_program = trim("-L{$lib} {$static} -pie " . getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS_PROGRAM'));
return array_filter([
'EXTRA_CFLAGS' => getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS'),
'EXTRA_LIBS' => $config['libs'],
'EXTRA_LDFLAGS' => $extra_ldflags,
'EXTRA_LDFLAGS_PROGRAM' => $extra_ldflags_program,
'EXTRA_LDFLAGS' => getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS'),
'EXTRA_LDFLAGS_PROGRAM' => "-L{$lib} {$static} -pie",
]);
}

View File

@@ -15,11 +15,9 @@ class icu extends LinuxLibraryBase
protected function build(): void
{
$userCxxFlags = trim((string) getenv('SPC_DEFAULT_CXX_FLAGS'));
$userLdFlags = trim((string) getenv('SPC_DEFAULT_LD_FLAGS'));
$cppflags = 'CPPFLAGS="-DU_CHARSET_IS_UTF8=1 -DU_USING_ICU_NAMESPACE=1 -DU_STATIC_IMPLEMENTATION=1 -DPIC -fPIC"';
$cxxflags = "CXXFLAGS=\"-std=c++17 -DPIC -fPIC -fno-ident {$userCxxFlags}\"";
$ldflags = SPCTarget::isStatic() ? "LDFLAGS=\"-static {$userLdFlags}\"" : "LDFLAGS=\"{$userLdFlags}\"";
$cxxflags = 'CXXFLAGS="-std=c++17 -DPIC -fPIC -fno-ident"';
$ldflags = SPCTarget::isStatic() ? 'LDFLAGS="-static"' : '';
shell()->cd($this->source_dir . '/source')->initializeEnv($this)
->exec(
"{$cppflags} {$cxxflags} {$ldflags} " .

View File

@@ -1,12 +0,0 @@
<?php
declare(strict_types=1);
namespace SPC\builder\linux\library;
class libmpdec extends LinuxLibraryBase
{
use \SPC\builder\unix\library\libmpdec;
public const NAME = 'libmpdec';
}

View File

@@ -35,10 +35,13 @@ class liburing extends LinuxLibraryBase
]);
}
$shared = getenv('SPC_LINK_STATIC') ? 'ENABLE_SHARED=0' : 'ENABLE_SHARED=1';
$make
->removeConfigureArgs(
'--disable-shared',
'--enable-static',
'--disable-static',
'--enable-shared',
'--disable-shared',
'--with-pic',
'--enable-pic',
)
@@ -46,7 +49,7 @@ class liburing extends LinuxLibraryBase
$use_libc ? '--use-libc' : '',
)
->configure()
->make('library ENABLE_SHARED=0', 'install ENABLE_SHARED=0', with_clean: false);
->make("library {$shared}", "install {$shared}", with_clean: false);
$this->patchPkgconfPrefix();
}

View File

@@ -56,15 +56,11 @@ class openssl extends LinuxLibraryBase
// TODO: in v3 use the following: $openssl_dir ??= SystemUtil::getOSRelease()['dist'] === 'redhat' ? '/etc/pki/tls' : '/etc/ssl';
$openssl_dir ??= '/etc/ssl';
$ex_lib = trim($ex_lib);
// OpenSSL's Configure ignores env CFLAGS for its target template; pass our flags as extra args after the target.
$userCFlags = trim((string) getenv('SPC_DEFAULT_C_FLAGS'));
$userLdFlags = trim((string) getenv('SPC_DEFAULT_LD_FLAGS'));
$userExtraFlags = trim($userCFlags . ' ' . $userLdFlags);
$noShared = getenv('SPC_LINK_STATIC') ? 'no-shared' : '';
shell()->cd($this->source_dir)->initializeEnv($this)
->exec(
"{$env} ./Configure no-shared {$extra} " .
"./Configure {$noShared} {$extra} " .
'--prefix=' . BUILD_ROOT_PATH . ' ' .
'--libdir=' . BUILD_LIB_PATH . ' ' .
"--openssldir={$openssl_dir} " .
@@ -72,8 +68,7 @@ class openssl extends LinuxLibraryBase
'enable-pie ' .
'no-legacy ' .
'no-tests ' .
"linux-{$arch} " .
$userExtraFlags
"linux-{$arch}"
)
->exec('make clean')
->exec("make -j{$this->builder->concurrency} CNF_EX_LIBS=\"{$ex_lib}\"")

View File

@@ -96,8 +96,6 @@ class MacOSBuilder extends UnixBuilderBase
('--with-config-file-path=' . $this->getOption('with-config-file-path') . ' ') : '';
$config_file_scan_dir = $this->getOption('with-config-file-scan-dir', false) ?
('--with-config-file-scan-dir=' . $this->getOption('with-config-file-scan-dir') . ' ') : '';
$sysconfdir = $this->getOption('with-sysconfdir', false) ?
('--sysconfdir=' . $this->getOption('with-sysconfdir') . ' ') : '';
$enableCli = ($build_target & BUILD_TARGET_CLI) === BUILD_TARGET_CLI;
$enableFpm = ($build_target & BUILD_TARGET_FPM) === BUILD_TARGET_FPM;
@@ -131,7 +129,6 @@ class MacOSBuilder extends UnixBuilderBase
($enableCgi ? '--enable-cgi ' : '--disable-cgi ') .
$config_file_path .
$config_file_scan_dir .
$sysconfdir .
$json_74 .
$zts .
$this->makeStaticExtensionArgs() . ' ' .
@@ -296,7 +293,7 @@ class MacOSBuilder extends UnixBuilderBase
private function getMakeExtraVars(): array
{
$config = (new SPCConfigUtil($this, ['libs_only_deps' => true]))->config(array_keys($this->getExts(false)), [], $this->getOption('with-suggested-exts'), $this->lib_list);
$config = (new SPCConfigUtil($this, ['libs_only_deps' => true]))->config($this->ext_list, $this->lib_list, $this->getOption('with-suggested-exts'), $this->getOption('with-suggested-libs'));
return array_filter([
'EXTRA_CFLAGS' => getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS'),
'EXTRA_LDFLAGS_PROGRAM' => '-L' . BUILD_LIB_PATH,

View File

@@ -1,12 +0,0 @@
<?php
declare(strict_types=1);
namespace SPC\builder\macos\library;
class libmpdec extends MacOSLibraryBase
{
use \SPC\builder\unix\library\libmpdec;
public const NAME = 'libmpdec';
}

View File

@@ -43,7 +43,7 @@ class openssl extends MacOSLibraryBase
shell()->cd($this->source_dir)->initializeEnv($this)
->exec(
"./Configure no-shared {$extra} " .
"./Configure {$extra} " .
'--prefix=' . BUILD_ROOT_PATH . ' ' . // use prefix=/
'--libdir=lib ' .
'--openssldir=/etc/ssl ' .

View File

@@ -15,7 +15,7 @@ trait UnixLibraryTrait
{
$libs = $include_self ? [$this] : [];
array_unshift($libs, ...array_values($this->getDependencies(recursive: true)));
$config = new SPCConfigUtil($this->builder, options: ['libs_only_deps' => true, 'absolute_libs' => true]);
$config = new SPCConfigUtil($this->builder, options: ['libs_only_deps' => true]);
$res = $config->config(libraries: array_map(fn ($x) => $x->getName(), $libs));
return $res['libs'];
}

View File

@@ -7,6 +7,7 @@ namespace SPC\builder\traits;
use SPC\exception\ExecutionException;
use SPC\exception\SPCInternalException;
use SPC\exception\WrongUsageException;
use SPC\store\pkg\Zig;
use SPC\toolchain\ToolchainManager;
use SPC\toolchain\ZigToolchain;
use SPC\util\SPCTarget;
@@ -50,7 +51,7 @@ trait UnixSystemUtilTrait
$defined = array_unique($defined);
sort($defined);
// export
if (SPCTarget::getTargetOS() === 'Linux' && ToolchainManager::getToolchainClass() !== ZigToolchain::class) {
if (SPCTarget::getTargetOS() === 'Linux') {
file_put_contents("{$lib_file}.dynsym", "{\n" . implode("\n", array_map(fn ($x) => " {$x};", $defined)) . "};\n");
} else {
file_put_contents("{$lib_file}.dynsym", implode("\n", $defined) . "\n");
@@ -73,6 +74,10 @@ trait UnixSystemUtilTrait
throw new SPCInternalException("The symbol file {$symbol_file} does not exist, please check if nm command is available.");
}
// macOS/zig
// https://github.com/ziglang/zig/issues/24662
if (ToolchainManager::getToolchainClass() === ZigToolchain::class) {
return '-Wl,--export-dynamic'; // needs release 0.16, can be removed then
}
if (SPCTarget::getTargetOS() !== 'Linux' || ToolchainManager::getToolchainClass() === ZigToolchain::class) {
return "-Wl,-exported_symbols_list,{$symbol_file}";
}

View File

@@ -145,7 +145,7 @@ abstract class UnixBuilderBase extends BuilderBase
throw new SPCInternalException("Deploy failed. Cannot find file after copy: {$dst}");
}
if (!$this->getOption('no-strip') && !$this->getOption('pgi') && !$this->getOption('cs-pgi')) {
if (!$this->getOption('no-strip')) {
// extract debug info
$this->extractDebugInfo($dst);
// extra strip
@@ -229,7 +229,7 @@ abstract class UnixBuilderBase extends BuilderBase
copy(ROOT_DIR . '/src/globals/common-tests/embed.c', $sample_file_path . '/embed.c');
copy(ROOT_DIR . '/src/globals/common-tests/embed.php', $sample_file_path . '/embed.php');
$util = new SPCConfigUtil($this);
$config = $util->config(array_keys($this->getExts(false)), [], $this->getOption('with-suggested-exts'), $this->lib_list);
$config = $util->config($this->ext_list, $this->lib_list, $this->getOption('with-suggested-exts'), $this->getOption('with-suggested-libs'));
$lens = "{$config['cflags']} {$config['ldflags']} {$config['libs']}";
if (SPCTarget::isStatic()) {
$lens .= ' -static';
@@ -440,7 +440,7 @@ abstract class UnixBuilderBase extends BuilderBase
$staticFlags = '-static-pie';
}
$config = (new SPCConfigUtil($this))->config(array_keys($this->getExts(false)), [], false, $this->lib_list);
$config = (new SPCConfigUtil($this))->config($this->ext_list, $this->lib_list);
$cflags = "{$this->arch_c_flags} {$config['cflags']} " . getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS') . ' -DFRANKENPHP_VERSION=' . $frankenPhpVersion;
$libs = $config['libs'];
// Go's gcc driver doesn't automatically link against -lgcov or -lrt. Ugly, but necessary fix.
@@ -450,24 +450,21 @@ abstract class UnixBuilderBase extends BuilderBase
$cflags .= ' -Wno-error=missing-profile';
$libs .= ' -lgcov';
}
$extraLdProgram = (string) getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS_PROGRAM');
$env = [...[
'CGO_ENABLED' => '1',
'CGO_CFLAGS' => clean_spaces($cflags),
'CGO_LDFLAGS' => trim("{$this->arch_ld_flags} {$staticFlags} {$config['ldflags']} {$libs} {$extraLdProgram}"),
'CGO_LDFLAGS' => "{$this->arch_ld_flags} {$staticFlags} {$config['ldflags']} {$libs}",
'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}",
'LD_LIBRARY_PATH' => BUILD_LIB_PATH,
], ...GoXcaddy::getEnvironment()];
$pgo = file_exists("{$frankenphpSourceDir}/caddy/frankenphp/default.pgo") ? "--pgo {$frankenphpSourceDir}/caddy/frankenphp/default.pgo " : '';
shell()->cd(BUILD_BIN_PATH)
->setEnv($env)
->exec("xcaddy build --output frankenphp {$pgo}{$xcaddyModules}");
->exec("xcaddy build --output frankenphp {$xcaddyModules}");
$this->deploySAPIBinary(BUILD_TARGET_FRANKENPHP);
}

View File

@@ -20,11 +20,6 @@ trait brotli
FileSystem::replaceFileLineContainsString(BUILD_LIB_PATH . '/pkgconfig/libbrotlidec.pc', 'Libs: -L${libdir} -lbrotlidec', 'Libs: -L${libdir} -lbrotlidec -lbrotlicommon');
FileSystem::replaceFileLineContainsString(BUILD_LIB_PATH . '/pkgconfig/libbrotlienc.pc', 'Libs: -L${libdir} -lbrotlienc', 'Libs: -L${libdir} -lbrotlienc -lbrotlicommon');
shell()->cd(BUILD_ROOT_PATH . '/lib')->exec('ln -sf libbrotlicommon.a libbrotli.a');
foreach (FileSystem::scanDirFiles(BUILD_ROOT_PATH . '/lib/', false, true) as $filename) {
if (str_starts_with($filename, 'libbrotli') && (str_contains($filename, '.so') || str_ends_with($filename, '.dylib'))) {
unlink(BUILD_ROOT_PATH . '/lib/' . $filename);
}
}
if (file_exists(BUILD_BIN_PATH . '/brotli')) {
unlink(BUILD_BIN_PATH . '/brotli');

View File

@@ -10,8 +10,7 @@ trait bzip2
{
public function patchBeforeBuild(): bool
{
$extra = trim((string) getenv('SPC_DEFAULT_C_FLAGS'));
FileSystem::replaceFileStr($this->source_dir . '/Makefile', 'CFLAGS=-Wall', "CFLAGS={$extra} -Wall");
FileSystem::replaceFileStr($this->source_dir . '/Makefile', 'CFLAGS=-Wall', 'CFLAGS=-fPIC -Wall');
return true;
}

View File

@@ -4,8 +4,8 @@ declare(strict_types=1);
namespace SPC\builder\unix\library;
use SPC\store\FileSystem;
use SPC\util\executor\UnixCMakeExecutor;
use SPC\util\SPCConfigUtil;
trait curl
{
@@ -13,6 +13,13 @@ trait curl
{
shell()->cd($this->source_dir)->exec('sed -i.save s@\${CMAKE_C_IMPLICIT_LINK_LIBRARIES}@@ ./CMakeLists.txt');
$linkerFlags = null;
if ($this->builder->getLib('krb5') && !getenv('SPC_LINK_STATIC')) {
$util = new SPCConfigUtil($this->builder, ['libs_only_deps' => true]);
$config = $util->config(libraries: ['krb5']);
$linkerFlags = $config['ldflags'] . ' -Wl,--whole-archive -lgssapi_krb5 -lkrb5 -lk5crypto -lcom_err -lkrb5support -Wl,--no-whole-archive -Wl,--no-undefined';
}
UnixCMakeExecutor::create($this)
->optionalLib('openssl', '-DCURL_USE_OPENSSL=ON -DCURL_CA_BUNDLE=OFF -DCURL_CA_PATH=OFF -DCURL_CA_FALLBACK=ON', '-DCURL_USE_OPENSSL=OFF -DCURL_ENABLE_SSL=OFF')
->optionalLib('brotli', ...cmake_boolean_args('CURL_BROTLI'))
@@ -30,20 +37,12 @@ trait curl
->addConfigureArgs(
'-DBUILD_CURL_EXE=OFF',
'-DBUILD_LIBCURL_DOCS=OFF',
'-DOPENSSL_ROOT_DIR=' . BUILD_ROOT_PATH,
$linkerFlags ? "-DCMAKE_SHARED_LINKER_FLAGS='{$linkerFlags}'" : null
)
->build();
// patch pkgconf
$this->patchPkgconfPrefix(['libcurl.pc']);
// On glibc <2.28 without built-in pthreads, FindThreads sets
// INTERFACE_LINK_LIBRARIES to '-lpthread'
// curls .pc generator walks and prepends '-l' to each
// entry, resulting in -l-lpthread
FileSystem::replaceFileRegex(
BUILD_LIB_PATH . '/pkgconfig/libcurl.pc',
'/-l(-l\S+)/',
'$1'
);
shell()->cd(BUILD_LIB_PATH . '/cmake/CURL/')
->exec("sed -ie 's|\"/lib/libcurl.a\"|\"" . BUILD_LIB_PATH . "/libcurl.a\"|g' CURLTargets-release.cmake");
}

View File

@@ -10,9 +10,8 @@ trait fastlz
{
protected function build(): void
{
$extra = trim((string) getenv('SPC_DEFAULT_C_FLAGS'));
shell()->cd($this->source_dir)->initializeEnv($this)
->exec((getenv('CC') ?: 'cc') . " -c {$extra} fastlz.c -o fastlz.o")
->exec((getenv('CC') ?: 'cc') . ' -c -O3 -fPIC fastlz.c -o fastlz.o')
->exec((getenv('AR') ?: 'ar') . ' rcs libfastlz.a fastlz.o');
if (!copy($this->source_dir . '/fastlz.h', BUILD_INCLUDE_PATH . '/fastlz.h')) {

View File

@@ -13,8 +13,8 @@ trait freetype
{
$cmake = UnixCMakeExecutor::create($this)
->optionalLib('libpng', ...cmake_boolean_args('FT_DISABLE_PNG', true))
->addConfigureArgs('-DFT_DISABLE_BZIP2=ON')
->addConfigureArgs('-DFT_DISABLE_BROTLI=ON')
->optionalLib('bzip2', ...cmake_boolean_args('FT_DISABLE_BZIP2', true))
->optionalLib('brotli', ...cmake_boolean_args('FT_DISABLE_BROTLI', true))
->addConfigureArgs('-DFT_DISABLE_HARFBUZZ=ON');
// fix cmake 4.0 compatibility

View File

@@ -34,9 +34,6 @@ trait imagemagick
->addConfigureArgs(
'--disable-openmp',
'--without-x',
// implicit --with-gcc-arch
// bleeds host cpu features into built binaries
'--without-gcc-arch',
);
// special: linux-static target needs `-static`

View File

@@ -10,8 +10,7 @@ trait jbig
{
public function patchBeforeBuild(): bool
{
$extra = trim((string) getenv('SPC_DEFAULT_C_FLAGS'));
FileSystem::replaceFileStr($this->source_dir . '/Makefile', 'CFLAGS = -O2 -W -Wno-unused-result', "CFLAGS = {$extra} -W -Wno-unused-result");
FileSystem::replaceFileStr($this->source_dir . '/Makefile', 'CFLAGS = -O2 -W -Wno-unused-result', 'CFLAGS = -O2 -W -Wno-unused-result -fPIC');
return true;
}

View File

@@ -4,8 +4,6 @@ declare(strict_types=1);
namespace SPC\builder\unix\library;
use SPC\toolchain\ToolchainManager;
use SPC\toolchain\ZigToolchain;
use SPC\util\executor\UnixAutoconfExecutor;
use SPC\util\SPCConfigUtil;
@@ -15,10 +13,7 @@ trait krb5
{
$origin_source_dir = $this->source_dir;
$this->source_dir .= '/src';
shell()->cd($this->source_dir)->exec('ls -lah');
if (!file_exists($this->source_dir . '/configure')) {
shell()->cd($this->source_dir)->exec('autoreconf -if');
}
shell()->cd($this->source_dir)->exec('autoreconf -if');
$libs = array_map(fn ($x) => $x->getName(), $this->getDependencies(true));
$spc = new SPCConfigUtil($this->builder, ['no_php' => true, 'libs_only_deps' => true]);
$config = $spc->config(libraries: $libs, include_suggest_lib: $this->builder->getOption('with-suggested-libs', false));
@@ -41,16 +36,22 @@ trait krb5
$extraEnv['LDFLAGS'] = '-framework Kerberos';
$args[] = 'ac_cv_func_secure_getenv=no';
}
$make = UnixAutoconfExecutor::create($this)
UnixAutoconfExecutor::create($this)
->appendEnv($extraEnv)
->optionalLib('ldap', '--with-ldap', '--without-ldap')
->optionalLib('libedit', '--with-libedit', '--without-libedit')
->configure(...$args);
if (ToolchainManager::getToolchainClass() === ZigToolchain::class) {
$make->exec('find . -name Makefile -exec sed -i "s/-Werror=incompatible-pointer-types//g" {} +');
}
$make->make();
->removeConfigureArgs(
'--enable-static',
'--disable-static',
'--enable-shared',
'--disable-shared'
)
->addConfigureArgs(
'--enable-static',
'--disable-shared'
)
->configure(...$args)
->make();
$this->patchPkgconfPrefix([
'krb5-gssapi.pc',
'krb5.pc',

View File

@@ -4,11 +4,9 @@ declare(strict_types=1);
namespace SPC\builder\unix\library;
use SPC\builder\linux\SystemUtil;
use SPC\toolchain\ToolchainManager;
use SPC\toolchain\ZigToolchain;
use SPC\util\executor\UnixCMakeExecutor;
use SPC\util\SPCTarget;
trait libaom
{
@@ -19,23 +17,9 @@ trait libaom
$new = trim($extra . ' -D_GNU_SOURCE');
f_putenv("SPC_COMPILER_EXTRA={$new}");
}
$targetCpu = SPCTarget::getTargetArch();
if (str_starts_with($targetCpu, 'aarch')) {
$targetCpu = str_replace('aarch', 'arm', $targetCpu);
}
if (!SystemUtil::findCommand('nasm') && !SystemUtil::findCommand('yasm')) {
$targetCpu = 'generic';
}
UnixCMakeExecutor::create($this)
->setBuildDir("{$this->source_dir}/builddir")
->addConfigureArgs(
"-DAOM_TARGET_CPU={$targetCpu}",
'-DCONFIG_RUNTIME_CPU_DETECT=1',
'-DENABLE_EXAMPLES=0',
'-DENABLE_TOOLS=0',
'-DENABLE_TESTS=0',
'-DENABLE_DOCS=0'
)
->addConfigureArgs('-DAOM_TARGET_CPU=generic')
->build();
f_putenv("SPC_COMPILER_EXTRA={$extra}");
$this->patchPkgconfPrefix(['aom.pc']);

View File

@@ -4,8 +4,6 @@ declare(strict_types=1);
namespace SPC\builder\unix\library;
use SPC\store\FileSystem;
trait libargon2
{
protected function build()
@@ -17,12 +15,6 @@ trait libargon2
$this->patchPkgconfPrefix(['libargon2.pc']);
foreach (FileSystem::scanDirFiles(BUILD_ROOT_PATH . '/lib/', false, true) as $filename) {
if (str_starts_with($filename, 'libargon2') && (str_contains($filename, '.so') || str_ends_with($filename, '.dylib'))) {
unlink(BUILD_ROOT_PATH . '/lib/' . $filename);
}
}
if (file_exists(BUILD_BIN_PATH . '/argon2')) {
unlink(BUILD_BIN_PATH . '/argon2');
}

View File

@@ -11,11 +11,7 @@ trait libde265
protected function build(): void
{
UnixCMakeExecutor::create($this)
->addConfigureArgs(
'-DENABLE_SDL=OFF',
'-DENABLE_DECODER=OFF',
'-DHAVE_NEON=OFF',
)
->addConfigureArgs('-DENABLE_SDL=OFF')
->build();
$this->patchPkgconfPrefix(['libde265.pc']);
}

View File

@@ -11,28 +11,15 @@ trait libheif
{
public function patchBeforeBuild(): bool
{
$patched = false;
if (!str_contains(file_get_contents($this->source_dir . '/CMakeLists.txt'), 'libbrotlienc')) {
FileSystem::replaceFileStr(
$this->source_dir . '/CMakeLists.txt',
'list(APPEND REQUIRES_PRIVATE "libbrotlidec")',
'list(APPEND REQUIRES_PRIVATE "libbrotlidec")' . "\n" . ' list(APPEND REQUIRES_PRIVATE "libbrotlienc")'
);
$patched = true;
return true;
}
// libheif 1.22+ ships a C-incompatible header: `struct heif_bad_pixel`
$heif_properties = $this->source_dir . '/libheif/api/libheif/heif_properties.h';
if (file_exists($heif_properties)
&& str_contains(file_get_contents($heif_properties), 'struct heif_bad_pixel { uint32_t row; uint32_t column; };')
) {
FileSystem::replaceFileStr(
$heif_properties,
'struct heif_bad_pixel { uint32_t row; uint32_t column; };',
'typedef struct heif_bad_pixel { uint32_t row; uint32_t column; } heif_bad_pixel;'
);
$patched = true;
}
return $patched;
return false;
}
protected function build(): void

View File

@@ -14,10 +14,6 @@ trait libjpeg
->addConfigureArgs(
'-DENABLE_STATIC=ON',
'-DENABLE_SHARED=OFF',
'-DWITH_SYSTEM_ZLIB=ON',
'-DWITH_TOOLS=OFF',
'-DWITH_TESTS=OFF',
'-DWITH_SIMD=OFF',
)
->build();
// patch pkgconfig

View File

@@ -12,13 +12,6 @@ trait liblz4
{
// disable executables
FileSystem::replaceFileStr($this->source_dir . '/programs/Makefile', 'install: lz4', "install: lz4\n\ninstallewfwef: lz4");
// zig-cc / clang -flto -c with multiple input files only produces an .o for the first source,
// leaving liblz4.a with just lz4.o. Compile sources individually so all .o files exist.
FileSystem::replaceFileStr(
$this->source_dir . '/lib/Makefile',
"liblz4.a: \$(SRCFILES)\nifeq (\$(BUILD_STATIC),yes) # can be disabled on command line\n\t@echo compiling static library\n\t\$(COMPILE.c) \$^\n\t\$(AR) rcs \$@ *.o\nendif",
"liblz4.a: \$(SRCFILES:.c=.o)\nifeq (\$(BUILD_STATIC),yes) # can be disabled on command line\n\t@echo compiling static library\n\t\$(AR) rcs \$@ \$^\nendif"
);
return true;
}
@@ -34,11 +27,5 @@ trait liblz4
->exec("make install PREFIX='' DESTDIR=" . BUILD_ROOT_PATH);
$this->patchPkgconfPrefix(['liblz4.pc']);
foreach (FileSystem::scanDirFiles(BUILD_LIB_PATH . '/', false, true) as $filename) {
if (str_starts_with($filename, 'liblz4') && (str_contains($filename, '.so') || str_ends_with($filename, '.dylib'))) {
unlink(BUILD_ROOT_PATH . '/lib/' . $filename);
}
}
}
}

View File

@@ -1,17 +0,0 @@
<?php
declare(strict_types=1);
namespace SPC\builder\unix\library;
use SPC\util\executor\UnixAutoconfExecutor;
trait libmpdec
{
protected function build(): void
{
UnixAutoconfExecutor::create($this)
->configure('--disable-cxx --disable-shared --enable-static')
->make();
}
}

View File

@@ -13,6 +13,7 @@ trait libuuid
{
UnixCMakeExecutor::create($this)->toStep(2)->build();
copy($this->source_dir . '/build/libuuid.a', BUILD_LIB_PATH . '/libuuid.a');
copy($this->source_dir . '/build/libuuid.so', BUILD_LIB_PATH . '/libuuid.so');
FileSystem::createDir(BUILD_INCLUDE_PATH . '/uuid');
copy($this->source_dir . '/uuid.h', BUILD_INCLUDE_PATH . '/uuid/uuid.h');
$pc = FileSystem::readFile($this->source_dir . '/uuid.pc.in');

View File

@@ -11,7 +11,7 @@ trait libuv
protected function build(): void
{
UnixCMakeExecutor::create($this)
->addConfigureArgs('-DLIBUV_BUILD_SHARED=OFF')
->addConfigureArgs('-DLIBUV_BUILD_SHARED=' . (getenv('SPC_LINK_STATIC') ? 'OFF' : 'ON'))
->build();
// patch pkgconfig
$this->patchPkgconfPrefix(['libuv-static.pc']);

View File

@@ -6,10 +6,29 @@ namespace SPC\builder\unix\library;
use SPC\builder\linux\library\LinuxLibraryBase;
use SPC\store\FileSystem;
use SPC\toolchain\ToolchainManager;
use SPC\toolchain\ZigToolchain;
use SPC\util\executor\UnixCMakeExecutor;
trait libxml2
{
public function patchBeforeBuild(): bool
{
if (ToolchainManager::getToolchainClass() !== ZigToolchain::class) {
return false;
}
$patched = (bool) FileSystem::replaceFileStr(
$this->source_dir . '/configure.ac',
'AX_APPEND_FLAG([-Wl,--version-script=], [VERSION_SCRIPT_FLAGS])',
'',
);
return $patched || FileSystem::replaceFileStr(
$this->source_dir . '/CMakeLists.txt',
'target_link_options(LibXml2 PRIVATE "LINKER:--version-script=${CMAKE_CURRENT_SOURCE_DIR}/libxml2.syms")',
'',
);
}
public function build(): void
{
$cmake = UnixCMakeExecutor::create($this)
@@ -20,7 +39,6 @@ trait libxml2
"-DZLIB_INCLUDE_DIR={$this->getIncludeDir()}",
'-DLIBXML2_WITH_ZLIB=OFF',
)
->optionalLib('xz', ...cmake_boolean_args('LIBXML2_WITH_LZMA'))
->addConfigureArgs(
'-DLIBXML2_WITH_ICONV=ON',
'-DLIBXML2_WITH_ICU=OFF', // optional, but discouraged: https://gitlab.gnome.org/GNOME/libxml2/-/blob/master/README.md

View File

@@ -13,7 +13,7 @@ trait mimalloc
{
$cmake = UnixCMakeExecutor::create($this)
->addConfigureArgs(
'-DMI_BUILD_SHARED=OFF',
'-DMI_BUILD_SHARED=' . (getenv('SPC_LINK_STATIC') ? 'OFF' : 'ON'),
'-DMI_BUILD_OBJECT=OFF',
'-DMI_INSTALL_TOPLEVEL=ON',
);

View File

@@ -10,29 +10,13 @@ use SPC\util\SPCTarget;
trait ncurses
{
public function patchBeforeBuild(): bool
{
// MKlib_gen.sh feeds preprocessor stdout through a sed/awk pipeline into lib_gen.c.
// zig-cc/clang leaks the "N warning(s) generated." summary onto stdout (not stderr),
// and that line ends up as invalid C in the generated source. Filter it out of the pipe.
$mklibGen = $this->source_dir . '/ncurses/base/MKlib_gen.sh';
if (!str_contains((string) file_get_contents($mklibGen), "| grep -v ' generated")) {
FileSystem::replaceFileStr(
$mklibGen,
'$preprocessor $TMP 2>/dev/null \\',
"\$preprocessor \$TMP 2>/dev/null \\\n| grep -v ' generated\\.\$' \\",
);
}
return true;
}
protected function build(): void
{
$filelist = FileSystem::scanDirFiles(BUILD_BIN_PATH, relative: true);
UnixAutoconfExecutor::create($this)
->appendEnv([
'CFLAGS' => '-std=c17 -w',
'CFLAGS' => '-std=c17',
'LDFLAGS' => SPCTarget::isStatic() ? '-static' : '',
])
->configure(

View File

@@ -12,6 +12,9 @@ trait postgresql
{
public function patchBeforeBuild(): bool
{
if (!getenv('SPC_LINK_STATIC')) {
return false;
}
// skip the test on platforms where libpq infrastructure may be provided by statically-linked libraries
FileSystem::replaceFileStr("{$this->source_dir}/src/interfaces/libpq/Makefile", 'invokes exit\'; exit 1;', 'invokes exit\';');
// disable shared libs build
@@ -92,10 +95,11 @@ trait postgresql
->exec('make -C src/interfaces/libpq install');
// remove dynamic libs
shell()->cd($this->source_dir . '/build')
->exec("rm -rf {$this->getBuildRootPath()}/lib/*.so*")
->exec("rm -rf {$this->getBuildRootPath()}/lib/*.dylib");
if (getenv('SPC_LINK_STATIC')) {
shell()->cd($this->source_dir . '/build')
->exec("rm -rf {$this->getBuildRootPath()}/lib/*.so*")
->exec("rm -rf {$this->getBuildRootPath()}/lib/*.dylib");
}
FileSystem::replaceFileStr("{$this->getLibDir()}/pkgconfig/libpq.pc", '-lldap', '-lldap -llber');
}
}

View File

@@ -14,8 +14,6 @@ trait qdbm
{
$ac = UnixAutoconfExecutor::create($this)->configure();
FileSystem::replaceFileRegex($this->source_dir . '/Makefile', '/MYLIBS = libqdbm.a.*/m', 'MYLIBS = libqdbm.a');
$extra = trim((string) getenv('SPC_DEFAULT_C_FLAGS'));
FileSystem::replaceFileRegex($this->source_dir . '/Makefile', '/^CFLAGS = .*$/m', "CFLAGS = -Wall {$extra}");
$ac->make($this instanceof MacOSLibraryBase ? 'mac' : '');
$this->patchPkgconfPrefix(['qdbm.pc']);
}

View File

@@ -14,7 +14,7 @@ trait tidy
->setBuildDir("{$this->source_dir}/build-dir")
->addConfigureArgs(
'-DSUPPORT_CONSOLE_APP=OFF',
'-DBUILD_SHARED_LIB=OFF'
'-DBUILD_SHARED_LIB=' . (getenv('SPC_LINK_STATIC') ? 'OFF' : 'ON')
);
if (version_compare(get_cmake_version(), '4.0.0', '>=')) {
$cmake->addConfigureArgs('-DCMAKE_POLICY_VERSION_MINIMUM=3.5');

View File

@@ -5,7 +5,6 @@ declare(strict_types=1);
namespace SPC\builder\unix\library;
use SPC\exception\WrongUsageException;
use SPC\store\FileSystem;
use SPC\util\executor\UnixAutoconfExecutor;
trait unixodbc
@@ -21,15 +20,7 @@ trait unixodbc
'Linux' => '/etc',
default => throw new WrongUsageException('Unsupported OS: ' . PHP_OS_FAMILY),
};
// libltdl is incompatible with -flto (https://bugs.gentoo.org/532672)
$stripLto = static fn ($s) => preg_replace('/(^|\s)-flto(=\S+)?(?=\s|$)/', ' ', (string) $s);
$origC = $this->builder->arch_c_flags;
$origCxx = $this->builder->arch_cxx_flags;
$origLd = $this->builder->arch_ld_flags;
$this->builder->arch_c_flags = clean_spaces($stripLto($origC));
$this->builder->arch_cxx_flags = clean_spaces($stripLto($origCxx));
$this->builder->arch_ld_flags = clean_spaces($stripLto($origLd));
$make = UnixAutoconfExecutor::create($this)
UnixAutoconfExecutor::create($this)
->configure(
'--disable-debug',
'--disable-dependency-tracking',
@@ -37,27 +28,9 @@ trait unixodbc
'--with-included-ltdl',
"--sysconfdir={$sysconf_selector}",
'--enable-gui=no',
);
file_put_contents(
"{$this->source_dir}/exe/Makefile",
".PHONY: all install clean check distclean install-strip\nall install clean check distclean install-strip:\n\t@true\n",
);
$make->make();
$this->builder->arch_c_flags = $origC;
$this->builder->arch_cxx_flags = $origCxx;
$this->builder->arch_ld_flags = $origLd;
$pkgConfigs = ['odbc.pc', 'odbccr.pc', 'odbcinst.pc'];
$this->patchPkgconfPrefix($pkgConfigs);
foreach ($pkgConfigs as $file) {
FileSystem::replaceFileStr(
BUILD_LIB_PATH . "/pkgconfig/{$file}",
'$(top_build_prefix)libltdl/libltdlc.la',
''
);
}
)
->make();
$this->patchPkgconfPrefix(['odbc.pc', 'odbccr.pc', 'odbcinst.pc']);
$this->patchLaDependencyPrefix();
}
}

View File

@@ -10,7 +10,14 @@ trait xz
{
public function build(): void
{
UnixAutoconfExecutor::create($this)
$make = UnixAutoconfExecutor::create($this);
if (!getenv('SPC_LINK_STATIC')) {
// liblzma can only build one of static or shared at a time
$make
->removeConfigureArgs('--enable-static')
->addConfigureArgs('--disable-static');
}
$make
->configure(
'--disable-scripts',
'--disable-doc',

View File

@@ -10,7 +10,8 @@ trait zlib
{
protected function build(): void
{
UnixAutoconfExecutor::create($this)->exec("./configure --static --prefix={$this->getBuildRootPath()}")->make();
$static = getenv('SPC_LINK_STATIC') ? '--static' : '';
UnixAutoconfExecutor::create($this)->exec("./configure {$static} --prefix={$this->getBuildRootPath()}")->make();
$this->patchPkgconfPrefix(['zlib.pc']);
}
}

View File

@@ -14,9 +14,9 @@ trait zstd
->setBuildDir("{$this->source_dir}/build/cmake/build")
->addConfigureArgs(
'-DZSTD_BUILD_STATIC=ON',
'-DZSTD_BUILD_SHARED=OFF',
'-DZSTD_BUILD_SHARED=' . (getenv('SPC_LINK_STATIC') ? 'OFF' : 'ON'),
)
->build();
$this->patchPkgconfPrefix(['libzstd.pc']);
$this->patchPkgconfPrefix();
}
}

View File

@@ -1,36 +0,0 @@
<?php
declare(strict_types=1);
namespace SPC\builder\windows\library;
use SPC\store\FileSystem;
class brotli extends WindowsLibraryBase
{
public const NAME = 'brotli';
protected function build(): void
{
// reset cmake
FileSystem::resetDir($this->source_dir . '\build');
// start build
cmd()->cd($this->source_dir)
->execWithWrapper(
$this->builder->makeSimpleWrapper('cmake'),
'-B build ' .
'-A x64 ' .
"-DCMAKE_TOOLCHAIN_FILE={$this->builder->cmake_toolchain_file} " .
'-DCMAKE_BUILD_TYPE=Release ' .
'-DBUILD_SHARED_LIBS=OFF ' .
'-DBROTLI_BUILD_TOOLS=OFF ' .
'-DBROTLI_BUNDLED_MODE=OFF ' .
'-DCMAKE_INSTALL_PREFIX=' . BUILD_ROOT_PATH . ' '
)
->execWithWrapper(
$this->builder->makeSimpleWrapper('cmake'),
"--build build --config Release --target install -j{$this->builder->concurrency}"
);
}
}

View File

@@ -24,8 +24,6 @@ class freetype extends WindowsLibraryBase
"-DCMAKE_TOOLCHAIN_FILE={$this->builder->cmake_toolchain_file} " .
'-DCMAKE_BUILD_TYPE=Release ' .
'-DBUILD_SHARED_LIBS=OFF ' .
'-DFT_DISABLE_BROTLI=TRUE ' .
'-DFT_DISABLE_BZIP2=TRUE ' .
'-DCMAKE_INSTALL_PREFIX=' . BUILD_ROOT_PATH . ' '
)
->execWithWrapper(

View File

@@ -12,16 +12,16 @@ class icu_static_win extends WindowsLibraryBase
protected function build(): void
{
copy("{$this->source_dir}\\lib\\icudt.lib", "{$this->getLibDir()}\\icudt.lib");
copy("{$this->source_dir}\\lib\\icuin.lib", "{$this->getLibDir()}\\icuin.lib");
copy("{$this->source_dir}\\lib\\icuio.lib", "{$this->getLibDir()}\\icuio.lib");
copy("{$this->source_dir}\\lib\\icuuc.lib", "{$this->getLibDir()}\\icuuc.lib");
copy("{$this->source_dir}\\x64-windows-static\\lib\\icudt.lib", "{$this->getLibDir()}\\icudt.lib");
copy("{$this->source_dir}\\x64-windows-static\\lib\\icuin.lib", "{$this->getLibDir()}\\icuin.lib");
copy("{$this->source_dir}\\x64-windows-static\\lib\\icuio.lib", "{$this->getLibDir()}\\icuio.lib");
copy("{$this->source_dir}\\x64-windows-static\\lib\\icuuc.lib", "{$this->getLibDir()}\\icuuc.lib");
// create libpq folder in buildroot/includes/libpq
if (!file_exists("{$this->getIncludeDir()}\\unicode")) {
mkdir("{$this->getIncludeDir()}\\unicode");
}
FileSystem::copyDir("{$this->source_dir}\\include\\unicode", "{$this->getIncludeDir()}\\unicode");
FileSystem::copyDir("{$this->source_dir}\\x64-windows-static\\include\\unicode", "{$this->getIncludeDir()}\\unicode");
}
}

View File

@@ -1,41 +0,0 @@
<?php
declare(strict_types=1);
namespace SPC\builder\windows\library;
use SPC\store\FileSystem;
class libaom extends WindowsLibraryBase
{
public const NAME = 'libaom';
protected function build(): void
{
// libaom source tree contains a build/cmake/ directory with its own
// cmake modules, so we must use a different name for the build dir.
FileSystem::resetDir($this->source_dir . '\builddir');
// start build
cmd()->cd($this->source_dir)
->execWithWrapper(
$this->builder->makeSimpleWrapper('cmake'),
'-S . -B builddir ' .
'-A x64 ' .
"-DCMAKE_TOOLCHAIN_FILE={$this->builder->cmake_toolchain_file} " .
'-DCMAKE_BUILD_TYPE=Release ' .
'-DBUILD_SHARED_LIBS=OFF ' .
'-DAOM_TARGET_CPU=generic ' .
'-DENABLE_DOCS=OFF ' .
'-DENABLE_EXAMPLES=OFF ' .
'-DENABLE_TESTDATA=OFF ' .
'-DENABLE_TESTS=OFF ' .
'-DENABLE_TOOLS=OFF ' .
'-DCMAKE_INSTALL_PREFIX=' . BUILD_ROOT_PATH . ' '
)
->execWithWrapper(
$this->builder->makeSimpleWrapper('cmake'),
"--build builddir --config Release --target install -j{$this->builder->concurrency}"
);
}
}

View File

@@ -28,7 +28,6 @@ class libjpeg extends WindowsLibraryBase
'-DENABLE_STATIC=ON ' .
'-DBUILD_TESTING=OFF ' .
'-DWITH_JAVA=OFF ' .
'-DWITH_SIMD=OFF ' .
'-DWITH_CRT_DLL=OFF ' .
"-DENABLE_ZLIB_COMPRESSION={$zlib} " .
'-DCMAKE_INSTALL_PREFIX=' . BUILD_ROOT_PATH . ' '

View File

@@ -1,31 +0,0 @@
<?php
declare(strict_types=1);
namespace SPC\builder\windows\library;
class libmpdec extends WindowsLibraryBase
{
public const NAME = 'libmpdec';
protected function build(): void
{
$makefile_dir = $this->source_dir . '\libmpdec';
$nmake = $this->builder->makeSimpleWrapper('nmake /nologo');
cmd()->cd($makefile_dir)
->exec('copy /y Makefile.vc Makefile')
->execWithWrapper($nmake, 'clean')
->execWithWrapper($nmake, 'MACHINE=x64');
// Copy static lib (rename from versioned name to libmpdec_a.lib)
$libs = glob($makefile_dir . '\libmpdec-*.lib');
foreach ($libs as $lib) {
if (!str_contains($lib, '.dll.')) {
copy($lib, BUILD_LIB_PATH . '\libmpdec_a.lib');
break;
}
}
copy($makefile_dir . '\mpdecimal.h', BUILD_INCLUDE_PATH . '\mpdecimal.h');
}
}

View File

@@ -29,7 +29,6 @@ class ngtcp2 extends WindowsLibraryBase
'-DBUILD_SHARED_LIBS=OFF ' .
'-DENABLE_STATIC_CRT=ON ' .
'-DENABLE_LIB_ONLY=ON ' .
'-DENABLE_OPENSSL=OFF ' .
'-DCMAKE_INSTALL_PREFIX=' . BUILD_ROOT_PATH . ' '
)
->execWithWrapper(

View File

@@ -33,7 +33,6 @@ class openssl extends WindowsLibraryBase
->execWithWrapper(
$this->builder->makeSimpleWrapper($this->perl),
'Configure zlib VC-WIN64A ' .
'no-shared ' .
'--prefix=' . quote(BUILD_ROOT_PATH) . ' ' .
'--with-zlib-lib=' . quote(BUILD_LIB_PATH) . ' ' .
'--with-zlib-include=' . quote(BUILD_INCLUDE_PATH) . ' ' .

View File

@@ -10,9 +10,9 @@ class postgresql_win extends WindowsLibraryBase
protected function build(): void
{
copy($this->source_dir . '\lib\libpq.lib', BUILD_LIB_PATH . '\libpq.lib');
copy($this->source_dir . '\lib\libpgport.lib', BUILD_LIB_PATH . '\libpgport.lib');
copy($this->source_dir . '\lib\libpgcommon.lib', BUILD_LIB_PATH . '\libpgcommon.lib');
copy($this->source_dir . '\pgsql\lib\libpq.lib', BUILD_LIB_PATH . '\libpq.lib');
copy($this->source_dir . '\pgsql\lib\libpgport.lib', BUILD_LIB_PATH . '\libpgport.lib');
copy($this->source_dir . '\pgsql\lib\libpgcommon.lib', BUILD_LIB_PATH . '\libpgcommon.lib');
// create libpq folder in buildroot/includes/libpq
if (!file_exists(BUILD_INCLUDE_PATH . '\libpq')) {
@@ -21,7 +21,7 @@ class postgresql_win extends WindowsLibraryBase
$headerFiles = ['libpq-fe.h', 'postgres_ext.h', 'pg_config_ext.h', 'libpq\libpq-fs.h'];
foreach ($headerFiles as $header) {
copy($this->source_dir . '\include\\' . $header, BUILD_INCLUDE_PATH . '\\' . $header);
copy($this->source_dir . '\pgsql\include\\' . $header, BUILD_INCLUDE_PATH . '\\' . $header);
}
}
}

View File

@@ -31,24 +31,8 @@ class zlib extends WindowsLibraryBase
$this->builder->makeSimpleWrapper('cmake'),
"--build build --config Release --target install -j{$this->builder->concurrency}"
);
$detect_list = [
'zlibstatic.lib',
'zs.lib',
'libzs.lib',
'libz.lib',
];
foreach ($detect_list as $item) {
if (file_exists(BUILD_LIB_PATH . '\\' . $item)) {
FileSystem::copy(BUILD_LIB_PATH . '\\' . $item, BUILD_LIB_PATH . '\zlib_a.lib');
FileSystem::copy(BUILD_LIB_PATH . '\\' . $item, BUILD_LIB_PATH . '\zlibstatic.lib');
break;
}
}
FileSystem::removeFileIfExists(BUILD_ROOT_PATH . '\bin\zlib.dll');
FileSystem::removeFileIfExists(BUILD_LIB_PATH . '\zlib.lib');
FileSystem::removeFileIfExists(BUILD_LIB_PATH . '\libz.dll');
FileSystem::removeFileIfExists(BUILD_LIB_PATH . '\libz.lib');
FileSystem::removeFileIfExists(BUILD_LIB_PATH . '\z.lib');
FileSystem::removeFileIfExists(BUILD_LIB_PATH . '\z.dll');
copy(BUILD_LIB_PATH . '\zlibstatic.lib', BUILD_LIB_PATH . '\zlib_a.lib');
unlink(BUILD_ROOT_PATH . '\bin\zlib.dll');
unlink(BUILD_LIB_PATH . '\zlib.lib');
}
}

View File

@@ -19,7 +19,7 @@ class BuildLibsCommand extends BuildCommand
{
$this->addArgument('libraries', InputArgument::REQUIRED, 'The libraries will be compiled, comma separated');
$this->addOption('clean', null, null, 'Clean old download cache and source before fetch');
$this->addOption('all', 'A', null, 'Build all libs that static-php-cli has');
$this->addOption('all', 'A', null, 'Build all libs that static-php-cli needed');
}
public function initialize(InputInterface $input, OutputInterface $output): void

View File

@@ -39,7 +39,6 @@ class BuildPHPCommand extends BuildCommand
$this->addOption('disable-opcache-jit', null, null, 'disable opcache jit');
$this->addOption('with-config-file-path', null, InputOption::VALUE_REQUIRED, 'Set the path in which to look for php.ini', $isWindows ? null : '/usr/local/etc/php');
$this->addOption('with-config-file-scan-dir', null, InputOption::VALUE_REQUIRED, 'Set the directory to scan for .ini files after reading php.ini', $isWindows ? null : '/usr/local/etc/php/conf.d');
$this->addOption('with-sysconfdir', null, InputOption::VALUE_REQUIRED, 'Set the sysconfdir (e.g. /etc/php-zts) used by configure (not available on Windows)');
$this->addOption('with-hardcoded-ini', 'I', InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED, 'Patch PHP source code, inject hardcoded INI');
$this->addOption('with-micro-fake-cli', null, null, 'Let phpmicro\'s PHP_SAPI use "cli" instead of "micro"');
$this->addOption('with-suggested-libs', 'L', null, 'Build with suggested libs for selected exts and libs');
@@ -50,9 +49,6 @@ class BuildPHPCommand extends BuildCommand
$this->addOption('with-micro-logo', null, InputOption::VALUE_REQUIRED, 'Use custom .ico for micro.sfx (windows only)');
$this->addOption('enable-micro-win32', null, null, 'Enable win32 mode for phpmicro (Windows only)');
$this->addOption('with-frankenphp-app', null, InputOption::VALUE_REQUIRED, 'Path to a folder to be embedded in FrankenPHP');
$this->addOption('pgi', null, null, 'Build instrumented binaries (-fprofile-generate). Run them to collect .profraw files, then re-run with --pgo.');
$this->addOption('cs-pgi', null, null, 'Build cs-instrumented binaries (-fprofile-use=<existing.profdata> -fcs-profile-generate). Requires a prior --pgi+--pgo cycle.');
$this->addOption('pgo', null, null, 'Build optimised binaries (-fprofile-use) from .profraw collected by a previous --pgi run.');
}
public function handle(): int
@@ -181,7 +177,7 @@ class BuildPHPCommand extends BuildCommand
// compile libraries
$builder->proveLibs($libraries);
// check extensions
$builder->proveExts($static_extensions, $shared_extensions, build_target: $rule);
$builder->proveExts($static_extensions, $shared_extensions);
// validate libs and extensions
$builder->validateLibsAndExts();
@@ -214,8 +210,9 @@ class BuildPHPCommand extends BuildCommand
// clean old modules that may conflict with the new php build
FileSystem::removeDir(BUILD_MODULES_PATH);
// start to build
$builder->buildPHP($rule);
$builder->testPHP($rule);
// compile stopwatch :P

View File

@@ -10,7 +10,6 @@ use SPC\store\pkg\Zig;
use SPC\toolchain\ToolchainManager;
use SPC\toolchain\ZigToolchain;
use SPC\util\ConfigValidator;
use SPC\util\DependencyUtil;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Process\Process;
@@ -20,10 +19,6 @@ class CraftCommand extends BuildCommand
public function configure(): void
{
$this->addArgument('craft', null, 'Path to craft.yml file', WORKING_DIR . '/craft.yml');
$this->addOption('pgi', null, null, 'Forward --pgi to the inner build (instrumented binaries).');
$this->addOption('cs-pgi', null, null, 'Forward --cs-pgi to the inner build (cs-instrumented binaries).');
$this->addOption('pgo', null, null, 'Forward --pgo to the inner build (use collected profile data).');
$this->addOption('libs-only', null, null, 'Build only the libraries needed by the configured exts (skip PHP and extension build).');
}
public function handle(): int
@@ -108,38 +103,12 @@ class CraftCommand extends BuildCommand
// craft build
if ($craft['craft-options']['build']) {
if ($this->getOption('libs-only')) {
$exts = array_merge($craft['extensions'], $craft['shared-extensions'] ?? []);
$include_suggested_exts = (bool) ($craft['build-options']['with-suggested-exts'] ?? false);
$include_suggested_libs = (bool) ($craft['build-options']['with-suggested-libs'] ?? false);
[, $needed_libs] = DependencyUtil::getExtsAndLibs(
$exts,
$craft['libs'],
$include_suggested_exts,
$include_suggested_libs,
);
if ($needed_libs === []) {
$this->output->writeln('<comment>No libs needed for the configured extensions; skipping build:libs.</comment>');
} else {
$retcode = $this->runCommand('build:libs', implode(',', $needed_libs));
if ($retcode !== 0) {
$this->output->writeln('<error>craft build:libs failed</error>');
return static::FAILURE;
}
}
} else {
$args = [$static_extensions, "--with-libs={$libs}", "--build-shared={$shared_extensions}", ...array_map(fn ($x) => "--build-{$x}", $craft['sapi'])];
$this->optionsToArguments($craft['build-options'], $args);
foreach (['pgi', 'cs-pgi', 'pgo'] as $pgoFlag) {
if ($this->getOption($pgoFlag)) {
$args[] = "--{$pgoFlag}";
}
}
$retcode = $this->runCommand('build', ...$args);
if ($retcode !== 0) {
$this->output->writeln('<error>craft build failed</error>');
return static::FAILURE;
}
$args = [$static_extensions, "--with-libs={$libs}", "--build-shared={$shared_extensions}", ...array_map(fn ($x) => "--build-{$x}", $craft['sapi'])];
$this->optionsToArguments($craft['build-options'], $args);
$retcode = $this->runCommand('build', ...$args);
if ($retcode !== 0) {
$this->output->writeln('<error>craft build failed</error>');
return static::FAILURE;
}
}

View File

@@ -30,7 +30,7 @@ class DownloadCommand extends BaseCommand
$this->addArgument('sources', InputArgument::REQUIRED, 'The sources will be compiled, comma separated');
$this->addOption('shallow-clone', null, null, 'Clone shallow');
$this->addOption('with-openssl11', null, null, 'Use openssl 1.1');
$this->addOption('with-php', null, InputOption::VALUE_REQUIRED, 'version in major.minor format (default 8.5)', '8.5');
$this->addOption('with-php', null, InputOption::VALUE_REQUIRED, 'version in major.minor format (default 8.4)', '8.4');
$this->addOption('clean', null, null, 'Clean old download cache and source before fetch');
$this->addOption('all', 'A', null, 'Fetch all sources that static-php-cli needed');
$this->addOption('custom-url', 'U', InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED, 'Specify custom source download url, e.g "php-src:https://downloads.php.net/~eric/php-8.3.0beta1.tar.gz"');

View File

@@ -39,7 +39,6 @@ class SPCConfigCommand extends BaseCommand
$util = new SPCConfigUtil(options: [
'no_php' => $this->getOption('no-php'),
'libs_only_deps' => $this->getOption('libs-only-deps'),
'absolute_libs' => $this->getOption('absolute-libs'),
]);
$config = $util->config($extensions, $libraries, $include_suggest_ext, $include_suggest_lib);

View File

@@ -74,10 +74,9 @@ class LinuxMuslCheck
SourcePatcher::patchFile('musl-1.2.5_CVE-2025-26519_0002.patch', SOURCE_PATH . "/{$musl_version_name}");
logger()->info('Installing musl wrapper');
shell()->cd(SOURCE_PATH . "/{$musl_version_name}")
->setEnv(['CC' => 'gcc', 'CXX' => 'g++', 'AR' => 'ar', 'LD' => 'ld', 'RANLIB' => 'ranlib'])
->exec('./configure --disable-gcc-wrapper')
->exec('make -j')
->exec("{$prefix}make install");
->exec('CC=gcc CXX=g++ AR=ar LD=ld ./configure --disable-gcc-wrapper')
->exec('CC=gcc CXX=g++ AR=ar LD=ld make -j')
->exec("CC=gcc CXX=g++ AR=ar LD=ld {$prefix}make install");
// TODO: add path using putenv instead of editing /etc/profile
return true;
}

View File

@@ -109,7 +109,7 @@ class LinuxToolCheckList
public function fixBuildTools(array $distro, array $missing): bool
{
$install_cmd = match ($distro['dist']) {
'ubuntu', 'debian', 'linuxmint', 'Deepin' => 'apt-get install -y',
'ubuntu', 'debian', 'Deepin' => 'apt-get install -y',
'alpine' => 'apk add',
'redhat' => 'dnf install -y',
'centos' => 'yum install -y',

View File

@@ -98,50 +98,31 @@ class Downloader
{
logger()->debug("finding {$name} source from github {$type} tarball");
$source['query'] ??= '';
$data = json_decode(self::curlExec(
url: "https://api.github.com/repos/{$source['repo']}/{$type}{$source['query']}",
hooks: [[CurlHook::class, 'setupGithubToken']],
retries: self::getRetryAttempts()
), true, 512, JSON_THROW_ON_ERROR);
// Use /releases/latest when possible: it returns the semantically latest stable
// release regardless of publish order, avoiding issues with concurrent release branches.
if ($type === 'releases' && empty($source['query']) && !($source['match'] ?? null)) {
$data = json_decode(self::curlExec(
url: "https://api.github.com/repos/{$source['repo']}/releases/latest",
hooks: [[CurlHook::class, 'setupGithubToken']],
retries: self::getRetryAttempts()
), true, 512, JSON_THROW_ON_ERROR);
if (!is_array($data) || empty($data['tarball_url'])) {
throw new DownloaderException("failed to find {$name} source");
$url = null;
foreach ($data as $rel) {
if (($rel['prerelease'] ?? false) === true && ($source['prefer-stable'] ?? false)) {
continue;
}
$url = $data['tarball_url'];
$version = $data['tag_name'] ?? $data['name'] ?? null;
} else {
$data = json_decode(self::curlExec(
url: "https://api.github.com/repos/{$source['repo']}/{$type}{$source['query']}",
hooks: [[CurlHook::class, 'setupGithubToken']],
retries: self::getRetryAttempts()
), true, 512, JSON_THROW_ON_ERROR);
$url = null;
$version = null;
foreach ($data as $rel) {
if (($rel['prerelease'] ?? false) === true && ($source['prefer-stable'] ?? false)) {
continue;
}
if (($rel['draft'] ?? false) === true && (($source['prefer-stable'] ?? false) || !$rel['tarball_url'])) {
continue;
}
if (!($source['match'] ?? null)) {
$url = $rel['tarball_url'] ?? null;
$version = $rel['tag_name'] ?? $rel['name'] ?? null;
break;
}
if (preg_match('|' . $source['match'] . '|', $rel['tarball_url'])) {
$url = $rel['tarball_url'];
$version = $rel['tag_name'] ?? $rel['name'] ?? null;
break;
}
if (($rel['draft'] ?? false) === true && (($source['prefer-stable'] ?? false) || !$rel['tarball_url'])) {
continue;
}
if (!$url) {
throw new DownloaderException("failed to find {$name} source");
if (!($source['match'] ?? null)) {
$url = $rel['tarball_url'] ?? null;
break;
}
if (preg_match('|' . $source['match'] . '|', $rel['tarball_url'])) {
$url = $rel['tarball_url'];
break;
}
}
if (!$url) {
throw new DownloaderException("failed to find {$name} source");
}
$headers = self::curlExec(
url: $url,
@@ -153,7 +134,7 @@ class Downloader
if ($matches) {
$filename = $matches['filename'];
} else {
$filename = "{$name}-" . ($version ?? 'latest') . '.tar.gz';
$filename = "{$name}-" . ($type === 'releases' ? $data['tag_name'] : $data['name']) . '.tar.gz';
}
return [$url, $filename];

View File

@@ -152,7 +152,7 @@ class FileSystem
$src_path = FileSystem::convertPath($from);
switch (PHP_OS_FAMILY) {
case 'Windows':
f_passthru('xcopy "' . $src_path . '" "' . $dst_path . '" /s/e/y/i');
f_passthru('xcopy "' . $src_path . '" "' . $dst_path . '" /s/e/v/y/i');
break;
case 'Linux':
case 'Darwin':

View File

@@ -95,10 +95,6 @@ class SourcePatcher
// patch php-src/build/php.m4 PKG_CHECK_MODULES -> PKG_CHECK_MODULES_STATIC
FileSystem::replaceFileStr(SOURCE_PATH . '/php-src/build/php.m4', 'PKG_CHECK_MODULES(', 'PKG_CHECK_MODULES_STATIC(');
if ($builder->getPHPVersionID() >= 80300 && $builder->getPHPVersionID() < 80400) {
self::patchFile('spc_fix_avx512_cache_before_80400.patch', SOURCE_PATH . '/php-src');
}
if ($builder->getOption('enable-micro-win32')) {
self::patchMicroWin32();
} else {
@@ -129,31 +125,6 @@ class SourcePatcher
FileSystem::replaceFileRegex(SOURCE_PATH . '/php-src/configure', '/have_capstone="yes"/', 'have_capstone="no"');
}
// PHP 8.2 and below: bcmath libbcmath uses K&R style C function
if (is_unix() && $builder->getPHPVersionID() < 80300) {
FileSystem::replaceFileStr(
SOURCE_PATH . '/php-src/configure',
"for ac_arg in '' -std=gnu23",
"for ac_arg in '' -std=gnu17",
);
}
// strip our build-time env vars from phpinfo's "Configure Command" ('|' delimiter: PHP_BUILD_PROVIDER may contain '#')
if (is_unix()) {
FileSystem::replaceFileStr(
SOURCE_PATH . '/php-src/configure',
'for var in CFLAGS CXXFLAGS CPPFLAGS LDFLAGS EXTRA_LDFLAGS_PROGRAM LIBS CC CXX; do',
'for var in CFLAGS CXXFLAGS CPPFLAGS LDFLAGS EXTRA_LDFLAGS_PROGRAM LIBS CC CXX '
. 'PKG_CONFIG PKG_CONFIG_PATH EXTENSION_DIR OPENSSL_LIBS '
. 'PHP_BUILD_SYSTEM PHP_BUILD_PROVIDER PHP_BUILD_COMPILER PHP_BUILD_ARCH; do',
);
FileSystem::replaceFileStr(
SOURCE_PATH . '/php-src/configure',
'clean_configure_args=$(echo $clean_configure_args | $SED -e "s#\'$var=$val\'##")',
'clean_configure_args=$(echo $clean_configure_args | $SED -e "s|\'$var=$val\'||")',
);
}
if (file_exists(SOURCE_PATH . '/php-src/configure.ac.bak')) {
// restore configure.ac
FileSystem::restoreBackupFile(SOURCE_PATH . '/php-src/configure.ac');
@@ -346,6 +317,20 @@ class SourcePatcher
logger()->info("Library [{$lib->getName()}] patched before make");
}
}
if (str_contains((string) getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS'), '-release')) {
FileSystem::replaceFileLineContainsString(
SOURCE_PATH . '/php-src/ext/standard/info.c',
'#ifdef CONFIGURE_COMMAND',
'#ifdef NO_CONFIGURE_COMMAND',
);
} else {
FileSystem::replaceFileLineContainsString(
SOURCE_PATH . '/php-src/ext/standard/info.c',
'#ifdef NO_CONFIGURE_COMMAND',
'#ifdef CONFIGURE_COMMAND',
);
}
}
public static function patchHardcodedINI(array $ini = []): bool
@@ -649,13 +634,7 @@ class SourcePatcher
FileSystem::replaceFileStr(SOURCE_PATH . '/php-src/ext/gd/libgd/gdft.c', '#ifndef MSWIN32', '#ifndef _WIN32');
}
// custom config.w32, because official config.w32 is hard-coded many things
if ($ver_id >= 80500) {
$origin = file_get_contents(ROOT_DIR . '/src/globals/extra/gd_config_85.w32');
} elseif ($ver_id >= 80100) {
$origin = file_get_contents(ROOT_DIR . '/src/globals/extra/gd_config_81.w32');
} else {
$origin = file_get_contents(ROOT_DIR . '/src/globals/extra/gd_config_80.w32');
}
$origin = $ver_id >= 80100 ? file_get_contents(ROOT_DIR . '/src/globals/extra/gd_config_81.w32') : file_get_contents(ROOT_DIR . '/src/globals/extra/gd_config_80.w32');
file_put_contents(SOURCE_PATH . '/php-src/ext/gd/config.w32.bak', file_get_contents(SOURCE_PATH . '/php-src/ext/gd/config.w32'));
return file_put_contents(SOURCE_PATH . '/php-src/ext/gd/config.w32', $origin) !== false;
}

View File

@@ -85,7 +85,7 @@ class GoXcaddy extends CustomPackage
'GOBIN' => "{$pkgroot}/go-xcaddy/bin",
'GOPATH' => "{$pkgroot}/go",
])
->exec('CGO_ENABLED=0 go install github.com/caddyserver/xcaddy/cmd/xcaddy@master');
->exec('CC=cc go install github.com/caddyserver/xcaddy/cmd/xcaddy@latest');
}
public static function getEnvironment(): array

View File

@@ -116,17 +116,18 @@ class Zig extends CustomPackage
break;
}
}
if (!$all_exist) {
$lock = json_decode(FileSystem::readFile(LockFile::LOCK_FILE), true);
$source_type = $lock[$name]['source_type'];
$filename = DOWNLOAD_PATH . '/' . ($lock[$name]['filename'] ?? $lock[$name]['dirname']);
$extract = "{$pkgroot}/zig";
FileSystem::extractPackage($name, $source_type, $filename, $extract);
$this->createZigCcScript($zig_bin_dir);
if ($all_exist) {
return;
}
$this->buildClangRuntimeBits($zig_bin_dir);
$lock = json_decode(FileSystem::readFile(LockFile::LOCK_FILE), true);
$source_type = $lock[$name]['source_type'];
$filename = DOWNLOAD_PATH . '/' . ($lock[$name]['filename'] ?? $lock[$name]['dirname']);
$extract = "{$pkgroot}/zig";
FileSystem::extractPackage($name, $source_type, $filename, $extract);
$this->createZigCcScript($zig_bin_dir);
}
public static function getEnvironment(): array
@@ -139,185 +140,6 @@ class Zig extends CustomPackage
return PKG_ROOT_PATH . '/zig';
}
/**
* Build the bits of clang's runtime that zig 0.16 doesn't ship: the
* profile runtime (so -fprofile-generate actually emits .profraw) and
* crtbegin.o/crtend.o (so shared libraries get __dso_handle and the
* __cxa_finalize atexit hook).
*
* Build from 2mb compiler-rt-<llvm>.src tar
* to avoid downloading 2gb full prebuilt tarball.
*/
private function buildClangRuntimeBits(string $zig_bin_dir): void
{
if (PHP_OS_FAMILY !== 'Linux') {
return;
}
$libDir = "{$zig_bin_dir}/lib";
$profileLib = "{$libDir}/libclang_rt.profile.a";
$crtBegin = "{$libDir}/clang_rt.crtbegin.o";
$crtEnd = "{$libDir}/clang_rt.crtend.o";
$cpuModelLib = "{$libDir}/libclang_rt.cpu_model.a";
if (file_exists($profileLib) && file_exists($crtBegin) && file_exists($crtEnd) && file_exists($cpuModelLib)) {
return;
}
$zig = "{$zig_bin_dir}/zig";
$verLine = trim((string) shell_exec(escapeshellarg($zig) . ' cc --version 2>/dev/null'));
if (!preg_match('/clang version (\d+\.\d+\.\d+)/', $verLine, $m)) {
logger()->warning('[zig] could not detect bundled clang version; skipping runtime bit build (--pgo + shared libs without __dso_handle)');
return;
}
$llvmVersion = $m[1];
logger()->info("Building clang runtime bits for LLVM {$llvmVersion} (zig's bundled clang)");
$srcRoot = $this->fetchCompilerRtSource($llvmVersion);
if ($srcRoot === null) {
return;
}
f_mkdir($libDir, recursive: true);
if (!file_exists($profileLib)) {
$this->buildProfileRuntime($zig, $srcRoot, $profileLib);
}
if (!file_exists($crtBegin) || !file_exists($crtEnd)) {
$this->buildCrtObjects($zig, $srcRoot, $crtBegin, $crtEnd);
}
if (!file_exists($cpuModelLib)) {
$this->buildCpuModelBuiltins($zig, $srcRoot, $cpuModelLib);
}
FileSystem::removeDir($srcRoot);
}
private function buildCpuModelBuiltins(string $zig, string $srcRoot, string $libPath): void
{
$builtins = "{$srcRoot}/lib/builtins";
$arch = php_uname('m');
$cpuModelDir = "{$builtins}/cpu_model";
if (is_dir($cpuModelDir)) {
$src = match (true) {
in_array($arch, ['x86_64', 'amd64', 'i386', 'i686', 'x86'], true) => "{$cpuModelDir}/x86.c",
in_array($arch, ['aarch64', 'arm64'], true) => "{$cpuModelDir}/aarch64.c",
str_starts_with($arch, 'riscv') => "{$cpuModelDir}/riscv.c",
default => null,
};
$includes = '-I' . escapeshellarg($builtins) . ' -I' . escapeshellarg($cpuModelDir);
} else {
$src = "{$builtins}/cpu_model.c";
$includes = '-I' . escapeshellarg($builtins);
}
if ($src === null || !is_file($src)) {
logger()->warning("[zig] cpu_model source not found for arch {$arch} under {$builtins} — __builtin_cpu_supports/__cpu_model will be unresolved");
return;
}
$objDir = "{$srcRoot}/obj-cpu-model";
f_mkdir($objDir, recursive: true);
$obj = "{$objDir}/cpu_model.o";
$cflags = '-c -O2 -fPIC ' . $includes;
$cmd = escapeshellarg($zig) . ' cc ' . $cflags . ' -o ' . escapeshellarg($obj) . ' ' . escapeshellarg($src) . ' 2>&1';
if (!$this->runZigCmd($cmd, $obj, "failed to compile {$src}")) {
return;
}
$arCmd = escapeshellarg($zig) . ' ar rcs ' . escapeshellarg($libPath) . ' ' . escapeshellarg($obj) . ' 2>&1';
if (!$this->runZigCmd($arCmd, $libPath, 'zig ar failed for cpu_model')) {
return;
}
logger()->info('[zig] libclang_rt.cpu_model.a installed (' . filesize($libPath) . ' bytes)');
}
private function fetchCompilerRtSource(string $llvmVersion): ?string
{
$pkgName = "compiler-rt-{$llvmVersion}";
$tarball = "compiler-rt-{$llvmVersion}.src.tar.xz";
$url = "https://github.com/llvm/llvm-project/releases/download/llvmorg-{$llvmVersion}/{$tarball}";
try {
Downloader::downloadPackage($pkgName, [
'type' => 'url',
'url' => $url,
'filename' => $tarball,
]);
} catch (\Throwable $e) {
logger()->warning("[zig] failed to download {$tarball}: {$e->getMessage()}");
return null;
}
$srcRoot = PKG_ROOT_PATH . "/compiler-rt-src-{$llvmVersion}";
FileSystem::removeDir($srcRoot);
FileSystem::extractPackage($pkgName, SPC_SOURCE_ARCHIVE, DOWNLOAD_PATH . '/' . $tarball, $srcRoot);
return $srcRoot;
}
private function buildProfileRuntime(string $zig, string $srcRoot, string $libPath): void
{
$profileSrc = "{$srcRoot}/lib/profile";
$profileInc = "{$srcRoot}/include";
if (!is_dir($profileSrc)) {
logger()->warning("[zig] profile src dir missing at {$profileSrc} — --pgo will not work");
return;
}
$sources = array_merge(
glob("{$profileSrc}/*.c") ?: [],
glob("{$profileSrc}/*.cpp") ?: []
);
$skip = ['/PlatformAIX', '/PlatformDarwin', '/PlatformFuchsia', '/PlatformOther', '/PlatformWindows', '/WindowsMMap'];
$sources = array_filter($sources, function ($f) use ($skip) {
foreach ($skip as $s) {
if (str_contains($f, $s)) {
return false;
}
}
return true;
});
$objDir = "{$srcRoot}/obj-profile";
f_mkdir($objDir, recursive: true);
$cflags = '-c -O2 -fPIC -fvisibility=hidden ' .
'-I' . escapeshellarg($profileInc) . ' ' .
'-DCOMPILER_RT_HAS_ATOMICS=1 -DCOMPILER_RT_HAS_FCNTL_LCK=1 -DCOMPILER_RT_HAS_UNAME=1';
$objs = [];
foreach ($sources as $src) {
$obj = $objDir . '/' . pathinfo($src, PATHINFO_FILENAME) . '.o';
$cmd = escapeshellarg($zig) . ' cc ' . $cflags . ' -o ' . escapeshellarg($obj) . ' ' . escapeshellarg($src) . ' 2>&1';
if (!$this->runZigCmd($cmd, $obj, "failed to compile {$src}")) {
return;
}
$objs[] = $obj;
}
$arCmd = escapeshellarg($zig) . ' ar rcs ' . escapeshellarg($libPath) . ' ' . implode(' ', array_map('escapeshellarg', $objs)) . ' 2>&1';
if (!$this->runZigCmd($arCmd, $libPath, 'zig ar failed')) {
return;
}
logger()->info('[zig] libclang_rt.profile.a installed (' . filesize($libPath) . ' bytes)');
}
private function buildCrtObjects(string $zig, string $srcRoot, string $crtBegin, string $crtEnd): void
{
$beginSrc = "{$srcRoot}/lib/builtins/crtbegin.c";
$endSrc = "{$srcRoot}/lib/builtins/crtend.c";
if (!is_file($beginSrc) || !is_file($endSrc)) {
logger()->error("[zig] crtbegin/crtend source missing under {$srcRoot}/lib/builtins — shared libs will lack __dso_handle");
return;
}
$cflags = '-c -O2 -fPIC -fvisibility=hidden -DCRT_HAS_INITFINI_ARRAY';
foreach ([[$beginSrc, $crtBegin], [$endSrc, $crtEnd]] as [$src, $dst]) {
$cmd = escapeshellarg($zig) . ' cc ' . $cflags . ' -o ' . escapeshellarg($dst) . ' ' . escapeshellarg($src) . ' 2>&1';
if (!$this->runZigCmd($cmd, $dst, "failed to compile {$src}")) {
return;
}
}
logger()->info('[zig] clang_rt.crtbegin.o + clang_rt.crtend.o installed (' . filesize($crtBegin) . ' + ' . filesize($crtEnd) . ' bytes)');
}
private function runZigCmd(string $cmd, string $dst, string $errPrefix): bool
{
exec($cmd, $out, $rc);
if ($rc !== 0 || !is_file($dst)) {
logger()->warning("[zig] {$errPrefix}: " . implode("\n", $out));
return false;
}
return true;
}
private function createZigCcScript(string $bin_dir): void
{
$script_path = __DIR__ . '/../scripts/zig-cc.sh';

View File

@@ -1,14 +1,9 @@
#!/usr/bin/env bash
SCRIPT_DIR="$(dirname "${BASH_SOURCE[0]}")"
BUILDROOT_INC="${BUILD_INCLUDE_PATH:-$SCRIPT_DIR/../../../buildroot/include}"
BUILDROOT_ABS="$(realpath "$BUILDROOT_INC" 2>/dev/null || true)"
BUILDROOT_ABS="$(realpath "$SCRIPT_DIR/../../../buildroot/include" 2>/dev/null || true)"
PARSED_ARGS=()
is_buildroot_inc() {
[[ -n "$BUILDROOT_ABS" && "$1" == "$BUILDROOT_ABS" ]]
}
while [[ $# -gt 0 ]]; do
case "$1" in
-isystem)
@@ -16,33 +11,27 @@ while [[ $# -gt 0 ]]; do
ARG="$1"
shift
ARG_ABS="$(realpath "$ARG" 2>/dev/null || true)"
is_buildroot_inc "$ARG_ABS" && PARSED_ARGS+=("-I$ARG") || PARSED_ARGS+=("-isystem" "$ARG")
[[ "$ARG_ABS" == "$BUILDROOT_ABS" ]] && PARSED_ARGS+=("-I$ARG") || PARSED_ARGS+=("-isystem" "$ARG")
;;
-isystem*)
ARG="${1#-isystem}"
shift
ARG_ABS="$(realpath "$ARG" 2>/dev/null || true)"
is_buildroot_inc "$ARG_ABS" && PARSED_ARGS+=("-I$ARG") || PARSED_ARGS+=("-isystem$ARG")
[[ "$ARG_ABS" == "$BUILDROOT_ABS" ]] && PARSED_ARGS+=("-I$ARG") || PARSED_ARGS+=("-isystem$ARG")
;;
-march=*|-mcpu=*)
OPT_NAME="${1%%=*}"
OPT_VALUE="${1#*=}"
# zig rejects -march=armv8-a but accepts -mcpu=generic+v8a; rewrite
# armv<X>[.<Y>]-a[+feat] -> generic+v<X>[_<Y>]a[+feat] so it goes through.
if [[ "$OPT_VALUE" =~ ^armv([89])(\.([0-9]+))?-a(\+.*)?$ ]]; then
arch_feat="v${BASH_REMATCH[1]}"
[[ -n "${BASH_REMATCH[3]}" ]] && arch_feat="${arch_feat}_${BASH_REMATCH[3]}"
OPT_VALUE="generic+${arch_feat}a${BASH_REMATCH[4]}"
# Skip armv8- flags entirely as Zig doesn't support them
if [[ "$OPT_VALUE" == armv8-* ]]; then
shift
continue
fi
# zig uses snake_case in CPU/feature names (x86-64 -> x86_64).
# replace -march=x86-64 with -march=x86_64
OPT_VALUE="${OPT_VALUE//-/_}"
PARSED_ARGS+=("${OPT_NAME}=${OPT_VALUE}")
shift
;;
-Wlogical-op|-Wduplicated-cond|-Wduplicated-branches|-Wno-clobbered|-Wjump-misses-init|-Wformat-truncation|-Warray-bounds=*|-Wimplicit-fallthrough=*)
# GCC-only warning flags that clang/zig doesn't recognize; drop to silence -Wunknown-warning-option noise
shift
;;
*)
PARSED_ARGS+=("$1")
shift
@@ -50,27 +39,6 @@ while [[ $# -gt 0 ]]; do
esac
done
IS_LINK=1
NEED_PROFILE_RT=0 # https://codeberg.org/ziglang/zig/issues/32066
NEED_CRT=0 # https://codeberg.org/ziglang/zig/issues/32064
for _a in "${PARSED_ARGS[@]}"; do
case "$_a" in
-c|-S|-E|-M|-MM) IS_LINK=0 ;;
-fprofile-generate*|-fprofile-instr-generate*|-fcs-profile-generate*) NEED_PROFILE_RT=1 ;;
-shared) NEED_CRT=1 ;;
esac
done
[[ "$SPC_COMPILER_EXTRA" == *-fprofile-generate* || "$SPC_COMPILER_EXTRA" == *-fcs-profile-generate* ]] && NEED_PROFILE_RT=1
if [[ $IS_LINK -eq 1 && $NEED_PROFILE_RT -eq 1 && -f "$SCRIPT_DIR/lib/libclang_rt.profile.a" ]]; then
PARSED_ARGS+=("-x" "none" "$SCRIPT_DIR/lib/libclang_rt.profile.a" "-Wl,-u,__llvm_profile_runtime")
fi
if [[ $IS_LINK -eq 1 && $NEED_CRT -eq 1 && -f "$SCRIPT_DIR/lib/clang_rt.crtbegin.o" && -f "$SCRIPT_DIR/lib/clang_rt.crtend.o" ]]; then
PARSED_ARGS+=("-x" "none" "$SCRIPT_DIR/lib/clang_rt.crtbegin.o" "$SCRIPT_DIR/lib/clang_rt.crtend.o")
fi
if [[ $IS_LINK -eq 1 && -f "$SCRIPT_DIR/lib/libclang_rt.cpu_model.a" ]]; then
PARSED_ARGS+=("-x" "none" "$SCRIPT_DIR/lib/libclang_rt.cpu_model.a")
fi
[[ -n "$SPC_TARGET" ]] && TARGET="-target $SPC_TARGET" || TARGET=""
if [[ "$SPC_TARGET" =~ \.[0-9]+\.[0-9]+ ]]; then

View File

@@ -20,7 +20,7 @@ class PhpSource extends CustomSourceBase
public function fetch(bool $force = false, ?array $config = null, int $lock_as = SPC_DOWNLOAD_SOURCE): void
{
$major = defined('SPC_BUILD_PHP_VERSION') ? SPC_BUILD_PHP_VERSION : '8.5';
$major = defined('SPC_BUILD_PHP_VERSION') ? SPC_BUILD_PHP_VERSION : '8.4';
if ($major === 'git') {
Downloader::downloadSource('php-src', ['type' => 'git', 'url' => 'https://github.com/php/php-src.git', 'rev' => 'master'], $force);
} else {

View File

@@ -21,7 +21,6 @@ class ClangNativeToolchain implements ToolchainInterface
GlobalEnvManager::putenv('SPC_LINUX_DEFAULT_CC=clang');
GlobalEnvManager::putenv('SPC_LINUX_DEFAULT_CXX=clang++');
GlobalEnvManager::putenv('SPC_LINUX_DEFAULT_AR=ar');
GlobalEnvManager::putenv('SPC_LINUX_DEFAULT_RANLIB=ranlib');
GlobalEnvManager::putenv('SPC_LINUX_DEFAULT_LD=ld');
}

View File

@@ -18,7 +18,6 @@ class GccNativeToolchain implements ToolchainInterface
GlobalEnvManager::putenv('SPC_LINUX_DEFAULT_CC=gcc');
GlobalEnvManager::putenv('SPC_LINUX_DEFAULT_CXX=g++');
GlobalEnvManager::putenv('SPC_LINUX_DEFAULT_AR=ar');
GlobalEnvManager::putenv('SPC_LINUX_DEFAULT_RANLIB=ranlib');
GlobalEnvManager::putenv('SPC_LINUX_DEFAULT_LD=ld');
}

View File

@@ -16,7 +16,6 @@ class MuslToolchain implements ToolchainInterface
GlobalEnvManager::putenv("SPC_LINUX_DEFAULT_CC={$arch}-linux-musl-gcc");
GlobalEnvManager::putenv("SPC_LINUX_DEFAULT_CXX={$arch}-linux-musl-g++");
GlobalEnvManager::putenv("SPC_LINUX_DEFAULT_AR={$arch}-linux-musl-ar");
GlobalEnvManager::putenv("SPC_LINUX_DEFAULT_RANLIB={$arch}-linux-musl-ranlib");
GlobalEnvManager::putenv("SPC_LINUX_DEFAULT_LD={$arch}-linux-musl-ld");
GlobalEnvManager::addPathIfNotExists('/usr/local/musl/bin');
GlobalEnvManager::addPathIfNotExists("/usr/local/musl/{$arch}-linux-musl/bin");

View File

@@ -16,8 +16,28 @@ class ZigToolchain implements ToolchainInterface
GlobalEnvManager::putenv('SPC_LINUX_DEFAULT_CC=zig-cc');
GlobalEnvManager::putenv('SPC_LINUX_DEFAULT_CXX=zig-c++');
GlobalEnvManager::putenv('SPC_LINUX_DEFAULT_AR=zig-ar');
GlobalEnvManager::putenv('SPC_LINUX_DEFAULT_RANLIB=zig-ranlib');
GlobalEnvManager::putenv('SPC_LINUX_DEFAULT_LD=zig-ld.lld');
// Generate additional objects needed for zig toolchain
$paths = ['/usr/lib/gcc', '/usr/local/lib/gcc'];
$objects = ['crtbeginS.o', 'crtendS.o'];
$found = [];
foreach ($objects as $obj) {
$located = null;
foreach ($paths as $base) {
$output = shell_exec("find {$base} -name {$obj} 2>/dev/null | grep -v '/32/' | head -n 1");
$line = trim((string) $output);
if ($line !== '') {
$located = $line;
break;
}
}
if ($located) {
$found[] = $located;
}
}
GlobalEnvManager::putenv('SPC_EXTRA_RUNTIME_OBJECTS=' . implode(' ', $found));
}
public function afterInit(): void
@@ -38,6 +58,10 @@ class ZigToolchain implements ToolchainInterface
GlobalEnvManager::putenv("SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS={$extraCflags}");
GlobalEnvManager::putenv('RANLIB=zig-ranlib');
GlobalEnvManager::putenv('OBJCOPY=zig-objcopy');
$defaultLdFlags = getenv('SPC_DEFAULT_LD_FLAGS') ?: '';
if (!str_contains($defaultLdFlags, '-Wl,--undefined-version') && !getenv('SPC_LINK_STATIC')) {
GlobalEnvManager::putenv("SPC_DEFAULT_LD_FLAGS={$defaultLdFlags} -Wl,--undefined-version");
}
$extra_libs = getenv('SPC_EXTRA_LIBS') ?: '';
if (!str_contains($extra_libs, '-lunwind')) {
// Add unwind library if not already present

View File

@@ -393,7 +393,7 @@ class ConfigValidator
}
// check php-version
if (isset($craft['php-version'])) {
// validate version, accept 8.x, 7.x, 8.x.x, 7.x.x, 8, 7
// validdate version, accept 8.x, 7.x, 8.x.x, 7.x.x, 8, 7
$version = strval($craft['php-version']);
if (!preg_match('/^(\d+)(\.\d+)?(\.\d+)?$/', $version, $matches)) {
throw new ValidationException('Craft file php-version is invalid');

View File

@@ -101,15 +101,11 @@ class DependencyUtil
/**
* Get extension dependencies in correct order
*
* @param array $exts Array of extension names
* @param array $additional_libs Array of additional libraries
* @param bool $include_suggested_exts Whether to follow ext-suggests edges
* @param array|bool $include_suggested_libs true = follow all lib-suggests edges;
* false = follow none;
* array = follow lib-suggests edges only when the suggested lib is in this list (i.e. it's already being built)
* @return array Ordered array of extension names
* @param array $exts Array of extension names
* @param array $additional_libs Array of additional libraries
* @return array Ordered array of extension names
*/
public static function getExtsAndLibs(array $exts, array $additional_libs = [], bool $include_suggested_exts = false, array|bool $include_suggested_libs = false): array
public static function getExtsAndLibs(array $exts, array $additional_libs = [], bool $include_suggested_exts = false, bool $include_suggested_libs = false): array
{
$dep_list = self::platExtToLibs();
@@ -131,20 +127,16 @@ class DependencyUtil
}
}
// include suggested libraries (all, or only those in the available set)
if ($include_suggested_libs !== false) {
$available = is_array($include_suggested_libs) ? $include_suggested_libs : null;
// include suggested libraries
if ($include_suggested_libs) {
// check every deps suggests
foreach ($dep_list as $name => $obj) {
$del_list = [];
foreach ($obj['suggests'] as $id => $suggest) {
if (str_starts_with($suggest, 'ext@')) {
continue;
if (!str_starts_with($suggest, 'ext@')) {
$dep_list[$name]['depends'][] = $suggest;
$del_list[] = $id;
}
if ($available !== null && !in_array($suggest, $available, true)) {
continue;
}
$dep_list[$name]['depends'][] = $suggest;
$del_list[] = $id;
}
foreach ($del_list as $id) {
unset($dep_list[$name]['suggests'][$id]);

View File

@@ -38,6 +38,13 @@ class GlobalEnvManager
// Define env vars for unix
if (is_unix()) {
if (!getenv('SPC_LINK_STATIC')) {
$ldLibPath = getenv('LD_LIBRARY_PATH=' . BUILD_LIB_PATH);
if ($ldLibPath) {
$ldLibPath = ":{$ldLibPath}";
}
self::putenv('LD_LIBRARY_PATH=' . BUILD_LIB_PATH . $ldLibPath);
}
self::addPathIfNotExists(BUILD_BIN_PATH);
self::addPathIfNotExists(PKG_ROOT_PATH . '/bin');
$pkgConfigPath = getenv('PKG_CONFIG_PATH');

View File

@@ -1,313 +0,0 @@
<?php
declare(strict_types=1);
namespace SPC\util;
use SPC\builder\BuilderBase;
use SPC\exception\WrongUsageException;
use SPC\store\FileSystem;
use SPC\store\SourcePatcher;
/**
* Two-call PGO driver: --pgi instruments, --pgo uses the .profraw the user
* collected by running the instrumented binaries.
*/
class PgoManager
{
public const MODE_INSTRUMENT = 'instrument';
public const MODE_CS_INSTRUMENT = 'cs-instrument';
public const MODE_USE = 'use';
private const TRAINABLE = [
'cli' => BUILD_TARGET_CLI,
'micro' => BUILD_TARGET_MICRO,
'cgi' => BUILD_TARGET_CGI,
'fpm' => BUILD_TARGET_FPM,
'embed' => BUILD_TARGET_EMBED,
'frankenphp' => BUILD_TARGET_FRANKENPHP,
];
/**
* Applied during --pgi only: explicit __llvm_profile_write_file() at
* shutdown, since Go/frankenphp exits skip libc atexit.
*/
private const SHUTDOWN_PATCHES = [
'php-src' => 'spc_pgo_flush_php_main.patch',
'frankenphp' => 'spc_pgo_flush_frankenphp.patch',
];
private string $profileRoot;
private string $mode;
private function __construct()
{
$this->profileRoot = BUILD_ROOT_PATH . '/pgo-data';
}
/** Build a PgoManager for the active --pgi/--cs-pgi/--pgo option, or null if none set. */
public static function fromBuilder(BuilderBase $builder, int $rule): ?self
{
$modes = array_filter(['pgi', 'cs-pgi', 'pgo'], fn ($m) => (bool) $builder->getOption($m));
if (count($modes) > 1) {
throw new WrongUsageException('--pgi, --cs-pgi, and --pgo are mutually exclusive');
}
$mode = array_values($modes)[0] ?? null;
if ($mode === null) {
return null;
}
$instance = new self();
match ($mode) {
'pgi' => $instance->setupInstrument($rule),
'cs-pgi' => $instance->setupCsInstrument($rule),
'pgo' => $instance->setupUse($rule),
};
return $instance;
}
/** Patches php-src/libtool to passthrough -fcs-profile-* flags (otherwise dropped during shared lib link). */
public static function patchBeforeMake(BuilderBase $builder): void
{
if (!$builder->getOption('cs-pgi')) {
return;
}
$libtool = SOURCE_PATH . '/php-src/libtool';
if (!is_file($libtool)) {
return;
}
$contents = file_get_contents($libtool);
if (str_contains($contents, '-fcs-profile-*')) {
return;
}
$patched = str_replace('-fprofile-*|-F*', '-fprofile-*|-fcs-profile-*|-F*', $contents);
if ($patched === $contents) {
logger()->warning('pgo --cs-pgi: could not patch libtool for -fcs-profile-* passthrough');
return;
}
file_put_contents($libtool, $patched);
logger()->info('pgo --cs-pgi: patched libtool for -fcs-profile-* passthrough');
}
public function applyForSapi(string $sapi): void
{
$sapi = $this->resolveSapi($sapi);
if (!isset(self::TRAINABLE[$sapi])) {
return;
}
if ($this->mode === self::MODE_USE && !is_file($this->profDataFile($sapi))) {
logger()->warning("pgo --pgo: no profdata for {$sapi}, building without PGO for this sapi");
$this->setFlag('SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS', '');
$this->setFlag('SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS_PROGRAM', '');
return;
}
$flags = match ($this->mode) {
self::MODE_INSTRUMENT => '-fprofile-generate=' . $this->rawDir($sapi)
. ' -fprofile-update=atomic',
self::MODE_CS_INSTRUMENT => '-fprofile-use=' . $this->profDataFile($sapi)
. ' -fcs-profile-generate=' . $this->csRawDir($sapi)
. ' -fprofile-update=atomic'
. ' -Wno-error=profile-instr-unprofiled'
. ' -Wno-error=profile-instr-out-of-date'
. ' -Wno-backend-plugin',
default => '-fprofile-use=' . $this->profDataFile($sapi)
. ' -Wno-error=profile-instr-unprofiled'
. ' -Wno-error=profile-instr-out-of-date'
. ' -Wno-backend-plugin',
};
$this->setFlag('SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS', $flags);
$this->setFlag('SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS_PROGRAM', $this->ldOnly($flags, $sapi));
logger()->info("pgo {$this->mode} ({$sapi})");
}
/** Setup --pgi: build with -fprofile-generate=<sapi-dir>. */
private function setupInstrument(int $rule): void
{
$this->validateRule($rule);
FileSystem::removeDir($this->profileRoot);
f_mkdir($this->profileRoot, recursive: true);
foreach ($this->trainableIn($rule) as $sapi) {
f_mkdir($this->rawDir($sapi), recursive: true);
}
$this->mode = self::MODE_INSTRUMENT;
$this->applyShutdownPatches();
$this->applyForSapi($this->trainableIn($rule)[0]);
logger()->info('pgo --pgi: instrumented build, profraw will land under ' . $this->profileRoot . '/<sapi>/');
}
/** Setup --cs-pgi: build with -fprofile-use=<sapi.profdata> -fcs-profile-generate=<cs-dir>. Requires existing .profdata. */
private function setupCsInstrument(int $rule): void
{
$this->validateRule($rule);
foreach ($this->trainableIn($rule) as $sapi) {
if (!is_file($this->profDataFile($sapi))) {
throw new WrongUsageException("--cs-pgi: missing {$sapi}.profdata; run --pgi + --pgo first");
}
f_mkdir($this->csRawDir($sapi), recursive: true);
}
$this->mode = self::MODE_CS_INSTRUMENT;
$this->applyShutdownPatches();
$this->applyForSapi($this->trainableIn($rule)[0]);
logger()->info('pgo --cs-pgi: cs-instrumented build, cs-profraw under ' . $this->profileRoot . '/cs-<sapi>/');
}
/** Setup --pgo: merge collected .profraw, then build with -fprofile-use=<sapi.profdata>. */
private function setupUse(int $rule): void
{
$this->validateRule($rule);
if (trim((string) shell_exec('command -v llvm-profdata 2>/dev/null')) === '') {
throw new WrongUsageException('--pgo: llvm-profdata not on PATH');
}
foreach ($this->trainableIn($rule) as $sapi) {
$this->mergeSapi($sapi);
}
$this->mode = self::MODE_USE;
$this->applyForSapi($this->trainableIn($rule)[0]);
}
/**
* Static-embed mode links libphp.a into frankenphp; both end up in one
* binary so must share one profdata. Shared-embed mode keeps libphp.so
* standalone — embed and frankenphp keep separate profiles.
*/
private function resolveSapi(string $sapi): string
{
if ($sapi === 'embed' && getenv('SPC_CMD_VAR_PHP_EMBED_TYPE') === 'static') {
return 'frankenphp';
}
return $sapi;
}
private function validateRule(int $rule): void
{
if (empty($this->trainableIn($rule))) {
throw new WrongUsageException('--pgi/--pgo: no trainable SAPI in build rule (need one of: ' . implode(', ', array_keys(self::TRAINABLE)) . ')');
}
}
private function mergeSapi(string $sapi): void
{
$raws = glob($this->rawDir($sapi) . '/*.profraw') ?: [];
$csRaws = glob($this->csRawDir($sapi) . '/*.profraw') ?: [];
if (empty($raws) && empty($csRaws)) {
if ($sapi === 'frankenphp') {
logger()->warning('pgo --pgo: no .profraw for frankenphp (cgo glue PGO will be skipped); run --pgi, exercise frankenphp longer, then re-run --pgo to include it');
return;
}
throw new WrongUsageException("--pgo: no .profraw for {$sapi}; run --pgi, exercise the binary, then re-run --pgo");
}
$out = $this->profDataFile($sapi);
$inputs = array_merge($raws, $csRaws);
$argv = implode(' ', array_map('escapeshellarg', $inputs));
shell()->exec('llvm-profdata merge --failure-mode=warn -output=' . escapeshellarg($out) . ' ' . $argv);
if (!is_file($out) || filesize($out) === 0) {
throw new WrongUsageException("--pgo: empty merge output for {$sapi}");
}
logger()->info("pgo merged {$sapi}: " . filesize($out) . ' bytes');
}
private function rawDir(string $sapi): string
{
return $this->profileRoot . '/' . $sapi;
}
private function csRawDir(string $sapi): string
{
return $this->profileRoot . '/cs-' . $sapi;
}
private function profDataFile(string $sapi): string
{
return $this->profileRoot . '/' . $sapi . '.profdata';
}
/** @return list<string> */
private function trainableIn(int $rule): array
{
$out = [];
foreach (self::TRAINABLE as $sapi => $mask) {
if (($rule & $mask) !== $mask) {
continue;
}
$resolved = $this->resolveSapi($sapi);
if (!in_array($resolved, $out, true)) {
$out[] = $resolved;
}
}
return $out;
}
/** Strip the previous PGO flags from $var and append the new ones. */
private function setFlag(string $var, string $append): void
{
$cur = (string) getenv($var);
$cur = preg_replace('/\s*-f(cs-)?profile-(generate|use)=\S+/', '', $cur) ?? $cur;
$cur = preg_replace('/\s*-Wno-error=profile-instr-\S+/', '', $cur) ?? $cur;
$cur = preg_replace('/\s*-Wno-backend-plugin/', '', $cur) ?? $cur;
f_putenv($var . '=' . trim($cur . ' ' . $append));
}
/**
* Linker flags: cli wants -fprofile-use= at link too (LTO does its
* profile-driven inlining/reordering at link time). Strip -Wno-error
* flags (linker doesn't accept them).
*/
private function ldOnly(string $flags, string $sapi = ''): string
{
$patterns = ['/\s*-Wno-error=\S+/', '/\s*-Wno-backend-plugin/'];
if ($sapi === 'frankenphp') {
$patterns[] = '/\s*-fprofile-use=\S+/';
$patterns[] = '/\s*-fcs-profile-generate=\S+/';
}
return trim(preg_replace($patterns, '', $flags) ?? $flags);
}
/** --pgi patch: inject __llvm_profile_write_file() flush handler to php and frankenphp sources. */
private function applyShutdownPatches(): void
{
$applied = [];
foreach (self::SHUTDOWN_PATCHES as $dir => $patch) {
$cwd = SOURCE_PATH . '/' . $dir;
if (!is_dir($cwd)) {
continue;
}
if (!SourcePatcher::patchFile($patch, $cwd)) {
throw new WrongUsageException("--pgi: patch {$patch} failed to apply in {$cwd}");
}
$applied[] = ['cwd' => $cwd, 'patch' => $patch];
logger()->info("pgo --pgi: applied {$patch}");
}
if ($applied === []) {
return;
}
register_shutdown_function(static function () use ($applied): void {
foreach ($applied as $entry) {
$cwd = $entry['cwd'];
$patch = $entry['patch'];
if (!is_dir($cwd)) {
continue;
}
$patch_file = ROOT_DIR . "/src/globals/patch/{$patch}";
if (!is_file($patch_file)) {
continue;
}
$args = ' -p1 -s -R -F0 ';
exec('cd ' . escapeshellarg($cwd) . ' && patch --dry-run' . $args
. ' < ' . escapeshellarg($patch_file) . ' >/dev/null 2>&1', $_, $detect_status);
if ($detect_status !== 0) {
logger()->info("pgo --pgi: {$patch} already clean, skipping revert");
continue;
}
exec('cd ' . escapeshellarg($cwd) . ' && patch' . $args
. ' < ' . escapeshellarg($patch_file), $out, $apply_status);
if ($apply_status === 0) {
logger()->info("pgo --pgi: reverted {$patch}");
} else {
logger()->warning("pgo --pgi: failed to revert {$patch} (status {$apply_status}): " . implode("\n", $out));
}
}
});
}
}

View File

@@ -59,10 +59,10 @@ class PkgConfigUtil
* @param string $pkg_config_str .pc file string, accepts multiple files
* @return string CFLAGS string, e.g. "-Wno-implicit-int-float-conversion ..."
*/
public static function getCflags(string $pkg_config_str): string
public static function getCflags(string $pkg_config_str, string $extra = '--static'): string
{
// get other things
$result = self::execWithResult("pkg-config --static --cflags-only-other {$pkg_config_str}");
$result = self::execWithResult("pkg-config {$extra} --cflags-only-other {$pkg_config_str}");
return trim($result);
}
@@ -75,14 +75,14 @@ class PkgConfigUtil
* @param string $pkg_config_str .pc file string, accepts multiple files
* @return array Unique libs array, e.g. [-lz, -lxml, ...]
*/
public static function getLibsArray(string $pkg_config_str): array
public static function getLibsArray(string $pkg_config_str, string $extra = '--static'): array
{
// Use this instead of shell() to avoid unnecessary outputs
$result = self::execWithResult("pkg-config --static --libs-only-l {$pkg_config_str}");
$result = self::execWithResult("pkg-config {$extra} --libs-only-l {$pkg_config_str}");
$libs = explode(' ', trim($result));
// get other things
$result = self::execWithResult("pkg-config --static --libs-only-other {$pkg_config_str}");
$result = self::execWithResult("pkg-config {$extra} --libs-only-other {$pkg_config_str}");
// convert libxxx.a to -L{path} -lxxx
$exp = explode(' ', trim($result));
foreach ($exp as $item) {

View File

@@ -20,13 +20,10 @@ class SPCConfigUtil
private bool $libs_only_deps;
private bool $absolute_libs;
/**
* @param array{
* no_php?: bool,
* libs_only_deps?: bool,
* absolute_libs?: bool
* libs_only_deps?: bool
* } $options Options pass to spc-config
*/
public function __construct(?BuilderBase $builder = null, array $options = [])
@@ -36,24 +33,22 @@ class SPCConfigUtil
}
$this->no_php = $options['no_php'] ?? false;
$this->libs_only_deps = $options['libs_only_deps'] ?? false;
$this->absolute_libs = $options['absolute_libs'] ?? false;
}
/**
* Generate configuration for building PHP extensions.
*
* @param array $extensions Extension name list
* @param array $libraries Additional library name list
* @param bool $include_suggest_ext Include suggested extensions
* @param array|bool $include_suggest_lib true/false to include all/no suggested libs; array to include only suggests that point at libs in the array erse of libs being built)
* @param array $extensions Extension name list
* @param array $libraries Additional library name list
* @param bool $include_suggest_ext Include suggested extensions
* @param bool $include_suggest_lib Include suggested libraries
* @return array{
* cflags: string,
* ldflags: string,
* libs: string
* }
* @throws WrongUsageException
*/
public function config(array $extensions = [], array $libraries = [], bool $include_suggest_ext = false, array|bool $include_suggest_lib = false): array
public function config(array $extensions = [], array $libraries = [], bool $include_suggest_ext = false, bool $include_suggest_lib = false): array
{
logger()->debug('config extensions: ' . implode(',', $extensions));
logger()->debug('config libs: ' . implode(',', $libraries));
@@ -78,7 +73,7 @@ class SPCConfigUtil
ob_get_clean();
$ldflags = $this->getLdflagsString();
$cflags = $this->getIncludesString($libraries);
$libs = $this->getLibsString($libraries, !$this->absolute_libs);
$libs = $this->getLibsString($libraries);
// additional OS-specific libraries (e.g. macOS -lresolv)
if ($extra_libs = SPCTarget::getRuntimeLibs()) {
@@ -240,7 +235,8 @@ class SPCConfigUtil
}
}
$pc_cflags = implode(' ', $pc);
if ($pc_cflags !== '' && ($pc_cflags = PkgConfigUtil::getCflags($pc_cflags)) !== '') {
$static = getenv('SPC_LINK_STATIC') ? '--static' : '';
if ($pc_cflags !== '' && ($pc_cflags = PkgConfigUtil::getCflags($pc_cflags, $static)) !== '') {
$arr = explode(' ', $pc_cflags);
$arr = array_unique($arr);
$arr = array_filter($arr, fn ($x) => !str_starts_with($x, 'SHELL:-Xarch_'));
@@ -257,7 +253,7 @@ class SPCConfigUtil
return '-L' . BUILD_LIB_PATH;
}
private function getLibsString(array $libraries, bool $use_short_libs = true): string
private function getLibsString(array $libraries): string
{
$lib_names = [];
$frameworks = [];
@@ -265,6 +261,11 @@ class SPCConfigUtil
foreach ($libraries as $library) {
// add pkg-configs libs
$pkg_configs = Config::getLib($library, 'pkg-configs', []);
$static = getenv('SPC_LINK_STATIC') ? '--static' : null;
if (!$static) {
$target = Config::getLib($library, 'target');
$static = $target && !in_array('shared', $target) ? '--static' : '';
}
$pkg_config_path = getenv('PKG_CONFIG_PATH') ?: '';
$search_paths = array_filter(explode(is_unix() ? ':' : ';', $pkg_config_path));
foreach ($pkg_configs as $file) {
@@ -281,14 +282,14 @@ class SPCConfigUtil
$pkg_configs = implode(' ', $pkg_configs);
if ($pkg_configs !== '') {
// static libs with dependencies come in reverse order, so reverse this too
$pc_libs = array_reverse(PkgConfigUtil::getLibsArray($pkg_configs));
$pc_libs = array_reverse(PkgConfigUtil::getLibsArray($static, $pkg_configs));
$lib_names = [...$lib_names, ...$pc_libs];
}
// convert all static-libs to short names
$libs = array_reverse(Config::getLib($library, 'static-libs', []));
foreach ($libs as $lib) {
// check file existence
if (!file_exists(BUILD_LIB_PATH . "/{$lib}")) {
if (!file_exists(BUILD_LIB_PATH . "/{$lib}") && getenv('SPC_LINK_STATIC')) {
throw new WrongUsageException("Library file '{$lib}' for lib [{$library}] does not exist in '" . BUILD_LIB_PATH . "'. Please build it first.");
}
$lib_names[] = $this->getShortLibName($lib);
@@ -317,8 +318,8 @@ class SPCConfigUtil
if (in_array('imap', $libraries) && SPCTarget::getLibc() === 'glibc') {
$lib_names[] = '-lcrypt';
}
if (!$use_short_libs) {
$lib_names = array_map(fn ($l) => $this->getFullLibName($l), $lib_names);
if (getenv('SPC_LINK_STATIC')) {
$lib_names = array_map(fn ($l) => $this->getStaticLibname($l), $lib_names);
}
return implode(' ', $lib_names);
}
@@ -332,7 +333,7 @@ class SPCConfigUtil
return '-l' . substr($lib, 3, -2);
}
private function getFullLibName(string $lib)
private function getStaticLibname(string $lib)
{
if (!str_starts_with($lib, '-l')) {
return $lib;
@@ -340,7 +341,7 @@ class SPCConfigUtil
$libname = substr($lib, 2);
$staticLib = BUILD_LIB_PATH . '/' . "lib{$libname}.a";
if (file_exists($staticLib)) {
return $staticLib;
return "-l:lib{$libname}.a";
}
return $lib;
}

View File

@@ -127,19 +127,4 @@ class SPCTarget
default => PHP_OS_FAMILY,
};
}
/**
* Returns the target OS arch, e.g. x86_64, aarch64, arm, x86.
*/
public static function getTargetArch(): string
{
$target = (string) getenv('SPC_TARGET');
return match (true) {
str_starts_with($target, 'aarch64') => 'aarch64',
str_starts_with($target, 'arm-') => 'arm',
str_starts_with($target, 'x86_64-') => 'x86_64',
str_starts_with($target, 'x86-') => 'x86',
default => GNU_ARCH,
};
}
}

View File

@@ -126,7 +126,7 @@ class UnixAutoconfExecutor extends Executor
{
return [
'--enable-static',
'--disable-shared',
getenv('SPC_LINK_STATIC') ? '--disable-shared' : '--enable-shared',
"--prefix={$this->library->getBuildRootPath()}",
'--with-pic',
'--enable-pic',

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