Skip to content

Commit

Permalink
complete rework for proper ffi usability, resolves issues found in ex…
Browse files Browse the repository at this point in the history
…t-uv

- added back `ext-uv` C source code until all functions within is implemented.
- added functions/methods for direct Zval handling, a rewrite from https://github.com/lisachenko/z-engine.
- updated each platform `libuv` cdef *.h header files, currently only Windows version is used for implementation at the moment.
- added `zend api` *.h headers.
- additional tests implemented.
- updated examples to use ffi version by adding `require 'vendor/autoload.php';`
- updated CI to build/use libuv 1.44.2.
- additional stubs/updates for IDE static analysis.
- update Readme sections and progress.
- discovered `ext-uv` issue amphp/ext-uv#78 not really a real issue. The tests and examples using old `libuv` version that does not do a conversion on Windows from '0.0.0.0', changing to '127.0.0.1' everything works.
- also `uv_tty_init($loop, STDOUT,0)` can be used instead for `uv_pipe_open($loop, STDOUT)` that does not work on Windows and according to libuv/help#120 it's the best solution.
- added an emulation mode for `uv_pipe_open($loop, STDOUT)` under Windows, by using `uv_pipe()` internally.
- Todo: address amphp/ext-uv#82 and amphp/ext-uv#45
  • Loading branch information
TheTechsTech committed Aug 3, 2022
1 parent 78264ce commit decd82c
Show file tree
Hide file tree
Showing 113 changed files with 25,676 additions and 10,914 deletions.
5 changes: 5 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,8 @@
/codecov.yml export-ignore
/composer.lock export-ignore
/.cdef export-ignore
/php-8.* export-ignore
/cmd export-ignore
/php_uv.c export-ignore
/php_uv.h export-ignore
/uv.c export-ignore
2 changes: 1 addition & 1 deletion .github/workflows/Linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
version:
description: 'What version of libuv to compile and commit to repo?'
required: true
default: 1.44.1
default: 1.44.2
type: number

jobs:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/Windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
version:
description: 'What version of libuv to compile and commit to repo?'
required: true
default: 1.44.1
default: 1.44.2
type: number

jobs:
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/macOS.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ on:
version:
description: 'What version of libuv to compile and commit to repo?'
required: true
default: 1.44.1
default: 1.44.2
type: number

jobs:
macos:
runs-on: macos-10.15
runs-on: macos-latest
continue-on-error: true
env:
VERSION: ${{ github.event.inputs.version }}
Expand Down Expand Up @@ -45,5 +45,5 @@ jobs:
mkdir -p lib/macOS/
cp -f libuv-${{ env.VERSION }}/build/libuv.1.0.0.dylib lib/macOS/
git add lib
git commit -m "created libuv.1.0.0.dylib - for macOS 10.15"
git commit -m "created libuv.1.0.0.dylib - for macOS latest"
git push -q
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,11 @@ DartConfiguration.tcl
libuv.zip
libuv*/
.cdef/
phpunit
#uv.c
test.php
#php_uv.h
#php_uv.c
php-8.*/
php-7.*/
cmd/
86 changes: 50 additions & 36 deletions .ignore_autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

declare(strict_types=1);

\define('DS', \DIRECTORY_SEPARATOR);
if (!\defined('DS'))
\define('DS', \DIRECTORY_SEPARATOR);

if (\file_exists('..' . \DS . '.gitignore')) {
$ignore = \file_get_contents('..' . \DS . '.gitignore');
if (\strpos($ignore, '.cdef/') === false) {
$ignore .= '.cdef' . \DS . \PHP_EOL;
$ignore .= '.cdef/' . \PHP_EOL;
\file_put_contents('..' . \DS . '.gitignore', $ignore);
}
} else {
Expand All @@ -24,6 +25,7 @@
} else {
\file_put_contents('..' . \DS . '.gitattributes', '/.cdef export-ignore' . \PHP_EOL);
}

echo "- Initialized .gitattributes" . \PHP_EOL;

