Skip to content

Commit 23db10d

Browse files
committed
Add libiconv,libssh2,libxml2,xz
1 parent 5a83412 commit 23db10d

File tree

9 files changed

+190
-30
lines changed

9 files changed

+190
-30
lines changed

config/pkg/lib/libiconv.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
libiconv:
2+
type: library
3+
artifact:
4+
source:
5+
type: filelist
6+
url: 'https://ftp.gnu.org/gnu/libiconv/'
7+
regex: '/href="(?<file>libiconv-(?<version>[^"]+)\.tar\.gz)"/'
8+
binary: hosted
9+
metadata:
10+
license-files: [COPYING.LIB]
11+
license: LGPL-2.0-or-later
12+
headers:
13+
- iconv.h
14+
- libcharset.h
15+
- localcharset.h
16+
static-libs@unix:
17+
- libiconv.a
18+
- libcharset.a

config/pkg/lib/libssh2.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
libssh2:
2+
type: library
3+
artifact:
4+
source:
5+
type: ghrel
6+
repo: libssh2/libssh2
7+
match: libssh2.+\.tar\.gz
8+
prefer-stable: true
9+
binary: hosted
10+
metadata:
11+
license-files: [COPYING]
12+
license: BSD-3-Clause
13+
depends:
14+
- openssl
15+
headers:
16+
- libssh2.h
17+
- libssh2_publickey.h
18+
- libssh2_sftp.h
19+
static-libs@unix:
20+
- libssh2.a
21+
pkg-configs:
22+
- libssh2

config/pkg/lib/libxml2.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
libxml2:
2+
type: library
3+
artifact:
4+
source:
5+
type: ghtagtar
6+
repo: GNOME/libxml2
7+
match: 'v2\.\d+\.\d+$'
8+
metadata:
9+
license-files: [Copyright]
10+
license: MIT
11+
depends@unix:
12+
- libiconv
13+
suggests@unix:
14+
- xz
15+
- zlib
16+
headers:
17+
- libxml2
18+
pkg-configs:
19+
- libxml-2.0

config/pkg/lib/xz.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
xz:
2+
type: library
3+
artifact:
4+
source:
5+
type: ghrel
6+
repo: tukaani-project/xz
7+
match: xz.+\.tar\.xz
8+
prefer-stable: true
9+
binary: hosted
10+
metadata:
11+
license-files: [COPYING]
12+
license: 0BSD
13+
depends@unix:
14+
- libiconv
15+
headers@unix:
16+
- lzma
17+
static-libs@unix:
18+
- liblzma.a
19+
pkg-configs:
20+
- liblzma

src/Package/Library/libiconv.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,17 @@
1212
#[Library('libiconv')]
1313
class libiconv
1414
{
15+
#[BuildFor('Linux')]
1516
#[BuildFor('Darwin')]
16-
public function build(LibraryPackage $package): void
17+
public function build(LibraryPackage $lib): void
1718
{
18-
UnixAutoconfExecutor::create($package)
19+
UnixAutoconfExecutor::create($lib)
1920
->configure(
2021
'--enable-extra-encodings',
2122
'--enable-year2038',
2223
)
2324
->make('install-lib', with_install: false)
24-
->make('install-lib', with_install: false, dir: "{$package->getSourceDir()}/libcharset");
25-
$package->patchLaDependencyPrefix();
25+
->make('install-lib', with_install: false, dir: $lib->getSourceDir() . '/libcharset');
26+
$lib->patchLaDependencyPrefix();
2627
}
2728
}

src/Package/Library/libssh2.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Package\Library;
6+
7+
use StaticPHP\Attribute\Package\BuildFor;
8+
use StaticPHP\Attribute\Package\Library;
9+
use StaticPHP\Package\LibraryPackage;
10+
use StaticPHP\Runtime\Executor\UnixCMakeExecutor;
11+
12+
#[Library('libssh2')]
13+
class libssh2
14+
{
15+
#[BuildFor('Linux')]
16+
#[BuildFor('Darwin')]
17+
public function build(LibraryPackage $lib): void
18+
{
19+
UnixCMakeExecutor::create($lib)
20+
->optionalPackage('zlib', ...cmake_boolean_args('ENABLE_ZLIB_COMPRESSION'))
21+
->addConfigureArgs(
22+
'-DBUILD_EXAMPLES=OFF',
23+
'-DBUILD_TESTING=OFF'
24+
)
25+
->build();
26+
27+
$lib->patchPkgconfPrefix(['libssh2.pc']);
28+
}
29+
}

src/Package/Library/libxml2.php

Lines changed: 45 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,47 +8,68 @@
88
use StaticPHP\Attribute\Package\Library;
99
use StaticPHP\Package\LibraryPackage;
1010
use StaticPHP\Runtime\Executor\UnixCMakeExecutor;
11-
use StaticPHP\Runtime\SystemTarget;
1211
use StaticPHP\Util\FileSystem;
1312

