Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
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
14 changes: 14 additions & 0 deletions config/lib.json
Original file line number Diff line number Diff line change
Expand Up @@ -862,6 +862,9 @@
},
"openssl": {
"source": "openssl",
"pkg-configs": [
"openssl"
],
"static-libs-unix": [
"libssl.a",
"libcrypto.a"
Expand Down Expand Up @@ -974,6 +977,11 @@
},
"unixodbc": {
"source": "unixodbc",
"pkg-configs": [
"odbc",
"odbccr",
"odbcinst"
],
"static-libs-unix": [
"libodbc.a",
"libodbccr.a",
Expand Down Expand Up @@ -1015,6 +1023,9 @@
},
"zlib": {
"source": "zlib",
"pkg-configs": [
"zlib"
],
"static-libs-unix": [
"libz.a"
],
Expand All @@ -1028,6 +1039,9 @@
},
"zstd": {
"source": "zstd",
"pkg-configs": [
"libzstd"
],
Comment thread
crazywhalecc marked this conversation as resolved.
"static-libs-unix": [
"libzstd.a"
],
Expand Down
3 changes: 2 additions & 1 deletion src/SPC/builder/Extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ public function getLibFilesString(): string
fn ($x) => $x->getStaticLibFiles(),
$this->getLibraryDependencies(recursive: true)
);
return implode(' ', $ret);
$libs = implode(' ', $ret);
return deduplicate_flags($libs);
}

/**
Expand Down
18 changes: 18 additions & 0 deletions src/SPC/builder/LibraryBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,24 @@ protected function installLicense(): void

protected function isLibraryInstalled(): bool
{
if ($pkg_configs = Config::getLib(static::NAME, 'pkg-configs', [])) {
$pkg_config_path = getenv('PKG_CONFIG_PATH') ?: '';
$search_paths = array_unique(array_filter(explode(is_unix() ? ':' : ';', $pkg_config_path)));

foreach ($pkg_configs as $name) {
$found = false;
foreach ($search_paths as $path) {
if (file_exists($path . "/{$name}.pc")) {
$found = true;
break;
}
}
if (!$found) {
return false;
}
}
return true; // allow using system dependencies if pkg_config_path is explicitly defined
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bypassing check could cause many problems in the future I think. Skipping building and using dynamic libraries should be two separate things, we cannot just do for checking though.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This behaviour was already intended before, you even documented it: https://github.com/crazywhalecc/static-php-cli/blob/main/docs/en/develop/system-build-tools.md#pkg-config-compilation-nix-only

It was simply bugged before.

Comment thread
henderkes marked this conversation as resolved.
Outdated
}
foreach (Config::getLib(static::NAME, 'static-libs', []) as $name) {
if (!file_exists(BUILD_LIB_PATH . "/{$name}")) {
return false;
Expand Down
4 changes: 4 additions & 0 deletions src/SPC/builder/traits/UnixSystemUtilTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ public static function getDynamicExportedSymbols(string $lib_file): ?string
if (!is_file($symbol_file)) {
throw new SPCInternalException("The symbol file {$symbol_file} does not exist, please check if nm command is available.");
}
// https://github.com/ziglang/zig/issues/24662
if (ToolchainManager::getToolchainClass() === ZigToolchain::class) {
return '-Wl,--export-dynamic'; // needs release 0.16, can be removed then
}
// macOS/zig
if (SPCTarget::getTargetOS() !== 'Linux' || ToolchainManager::getToolchainClass() === ZigToolchain::class) {
return "-Wl,-exported_symbols_list,{$symbol_file}";
Expand Down
1 change: 1 addition & 0 deletions src/SPC/builder/unix/UnixBuilderBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,7 @@ protected function buildFrankenphp(): void
'-ldflags \"-linkmode=external ' . $extLdFlags . ' ' .
'-X \'github.com/caddyserver/caddy/v2/modules/caddyhttp.ServerHeader=FrankenPHP Caddy\' ' .
'-X \'github.com/caddyserver/caddy/v2.CustomVersion=FrankenPHP ' .
'-X \'github.com/caddyserver/caddy/v2.CustomBinaryName=frankenphp ' .
"v{$frankenPhpVersion} PHP {$libphpVersion} Caddy'\\\" " .
"-tags={$muslTags}nobadger,nomysql,nopgx{$nobrotli}{$nowatcher}",
'LD_LIBRARY_PATH' => BUILD_LIB_PATH,
Expand Down
3 changes: 1 addition & 2 deletions src/SPC/builder/unix/library/postgresql.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@ protected function build(): void

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

FileSystem::replaceFileStr("{$this->getLibDir()}/pkgconfig/libpq.pc", '-lldap', '-lldap -llber');
Expand Down
16 changes: 4 additions & 12 deletions src/SPC/util/executor/UnixAutoconfExecutor.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,24 @@ class UnixAutoconfExecutor extends Executor

protected array $configure_args = [];

protected array $ignore_args = [];

public function __construct(protected BSDLibraryBase|LinuxLibraryBase|MacOSLibraryBase $library)
{
parent::__construct($library);
$this->initShell();
$this->configure_args = $this->getDefaultConfigureArgs();
}

/**
* Run ./configure
*/
public function configure(...$args): static
{
// remove all the ignored args
$args = array_merge($args, $this->getDefaultConfigureArgs(), $this->configure_args);
$args = array_diff($args, $this->ignore_args);
$args = array_merge($args, $this->configure_args);
$configure_args = implode(' ', $args);

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

public function getConfigureArgsString(): string
{
return implode(' ', array_merge($this->getDefaultConfigureArgs(), $this->configure_args));
}

/**
* Run make
*
Expand Down Expand Up @@ -111,7 +103,7 @@ public function addConfigureArgs(...$args): static
*/
public function removeConfigureArgs(...$args): static
{
$this->ignore_args = [...$this->ignore_args, ...$args];
$this->configure_args = array_diff($this->configure_args, $args);
return $this;
}

Expand All @@ -133,8 +125,8 @@ public function appendEnv(array $env): static
private function getDefaultConfigureArgs(): array
{
return [
'--disable-shared',
'--enable-static',
'--disable-shared',
"--prefix={$this->library->getBuildRootPath()}",
'--with-pic',
'--enable-pic',
Expand Down