if (\file_exists('..' . \DS . 'composer.json'))
Expand All @@ -33,9 +35,9 @@

if (isset($composerJson['autoload'])) {
if (isset($composerJson['autoload']['files']) && !\in_array('.cdef/preload.php', $composerJson['autoload']['files']))
\array_push($composerJson['autoload']['files'], ".cdef/preload.php", ".cdef/ffi/UVConstants.php", ".cdef/ffi/UVFunctions.php");
\array_push($composerJson['autoload']['files'], ".cdef/preload.php", ".cdef/ffi/UVConstants.php", ".cdef/ffi/UVFunctions.php", ".cdef/ffi/ZEFunctions.php");
elseif (!isset($composerJson['autoload']['files']))
$composerJson = \array_merge($composerJson, ["autoload" => ["files" => [".cdef/preload.php", ".cdef/ffi/UVConstants.php", ".cdef/ffi/UVFunctions.php"]]]);
$composerJson = \array_merge($composerJson, ["autoload" => ["files" => [".cdef/preload.php", ".cdef/ffi/UVConstants.php", ".cdef/ffi/UVFunctions.php", ".cdef/ffi/ZEFunctions.php"]]]);

if (isset($composerJson['autoload']['classmap']) && !\in_array('.cdef/ffi/', $composerJson['autoload']['classmap']))
\array_push($composerJson['autoload']['classmap'], ".cdef/ffi/");
Expand All @@ -47,7 +49,8 @@
"files" => [
".cdef/preload.php",
".cdef/ffi/UVConstants.php",
".cdef/ffi/UVFunctions.php"
".cdef/ffi/UVFunctions.php",
".cdef/ffi/ZEFunctions.php"
],
"classmap" => [
".cdef/ffi/"
Expand All @@ -65,11 +68,11 @@
);
echo "- Initialized `autoload` & `require` composer.json" . \PHP_EOL;

function recursiveDelete($directory, $options = array())
function recursiveDelete($directory, $options = [])
{
if (!isset($options['traverseSymlinks']))
$options['traverseSymlinks'] = false;
$files = \array_diff(\scandir($directory), array('.', '..'));
$files = \array_diff(\scandir($directory), ['.', '..']);
foreach ($files as $file) {
$dirFile = $directory . \DS . $file;
if (\is_dir($dirFile)) {
Expand All @@ -86,11 +89,13 @@ function recursiveDelete($directory, $options = array())
return \rmdir($directory);
}


$isWindows = '\\' === \DS;
$delete = '';
if ('\\' !== \DS) {
\unlink('..' . \DS . 'cdef' . \DS . 'headers' . \DS . 'windows.h');
\unlink('..' . \DS . '.cdef' . \DS . 'Headers' . \DS . 'extra_windows.h');
if (!$isWindows) {
$files = ['zeWin8.h', 'zeWin8ts.h', 'zeWin7.h', 'zeWin7ts.h', 'windows.h', 'msvcrt.h'];
foreach ($files as $file)
\unlink('..' . \DS . 'cdef' . \DS . 'headers' . \DS . $file);

\unlink('..' . \DS . '.cdef' . \DS . 'lib' . \DS . 'Windows' . \DS . 'uv.dll');
\rmdir('..' . \DS . '.cdef' . \DS . 'lib' . \DS . 'Windows');
$delete .= 'Windows ';
Expand All @@ -110,50 +115,55 @@ function recursiveDelete($directory, $options = array())
$delete .= 'Raspberry Pi ';
}

$os = [];
$files = \glob('/etc/*-release');
foreach ($files as $file) {
$lines = \array_filter(\array_map(function ($line) {
// split value from key
$parts = \explode('=', $line);
// makes sure that "useless" lines are ignored (together with array_filter)
if (\count($parts) !== 2)
return false;

// remove quotes, if the value is quoted
$parts[1] = \str_replace(['"', "'"], '', $parts[1]);
return $parts;
}, \file($file)));

foreach ($lines as $line)
$os[$line[0]] = $line[1];
if ($isWindows)
$version = 0;
else {
$os = [];
$files = \glob('/etc/*-release');
foreach ($files as $file) {
$lines = \array_filter(\array_map(function ($line) {
// split value from key
$parts = \explode('=', $line);
// makes sure that "useless" lines are ignored (together with array_filter)
if (\count($parts) !== 2)
return false;

// remove quotes, if the value is quoted
$parts[1] = \str_replace(['"', "'"], '', $parts[1]);
return $parts;
}, \file($file)));

foreach ($lines as $line)
$os[$line[0]] = $line[1];
}

$id = \trim((string) $os['ID']);
$like = \trim((string) $os['ID_LIKE']);
$version = \trim((string) $os['VERSION_ID']);
}

$id = \trim((string) $os['ID']);
$like = \trim((string) $os['ID_LIKE']);
$version = \trim((string) $os['VERSION_ID']);
if ((float)$version !== 20.04) {
if ((float)$version !== 20.04 || $isWindows) {
\unlink('..' . \DS . 'cdef' . \DS . 'headers' . \DS . 'ubuntu20.04.h');
\unlink('..' . \DS . '.cdef' . \DS . 'lib' . \DS . 'Linux' . \DS . 'ubuntu20.04' . \DS . 'libuv.so.1.0.0');
\rmdir('..' . \DS . '.cdef' . \DS . 'lib' . \DS . 'Linux' . \DS . 'ubuntu20.04');
$delete .= 'Ubuntu 20.04 ';
}

if ((float)$version !== 18.04) {
if ((float)$version !== 18.04 || $isWindows) {
\unlink('..' . \DS . 'cdef' . \DS . 'headers' . \DS . 'ubuntu18.04.h');
\unlink('..' . \DS . '.cdef' . \DS . 'lib' . \DS . 'Linux' . \DS . 'ubuntu18.04' . \DS . 'libuv.so.1.0.0');
\rmdir('..' . \DS . '.cdef' . \DS . 'lib' . \DS . 'Linux' . \DS . 'ubuntu18.04');
$delete .= 'Ubuntu 18.04 ';
}

if (!(float)$version >= 8) {
if (!(float)$version >= 8 || $isWindows) {
\unlink('..' . \DS . 'cdef' . \DS . 'headers' . \DS . 'centos8+.h');
\unlink('..' . \DS . '.cdef' . \DS . 'lib' . \DS . 'Linux' . \DS . 'centos8+' . \DS . 'libuv.so.1.0.0');
\rmdir('..' . \DS . '.cdef' . \DS . 'lib' . \DS . 'Linux' . \DS . 'centos8+');
$delete .= 'Centos 8+ ';
}

if (!(float)$version < 8) {
if (!(float)$version < 8 || $isWindows) {
\unlink('..' . \DS . 'cdef' . \DS . 'headers' . \DS . 'centos7.h');
\unlink('..' . \DS . '.cdef' . \DS . 'lib' . \DS . 'Linux' . \DS . 'centos7' . \DS . 'libuv.so.1.0.0');
\rmdir('..' . \DS . '.cdef' . \DS . 'lib' . \DS . 'Linux' . \DS . 'centos7');
Expand All @@ -164,4 +174,8 @@ function recursiveDelete($directory, $options = array())
\recursiveDelete('..' . \DS . '.cdef' . \DS . 'headers' . \DS . 'original' . \DS . 'uv');
echo "- Removed unneeded `libuv` binary libraries and .h headers" . $delete . \PHP_EOL;

unlink(__FILE__);
\chmod('..' . \DS . 'cdef', 0644);
if (\file_exists('..' . \DS . 'vendor' . \DS . 'symplely' . \DS . 'uv-ffi' . \DS . 'composer.json'))
\recursiveDelete('..' . \DS . 'vendor' . \DS . 'symplely' . \DS . 'uv-ffi');

\unlink(__FILE__);
Loading

0 comments on commit decd82c

Please sign in to comment.