Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
18 changes: 18 additions & 0 deletions config/pkg/ext/ext-wikidiff2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
ext-wikidiff2:
type: php-extension
artifact:
source:
type: git
url: 'https://github.com/wikimedia/mediawiki-php-wikidiff2'
rev: master
metadata:
license-files: [COPYING]
license: GPL-2.0-or-later
depends:
- libthai
lang: cpp
php-extension:
os:
- Linux
- Darwin
arg-type: enable
17 changes: 17 additions & 0 deletions config/pkg/lib/libdatrie.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
libdatrie:
type: library
artifact:
source:
type: ghrel
repo: tlwg/libdatrie
match: libdatrie-.+\.tar\.xz
prefer-stable: true
metadata:
license-files: [COPYING]
license: LGPL-2.1-or-later
headers:
- datrie/trie.h
pkg-configs:
- datrie-0.2
static-libs@unix:
- libdatrie.a
19 changes: 19 additions & 0 deletions config/pkg/lib/libthai.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
libthai:
type: library
artifact:
source:
type: ghrel
repo: tlwg/libthai
match: libthai-.+\.tar\.xz
prefer-stable: true
metadata:
license-files: [COPYING]
license: LGPL-2.1-or-later
depends:
- libdatrie
headers:
- thai/thailib.h
pkg-configs:
- libthai
static-libs@unix:
- libthai.a
29 changes: 29 additions & 0 deletions src/Package/Extension/wikidiff2.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

namespace Package\Extension;

use Package\Target\php;
use StaticPHP\Attribute\Package\BeforeStage;
use StaticPHP\Attribute\Package\Extension;
use StaticPHP\Attribute\PatchDescription;
use StaticPHP\Package\PackageInstaller;
use StaticPHP\Package\PhpExtensionPackage;
use StaticPHP\Util\FileSystem;

#[Extension('wikidiff2')]
class wikidiff2 extends PhpExtensionPackage
{
#[BeforeStage('php', [php::class, 'buildconfForUnix'], 'ext-wikidiff2')]
#[PatchDescription('Copy src/php_wikidiff2.h to extension root so php-src build/genif.sh finds phpext_wikidiff2_ptr')]
public function copyHeaderForStaticBuild(PackageInstaller $installer): void
{
$ext_dir = $installer->getTargetPackage('php')->getSourceDir() . '/ext/wikidiff2';
$src_h = "{$ext_dir}/src/php_wikidiff2.h";
$dst_h = "{$ext_dir}/php_wikidiff2.h";
if (file_exists($src_h)) {
FileSystem::copy($src_h, $dst_h);
}
}
}
24 changes: 24 additions & 0 deletions src/Package/Library/libdatrie.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

namespace Package\Library;

use StaticPHP\Attribute\Package\BuildFor;
use StaticPHP\Attribute\Package\Library;
use StaticPHP\Package\LibraryPackage;
use StaticPHP\Runtime\Executor\UnixAutoconfExecutor;

#[Library('libdatrie')]
class libdatrie
{
#[BuildFor('Linux')]
#[BuildFor('Darwin')]
public function buildUnix(LibraryPackage $lib): void
{
UnixAutoconfExecutor::create($lib)
->addConfigureArgs('--disable-doxygen-doc')
->configure()
->make('SUBDIRS=datrie', with_install: 'SUBDIRS=datrie install');
}
}
26 changes: 26 additions & 0 deletions src/Package/Library/libthai.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

namespace Package\Library;

use StaticPHP\Attribute\Package\BuildFor;
use StaticPHP\Attribute\Package\Library;
use StaticPHP\Package\LibraryPackage;
use StaticPHP\Runtime\Executor\UnixAutoconfExecutor;

#[Library('libthai')]
class libthai
{
#[BuildFor('Linux')]
#[BuildFor('Darwin')]
public function buildUnix(LibraryPackage $lib): void
{
// Override dictdatadir only at build time so the static binary falls
// back to /usr/share/libthai/thbrk.tri without `make install` touching /usr/share.
UnixAutoconfExecutor::create($lib)
->addConfigureArgs('--disable-doxygen-doc', '--disable-dict')
->configure()
->make('dictdatadir=/usr/share/libthai');
}
}
16 changes: 16 additions & 0 deletions src/globals/ext-tests/wikidiff2.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

assert(function_exists('wikidiff2_do_diff'));
assert(function_exists('wikidiff2_inline_json_diff'));

$table = wikidiff2_do_diff("hello world\n", "hello php\n", 2);
assert(is_string($table));
assert(str_contains($table, 'world'));
assert(str_contains($table, 'php'));

$json = wikidiff2_inline_json_diff("hello world\n", "hello php\n", 2);
assert(is_string($json));
$decoded = json_decode($json, true);
assert(is_array($decoded) && isset($decoded['diff']));
Loading