Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add multiple extensions for Windows #488

Merged
merged 5 commits into from
Jun 29, 2024
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
27 changes: 16 additions & 11 deletions config/ext.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,9 @@
"type": "builtin"
},
"bz2": {
"support": {
"Windows": "wip"
},
"type": "builtin",
"arg-type": "with-prefix",
"arg-type-unix": "with-prefix",
"arg-type-windows": "with",
"lib-depends": [
"bzip2"
]
Expand Down Expand Up @@ -473,7 +471,6 @@
},
"pdo_sqlsrv": {
"support": {
"Windows": "wip",
"BSD": "wip"
},
"type": "external",
Expand Down Expand Up @@ -519,7 +516,6 @@
},
"rar": {
"support": {
"Windows": "wip",
"BSD": "wip",
"Darwin": "partial"
},
Expand Down Expand Up @@ -636,12 +632,11 @@
},
"sqlsrv": {
"support": {
"Windows": "wip",
"BSD": "wip"
},
"type": "external",
"source": "sqlsrv",
"lib-depends": [
"lib-depends-unix": [
"unixodbc"
],
"ext-depends-linux": [
Expand Down Expand Up @@ -925,12 +920,12 @@
},
"yaml": {
"support": {
"Windows": "wip",
"BSD": "wip"
},
"type": "external",
"source": "yaml",
"arg-type": "with-prefix",
"arg-type-unix": "with-prefix",
"arg-type-windows": "with",
"lib-depends": [
"libyaml"
]
Expand All @@ -943,8 +938,18 @@
"type": "builtin",
"arg-type": "with-prefix",
"arg-type-windows": "enable",
"lib-depends": [
"lib-depends-unix": [
"libzip"
],
"ext-depends-windows": [
"zlib",
"bz2"
],
"lib-depends-windows": [
"libzip",
"zlib",
"bzip2",
"xz"
]
},
"zlib": {
Expand Down
33 changes: 18 additions & 15 deletions config/lib.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@
"libbz2.a"
],
"static-libs-windows": [
[
"libbz2.lib",
"libbz2_a.lib"
]
"libbz2.lib",
"libbz2_a.lib"
],
"headers": [
"bzlib.h"
Expand Down Expand Up @@ -448,23 +446,30 @@
"libzip.a"
],
"static-libs-windows": [
[
"zip.lib",
"libzip_a.lib"
]
"zip.lib",
"libzip_a.lib"
],
"headers": [
"zip.h",
"zipconf.h"
],
"lib-depends": [
"lib-depends-unix": [
"zlib"
],
"lib-suggests": [
"lib-suggests-unix": [
"bzip2",
"xz",
"zstd",
"openssl"
],
"lib-depends-windows": [
"zlib",
"bzip2",
"xz"
],
"lib-suggests-windows": [
"zstd",
"openssl"
]
},
"ncurses": {
Expand Down Expand Up @@ -625,10 +630,8 @@
"liblzma.a"
],
"static-libs-windows": [
[
"liblzma.lib",
"liblzma_a.lib"
]
"liblzma.lib",
"liblzma_a.lib"
],
"headers-unix": [
"lzma"
Expand All @@ -637,7 +640,7 @@
"lzma",
"lzma.h"
],
"lib-depends": [
"lib-depends-unix": [
"libiconv"
]
},
Expand Down
2 changes: 1 addition & 1 deletion src/SPC/ConsoleApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*/
final class ConsoleApplication extends Application
{
public const VERSION = '2.2.4';
public const VERSION = '2.3.0';

public function __construct()
{
Expand Down
36 changes: 36 additions & 0 deletions src/SPC/builder/extension/sqlsrv.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

namespace SPC\builder\extension;

use SPC\builder\Extension;
use SPC\store\FileSystem;
use SPC\util\CustomExt;

#[CustomExt('sqlsrv')]
class sqlsrv extends Extension
{
private bool $pdo_sqlsrv_patched = false;

public function patchBeforeBuildconf(): bool
{
if (PHP_OS_FAMILY === 'Windows' && $this->builder->getExt('pdo_sqlsrv') === null) {
// support sqlsrv without pdo_sqlsrv
FileSystem::replaceFileStr(SOURCE_PATH . '/php-src/ext/sqlsrv/config.w32', 'PHP_PDO_SQLSRV', '"no"');
$this->pdo_sqlsrv_patched = true;
return true;
}
return false;
}

public function patchBeforeConfigure(): bool
{
if ($this->pdo_sqlsrv_patched) {
// revert pdo_sqlsrv patch
FileSystem::replaceFileStr(SOURCE_PATH . '/php-src/ext/sqlsrv/config.w32', '"no" == "no"', 'PHP_PDO_SQLSRV == "no"');
return true;
}
return false;
}
}
21 changes: 21 additions & 0 deletions src/SPC/builder/windows/library/bzip2.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace SPC\builder\windows\library;

class bzip2 extends WindowsLibraryBase
{
public const NAME = 'bzip2';

protected function build(): void
{
$nmake = $this->builder->makeSimpleWrapper('nmake /nologo /f Makefile.msc CFLAGS="-DWIN32 -MT -Ox -D_FILE_OFFSET_BITS=64 -nologo"');
cmd()->cd($this->source_dir)
->execWithWrapper($nmake, 'clean')
->execWithWrapper($nmake, 'lib');
copy($this->source_dir . '\libbz2.lib', BUILD_LIB_PATH . '\libbz2.lib');
copy($this->source_dir . '\libbz2.lib', BUILD_LIB_PATH . '\libbz2_a.lib');
copy($this->source_dir . '\bzlib.h', BUILD_INCLUDE_PATH . '\bzlib.h');
}
}
44 changes: 44 additions & 0 deletions src/SPC/builder/windows/library/libyaml.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

declare(strict_types=1);

namespace SPC\builder\windows\library;

use SPC\store\FileSystem;

class libyaml extends WindowsLibraryBase
{
public const NAME = 'libyaml';

protected function build(): void
{
// reset cmake
FileSystem::resetDir($this->source_dir . '\build');

// check missing files: cmake\config.h.in and .\YamlConfig.cmake.in
if (!file_exists($this->source_dir . '\cmake\config.h.in')) {
FileSystem::createDir($this->source_dir . '\cmake');
copy(ROOT_DIR . '\src\globals\extra\libyaml_config.h.in', $this->source_dir . '\cmake\config.h.in');
}
if (!file_exists($this->source_dir . '\YamlConfig.cmake.in')) {
copy(ROOT_DIR . '\src\globals\extra\libyaml_YamlConfig.cmake.in', $this->source_dir . '\YamlConfig.cmake.in');
}

// start build
cmd()->cd($this->source_dir)
->execWithWrapper(
$this->builder->makeSimpleWrapper('cmake'),
'-B build ' .
'-A x64 ' .
"-DCMAKE_TOOLCHAIN_FILE={$this->builder->cmake_toolchain_file} " .
'-DCMAKE_BUILD_TYPE=Release ' .
'-DBUILD_SHARED_LIBS=OFF ' .
'-DBUILD_TESTING=OFF ' .
'-DCMAKE_INSTALL_PREFIX=' . BUILD_ROOT_PATH . ' '
)
->execWithWrapper(
$this->builder->makeSimpleWrapper('cmake'),
"--build build --config Release --target install -j{$this->builder->concurrency}"
);
}
}
46 changes: 46 additions & 0 deletions src/SPC/builder/windows/library/libzip.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

declare(strict_types=1);

namespace SPC\builder\windows\library;

use SPC\store\FileSystem;

class libzip extends WindowsLibraryBase
{
public const NAME = 'libzip';

protected function build(): void
{
// reset cmake
FileSystem::resetDir($this->source_dir . '\build');

$openssl = $this->builder->getLib('openssl') ? 'ON' : 'OFF';
$zstd = $this->builder->getLib('zstd') ? 'ON' : 'OFF';

// start build
cmd()->cd($this->source_dir)
->execWithWrapper(
$this->builder->makeSimpleWrapper('cmake'),
'-B build ' .
'-A x64 ' .
"-DCMAKE_TOOLCHAIN_FILE={$this->builder->cmake_toolchain_file} " .
'-DCMAKE_BUILD_TYPE=Release ' .
'-DBUILD_SHARED_LIBS=OFF ' .
'-DENABLE_BZIP2=ON ' .
'-DENABLE_LZMA=ON ' .
"-DENABLE_ZSTD={$zstd} " .
"-DENABLE_OPENSSL={$openssl} " .
'-DBUILD_TOOLS=OFF ' .
'-DBUILD_DOC=OFF ' .
'-DBUILD_EXAMPLES=OFF ' .
'-DBUILD_REGRESS=OFF ' .
'-DCMAKE_INSTALL_PREFIX=' . BUILD_ROOT_PATH . ' '
)
->execWithWrapper(
$this->builder->makeSimpleWrapper('cmake'),
"--build build --config Release --target install -j{$this->builder->concurrency}"
);
copy(BUILD_LIB_PATH . '\zip.lib', BUILD_LIB_PATH . '\libzip_a.lib');
}
}
39 changes: 39 additions & 0 deletions src/SPC/builder/windows/library/xz.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

declare(strict_types=1);

namespace SPC\builder\windows\library;

use SPC\store\FileSystem;

class xz extends WindowsLibraryBase
{
public const NAME = 'xz';

protected function build(): void
{
// reset cmake
FileSystem::resetDir($this->source_dir . '\build');

// start build
cmd()->cd($this->source_dir)
->execWithWrapper(
$this->builder->makeSimpleWrapper('cmake'),
'-B build ' .
'-A x64 ' .
"-DCMAKE_TOOLCHAIN_FILE={$this->builder->cmake_toolchain_file} " .
'-DCMAKE_BUILD_TYPE=Release ' .
'-DBUILD_SHARED_LIBS=OFF ' .
'-DCMAKE_INSTALL_PREFIX=' . BUILD_ROOT_PATH . ' '
)
->execWithWrapper(
$this->builder->makeSimpleWrapper('cmake'),
"--build build --config Release --target install -j{$this->builder->concurrency}"
);

// copy liblzma.lib to liblzma_a.lib
copy(BUILD_LIB_PATH . '/liblzma.lib', BUILD_LIB_PATH . '/liblzma_a.lib');
// patch lzma.h
FileSystem::replaceFileStr(BUILD_INCLUDE_PATH . '/lzma.h', 'defined(LZMA_API_STATIC)', 'defined(_WIN32)');
}
}
2 changes: 1 addition & 1 deletion src/SPC/store/FileSystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ private static function replaceFile(string $filename, int $replace_type = REPLAC
private static function emitSourceExtractHook(string $name): void
{
foreach ((self::$_extract_hook[$name] ?? []) as $hook) {
if ($hook() === true) {
if ($hook($name) === true) {
logger()->info('Patched source [' . $name . '] after extracted');
}
}
Expand Down
Loading