Skip to content

Commit 03a33d8

Browse files
committed
fix frankenphp build
1 parent 176e562 commit 03a33d8

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

src/SPC/builder/unix/UnixBuilderBase.php

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
use SPC\store\Downloader;
1717
use SPC\store\FileSystem;
1818
use SPC\store\pkg\GoXcaddy;
19+
use SPC\store\pkg\Zig;
1920
use SPC\util\DependencyUtil;
21+
use SPC\util\GlobalEnvManager;
2022
use SPC\util\SPCConfigUtil;
2123

2224
abstract class UnixBuilderBase extends BuilderBase
@@ -52,7 +54,7 @@ public function getAllStaticLibFiles(): array
5254
array_unshift($libFiles, ...$lib->getStaticLibs());
5355
}
5456
}
55-
return array_map(fn ($x) => realpath(BUILD_LIB_PATH . "/{$x}"), $libFiles);
57+
return array_map(fn($x) => realpath(BUILD_LIB_PATH . "/{$x}"), $libFiles);
5658
}
5759

5860
/**
@@ -98,7 +100,8 @@ public function makeAutoconfArgs(string $name, array $libSpecs): string
98100
if ($lib instanceof LinuxLibraryBase || $lib instanceof MacOSLibraryBase || $lib instanceof BSDLibraryBase) {
99101
logger()->info("{$name} \033[32;1mwith\033[0;1m {$libName} support");
100102
$ret .= "--with-{$libName}=yes " . $lib->makeAutoconfEnv($prefix) . ' ';
101-
} else {
103+
}
104+
else {
102105
logger()->info("{$name} \033[31;1mwithout\033[0;1m {$libName} support");
103106
$ret .= ($disableArgs ?? "--with-{$libName}=no") . ' ';
104107
}
@@ -212,7 +215,8 @@ protected function sanityCheck(int $build_target): void
212215
if (getenv('SPC_CMD_VAR_PHP_EMBED_TYPE') === 'shared') {
213216
$ext_path = 'LD_LIBRARY_PATH=' . BUILD_ROOT_PATH . '/lib:$LD_LIBRARY_PATH ';
214217
FileSystem::removeFileIfExists(BUILD_ROOT_PATH . '/lib/libphp.a');
215-
} else {
218+
}
219+
else {
216220
$ext_path = '';
217221
FileSystem::removeFileIfExists(BUILD_ROOT_PATH . '/lib/libphp.so');
218222
}
@@ -241,7 +245,7 @@ protected function sanityCheck(int $build_target): void
241245
/**
242246
* 将编译好的二进制文件发布到 buildroot
243247
*
244-
* @param int $type 发布类型
248+
* @param int $type 发布类型
245249
* @throws RuntimeException
246250
* @throws FileSystemException
247251
*/
@@ -333,7 +337,7 @@ protected function buildFrankenphp(): void
333337

334338
$config = (new SPCConfigUtil($this))->config($this->ext_list, $this->lib_list, with_dependencies: true);
335339

336-
$env = [...GoXcaddy::getEnvironment(), ...[
340+
$env = [
337341
'CGO_ENABLED' => '1',
338342
'CGO_CFLAGS' => $config['cflags'],
339343
'CGO_LDFLAGS' => "{$config['ldflags']} {$config['libs']} {$lrt}",
@@ -343,7 +347,14 @@ protected function buildFrankenphp(): void
343347
"{$frankenPhpVersion} PHP {$libphpVersion} Caddy'\\\" " .
344348
"-tags={$muslTags}nobadger,nomysql,nopgx{$nobrotli}{$nowatcher}",
345349
'LD_LIBRARY_PATH' => BUILD_LIB_PATH,
346-
]];
350+
];
351+
foreach (GoXcaddy::getEnvironment() as $key => $value) {
352+
if ($key === 'PATH') {
353+
GlobalEnvManager::addPathIfNotExists($value);
354+
} else {
355+
$env[$key] = $value;
356+
}
357+
}
347358
shell()->cd(BUILD_BIN_PATH)
348359
->setEnv($env)
349360
->exec("xcaddy build --output frankenphp {$xcaddyModules}");

src/SPC/util/GlobalEnvManager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public static function putenv(string $val): void
117117
self::$env_cache[] = $val;
118118
}
119119

120-
private static function addPathIfNotExists(string $path): void
120+
public static function addPathIfNotExists(string $path): void
121121
{
122122
if (is_unix() && !str_contains(getenv('PATH'), $path)) {
123123
self::putenv("PATH={$path}:" . getenv('PATH'));

0 commit comments

Comments
 (0)