Skip to content

Commit 9634b8b

Browse files
authored
set custom binary name for frankenphp, allow linking against system openssl (fix mssql issues) (#1056)
2 parents 8c4e3d5 + 5d5a50a commit 9634b8b

File tree

7 files changed

+47
-15
lines changed

7 files changed

+47
-15
lines changed

config/lib.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -862,6 +862,9 @@
862862
},
863863
"openssl": {
864864
"source": "openssl",
865+
"pkg-configs": [
866+
"openssl"
867+
],
865868
"static-libs-unix": [
866869
"libssl.a",
867870
"libcrypto.a"
@@ -974,6 +977,11 @@
974977
},
975978
"unixodbc": {
976979
"source": "unixodbc",
980+
"pkg-configs": [
981+
"odbc",
982+
"odbccr",
983+
"odbcinst"
984+
],
977985
"static-libs-unix": [
978986
"libodbc.a",
979987
"libodbccr.a",
@@ -1015,6 +1023,9 @@
10151023
},
10161024
"zlib": {
10171025
"source": "zlib",
1026+
"pkg-configs": [
1027+
"zlib"
1028+
],
10181029
"static-libs-unix": [
10191030
"libz.a"
10201031
],
@@ -1028,6 +1039,9 @@
10281039
},
10291040
"zstd": {
10301041
"source": "zstd",
1042+
"pkg-configs": [
1043+
"libzstd"
1044+
],
10311045
"static-libs-unix": [
10321046
"libzstd.a"
10331047
],

src/SPC/builder/Extension.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ public function getLibFilesString(): string
9696
fn ($x) => $x->getStaticLibFiles(),
9797
$this->getLibraryDependencies(recursive: true)
9898
);
99-
return implode(' ', $ret);
99+
$libs = implode(' ', $ret);
100+
return deduplicate_flags($libs);
100101
}
101102

102103
/**

src/SPC/builder/LibraryBase.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,27 @@ protected function installLicense(): void
365365

366366
protected function isLibraryInstalled(): bool
367367
{
368+
if ($pkg_configs = Config::getLib(static::NAME, 'pkg-configs', [])) {
369+
$pkg_config_path = getenv('PKG_CONFIG_PATH') ?: '';
370+
$search_paths = array_unique(array_filter(explode(is_unix() ? ':' : ';', $pkg_config_path)));
371+
372+
foreach ($pkg_configs as $name) {
373+
$found = false;
374+
foreach ($search_paths as $path) {
375+
if (file_exists($path . "/{$name}.pc")) {
376+
$found = true;
377+
break;
378+
}
379+
}
380+
if (!$found) {
381+
return false;
382+
}
383+
}
384+
// allow using system dependencies if pkg_config_path is explicitly defined
385+
if (count($search_paths) > 1) {
386+
return true;
387+
}
388+
}
368389
foreach (Config::getLib(static::NAME, 'static-libs', []) as $name) {
369390
if (!file_exists(BUILD_LIB_PATH . "/{$name}")) {
370391
return false;

src/SPC/builder/traits/UnixSystemUtilTrait.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ public static function getDynamicExportedSymbols(string $lib_file): ?string
7272
if (!is_file($symbol_file)) {
7373
throw new SPCInternalException("The symbol file {$symbol_file} does not exist, please check if nm command is available.");
7474
}
75+
// https://github.com/ziglang/zig/issues/24662
76+
if (ToolchainManager::getToolchainClass() === ZigToolchain::class) {
77+
return '-Wl,--export-dynamic'; // needs release 0.16, can be removed then
78+
}
7579
// macOS/zig
7680
if (SPCTarget::getTargetOS() !== 'Linux' || ToolchainManager::getToolchainClass() === ZigToolchain::class) {
7781
return "-Wl,-exported_symbols_list,{$symbol_file}";

src/SPC/builder/unix/UnixBuilderBase.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,7 @@ protected function buildFrankenphp(): void
458458
'-ldflags \"-linkmode=external ' . $extLdFlags . ' ' .
459459
'-X \'github.com/caddyserver/caddy/v2/modules/caddyhttp.ServerHeader=FrankenPHP Caddy\' ' .
460460
'-X \'github.com/caddyserver/caddy/v2.CustomVersion=FrankenPHP ' .
461+
'-X \'github.com/caddyserver/caddy/v2.CustomBinaryName=frankenphp ' .
461462
"v{$frankenPhpVersion} PHP {$libphpVersion} Caddy'\\\" " .
462463
"-tags={$muslTags}nobadger,nomysql,nopgx{$nobrotli}{$nowatcher}",
463464
'LD_LIBRARY_PATH' => BUILD_LIB_PATH,

src/SPC/builder/unix/library/postgresql.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,7 @@ protected function build(): void
9393

9494
// remove dynamic libs
9595
shell()->cd($this->source_dir . '/build')
96-
->exec("rm -rf {$this->getBuildRootPath()}/lib/*.so.*")
97-
->exec("rm -rf {$this->getBuildRootPath()}/lib/*.so")
96+
->exec("rm -rf {$this->getBuildRootPath()}/lib/*.so*")
9897
->exec("rm -rf {$this->getBuildRootPath()}/lib/*.dylib");
9998

10099
FileSystem::replaceFileStr("{$this->getLibDir()}/pkgconfig/libpq.pc", '-lldap', '-lldap -llber');

src/SPC/util/executor/UnixAutoconfExecutor.php

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,32 +16,24 @@ class UnixAutoconfExecutor extends Executor
1616

1717
protected array $configure_args = [];
1818

19-
protected array $ignore_args = [];
20-
2119
public function __construct(protected BSDLibraryBase|LinuxLibraryBase|MacOSLibraryBase $library)
2220
{
2321
parent::__construct($library);
2422
$this->initShell();
23+
$this->configure_args = $this->getDefaultConfigureArgs();
2524
}
2625

2726
/**
2827
* Run ./configure
2928
*/
3029
public function configure(...$args): static
3130
{
32-
// remove all the ignored args
33-
$args = array_merge($args, $this->getDefaultConfigureArgs(), $this->configure_args);
34-
$args = array_diff($args, $this->ignore_args);
31+
$args = array_merge($args, $this->configure_args);
3532
$configure_args = implode(' ', $args);
3633

3734
return $this->seekLogFileOnException(fn () => $this->shell->exec("./configure {$configure_args}"));
3835
}
3936

40-
public function getConfigureArgsString(): string
41-
{
42-
return implode(' ', array_merge($this->getDefaultConfigureArgs(), $this->configure_args));
43-
}
44-
4537
/**
4638
* Run make
4739
*
@@ -111,7 +103,7 @@ public function addConfigureArgs(...$args): static
111103
*/
112104
public function removeConfigureArgs(...$args): static
113105
{
114-
$this->ignore_args = [...$this->ignore_args, ...$args];
106+
$this->configure_args = array_diff($this->configure_args, $args);
115107
return $this;
116108
}
117109

@@ -133,8 +125,8 @@ public function appendEnv(array $env): static
133125
private function getDefaultConfigureArgs(): array
134126
{
135127
return [
136-
'--disable-shared',
137128
'--enable-static',
129+
'--disable-shared',
138130
"--prefix={$this->library->getBuildRootPath()}",
139131
'--with-pic',
140132
'--enable-pic',

0 commit comments

Comments
 (0)