Skip to content
Merged
Show file tree
Hide file tree
Changes from 72 commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
52f40b7
the release option also affects shared extensions, which is unwanted,…
henderkes Jun 12, 2025
0a24a6a
move check when to build to extension.php instead of builder
henderkes Jun 12, 2025
d249391
don't add configure command to phpinfo when -release is set
henderkes Jun 12, 2025
302cf83
properly handle different php versions, clean up only required files
henderkes Jun 13, 2025
b265d6d
don't set unknown linker flags on macos
henderkes Jun 13, 2025
962de5b
add edant/watcher, to make spc-packages easier
henderkes Jun 13, 2025
3efabee
Remove redundant sanity check call
crazywhalecc Jun 13, 2025
bafa67c
add patchelf to gnu docker
henderkes Jun 17, 2025
7b3ea7e
fix installing patchelf
henderkes Jun 17, 2025
9de5c62
extract elsewhere temporarily
henderkes Jun 17, 2025
aa61a9e
extra info on ext load failure
henderkes Jun 17, 2025
883cc4b
patch on 2.17...
henderkes Jun 17, 2025
3a85d96
yet another damn centos 7 patch
henderkes Jun 17, 2025
da75d2d
cs fix
henderkes Jun 17, 2025
1c439a0
Merge remote-tracking branch 'origin/main' into docs
henderkes Jun 18, 2025
cb0a90d
Add source hash comparator & refactor download lock
crazywhalecc Jun 14, 2025
57b2278
Define env in phpunit.xml
crazywhalecc Jun 16, 2025
c1870af
add frankenphp sapi
henderkes Jun 18, 2025
f64eb0d
build for bsd and macos too
henderkes Jun 18, 2025
c1e6832
cs fix
henderkes Jun 18, 2025
92338d4
don't bake the rpath in, otherwise we might run into issues when load…
henderkes Jun 18, 2025
c46f851
watcher...
henderkes Jun 18, 2025
abf3bfb
suggest watcher
henderkes Jun 18, 2025
dca43d6
nicer escaping
henderkes Jun 18, 2025
d635b10
specify system gcc to build xcaddy in spc-gnu-docker
henderkes Jun 18, 2025
d094824
--with github.com/dunglas/caddy-cbrotli requires brotli
henderkes Jun 18, 2025
e71f762
support building static frankenphp
henderkes Jun 18, 2025
f37c863
only needed on linux
henderkes Jun 18, 2025
d58534b
add support for frankenphp directory from file system, instead of pul…
henderkes Jun 18, 2025
82ee6f0
allow specifying if we want to build embed shared or static
henderkes Jun 18, 2025
a1e76d9
remove watcher suggestion
henderkes Jun 18, 2025
ba0ea5b
Refactor lock component to a single class (#773)
crazywhalecc Jun 18, 2025
f10ba86
add extension test for frankenphp
henderkes Jun 18, 2025
65b828c
embed version information
henderkes Jun 18, 2025
eee2ff6
don't embed minor version when loading libphp.so
henderkes Jun 18, 2025
ae56931
Remove go download from doctor
crazywhalecc Jun 18, 2025
8e2dffc
Add frankenphp sapi embed build at build command, not constant
crazywhalecc Jun 18, 2025
f709f3b
Add custom package downloader and extractor
crazywhalecc Jun 18, 2025
92284e9
Refactor go and frankenphp downloads and builds
crazywhalecc Jun 18, 2025
d6858e1
phpstan fix
crazywhalecc Jun 18, 2025
74b1dda
Fix test-extensions.php
crazywhalecc Jun 18, 2025
4ecaffd
Fix test-extensions.php
crazywhalecc Jun 18, 2025
becee5b
Use version instead of -v
crazywhalecc Jun 18, 2025
a76f49f
Remove libxml2 requirement for linux
crazywhalecc Jun 18, 2025
1a164fa
Merge pull request #775 from crazywhalecc/sapi/frankenphp-prerequisites
henderkes Jun 19, 2025
15979d4
fix double path
henderkes Jun 19, 2025
cb010d8
there's no documented functionality to download without building - xc…
henderkes Jun 19, 2025
b42409e
LD_LIBRARY_PATH for frankenphp sanity check
henderkes Jun 19, 2025
7dc3b7c
Merge remote-tracking branch 'origin/main' into sapi/frankenphp
crazywhalecc Jun 19, 2025
804468f
refactor common exec code out
henderkes Jun 19, 2025
16fccf8
Merge remote-tracking branch 'origin/sapi/frankenphp' into sapi/frank…
henderkes Jun 19, 2025
6e70f16
Merge remote-tracking branch 'origin/docs' into sapi/frankenphp
henderkes Jun 19, 2025
3af40a6
Merge pull request #772 from crazywhalecc/sapi/frankenphp
henderkes Jun 19, 2025
a9713c3
polish merge
henderkes Jun 19, 2025
cc09184
fix test
henderkes Jun 19, 2025
4977286
fix test
henderkes Jun 19, 2025
c2d6b9a
refactor lock file constant out
henderkes Jun 19, 2025
597db25
frankenphp requires ZTS
henderkes Jun 19, 2025
32dc5d3
leftover double path
henderkes Jun 19, 2025
ba6ed13
remove old file deletions
henderkes Jun 19, 2025
aec03b2
move enable zts check
henderkes Jun 19, 2025
2bc9fef
cs fix
henderkes Jun 19, 2025
5f3f999
run go mod frankenphp automatically when running craft
henderkes Jun 19, 2025
2f8e225
remove copy of property that meant downloader would only lock one sou…
henderkes Jun 19, 2025
fcf2c96
fix setting of variables
henderkes Jun 19, 2025
bcea200
base arch instead of hardcoded x86_64
henderkes Jun 19, 2025
4a70f26
test alpine directly too (spc-alpine-docker)
henderkes Jun 19, 2025
61a9264
libraries must link against -lphp dynamic!
henderkes Jun 19, 2025
1357990
Add github token hook for curlExec
crazywhalecc Jun 19, 2025
82ec773
musl: all-static!
henderkes Jun 19, 2025
437d681
Bump version, update docs, change owner dunglas to php
crazywhalecc Jun 19, 2025
a0047e3
Merge remote-tracking branch 'origin/docs' into docs
crazywhalecc Jun 19, 2025
fbd6360
rename go-mod-frankenphp to go-xcaddy
henderkes Jun 19, 2025
40d602c
xcaddy fails with this, because the module still calls itself dunglas…
henderkes Jun 19, 2025
dfac385
suggestions
henderkes Jun 19, 2025
608a555
fix incorrect array offset
henderkes Jun 19, 2025
16a4245
common static extension tests
henderkes Jun 19, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README-zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ bin/spc micro:combine my-app.phar -I "memory_limit=4G" -I "disable_functions=sys

如果你知道 [embed SAPI](https://github.com/php/php-src/tree/master/sapi/embed),你应该知道如何使用它。对于有可能编译用到引入其他库的问题,你可以使用 `buildroot/bin/php-config` 来获取编译时的配置。

另外,有关如何使用此功能的高级示例,请查看[如何使用它构建 FrankenPHP 的静态版本](https://github.com/dunglas/frankenphp/blob/main/docs/static.md)。
另外,有关如何使用此功能的高级示例,请查看[如何使用它构建 FrankenPHP 的静态版本](https://github.com/php/frankenphp/blob/main/docs/static.md)。

## 贡献

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ If you know [embed SAPI](https://github.com/php/php-src/tree/master/sapi/embed),
You may require the introduction of other libraries during compilation,
you can use `buildroot/bin/php-config` to obtain the compile-time configuration.

For an advanced example of how to use this feature, take a look at [how to use it to build a static version of FrankenPHP](https://github.com/dunglas/frankenphp/blob/main/docs/static.md).
For an advanced example of how to use this feature, take a look at [how to use it to build a static version of FrankenPHP](https://github.com/php/frankenphp/blob/main/docs/static.md).

## Contribution

Expand Down
3 changes: 2 additions & 1 deletion bin/spc-alpine-docker
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ RUN apk update; \
wget \
xz \
gettext-dev \
binutils-gold
binutils-gold \
patchelf

RUN curl -#fSL https://dl.static-php.dev/static-php-cli/bulk/php-8.4.4-cli-linux-\$(uname -m).tar.gz | tar -xz -C /usr/local/bin && \
chmod +x /usr/local/bin/php
Expand Down
9 changes: 7 additions & 2 deletions bin/spc-gnu-docker
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ RUN echo "source scl_source enable devtoolset-10" >> /etc/bashrc
RUN source /etc/bashrc
RUN yum install -y which

RUN curl -fsSL -o patchelf.tgz https://github.com/NixOS/patchelf/releases/download/0.18.0/patchelf-0.18.0-$BASE_ARCH.tar.gz && \
mkdir -p /patchelf && \
tar -xzf patchelf.tgz -C /patchelf --strip-components=1 && \
cp /patchelf/bin/patchelf /usr/bin/

RUN curl -o cmake.tgz -fsSL https://github.com/Kitware/CMake/releases/download/v3.31.4/cmake-3.31.4-linux-$BASE_ARCH.tar.gz && \
mkdir /cmake && \
tar -xzf cmake.tgz -C /cmake --strip-components 1
Expand All @@ -89,7 +94,7 @@ ENV PATH="/app/bin:/cmake/bin:$PATH"
ENV SPC_LIBC=glibc

ADD ./config/env.ini /app/config/env.ini
RUN bin/spc doctor --auto-fix --debug
RUN CC=gcc bin/spc doctor --auto-fix --debug

RUN curl -o make.tgz -fsSL https://ftp.gnu.org/gnu/make/make-4.4.tar.gz && \
tar -zxvf make.tgz && \
Expand Down Expand Up @@ -136,7 +141,7 @@ echo 'CC=/opt/rh/devtoolset-10/root/usr/bin/gcc' > /tmp/spc-gnu-docker.env
echo 'CXX=/opt/rh/devtoolset-10/root/usr/bin/g++' >> /tmp/spc-gnu-docker.env
echo 'AR=/opt/rh/devtoolset-10/root/usr/bin/ar' >> /tmp/spc-gnu-docker.env
echo 'LD=/opt/rh/devtoolset-10/root/usr/bin/ld' >> /tmp/spc-gnu-docker.env
echo 'SPC_DEFAULT_C_FLAGS=-fPIE -fPIC' >> /tmp/spc-gnu-docker.env
echo 'SPC_DEFAULT_C_FLAGS=-fPIC' >> /tmp/spc-gnu-docker.env
echo 'SPC_LIBC=glibc' >> /tmp/spc-gnu-docker.env
echo 'SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS_PROGRAM="-Wl,-O1 -pie"' >> /tmp/spc-gnu-docker.env
echo 'SPC_CMD_VAR_PHP_MAKE_EXTRA_LIBS="-ldl -lpthread -lm -lresolv -lutil -lrt"' >> /tmp/spc-gnu-docker.env
Expand Down
5 changes: 4 additions & 1 deletion config/env.ini
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ SPC_CONCURRENCY=${CPU_COUNT}
SPC_SKIP_PHP_VERSION_CHECK="no"
; Ignore some check item for bin/spc doctor command, comma separated (e.g. SPC_SKIP_DOCTOR_CHECK_ITEMS="if homebrew has installed")
SPC_SKIP_DOCTOR_CHECK_ITEMS=""
; extra modules that xcaddy will include in the FrankenPHP build
SPC_CMD_VAR_FRANKENPHP_XCADDY_MODULES="--with github.com/php/frankenphp/caddy --with github.com/dunglas/mercure/caddy --with github.com/dunglas/vulcain/caddy --with github.com/dunglas/caddy-cbrotli"

; EXTENSION_DIR where the built php will look for extension when a .ini instructs to load them
; only useful for builds targeting not pure-static linking
; default paths
Expand All @@ -66,7 +69,7 @@ SPC_LIBC=musl
CC=${SPC_LINUX_DEFAULT_CC}
CXX=${SPC_LINUX_DEFAULT_CXX}
AR=${SPC_LINUX_DEFAULT_AR}
LD=ld.gold
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"
Expand Down
9 changes: 9 additions & 0 deletions config/lib.json
Original file line number Diff line number Diff line change
Expand Up @@ -854,5 +854,14 @@
"zstd.h",
"zstd_errors.h"
]
},
"watcher": {
"source": "watcher",
"static-libs-unix": [
"libwatcher-c.a"
],
"headers": [
"wtr/watcher-c.h"
]
}
}
12 changes: 12 additions & 0 deletions config/pkg.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,17 @@
"extract-files": {
"upx-*-win64/upx.exe": "{pkg_root_path}/bin/upx.exe"
}
},
"go-mod-frankenphp-x86_64-linux": {
"type": "custom"
},
"go-mod-frankenphp-aarch64-linux": {
"type": "custom"
},
"go-mod-frankenphp-x86_64-macos": {
"type": "custom"
},
"go-mod-frankenphp-aarch64-macos": {
"type": "custom"
}
}
9 changes: 9 additions & 0 deletions config/source.json
Original file line number Diff line number Diff line change
Expand Up @@ -1070,5 +1070,14 @@
"type": "file",
"path": "LICENSE"
}
},
"watcher": {
"type": "ghtar",
"repo": "e-dant/watcher",
"prefer-stable": true,
"license": {
"type": "file",
"path": "license"
}
}
}
4 changes: 4 additions & 0 deletions docs/en/guide/manual-build.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ If the build is successful, you will see the `buildroot/bin` directory in the cu
- fpm: The build result is `buildroot/bin/php-fpm`.
- micro: The build result is `buildroot/bin/micro.sfx`. If you need to further package it with PHP code, please refer to [Packaging micro binary](./manual-build#command-micro-combine).
- embed: See [Using embed](./manual-build#embed-usage).
- frankenphp: The build result is `buildroot/bin/frankenphp`.

If the build fails, you can use the `--debug` parameter to view detailed error information,
or use the `--with-clean` to clear the old compilation results and recompile.
Expand Down Expand Up @@ -290,6 +291,7 @@ You need to specify a compilation target, choose from the following parameters:
- `--build-fpm`: Build a fpm sapi (php-fpm, used in conjunction with other traditional fpm architecture software such as nginx)
- `--build-micro`: Build a micro sapi (used to build a standalone executable binary containing PHP code)
- `--build-embed`: Build an embed sapi (used to embed into other C language programs)
- `--build-frankenphp`: Build a [FrankenPHP](https://github.com/php/frankenphp) executable
- `--build-all`: build all above sapi

```bash
Expand Down Expand Up @@ -509,6 +511,8 @@ When `bin/spc doctor` automatically repairs the Windows environment, tools such
Here is an example of installing the tool:

- Download and install UPX (Linux and Windows only): `bin/spc install-pkg upx`
- Download and install nasm (Windows only): `bin/spc install-pkg nasm`
- Download and install go-mod-frankenphp: `bin/spc install-pkg go-mod-frankenphp`

## Command - del-download

Expand Down
4 changes: 4 additions & 0 deletions docs/zh/guide/manual-build.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ bin/spc craft --debug
- fpm: 构建结果为 `buildroot/bin/php-fpm`。
- micro: 构建结果为 `buildroot/bin/micro.sfx`,如需进一步与 PHP 代码打包,请查看 [打包 micro 二进制](./manual-build#命令-micro-combine-打包-micro-二进制)。
- embed: 参见 [embed 使用](./manual-build#embed-使用)。
- frankenphp: 构建结果为 `buildroot/bin/frankenphp`。

如果中途构建出错,你可以使用 `--debug` 参数查看详细的错误信息,或者使用 `--with-clean` 参数清除旧的编译结果,重新编译。

Expand Down Expand Up @@ -250,6 +251,7 @@ bin/spc doctor --auto-fix
- `--build-fpm`: 构建一个 fpm sapi(php-fpm,用于和其他传统的 fpm 架构的软件如 nginx 配合使用)
- `--build-micro`: 构建一个 micro sapi(用于构建一个包含 PHP 代码的独立可执行二进制)
- `--build-embed`: 构建一个 embed sapi(用于嵌入到其他 C 语言程序中)
- `--build-frankenphp`: 构建一个 [frankenphp](https://github.com/php/frankenphp) 二进制
- `--build-all`: 构建以上所有 sapi

```bash
Expand Down Expand Up @@ -457,6 +459,8 @@ bin/spc dev:sort-config ext
下面是安装工具的示例:

- 下载安装 UPX(仅限 Linux 和 Windows): `bin/spc install-pkg upx`
- 下载安装 nasm(仅限 Windows): `bin/spc install-pkg nasm`
- 下载安装 go-mod-frankenphp: `bin/spc install-pkg go-mod-frankenphp`

## 命令 del-download - 删除已下载的资源

Expand Down
2 changes: 1 addition & 1 deletion src/SPC/ConsoleApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
*/
final class ConsoleApplication extends Application
{
public const VERSION = '2.6.0';
public const VERSION = '2.6.1';

public function __construct()
{
Expand Down
48 changes: 30 additions & 18 deletions src/SPC/builder/BuilderBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use SPC\exception\WrongUsageException;
use SPC\store\Config;
use SPC\store\FileSystem;
use SPC\store\LockFile;
use SPC\store\SourceManager;
use SPC\util\CustomExt;

Expand Down Expand Up @@ -262,17 +263,6 @@ public function buildSharedExts(): void
if (!$ext->isBuildShared()) {
continue;
}
if (Config::getExt($ext->getName(), 'type') === 'builtin' || Config::getExt($ext->getName(), 'build-with-php') === true) {
if (file_exists(BUILD_MODULES_PATH . '/' . $ext->getName() . '.so')) {
logger()->info('Shared extension [' . $ext->getName() . '] was already built by php-src/configure (' . $ext->getName() . '.so)');
continue;
}
if (Config::getExt($ext->getName(), 'build-with-php') === true) {
logger()->warning('Shared extension [' . $ext->getName() . '] did not build with php-src/configure (' . $ext->getName() . '.so)');
logger()->warning('Try deleting your build and source folders and running `spc build`` again.');
continue;
}
}
$ext->buildShared();
}
} catch (RuntimeException $e) {
Expand Down Expand Up @@ -361,15 +351,11 @@ public function getPHPVersion(): string
public function getPHPVersionFromArchive(?string $file = null): false|string
{
if ($file === null) {
$lock = file_exists(DOWNLOAD_PATH . '/.lock.json') ? file_get_contents(DOWNLOAD_PATH . '/.lock.json') : false;
if ($lock === false) {
return false;
}
$lock = json_decode($lock, true);
$file = $lock['php-src']['filename'] ?? null;
if ($file === null) {
$lock = LockFile::get('php-src');
if ($lock === null) {
return false;
}
$file = LockFile::getLockFullPath($lock);
}
if (preg_match('/php-(\d+\.\d+\.\d+(?:RC\d+)?)\.tar\.(?:gz|bz2|xz)/', $file, $match)) {
return $match[1];
Expand Down Expand Up @@ -415,6 +401,9 @@ public function getBuildTypeName(int $type): string
if (($type & BUILD_TARGET_EMBED) === BUILD_TARGET_EMBED) {
$ls[] = 'embed';
}
if (($type & BUILD_TARGET_FRANKENPHP) === BUILD_TARGET_FRANKENPHP) {
$ls[] = 'frankenphp';
}
return implode(', ', $ls);
}

Expand Down Expand Up @@ -521,6 +510,29 @@ public function emitPatchPoint(string $point_name): void
}
}

public function checkBeforeBuildPHP(int $rule): void
{
if (($rule & BUILD_TARGET_FRANKENPHP) === BUILD_TARGET_FRANKENPHP) {
if (!$this->getOption('enable-zts')) {
throw new WrongUsageException('FrankenPHP SAPI requires ZTS enabled PHP, build with `--enable-zts`!');
}
// frankenphp doesn't support windows, BSD is currently not supported by static-php-cli
if (!in_array(PHP_OS_FAMILY, ['Linux', 'Darwin'])) {
throw new WrongUsageException('FrankenPHP SAPI is only available on Linux and macOS!');
}
// frankenphp needs package go-mod-frankenphp installed
$pkg_dir = PKG_ROOT_PATH . '/go-mod-frankenphp-' . arch2gnu(php_uname('m')) . '-' . osfamily2shortname();
if (!file_exists("{$pkg_dir}/bin/go") || !file_exists("{$pkg_dir}/bin/xcaddy")) {
global $argv;
throw new WrongUsageException("FrankenPHP SAPI requires go-mod-frankenphp package, please install it first: {$argv[0]} install-pkg go-mod-frankenphp");
}
// frankenphp needs libxml2 lib on macos, see: https://github.com/php/frankenphp/blob/main/frankenphp.go#L17
if (PHP_OS_FAMILY === 'Darwin' && !$this->getLib('libxml2')) {
throw new WrongUsageException('FrankenPHP SAPI for macOS requires libxml2 library, please include the `xml` extension in your build.');
}
}
}

/**
* Generate micro extension test php code.
*/
Expand Down
30 changes: 25 additions & 5 deletions src/SPC/builder/Extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,12 @@ public function runCliCheckUnix(): void
// If you need to run some check, overwrite this or add your assert in src/globals/ext-tests/{extension_name}.php
// If check failed, throw RuntimeException
$sharedExtensions = $this->getSharedExtensionLoadString();
[$ret] = shell()->execWithResult(BUILD_BIN_PATH . '/php -n' . $sharedExtensions . ' --ri "' . $this->getDistName() . '"');
[$ret, $out] = shell()->execWithResult(BUILD_BIN_PATH . '/php -n' . $sharedExtensions . ' --ri "' . $this->getDistName() . '"');
if ($ret !== 0) {
throw new RuntimeException('extension ' . $this->getName() . ' failed compile check: php-cli returned ' . $ret);
throw new RuntimeException(
'extension ' . $this->getName() . ' failed runtime check: php-cli returned ' . $ret . "\n" .
join("\n", $out)
);
}

if (file_exists(ROOT_DIR . '/src/globals/ext-tests/' . $this->getName() . '.php')) {
Expand Down Expand Up @@ -328,6 +331,17 @@ public function validate(): void
*/
public function buildShared(): void
{
if (Config::getExt($this->getName(), 'type') === 'builtin' || Config::getExt($this->getName(), 'build-with-php') === true) {
if (file_exists(BUILD_MODULES_PATH . '/' . $this->getName() . '.so')) {
logger()->info('Shared extension [' . $this->getName() . '] was already built by php-src/configure (' . $this->getName() . '.so)');
return;
}
if (Config::getExt($this->getName(), 'build-with-php') === true) {
logger()->warning('Shared extension [' . $this->getName() . '] did not build with php-src/configure (' . $this->getName() . '.so)');
logger()->warning('Try deleting your build and source folders and running `spc build`` again.');
return;
}
}
logger()->info('Building extension [' . $this->getName() . '] as shared extension (' . $this->getName() . '.so)');
foreach ($this->dependencies as $dependency) {
if (!$dependency instanceof Extension) {
Expand Down Expand Up @@ -357,11 +371,16 @@ public function buildUnixShared(): void
{
$config = (new SPCConfigUtil($this->builder))->config([$this->getName()], with_dependencies: true);
[$staticLibString, $sharedLibString] = $this->getStaticAndSharedLibs();

// macOS ld64 doesn't understand these, while Linux and BSD do
// use them to make sure that all symbols are picked up, even if a library has already been visited before
$preStatic = PHP_OS_FAMILY !== 'Darwin' ? '-Wl,-Bstatic -Wl,--start-group ' : '';
$postStatic = PHP_OS_FAMILY !== 'Darwin' ? ' -Wl,--end-group -Wl,-Bdynamic ' : ' ';
$env = [
'CFLAGS' => $config['cflags'],
'CXXFLAGS' => $config['cflags'],
'LDFLAGS' => $config['ldflags'],
'LIBS' => '-Wl,-Bstatic -Wl,--start-group ' . $staticLibString . ' -Wl,--end-group -Wl,-Bdynamic ' . $sharedLibString,
'LIBS' => $preStatic . $staticLibString . $postStatic . $sharedLibString,
'LD_LIBRARY_PATH' => BUILD_LIB_PATH,
];

Expand All @@ -382,6 +401,7 @@ public function buildUnixShared(): void
'--enable-shared --disable-static'
);

// some extensions don't define their dependencies well, this patch is only needed for a few
FileSystem::replaceFileRegex(
$this->source_dir . '/Makefile',
'/^(.*_SHARED_LIBADD\s*=.*)$/m',
Expand Down Expand Up @@ -468,7 +488,7 @@ protected function addExtensionDependency(string $name, bool $optional = false):
*
* @return array [staticLibString, sharedLibString]
*/
private function getStaticAndSharedLibs(): array
protected function getStaticAndSharedLibs(): array
{
$config = (new SPCConfigUtil($this->builder))->config([$this->getName()], with_dependencies: true);
$sharedLibString = '';
Expand All @@ -483,7 +503,7 @@ private function getStaticAndSharedLibs(): array
continue;
}
$static_lib = 'lib' . $lib . '.a';
if (file_exists(BUILD_LIB_PATH . '/' . $static_lib)) {
if (file_exists(BUILD_LIB_PATH . '/' . $static_lib) && !str_contains($static_lib, 'libphp')) {
if (!str_contains($staticLibString, '-l' . $lib . ' ')) {
$staticLibString .= '-l' . $lib . ' ';
}
Expand Down
19 changes: 16 additions & 3 deletions src/SPC/builder/LibraryBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use SPC\store\Config;
use SPC\store\Downloader;
use SPC\store\FileSystem;
use SPC\store\LockFile;
use SPC\store\SourceManager;
use SPC\util\GlobalValueTrait;

Expand Down Expand Up @@ -46,12 +47,11 @@ public function __construct(?string $source_dir = null)
*/
public function setup(bool $force = false): int
{
$lock = json_decode(FileSystem::readFile(DOWNLOAD_PATH . '/.lock.json'), true) ?? [];
$source = Config::getLib(static::NAME, 'source');
// if source is locked as pre-built, we just tryInstall it
$pre_built_name = Downloader::getPreBuiltLockName($source);
if (isset($lock[$pre_built_name]) && ($lock[$pre_built_name]['lock_as'] ?? SPC_DOWNLOAD_SOURCE) === SPC_DOWNLOAD_PRE_BUILT) {
return $this->tryInstall($lock[$pre_built_name], $force);
if (($lock = LockFile::get($pre_built_name)) && $lock['lock_as'] === SPC_DOWNLOAD_PRE_BUILT) {
return $this->tryInstall($lock, $force);
}
return $this->tryBuild($force);
}
Expand Down Expand Up @@ -215,6 +215,19 @@ public function tryInstall(array $lock, bool $force_install = false): int
*/
public function tryBuild(bool $force_build = false): int
{
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',
);
}
if (file_exists($this->source_dir . '/.spc.patched')) {
$this->patched = true;
}
Expand Down
Loading
Loading