Skip to content

Commit

Permalink
Fix libuuid build source (#411)
Browse files Browse the repository at this point in the history
* fix libuuid build source

* fix libuuid build source tests
  • Loading branch information
crazywhalecc authored Apr 12, 2024
1 parent 8475357 commit 4cb1764
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 21 deletions.
3 changes: 3 additions & 0 deletions config/lib.json
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,9 @@
"source": "libuuid",
"static-libs-unix": [
"libuuid.a"
],
"headers": [
"uuid/uuid.h"
]
},
"libuv": {
Expand Down
2 changes: 1 addition & 1 deletion config/source.json
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@
},
"libuuid": {
"type": "git",
"url": "https://github.com/cloudbase/libuuid.git",
"url": "https://github.com/static-php/libuuid.git",
"rev": "master",
"license": {
"type": "file",
Expand Down
40 changes: 24 additions & 16 deletions src/SPC/builder/unix/library/libuuid.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,37 @@

trait libuuid
{
public function patchBeforeBuild(): bool
{
FileSystem::replaceFileStr($this->source_dir . '/configure', '-${am__api_version}', '');
return true;
}

/**
* @throws FileSystemException
* @throws RuntimeException
*/
protected function build(): void
{
shell()->cd($this->source_dir)
->exec('chmod +x configure')
->exec('chmod +x install-sh')
FileSystem::resetDir($this->source_dir . '/build');
shell()->cd($this->source_dir . '/build')
->exec(
'./configure ' .
'--enable-static --disable-shared ' .
'--prefix='
'cmake ' .
"{$this->builder->makeCmakeArgs()} " .
'..'
)
->exec('make clean')
->exec("make -j{$this->builder->concurrency}")
->exec('make install DESTDIR=' . BUILD_ROOT_PATH);
$this->patchPkgconfPrefix(['uuid.pc']);
->exec("cmake --build . -j {$this->builder->concurrency}");
copy($this->source_dir . '/build/libuuid.a', BUILD_LIB_PATH . '/libuuid.a');
FileSystem::createDir(BUILD_INCLUDE_PATH . '/uuid');
copy($this->source_dir . '/uuid.h', BUILD_INCLUDE_PATH . '/uuid/uuid.h');
$pc = FileSystem::readFile($this->source_dir . '/uuid.pc.in');
$pc = str_replace([
'@prefix@',
'@exec_prefix@',
'@libdir@',
'@includedir@',
'@LIBUUID_VERSION@',
], [
BUILD_ROOT_PATH,
'${prefix}',
'${prefix}/lib',
'${prefix}/include',
'1.0.3',
], $pc);
FileSystem::writeFile(BUILD_LIB_PATH . '/pkgconfig/uuid.pc', $pc);
}
}
8 changes: 4 additions & 4 deletions src/globals/test-extensions.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@

// If you want to test your added extensions and libs, add below (comma separated, example `bcmath,openssl`).
$extensions = match (PHP_OS_FAMILY) {
'Linux', 'Darwin' => 'dba',
'Windows' => 'mbstring,pdo_sqlite,mbregex,dba',
'Linux', 'Darwin' => 'uuid',
'Windows' => 'mbstring,pdo_sqlite,mbregex',
};

// If you want to test lib-suggests feature with extension, add them below (comma separated, example `libwebp,libavif`).
$with_libs = match (PHP_OS_FAMILY) {
'Linux', 'Darwin' => 'qdbm',
'Windows' => 'qdbm',
'Linux', 'Darwin' => '',
'Windows' => '',
};

// Please change your test base combination. We recommend testing with `common`.
Expand Down
6 changes: 6 additions & 0 deletions src/globals/tests/uuid.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php

declare(strict_types=1);

assert(function_exists('uuid_create'));
assert(strlen(uuid_create(0)) === 36);

0 comments on commit 4cb1764

Please sign in to comment.