Просмотр исходного кода

Merge pull request #64 from mpociot/libargon2-support

Add support for libargon2
Jerry Ma 1 год назад
Родитель
Сommit
cf198e0f0a

+ 7 - 0
config/ext.json

@@ -242,6 +242,13 @@
             "zlib"
         ]
     },
+    "password-argon2": {
+        "type": "builtin",
+        "arg-type": "with-prefix",
+        "lib-depends": [
+            "libargon2"
+        ]
+    },
     "pcntl": {
         "type": "builtin",
         "unix-only": true

+ 6 - 0
config/lib.json

@@ -163,6 +163,12 @@
             "libsodium"
         ]
     },
+    "libargon2": {
+        "source": "libargon2",
+        "static-libs-unix": [
+            "libargon2.a"
+        ]
+    },
     "libavif": {
         "source": "libavif",
         "static-libs-unix": [

+ 11 - 3
config/source.json

@@ -172,6 +172,15 @@
             "path": "LICENSE"
         }
     },
+    "libargon2": {
+        "type": "git",
+        "rev": "master",
+        "url": "https://github.com/mpociot/phc-winner-argon2",
+        "license": {
+            "type": "file",
+            "path": "LICENSE"
+        }
+    },
     "libavif": {
         "type": "ghtar",
         "repo": "AOMediaCodec/libavif",
@@ -376,9 +385,8 @@
         }
     },
     "pkg-config": {
-        "type": "filelist",
-        "url": "https://pkgconfig.freedesktop.org/releases/",
-        "regex": "/href=\"(?<file>pkg-config-(?<version>[^\"]+)\\.tar\\.gz)\"/",
+        "type": "url",
+        "url": "https://dl.static-php.dev/static-php-cli/deps/pkg-config/pkg-config-0.29.2.tar.gz",
         "license": {
             "type": "file",
             "path": "COPYING"

+ 21 - 0
src/SPC/builder/extension/password_argon2.php

@@ -0,0 +1,21 @@
+<?php
+
+declare(strict_types=1);
+
+namespace SPC\builder\extension;
+
+use SPC\builder\Extension;
+use SPC\exception\RuntimeException;
+use SPC\util\CustomExt;
+
+#[CustomExt('password-argon2')]
+class password_argon2 extends Extension
+{
+    public function runCliCheck(): void
+    {
+        [$ret] = shell()->execWithResult(BUILD_ROOT_PATH . '/bin/php -r "assert(defined(\'PASSWORD_ARGON2I\'));"');
+        if ($ret !== 0) {
+            throw new RuntimeException('extension ' . $this->getName() . ' failed sanity check');
+        }
+    }
+}

+ 25 - 0
src/SPC/builder/linux/library/libargon2.php

@@ -0,0 +1,25 @@
+<?php
+
+declare(strict_types=1);
+
+namespace SPC\builder\linux\library;
+
+use SPC\exception\WrongUsageException;
+use SPC\store\FileSystem;
+
+class libargon2 extends LinuxLibraryBase
+{
+    use \SPC\builder\unix\library\libargon2;
+
+    public const NAME = 'libargon2';
+
+    public function patchBeforeBuild(): bool
+    {
+        // detect libsodium (The libargon2 conflicts with the libsodium library.)
+        if ($this->builder->getLib('libsodium') !== null) {
+            throw new WrongUsageException('libargon2 (required by password-argon2) conflicts with the libsodium library !');
+        }
+        FileSystem::replaceFileStr($this->source_dir . '/Makefile', 'LIBRARY_REL ?= lib/x86_64-linux-gnu', 'LIBRARY_REL ?= lib');
+        return true;
+    }
+}

+ 12 - 0
src/SPC/builder/macos/library/libargon2.php

@@ -0,0 +1,12 @@
+<?php
+
+declare(strict_types=1);
+
+namespace SPC\builder\macos\library;
+
+class libargon2 extends MacOSLibraryBase
+{
+    use \SPC\builder\unix\library\libargon2;
+
+    public const NAME = 'libargon2';
+}

+ 26 - 0
src/SPC/builder/unix/library/libargon2.php

@@ -0,0 +1,26 @@
+<?php
+
+declare(strict_types=1);
+
+namespace SPC\builder\unix\library;
+
+use SPC\store\FileSystem;
+
+trait libargon2
+{
+    protected function build()
+    {
+        shell()->cd($this->source_dir)
+            ->exec("make PREFIX='' clean")
+            ->exec("make -j{$this->builder->concurrency} PREFIX=''")
+            ->exec("make install PREFIX='' DESTDIR=" . BUILD_ROOT_PATH);
+
+        $this->patchPkgconfPrefix(['libargon2.pc']);
+
+        foreach (FileSystem::scanDirFiles(BUILD_ROOT_PATH . '/lib/', false, true) as $filename) {
+            if (str_starts_with($filename, 'libargon2') && (str_contains($filename, '.so') || str_ends_with($filename, '.dylib'))) {
+                unlink(BUILD_ROOT_PATH . '/lib/' . $filename);
+            }
+        }
+    }
+}

+ 5 - 1
src/globals/test-extensions.php

@@ -3,6 +3,10 @@
 declare(strict_types=1);
 
 # If you want to test new extensions here, just modify it.
-$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';
+$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';
+
+if (PHP_OS_FAMILY === 'Darwin') {
+    $extensions .= ',sodium';
+}
 
 echo $extensions;