Skip to content

Commit cf198e0

Browse files
authored
Merge pull request #64 from mpociot/libargon2-support
Add support for libargon2
2 parents 3573007 + 248918e commit cf198e0

File tree

8 files changed

+113
-4
lines changed

8 files changed

+113
-4
lines changed

config/ext.json

+7
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,13 @@
242242
"zlib"
243243
]
244244
},
245+
"password-argon2": {
246+
"type": "builtin",
247+
"arg-type": "with-prefix",
248+
"lib-depends": [
249+
"libargon2"
250+
]
251+
},
245252
"pcntl": {
246253
"type": "builtin",
247254
"unix-only": true

config/lib.json

+6
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,12 @@
163163
"libsodium"
164164
]
165165
},
166+
"libargon2": {
167+
"source": "libargon2",
168+
"static-libs-unix": [
169+
"libargon2.a"
170+
]
171+
},
166172
"libavif": {
167173
"source": "libavif",
168174
"static-libs-unix": [

config/source.json

+11-3
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,15 @@
172172
"path": "LICENSE"
173173
}
174174
},
175+
"libargon2": {
176+
"type": "git",
177+
"rev": "master",
178+
"url": "https://github.com/mpociot/phc-winner-argon2",
179+
"license": {
180+
"type": "file",
181+
"path": "LICENSE"
182+
}
183+
},
175184
"libavif": {
176185
"type": "ghtar",
177186
"repo": "AOMediaCodec/libavif",
@@ -376,9 +385,8 @@
376385
}
377386
},
378387
"pkg-config": {
379-
"type": "filelist",
380-
"url": "https://pkgconfig.freedesktop.org/releases/",
381-
"regex": "/href=\"(?<file>pkg-config-(?<version>[^\"]+)\\.tar\\.gz)\"/",
388+
"type": "url",
389+
"url": "https://dl.static-php.dev/static-php-cli/deps/pkg-config/pkg-config-0.29.2.tar.gz",
382390
"license": {
383391
"type": "file",
384392
"path": "COPYING"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SPC\builder\extension;
6+
7+
use SPC\builder\Extension;
8+
use SPC\exception\RuntimeException;
9+
use SPC\util\CustomExt;
10+
11+
#[CustomExt('password-argon2')]
12+
class password_argon2 extends Extension
13+
{
14+
public function runCliCheck(): void
15+
{
16+
[$ret] = shell()->execWithResult(BUILD_ROOT_PATH . '/bin/php -r "assert(defined(\'PASSWORD_ARGON2I\'));"');
17+
if ($ret !== 0) {
18+
throw new RuntimeException('extension ' . $this->getName() . ' failed sanity check');
19+
}
20+
}
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SPC\builder\linux\library;
6+
7+
use SPC\exception\WrongUsageException;
8+
use SPC\store\FileSystem;
9+
10+
class libargon2 extends LinuxLibraryBase
11+
{
12+
use \SPC\builder\unix\library\libargon2;
13+
14+
public const NAME = 'libargon2';
15+
16+
public function patchBeforeBuild(): bool
17+
{
18+
// detect libsodium (The libargon2 conflicts with the libsodium library.)
19+
if ($this->builder->getLib('libsodium') !== null) {
20+
throw new WrongUsageException('libargon2 (required by password-argon2) conflicts with the libsodium library !');
21+
}
22+
FileSystem::replaceFileStr($this->source_dir . '/Makefile', 'LIBRARY_REL ?= lib/x86_64-linux-gnu', 'LIBRARY_REL ?= lib');
23+
return true;
24+
}
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SPC\builder\macos\library;
6+
7+
class libargon2 extends MacOSLibraryBase
8+
{
9+
use \SPC\builder\unix\library\libargon2;
10+
11+
public const NAME = 'libargon2';
12+
}
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SPC\builder\unix\library;
6+
7+
use SPC\store\FileSystem;
8+
9+
trait libargon2
10+
{
11+
protected function build()
12+
{
13+
shell()->cd($this->source_dir)
14+
->exec("make PREFIX='' clean")
15+
->exec("make -j{$this->builder->concurrency} PREFIX=''")
16+
->exec("make install PREFIX='' DESTDIR=" . BUILD_ROOT_PATH);
17+
18+
$this->patchPkgconfPrefix(['libargon2.pc']);
19+
20+
foreach (FileSystem::scanDirFiles(BUILD_ROOT_PATH . '/lib/', false, true) as $filename) {
21+
if (str_starts_with($filename, 'libargon2') && (str_contains($filename, '.so') || str_ends_with($filename, '.dylib'))) {
22+
unlink(BUILD_ROOT_PATH . '/lib/' . $filename);
23+
}
24+
}
25+
}
26+
}

src/globals/test-extensions.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
declare(strict_types=1);
44

55
# If you want to test new extensions here, just modify it.
6-
$extensions = 'apcu,bcmath,bz2,calendar,ctype,curl,dba,dom,event,exif,fileinfo,filter,ftp,gd,gmp,iconv,imagick,imap,intl,ldap,mbregex,mbstring,mysqli,mysqlnd,opcache,openssl,pcntl,pdo,pdo_mysql,pdo_pgsql,pdo_sqlite,pgsql,phar,posix,protobuf,readline,redis,session,shmop,simplexml,soap,sockets,sodium,sqlite3,swoole,sysvmsg,sysvsem,sysvshm,tokenizer,xml,xmlreader,xmlwriter,xsl,zip,zlib';
6+
$extensions = 'password-argon2,apcu,bcmath,bz2,calendar,ctype,curl,dba,dom,event,exif,fileinfo,filter,ftp,gd,gmp,iconv,imagick,imap,intl,mbregex,mbstring,mysqli,mysqlnd,opcache,openssl,pcntl,pdo,pdo_mysql,pdo_pgsql,pdo_sqlite,pgsql,phar,posix,protobuf,readline,redis,session,shmop,simplexml,soap,sockets,sqlite3,swoole,sysvmsg,sysvsem,sysvshm,tokenizer,xml,xmlreader,xmlwriter,xsl,zip,zlib';
7+
8+
if (PHP_OS_FAMILY === 'Darwin') {
9+
$extensions .= ',sodium';
10+
}
711

812
echo $extensions;

0 commit comments

Comments
 (0)