1413
#[Library('libxml2')]
1514
class libxml2
1615
{
17-
#[BuildFor('Darwin')]
18-
public function build(LibraryPackage $package): void
16+
#[BuildFor('Linux')]
17+
public function buildForLinux(LibraryPackage $lib): void
1918
{
20-
$cmake = UnixCMakeExecutor::create($package)
19+
UnixCMakeExecutor::create($lib)
2120
->optionalPackage(
2221
'zlib',
2322
'-DLIBXML2_WITH_ZLIB=ON ' .
24-
"-DZLIB_LIBRARY={$package->getLibDir()}/libz.a " .
25-
"-DZLIB_INCLUDE_DIR={$package->getIncludeDir()}",
23+
"-DZLIB_LIBRARY={$lib->getLibDir()}/libz.a " .
24+
"-DZLIB_INCLUDE_DIR={$lib->getIncludeDir()}",
2625
'-DLIBXML2_WITH_ZLIB=OFF',
2726
)
2827
->optionalPackage('xz', ...cmake_boolean_args('LIBXML2_WITH_LZMA'))
2928
->addConfigureArgs(
3029
'-DLIBXML2_WITH_ICONV=ON',
30+
'-DIconv_IS_BUILT_IN=OFF',
3131
'-DLIBXML2_WITH_ICU=OFF', // optional, but discouraged: https://gitlab.gnome.org/GNOME/libxml2/-/blob/master/README.md
3232
'-DLIBXML2_WITH_PYTHON=OFF',
3333
'-DLIBXML2_WITH_PROGRAMS=OFF',
3434
'-DLIBXML2_WITH_TESTS=OFF',
35-
);
36-
37-
if (SystemTarget::getTargetOS() === 'Linux') {
38-
$cmake->addConfigureArgs('-DIconv_IS_BUILT_IN=OFF');
39-
}
40-
41-
$cmake->build();
42-
43-
FileSystem::replaceFileStr(
44-
BUILD_LIB_PATH . '/pkgconfig/libxml-2.0.pc',
45-
'-lxml2 -liconv',
46-
'-lxml2'
47-
);
48-
FileSystem::replaceFileStr(
49-
BUILD_LIB_PATH . '/pkgconfig/libxml-2.0.pc',
50-
'-lxml2',
51-
'-lxml2 -liconv'
52-
);
35+
)
36+
->build();
37+
38+
$this->patchPkgConfig($lib);
39+
}
40+
41+
#[BuildFor('Darwin')]
42+
public function buildForDarwin(LibraryPackage $lib): void
43+
{
44+
UnixCMakeExecutor::create($lib)
45+
->optionalPackage(
46+
'zlib',
47+
'-DLIBXML2_WITH_ZLIB=ON ' .
48+
"-DZLIB_LIBRARY={$lib->getLibDir()}/libz.a " .
49+
"-DZLIB_INCLUDE_DIR={$lib->getIncludeDir()}",
50+
'-DLIBXML2_WITH_ZLIB=OFF',
51+
)
52+
->optionalPackage('xz', ...cmake_boolean_args('LIBXML2_WITH_LZMA'))
53+
->addConfigureArgs(
54+
'-DLIBXML2_WITH_ICONV=ON',
55+
'-DLIBXML2_WITH_ICU=OFF',
56+
'-DLIBXML2_WITH_PYTHON=OFF',
57+
'-DLIBXML2_WITH_PROGRAMS=OFF',
58+
'-DLIBXML2_WITH_TESTS=OFF',
59+
)
60+
->build();
61+
62+
$this->patchPkgConfig($lib);
63+
}
64+
65+
private function patchPkgConfig(LibraryPackage $lib): void
66+
{
67+
$pcFile = "{$lib->getLibDir()}/pkgconfig/libxml-2.0.pc";
68+
69+
// Remove -liconv from original
70+
FileSystem::replaceFileStr($pcFile, '-lxml2 -liconv', '-lxml2');
71+
72+
// Add -liconv after -lxml2
73+
FileSystem::replaceFileStr($pcFile, '-lxml2', '-lxml2 -liconv');
5374
}
5475
}

src/Package/Library/xz.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Package\Library;
6+
7+
use StaticPHP\Attribute\Package\BuildFor;
8+
use StaticPHP\Attribute\Package\Library;
9+
use StaticPHP\Package\LibraryPackage;
10+
use StaticPHP\Runtime\Executor\UnixAutoconfExecutor;
11+
12+
#[Library('xz')]
13+
class xz
14+
{
15+
#[BuildFor('Linux')]
16+
#[BuildFor('Darwin')]
17+
public function build(LibraryPackage $lib): void
18+
{
19+
UnixAutoconfExecutor::create($lib)
20+
->configure(
21+
'--disable-scripts',
22+
'--disable-doc',
23+
'--with-libiconv',
24+
'--bindir=/tmp/xz', // xz binary will corrupt `tar` command, that's really strange.
25+
)
26+
->make();
27+
$lib->patchPkgconfPrefix(['liblzma.pc']);
28+
$lib->patchLaDependencyPrefix();
29+
}
30+
}

src/StaticPHP/Command/BuildLibsCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
use Symfony\Component\Console\Attribute\AsCommand;
88
use Symfony\Component\Console\Input\InputArgument;
99

10-
#[AsCommand('build:libs')]
10+
#[AsCommand('build:libs', 'Build specified library packages')]
1111
class BuildLibsCommand extends BaseCommand
1212
{
13-
public function configure()
13+
public function configure(): void
1414
{
1515
$this->addArgument('libraries', InputArgument::REQUIRED, 'The library packages will be compiled, comma separated');
1616
}

0 commit comments

Comments
 (0)